Files
callstack__agent-device/scripts/fuzz/envelope.ts
devin-ai-integration[bot] 006c4cadc9 test: nightly parser fuzz lane — parser input fails as typed AppErrors, never hangs (#1414) (#1438)
* test: nightly parser fuzz lane with typed-AppError invariant (#1414)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(fuzz): run envelope, artifact promotion, and harness self-check tests (#1414)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(fuzz): shared scheduled-lane envelope on every terminal path, watchdog after ready (#1414)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(fuzz): envelope for malformed options; add scheduled-lane health consumer (#1414, #1430)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(lanes): actions:read scope, terminal error envelope, first-due grace (#1414, #1430)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(lanes): anchor first-run grace to schedule registration, use exec helper in tests (#1414, #1430)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(lanes): portable POSIX pickaxe pattern for schedule registration (#1414, #1430)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(fuzz): fast-check generators over the shared hazard list, drop the bundled lane-health work (#1414)

- Strip scripts/scheduled-lane/* and scheduled-lane-health.yml: that watcher is #1430's own
  deliverable and collides with PR #1439's implementation of the same lane. What this lane owes
  (a per-run envelope) moves into scripts/fuzz/envelope.ts.
- Rebase onto #1437 and rebuild the generator layer on fast-check: cases come from arbitraries
  sharing SELECTOR_VALUE_HAZARDS with the property suite, and counterexamples are shrunk, so a
  failure names a minimal input plus fast-check's seed/path instead of a 20k-char random string.
- Route harness.test.ts into the serialized subprocess-stub project.
- Drop the AGENT_DEVICE_FUZZ_STARTUP_DELAY_MS test seam: the ready handshake is now proven by a
  case budget far below real worker startup.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(fuzz): replay the regression corpus through the worker watchdog (#1414)

A promoted hang case used to wedge the unit job until the CI timeout, because corpus replay called
checkCase in-process. It now goes through the same worker-backed watchdog the nightly lane uses, so
such a case fails against a 5s per-case budget; the file moves to the serialized subprocess-stub
project with the rest of the worker-driven fuzz tests.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(fuzz): let the watchdog outlive vitest's default case timeout (#1414)

A wedged parser was surfacing as a bare 'Test timed out in 5000ms' instead of the named hang:
failure that says which input wedged, because the file's vitest timeout was shorter than the
watchdog budget times the number of replayed cases.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(fuzz): complete drift provenance in the lane envelope (#1414)

configHash now covers every input that decides what a seed generates (generate.ts and the shared property arbitraries, not just the arbitraries/targets/invariant), and tool records fast-check's installed version. A generation-loop edit or a fast-check upgrade previously changed the case set while the envelope looked unchanged. A test recomputes the hash with each input omitted so a future omission fails.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-07-28 11:29:25 +02:00

113 lines
4.5 KiB
TypeScript

// Run envelope for the parser fuzz lane (#1414), on #1430's shared contract.
//
// A scheduled lane goes dark quietly: it can stop running, or fail for weeks, while PR CI stays
// green. Freshness monitoring therefore needs one machine-readable record per run — green runs
// included. This module only maps the lane's own facts onto `scripts/lib/lane-envelope.ts`; the
// envelope shape itself is cross-lane and lives there.
//
// `error` (a crash, or config the harness could not parse) is reported as `result: 'fail'` with
// `data.stage: 'error'`: the shared contract deliberately has two results, and a lane that could
// not complete itself is not a passing lane.
import crypto from 'node:crypto';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { laneEnvelope } from '../lib/lane-envelope.ts';
import { runCmdSync } from '../../src/utils/exec.ts';
import type { FuzzFailure } from './invariant.ts';
const FILENAME = 'run-envelope.json';
/** Shared with the property suite (#1437): its hazard list feeds the fuzz arbitraries. */
const PROPERTY_ARBITRARIES = '../../src/__tests__/test-utils/property-arbitraries.ts';
const LANE = 'parser-fuzz';
const TOOL = 'scripts/fuzz/run.ts';
export type FuzzTargetRun = {
target: string;
cases: number;
failures: number;
durationMs: number;
};
export type FuzzRunMode = 'generate' | 'replay-corpus' | 'replay-artifact' | 'self-check';
export type FuzzEnvelopeDetails = {
mode: FuzzRunMode;
corpusEntries: number;
targetRuns: FuzzTargetRun[];
failures: (FuzzFailure & { artifact?: string })[];
reproCommands: string[];
};
/** `stage` separates "the lane ran and found violations" from "the lane could not run". */
export type FuzzEnvelopeData = FuzzEnvelopeDetails & {
stage: 'complete' | 'error';
config: Record<string, unknown>;
};
/** Writes the envelope for one fuzz run into `artifactDir`; returns its path. */
export function writeFuzzEnvelope(input: {
artifactDir: string;
startedAt: number;
finishedAt: number;
result: 'pass' | 'fail' | 'error';
config: Record<string, unknown>;
details: FuzzEnvelopeDetails;
}): string {
const seed = input.config.seed;
const envelope = laneEnvelope<FuzzEnvelopeData>({
lane: LANE,
commit: runCmdSync('git', ['rev-parse', 'HEAD'], { allowFailure: true }).stdout.trim(),
// fast-check is a case-generation input, not just a dependency: an upgrade can change what a
// seed produces, so its version belongs in provenance next to Node's.
tool: { node: process.version, 'fast-check': fastCheckVersion(), harness: TOOL },
configHash: harnessHash(),
seed: typeof seed === 'number' ? String(seed) : null,
startedAtMs: input.startedAt,
now: input.finishedAt,
result: input.result === 'pass' ? 'pass' : 'fail',
data: {
stage: input.result === 'error' ? 'error' : 'complete',
config: { mode: input.details.mode, ...input.config },
...input.details,
},
});
fs.mkdirSync(input.artifactDir, { recursive: true });
const file = path.join(input.artifactDir, FILENAME);
fs.writeFileSync(file, `${JSON.stringify(envelope, null, 2)}\n`);
return file;
}
/**
* Every module that decides which inputs a seed produces, or what counts as a violation: the
* arbitraries, the targets they are built for, the generation loop (numRuns, property, shrinking),
* and the invariant itself. Hashing a subset would let a changed case set look like an unchanged
* lane, which is exactly the drift this field exists to catch.
*/
const CASE_GENERATION_INPUTS = [
'arbitraries.ts',
'generate.ts',
'targets.ts',
'invariant.ts',
] as const;
/** Content hash of `CASE_GENERATION_INPUTS`, alongside their shared source of hazards. */
function harnessHash(): string {
const here = path.dirname(new URL(import.meta.url).pathname);
const digest = crypto.createHash('sha256');
for (const name of CASE_GENERATION_INPUTS) {
digest.update(fs.readFileSync(path.join(here, name)));
}
digest.update(fs.readFileSync(path.join(here, PROPERTY_ARBITRARIES)));
return `sha256:${digest.digest('hex').slice(0, 16)}`;
}
/** The generators read from the installed package, so its version is read from there too. */
function fastCheckVersion(): string {
const manifest = fileURLToPath(import.meta.resolve('fast-check/package.json'));
const parsed: unknown = JSON.parse(fs.readFileSync(manifest, 'utf8'));
const version = (parsed as { version?: unknown }).version;
return typeof version === 'string' ? version : 'unknown';
}