mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-12-01 23:57:21 +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>
298 lines
11 KiB
TypeScript
298 lines
11 KiB
TypeScript
/**
|
|
* Locks the sequential and parallel partitions of scenario-map Vitest runs
|
|
* (tools/scenario-map/path-coverage/partitions.ts): the include patterns of the base config's
|
|
* `fileParallelism: false` projects,
|
|
* glob matching, the split, the merge of partial runs, the partitioned runner and the build output
|
|
* copied into a prepared package.
|
|
*/
|
|
import { execFileSync } from 'node:child_process';
|
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
import type {
|
|
VitestRunOptions,
|
|
VitestRunResult,
|
|
} from '../../../tools/scenario-map/mutation/vitest-run.js';
|
|
import {
|
|
copyBuildOutput,
|
|
mergeVitestRuns,
|
|
partitionFiles,
|
|
runVitestPartitioned,
|
|
sequentialMatcher,
|
|
sequentialMatcherFor,
|
|
sequentialPatterns,
|
|
} from '../../../tools/scenario-map/path-coverage/partitions.js';
|
|
|
|
const SEQ = 'test/integration/lbug-pool.test.ts#pool > opens';
|
|
const PAR = 'test/unit/a.test.ts#a > adds';
|
|
|
|
const run = (overrides: Partial<VitestRunResult>): VitestRunResult => ({
|
|
tests: [],
|
|
status: 'survived',
|
|
outcome: 'survived',
|
|
reason: null,
|
|
outsideTest: [],
|
|
problems: [],
|
|
unhandledErrors: [],
|
|
wallClockMs: 10,
|
|
...overrides,
|
|
});
|
|
|
|
const test = (id: string): VitestRunResult['tests'][number] => ({
|
|
id,
|
|
taskId: null,
|
|
fullName: null,
|
|
location: null,
|
|
state: 'passed',
|
|
outcome: 'survived',
|
|
message: null,
|
|
});
|
|
|
|
describe('sequential patterns', () => {
|
|
it('reads the includes of every fileParallelism: false project and nothing else', () => {
|
|
const config = {
|
|
test: {
|
|
projects: [
|
|
{
|
|
test: {
|
|
name: 'lbug-db',
|
|
include: ['test/integration/lbug-*.test.ts', 7],
|
|
fileParallelism: false,
|
|
},
|
|
},
|
|
{ test: { name: 'default', include: ['test/**/*.test.ts'] } },
|
|
{
|
|
test: {
|
|
name: 'cli-e2e',
|
|
include: ['test/integration/e2e.test.ts'],
|
|
fileParallelism: false,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
};
|
|
expect(sequentialPatterns(config)).toEqual([
|
|
'test/integration/lbug-*.test.ts',
|
|
'test/integration/e2e.test.ts',
|
|
]);
|
|
});
|
|
|
|
it.each([
|
|
{ file: 'test/integration/lbug-pool.test.ts', match: true },
|
|
{ file: 'test/integration/nested/lbug-pool.test.ts', match: false },
|
|
{ file: 'test/integration/xlbug-pool.test.ts', match: false },
|
|
])('matches a single-segment glob: $file is $match', ({ file, match }) => {
|
|
expect(sequentialMatcher(['test/integration/lbug-*.test.ts'])(file)).toBe(match);
|
|
});
|
|
|
|
it('matches like Vitest: a ** segment may be empty', () => {
|
|
expect(sequentialMatcher(['test/**/*.test.ts'])('test/a.test.ts')).toBe(true);
|
|
});
|
|
|
|
it('puts the base config sequential files apart, keeping their order', () => {
|
|
const files = [
|
|
'test/unit/a.test.ts',
|
|
'test/integration/lbug-pool.test.ts',
|
|
'test/integration/rename-provider-ts.test.ts',
|
|
'test/integration/skills-e2e.test.ts',
|
|
];
|
|
expect(partitionFiles(files, sequentialMatcherFor('normal'))).toEqual({
|
|
sequential: [
|
|
'test/integration/lbug-pool.test.ts',
|
|
'test/integration/rename-provider-ts.test.ts',
|
|
'test/integration/skills-e2e.test.ts',
|
|
],
|
|
parallel: ['test/unit/a.test.ts'],
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('mergeVitestRuns', () => {
|
|
it('keeps request order and lets the first run that did not survive decide', () => {
|
|
const merged = mergeVitestRuns(
|
|
[SEQ, PAR],
|
|
[
|
|
run({ tests: [test(PAR)], problems: ['p1'] }),
|
|
run({
|
|
tests: [test(SEQ)],
|
|
status: 'killed',
|
|
outcome: 'killed-by-test:assertion',
|
|
reason: 'failed',
|
|
unhandledErrors: ['e'],
|
|
}),
|
|
],
|
|
);
|
|
expect([
|
|
merged.tests.map((entry) => entry.id),
|
|
merged.outcome,
|
|
merged.reason,
|
|
merged.problems,
|
|
merged.unhandledErrors,
|
|
merged.wallClockMs,
|
|
]).toEqual([[SEQ, PAR], 'killed-by-test:assertion', 'failed', ['p1'], ['e'], 20]);
|
|
});
|
|
});
|
|
|
|
describe('runVitestPartitioned', () => {
|
|
const options: VitestRunOptions = {
|
|
packageDir: '/p',
|
|
testIds: [PAR, SEQ],
|
|
vitest: { configFile: 'c.ts', project: 'mutation' },
|
|
workDir: '/w',
|
|
maxWorkers: 4,
|
|
};
|
|
const isSequential = (file: string): boolean => file.startsWith('test/integration/');
|
|
|
|
it('runs the sequential tests with one worker first, then the rest, and merges them', async () => {
|
|
const calls: [readonly string[], number | undefined, string][] = [];
|
|
const result = await runVitestPartitioned(
|
|
async (call) => {
|
|
calls.push([call.testIds, call.maxWorkers, call.workDir]);
|
|
return run({ tests: call.testIds.map(test) });
|
|
},
|
|
options,
|
|
isSequential,
|
|
);
|
|
expect([calls, result.tests.map((entry) => entry.id)]).toEqual([
|
|
[
|
|
[[SEQ], 1, '/w/sequential'],
|
|
[[PAR], 4, '/w/parallel'],
|
|
],
|
|
[PAR, SEQ],
|
|
]);
|
|
});
|
|
|
|
it('runs a request without sequential tests as it is', async () => {
|
|
const calls: VitestRunOptions[] = [];
|
|
await runVitestPartitioned(
|
|
async (call) => {
|
|
calls.push(call);
|
|
return run({});
|
|
},
|
|
{ ...options, testIds: [PAR] },
|
|
isSequential,
|
|
);
|
|
expect(calls).toEqual([{ ...options, testIds: [PAR] }]);
|
|
});
|
|
});
|
|
|
|
describe('copyBuildOutput', () => {
|
|
const temps: string[] = [];
|
|
afterEach(() => {
|
|
for (const dir of temps.splice(0)) rmSync(dir, { recursive: true, force: true });
|
|
});
|
|
|
|
it('gives inventory guards a private index without sharing Git configuration or writes', () => {
|
|
const base = mkdtempSync(path.join(os.tmpdir(), 'scenario-map-git-inventory-'));
|
|
temps.push(base);
|
|
const checkout = path.join(base, 'checkout');
|
|
const prepared = path.join(base, 'prepared');
|
|
for (const root of [checkout, prepared]) {
|
|
mkdirSync(path.join(root, 'gitnexus'), { recursive: true });
|
|
writeFileSync(path.join(root, 'gitnexus', 'case.ts'), 'export const value = 1;');
|
|
}
|
|
writeFileSync(path.join(checkout, 'public-manifest.json'), '{}');
|
|
writeFileSync(path.join(checkout, '.env'), 'fixture-only-private-value');
|
|
writeFileSync(path.join(prepared, 'gitnexus', 'case.ts'), 'export const value = 2;');
|
|
execFileSync('git', ['init', '--quiet', checkout]);
|
|
const git = (root: string, ...args: string[]) =>
|
|
execFileSync('git', args, { cwd: root, encoding: 'utf8' }).trim();
|
|
git(checkout, 'add', '--force', '--', 'gitnexus/case.ts', 'public-manifest.json', '.env');
|
|
git(checkout, 'remote', 'add', 'origin', 'https://example.com/source.git');
|
|
copyBuildOutput('normal', path.join(checkout, 'gitnexus'), path.join(prepared, 'gitnexus'));
|
|
expect(git(prepared, 'rev-parse', '--show-toplevel')).toBe(prepared.split(path.sep).join('/'));
|
|
expect(git(prepared, 'ls-files', '--stage')).toBe(
|
|
git(checkout, 'ls-files', '--stage', '--', 'gitnexus/case.ts', 'public-manifest.json'),
|
|
);
|
|
expect(git(prepared, 'remote')).toBe('');
|
|
expect(existsSync(path.join(prepared, '.env'))).toBe(false);
|
|
expect(readFileSync(path.join(prepared, 'public-manifest.json'), 'utf8')).toBe('{}');
|
|
expect(readFileSync(path.join(prepared, 'gitnexus', 'case.ts'), 'utf8')).toContain('value = 2');
|
|
git(prepared, 'update-index', '--force-remove', 'gitnexus/case.ts');
|
|
expect(git(checkout, 'ls-files').split('\n')).toEqual([
|
|
'.env',
|
|
'gitnexus/case.ts',
|
|
'public-manifest.json',
|
|
]);
|
|
});
|
|
|
|
it('preserves repository contract fixtures needed during test collection', () => {
|
|
const base = mkdtempSync(path.join(os.tmpdir(), 'scenario-map-contract-fixtures-'));
|
|
temps.push(base);
|
|
const checkout = path.join(base, 'checkout', 'gitnexus');
|
|
const prepared = path.join(base, 'prepared', 'gitnexus');
|
|
mkdirSync(checkout, { recursive: true });
|
|
mkdirSync(prepared, { recursive: true });
|
|
const fixtures = [
|
|
'.github/workflows/ci-tests.yml',
|
|
'.claude/skills/gitnexus-plan/SKILL.md',
|
|
'gitnexus-factory-plugin/.factory-plugin/plugin.json',
|
|
'Dockerfile.cli',
|
|
'render.yaml',
|
|
'AGENTS.md',
|
|
'CLAUDE.md',
|
|
'eval/workflow_bench/run-evolution.sh',
|
|
'gitnexus/prebuilds/bundled/manifest.json',
|
|
];
|
|
for (const file of fixtures) {
|
|
const target = path.join(checkout, '..', file);
|
|
mkdirSync(path.dirname(target), { recursive: true });
|
|
writeFileSync(target, file);
|
|
}
|
|
writeFileSync(path.join(checkout, '..', '.env'), 'private');
|
|
execFileSync('git', ['init', '--quiet', path.dirname(checkout)]);
|
|
execFileSync('git', ['add', '--force', '--', ...fixtures], { cwd: path.dirname(checkout) });
|
|
copyBuildOutput('normal', checkout, prepared);
|
|
expect(fixtures.map((file) => readFileSync(path.join(prepared, '..', file), 'utf8'))).toEqual(
|
|
fixtures,
|
|
);
|
|
expect(existsSync(path.join(prepared, '..', '.env'))).toBe(false);
|
|
});
|
|
|
|
it('copies vendor/ and dist/ that the checkout has into a normal-mode copy only', () => {
|
|
const base = mkdtempSync(path.join(os.tmpdir(), 'scenario-map-build-output-'));
|
|
temps.push(base);
|
|
const checkout = path.join(base, 'checkout');
|
|
const prepared = path.join(base, 'prepared');
|
|
mkdirSync(path.join(checkout, 'vendor', 'leiden'), { recursive: true });
|
|
mkdirSync(prepared);
|
|
writeFileSync(path.join(checkout, 'vendor', 'leiden', 'index.cjs'), 'leiden');
|
|
const controls = path.join(base, 'controls');
|
|
mkdirSync(controls);
|
|
copyBuildOutput('normal', checkout, prepared);
|
|
copyBuildOutput('controls', checkout, controls);
|
|
expect([
|
|
readFileSync(path.join(prepared, 'vendor', 'leiden', 'index.cjs'), 'utf8'),
|
|
existsSync(path.join(prepared, 'dist')),
|
|
existsSync(path.join(controls, 'vendor')),
|
|
]).toEqual(['leiden', false, false]);
|
|
});
|
|
|
|
it('includes the sibling hook fixtures read by package tests', () => {
|
|
const base = mkdtempSync(path.join(os.tmpdir(), 'scenario-map-hook-fixtures-'));
|
|
temps.push(base);
|
|
const checkout = path.join(base, 'checkout', 'gitnexus');
|
|
const prepared = path.join(base, 'prepared', 'gitnexus');
|
|
mkdirSync(checkout, { recursive: true });
|
|
mkdirSync(prepared, { recursive: true });
|
|
const hooks = [
|
|
'gitnexus-claude-plugin',
|
|
'gitnexus-cursor-integration',
|
|
'gitnexus-factory-plugin',
|
|
];
|
|
for (const plugin of hooks) {
|
|
const dir = path.join(checkout, '..', plugin, 'hooks');
|
|
mkdirSync(dir, { recursive: true });
|
|
writeFileSync(path.join(dir, 'registry-query.cjs'), plugin);
|
|
}
|
|
execFileSync('git', ['init', '--quiet', path.dirname(checkout)]);
|
|
execFileSync('git', ['add', '--', ...hooks], { cwd: path.dirname(checkout) });
|
|
copyBuildOutput('normal', checkout, prepared);
|
|
expect(
|
|
hooks.map((plugin) =>
|
|
readFileSync(path.join(prepared, '..', plugin, 'hooks', 'registry-query.cjs'), 'utf8'),
|
|
),
|
|
).toEqual(hooks);
|
|
});
|
|
});
|