fix: address scenario-map feedback (#3743)

This commit is contained in:
Gergo Magyar 2026-10-30 19:38:42 +00:00
parent 5abfc188dd
commit 96beddfbe5
5 changed files with 49 additions and 7 deletions

View file

@ -34,12 +34,14 @@ describe('report JSON', () => {
...entry,
keep: [{ test: entry.a, reason: 'intentional control' }],
}));
report.fingerprint.pairs[0].details = Array(1_000).fill('nested record detail');
const file = output();
const stringify = JSON.stringify;
// Model the V8 cap at a small scale: rows fit, the complete report and collections do not.
// Model the V8 cap at a small scale, including a collection nested inside one record.
const limit = 16_384;
expect(stringify(report.fingerprint.pairs).length).toBeGreaterThan(limit);
expect(stringify(report.fingerprint.kept).length).toBeGreaterThan(limit);
expect(stringify(report.fingerprint.pairs[0]).length).toBeGreaterThan(limit);
const capped = vi.spyOn(JSON, 'stringify').mockImplementation((value, replacer, space) => {
const text = stringify(value, replacer, space);
if (text !== undefined && text.length > limit) throw new RangeError('Invalid string length');

View file

@ -0,0 +1,41 @@
import { afterEach, expect, it, vi } from 'vitest';
import { FIXTURE_CAPTURE_KEY } from '../../../tools/scenario-map/path-coverage/fixture-capture.js';
const previousCapture = Reflect.get(globalThis, FIXTURE_CAPTURE_KEY);
afterEach(() => {
vi.doUnmock('vitest');
vi.resetModules();
vi.restoreAllMocks();
if (previousCapture === undefined) Reflect.deleteProperty(globalThis, FIXTURE_CAPTURE_KEY);
else Reflect.set(globalThis, FIXTURE_CAPTURE_KEY, previousCapture);
});
it('captures pipeline fixtures only while a candidate test is active', async () => {
let current: { id: string } | undefined;
// Reload the setup module even when the detector already installed it for this worker.
vi.resetModules();
const { TraceFixtureRoots } =
await import('../../../tools/scenario-map/value-flow/trace-fixtures.js');
const capture = vi.spyOn(TraceFixtureRoots.prototype, 'capture').mockImplementation(() => {});
vi.doMock('vitest', () => ({
TestRunner: { getCurrentTest: () => current },
inject: () => ({ taskIds: ['candidate'], preparedRoot: '/prepared', extraRoots: [], wrap: [] }),
aroundAll: vi.fn(),
aroundEach: vi.fn(),
}));
await import('../../../tools/scenario-map/value-flow/trace.setup.js');
const hook = Reflect.get(globalThis, FIXTURE_CAPTURE_KEY) as (root: string) => void;
hook('/suite-setup');
expect(capture).not.toHaveBeenCalled();
current = { id: 'sibling' };
hook('/sibling');
expect(capture).not.toHaveBeenCalled();
current = { id: 'candidate' };
hook('/candidate');
expect(capture).toHaveBeenCalledExactlyOnceWith('/candidate');
current = undefined;
hook('/suite-teardown');
expect(capture).toHaveBeenCalledTimes(1);
});

View file

@ -1,4 +1,4 @@
/** Report JSON can exceed V8's single-string limit. Keep I/O bounded by individual records. */
/** Report JSON can exceed V8's single-string limit. Serialize nested collections incrementally. */
import { JSONParser } from '@streamparser/json';
import { randomUUID } from 'node:crypto';
import { createReadStream, createWriteStream } from 'node:fs';
@ -9,13 +9,13 @@ import { pipeline } from 'node:stream/promises';
import { isRecord } from '../util.js';
import type { ScenarioMapReport } from './report.js';
/** Report collections (pairs, tests, anchors, etc.) are serialized one entry at a time. */
/** Recurse through collections so even a single oversized record never becomes one string. */
function* jsonChunks(value: unknown): Generator<string> {
if (Array.isArray(value)) {
yield '[';
for (let i = 0; i < value.length; i++) {
if (i > 0) yield ',\n';
yield JSON.stringify(value[i]) ?? 'null';
yield* jsonChunks(value[i]);
}
yield ']';
} else if (isRecord(value)) {

View file

@ -45,8 +45,7 @@ const currentTest = (): CurrentTest | null => {
const fixtures = new TraceFixtureRoots();
Reflect.set(globalThis, FIXTURE_CAPTURE_KEY, (root: unknown) => {
const test = TestRunner.getCurrentTest<RunnerTestCase | undefined>();
if (test === undefined || candidateTaskIds.has(test.id)) fixtures.capture(root);
if (currentTest() !== null) fixtures.capture(root);
});
const recorder = new TraceRecorder({
currentTest,

View file

@ -6,7 +6,7 @@
*
* Run ({@link runTrace}). One throwaway copy, `<work>/trace/prepared`, prepared like a shard's
* copy (tools/mutation/prepare, nothing blanked) and verified against the run manifest (run-group.ts
* `verifyPreparedCopy`; a mismatch runs nothing). Every manifest test in the candidate tests'
* `verifyPreparedCopy`; a mismatch runs nothing). Every runnable manifest test in the candidate tests'
* files runs twice through vitest-run.ts `runVitest`, each a fresh Vitest instance with the same
* selection: a baseline, then the traced run with trace.setup.ts added (`setupFiles`) and its
* context provided: the raw-record directory `<work>/trace/raw`, the prepared root, the extra