mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-29 23:37:41 +00:00
* fix: recover missed test scenarios Run the full core test inventory and retrieve identical callback bodies across setup contexts. Separate assertion evidence from context and retain conservative input, path and runtime provenance checks. Restore prepared test inputs and report missing runtime collection. Add the audited recall corpus and inventory regressions. * Address PR review feedback (#3743) Correct counted nouns in the inventory report, document fully skipped modules, and include unhandled runner errors in the incomplete-collection warning. * Address PR review feedback (#3743) Force-stage explicit temporary fixtures despite inherited Git ignores, and isolate recorded-file collection-error accounting in the inventory tests. * fix(review): simplify selection and guard mixed artifacts * feat(test): detect fixture consolidation opportunities Capture source inputs used by integration tests and compare fixture clones, executed blocks, and assertion subjects and values. Report partial overlaps with the unique checks and fixture spans that consolidation must preserve. Keep cross-language structural suggestions separate from observed equality. Use pinned jscpd with direct pair verification when longer representatives hide partial clones. Retain capture gaps and native/worker limitations. Validate with 1,245 detector regressions, 28 pipeline pair controls, and 12 manually labeled comparisons. Scan 30,698 core cases and find 3,111 opportunity groups; exclude the capture's 103 failed and 89 skipped cases. * Fix scenario-map review findings (#3743) Resolve assertion aliases by lexical binding and normalize duplicate static object keys. Capture fixture files through checked descriptors with bounded reads and guaranteed cleanup. * fix: address test duplicate audit false signals * refactor(test): reuse assertion binding analysis Reuse lexical bindings within each evidence extraction while retaining assertion-specific offsets and expansion limits. Deduplicate fixture coverage endpoints numerically without string conversion. Preserve complete assertion evidence across 29,286 static instances and weighted coverage across 10,000 generated interval cases. * Fix scenario-map review findings (#3743) Bind consolidation evidence to the assertion call accepted by the check extractor, so unsupported same-line calls cannot supply incorrect subjects or expectations. Keep source provenance private and serialized checks intact. Exercise omitted plugins alongside instrumented Vitest runs. * fix: retain input-shaped scenario controls (#3743) Compare assertion subject structure separately from exact input-bearing assertion keys, so changing literal inputs retains table-row and boundary classification. Preserve selectors, callee identity and regex values. Keep the control expectations unchanged. Add regressions for literal inputs, queried subjects and nested regex arguments; bump the fingerprint engine version so reclassified findings resurface. * test: give scenario cases unique titles Include the parameterized case index so repeated input expressions and truncated audit paths cannot collide in the CI execution inventory. * fix: scope assertion subjects to their bindings Prevent same-named declarations in different files or scopes from becoming exact assertion matches. Preserve same-binding consolidation and advance the fingerprint engine to version 5. * fix: raise full-suite planning heap budget The 30,953-case replay aborts at the default 4 GiB heap. Give only the Plan step 8 GiB and document the same local invocation. The identical four coverage slices complete in 4m34s at 8.2 GiB peak RSS, retaining all 116,409 candidate pairs. * fix: stream full-suite scenario reports The full inventory produces a 663 MiB report, exceeding V8's single-string limit. Write records incrementally and stream only required fields when reading baselines and publishing issue updates. Replay preserves all 116,398 pairs from 30,953 collected cases. The report remains partial when the trace run fails. * fix: preserve test lifecycles during capture Forced test repeats changed cache and file state. Capture ordinary runs, retain runnable siblings during tracing, and keep retry-bearing files inconclusive. Preserve failure details and mark failed captures partial. Use the original JSON serializer so test mocks cannot break fixture reads. * fix: limit trace capture to candidates Keep sibling tests in both passes for suite state, while recording only candidate task IDs. This prevents unrelated timing checks and large corpus tests from failing under tracing. * ci: budget full-suite trace collection * fix: address scenario-map feedback (#3743) --------- Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
253 lines
9 KiB
TypeScript
253 lines
9 KiB
TypeScript
/**
|
|
* Locks Layer 1 candidate retrieval (U4, R3, KTD5, KTD17): exact Jaccard >= 0.99 over block sets
|
|
* (the size-ratio and rare-block prefix filters never drop a qualifying pair), pairs sharing a
|
|
* checks-and-context key whatever their blocks, connected components with deterministic ids, the
|
|
* identical-blocks flag (KTD5 caps a non-identical pair at weak), the path-unattributable flag of
|
|
* concurrent tests (design §5.2), the largest group's size for shard planning, and the focus of a
|
|
* diff-scoped run (pairs without a focused test dropped before the groups form).
|
|
*/
|
|
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
findCandidates,
|
|
jaccard,
|
|
type CandidateTest,
|
|
} from '../../../tools/scenario-map/path-coverage/candidates.js';
|
|
|
|
const range = (from: number, to: number): number[] =>
|
|
Array.from({ length: to - from }, (_, i) => from + i);
|
|
|
|
const test = (
|
|
id: string,
|
|
blocks: readonly number[],
|
|
extra: Partial<Omit<CandidateTest, 'id' | 'blocks'>> = {},
|
|
): CandidateTest => ({
|
|
id,
|
|
blocks: [...blocks].sort((a, b) => a - b),
|
|
concurrent: false,
|
|
checksContext: null,
|
|
...extra,
|
|
});
|
|
|
|
const pairsOf = (tests: readonly CandidateTest[]): [string, string][] =>
|
|
findCandidates(tests).pairs.map((pair) => [pair.a, pair.b]);
|
|
|
|
/** mulberry32: a fixed-seed PRNG, so the corpus is the same on every run. */
|
|
function prng(seed: number): () => number {
|
|
let state = seed >>> 0;
|
|
return () => {
|
|
state = (state + 0x6d2b79f5) >>> 0;
|
|
let t = state;
|
|
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
};
|
|
}
|
|
|
|
/** 12 families of 6 near-copies: each copy drops ~0.3% of its family's blocks and adds 0-3 (about 60 pairs qualify, about 120 miss narrowly). */
|
|
function nearDuplicateCorpus(seed: number): CandidateTest[] {
|
|
const random = prng(seed);
|
|
return range(0, 12).flatMap((base) => {
|
|
const core = range(base * 1000, base * 1000 + 150 + base * 10);
|
|
return range(0, 6).map((copy) => {
|
|
const kept = core.filter(() => random() > 0.003);
|
|
const extra = range(0, 3)
|
|
.filter(() => random() > 0.8)
|
|
.map((i) => 900_000 + base * 100 + copy * 10 + i);
|
|
return test(`t${base}-${copy}`, [...kept, ...extra]);
|
|
});
|
|
});
|
|
}
|
|
|
|
/** Every pair at Jaccard >= 0.99 by exhaustive comparison, ids ordered, sorted. */
|
|
function bruteForcePairs(tests: readonly CandidateTest[]): [string, string][] {
|
|
const ids = (x: CandidateTest, y: CandidateTest): [string, string] =>
|
|
x.id < y.id ? [x.id, y.id] : [y.id, x.id];
|
|
return tests
|
|
.flatMap((x, i) => tests.slice(i + 1).map((y) => ({ x, y })))
|
|
.filter(({ x, y }) => jaccard(x.blocks, y.blocks) >= 0.99)
|
|
.map(({ x, y }) => ids(x, y))
|
|
.sort((p, q) => (p.join('\0') < q.join('\0') ? -1 : 1));
|
|
}
|
|
|
|
describe('jaccard', () => {
|
|
it.each([
|
|
{ name: 'identical', a: [1, 2, 3], b: [1, 2, 3], expected: 1 },
|
|
{ name: 'half overlap', a: [1, 2, 3], b: [2, 3, 4], expected: 0.5 },
|
|
{ name: 'disjoint', a: [1], b: [2], expected: 0 },
|
|
])('computes $name sets', ({ a, b, expected }) => {
|
|
expect(jaccard(a, b)).toBe(expected);
|
|
});
|
|
});
|
|
|
|
describe('findCandidates: Jaccard source', () => {
|
|
it('retrieves the same body across cleanup/import contexts and dissimilar setup coverage', () => {
|
|
const result = findCandidates([
|
|
test('direct', [1, 2], { checksContext: 'direct-context', bodyKey: 'same-body' }),
|
|
test('reexport', [1, 2, 3, 4], { checksContext: 'reexport-context', bodyKey: 'same-body' }),
|
|
test('other', [5], { checksContext: 'other-context', bodyKey: 'different-body' }),
|
|
]);
|
|
expect(result.pairs).toEqual([
|
|
expect.objectContaining({
|
|
a: 'direct',
|
|
b: 'reexport',
|
|
sources: ['body'],
|
|
identicalBlocks: false,
|
|
}),
|
|
]);
|
|
});
|
|
|
|
it.each([
|
|
{ name: 'one block removed (199/200)', b: range(0, 199) },
|
|
{ name: 'one block replaced (199/201)', b: [...range(0, 199), 500] },
|
|
])('makes a pair that differs by 1 in 200 a candidate: $name', ({ b }) => {
|
|
const result = findCandidates([test('a', range(0, 200)), test('b', b)]);
|
|
expect(result.pairs).toEqual([
|
|
expect.objectContaining({
|
|
a: 'a',
|
|
b: 'b',
|
|
sources: ['jaccard'],
|
|
identicalBlocks: false,
|
|
pathUnattributable: false,
|
|
}),
|
|
]);
|
|
expect(result.pairs[0].jaccard).toBeGreaterThanOrEqual(0.99);
|
|
});
|
|
|
|
it.each([
|
|
{ name: 'three blocks removed (197/200)', b: range(0, 197) },
|
|
{ name: 'three blocks replaced (197/203)', b: [...range(0, 197), 500, 501, 502] },
|
|
])('does not pair sets that differ by 3 in 200: $name', ({ b }) => {
|
|
expect(pairsOf([test('a', range(0, 200)), test('b', b)])).toEqual([]);
|
|
});
|
|
|
|
it('accepts a pair exactly at the threshold (99/100)', () => {
|
|
expect(pairsOf([test('a', range(0, 100)), test('b', range(0, 99))])).toEqual([['a', 'b']]);
|
|
});
|
|
|
|
it('marks identical block sets and never pairs empty ones through Jaccard', () => {
|
|
const result = findCandidates([
|
|
test('a', [3, 4, 5]),
|
|
test('b', [3, 4, 5]),
|
|
test('c', []),
|
|
test('d', []),
|
|
]);
|
|
expect(result.pairs).toEqual([
|
|
expect.objectContaining({ a: 'a', b: 'b', jaccard: 1, identicalBlocks: true }),
|
|
]);
|
|
});
|
|
|
|
it('finds exactly the brute-force pairs on a seeded near-duplicate corpus', () => {
|
|
const corpus = nearDuplicateCorpus(20261024);
|
|
const brute = bruteForcePairs(corpus);
|
|
expect(brute.length).toBeGreaterThan(40);
|
|
expect(pairsOf(corpus)).toEqual(brute);
|
|
});
|
|
});
|
|
|
|
describe('findCandidates: checks-and-context source', () => {
|
|
it('pairs tests with Jaccard 0.5 that share a checks-and-context key', () => {
|
|
const result = findCandidates([
|
|
test('a', [1, 2, 3], { checksContext: 'k1' }),
|
|
test('b', [2, 3, 4], { checksContext: 'k1' }),
|
|
test('c', [2, 3, 4], { checksContext: 'k2' }),
|
|
]);
|
|
expect(result.pairs).toEqual([
|
|
expect.objectContaining({ a: 'a', b: 'b', sources: ['checks-context'], jaccard: 0.5 }),
|
|
expect.objectContaining({ a: 'b', b: 'c', sources: ['jaccard'], jaccard: 1 }),
|
|
]);
|
|
});
|
|
|
|
it('records both sources on a pair found twice', () => {
|
|
const result = findCandidates([
|
|
test('a', [1, 2], { checksContext: 'k' }),
|
|
test('b', [1, 2], { checksContext: 'k' }),
|
|
]);
|
|
expect(result.pairs.map((pair) => pair.sources)).toEqual([['jaccard', 'checks-context']]);
|
|
expect(result.stats.bySource).toEqual({ jaccard: 0, checksContext: 0, both: 1, body: 0 });
|
|
});
|
|
});
|
|
|
|
describe('findCandidates: groups', () => {
|
|
const chain = [
|
|
test('a', range(0, 200)),
|
|
test('b', range(1, 201)),
|
|
test('c', range(2, 202)),
|
|
test('lone', range(5000, 5010)),
|
|
];
|
|
|
|
it('makes A-B and B-C one group of three with exactly two pairs when A-C misses', () => {
|
|
const result = findCandidates(chain);
|
|
expect(jaccard(chain[0].blocks, chain[2].blocks)).toBeLessThan(0.99);
|
|
expect(pairsOf(chain)).toEqual([
|
|
['a', 'b'],
|
|
['b', 'c'],
|
|
]);
|
|
expect(result.groups).toEqual([
|
|
{ id: result.pairs[0].group, tests: ['a', 'b', 'c'], pairs: 2 },
|
|
]);
|
|
expect(result.pairs.map((pair) => pair.group)).toEqual([
|
|
result.groups[0].id,
|
|
result.groups[0].id,
|
|
]);
|
|
expect(result.stats).toMatchObject({
|
|
tests: 4,
|
|
pairs: 2,
|
|
groups: 1,
|
|
largestGroup: { id: result.groups[0].id, tests: 3, pairs: 2 },
|
|
});
|
|
});
|
|
|
|
it('gives the same pairs and group ids whatever the input order', () => {
|
|
expect(findCandidates([...chain].reverse())).toEqual(findCandidates(chain));
|
|
});
|
|
|
|
it('picks the largest group by test count, then pair count', () => {
|
|
const result = findCandidates([
|
|
...chain,
|
|
test('x', [1], { checksContext: 'k' }),
|
|
test('y', [2], { checksContext: 'k' }),
|
|
]);
|
|
expect(result.groups.map((group) => group.tests.length).sort()).toEqual([2, 3]);
|
|
expect(result.stats.largestGroup).toMatchObject({ tests: 3, pairs: 2 });
|
|
});
|
|
});
|
|
|
|
describe('findCandidates: concurrent tests', () => {
|
|
it('flags every pair of a concurrent test as path-unattributable', () => {
|
|
const result = findCandidates([
|
|
test('a', [1, 2], { checksContext: 'k' }),
|
|
test('b', [1, 2], { checksContext: 'k', concurrent: true }),
|
|
test('c', [7, 8], { checksContext: 'k' }),
|
|
]);
|
|
expect(result.pairs.map((pair) => [pair.a, pair.b, pair.pathUnattributable])).toEqual([
|
|
['a', 'b', true],
|
|
['a', 'c', false],
|
|
['b', 'c', true],
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe('findCandidates: focus', () => {
|
|
it('keeps only pairs with a focused test, and groups only those', () => {
|
|
const result = findCandidates(
|
|
[
|
|
test('a', [1, 2], { checksContext: 'k' }),
|
|
test('b', [1, 2], { checksContext: 'k' }),
|
|
test('c', [1, 2], { checksContext: 'k' }),
|
|
test('d', [7, 8], { checksContext: 'j' }),
|
|
test('e', [7, 8], { checksContext: 'j' }),
|
|
],
|
|
(id) => id === 'a',
|
|
);
|
|
expect([
|
|
result.pairs.map((pair) => [pair.a, pair.b]),
|
|
result.groups.map((group) => group.tests),
|
|
]).toEqual([
|
|
[
|
|
['a', 'b'],
|
|
['a', 'c'],
|
|
],
|
|
[['a', 'b', 'c']],
|
|
]);
|
|
});
|
|
});
|