Files
callstack__agent-device/scripts/fuzz/validation-case.test.ts
Michał Pierzchała 80b4769230 test(fuzz): structured CLI/Maestro generators that reach command validation and assert error codes (#1781 B2) (#1866)
* test(fuzz): structured CLI/Maestro generators that reach command validation and assert error codes (#1781 B2)

* test(fuzz): pin the rediscovered #1433 excess-positional case and keep numeric flag samples inside their range

* style: apply oxfmt to the new fuzz modules

* perf(fuzz): derive the CLI validation surface lazily so unrelated harness paths keep their startup

* test(fuzz): resolve validation generators in the run path so corpus replay keeps its small module graph

* test(fuzz): weight the CLI budget toward command validation, pin the finite classes as seeds, guard lazy surface derivation

* docs(testing): describe the validation lane's layer split, seed-pinned classes, and PR-time gates

* refactor(fuzz): split the validation generator into CLI and Maestro modules, mirrored in tests

* refactor(fuzz): collapse the flag-shaped mutation classes and seed literals, derive class coverage from declarations

* fix(fuzz): hash every case-generation module in configHash, guarded by an import-closure test

* test(fuzz): assert CLI command and flag-key coverage against the registry, and close the six gaps it found
2026-08-20 08:00:08 +02:00

40 lines
1.6 KiB
TypeScript

// The validation case envelope and its judge (#1781 B2).
//
// The envelope is what carries a planted expectation from the generator to the judge, through the
// corpus, the artifact, and the worker boundary. A malformed one is a harness or corpus defect
// rather than a parser bug, but it must still surface red instead of crashing a nightly.
import { describe, expect, it } from 'vitest';
import { checkCase } from './invariant.ts';
import { getFuzzTarget } from './registry.ts';
import { decodeValidationCase, encodeValidationCase } from './validation-case.ts';
describe('validation case envelope', () => {
it('round-trips a case through the string form the corpus and artifacts carry', () => {
const original = {
payload: ['open', 'com.example.app'],
mutation: 'valid',
expect: { outcome: 'accept' },
} as const;
expect(decodeValidationCase(encodeValidationCase(original))).toEqual(original);
});
it.each([
['not json at all', 'plain text'],
['valid json that is not an envelope', '{"nope":1}'],
['an envelope without an expectation', '{"payload":["open"],"mutation":"x"}'],
[
'a reject expectation without a code',
'{"payload":[],"mutation":"x","expect":{"outcome":"reject"}}',
],
])('rejects %s', (_label, input) => {
expect(decodeValidationCase(input)).toBeNull();
});
it('reports a malformed envelope as a finding instead of crashing the worker', () => {
const failure = checkCase(getFuzzTarget('cli-validation'), 'not an envelope');
expect(failure?.kind).toBe('untyped-throw');
expect(failure?.detail).toContain('malformed validation case envelope');
});
});