mirror of
https://github.com/garrytan/gstack.git
synced 2026-10-02 17:40:02 +02:00
* test: delete test-infrastructure dead code (G) - exit-propagation drives the runner's real strict verdict (BunTestOutputClassifier + strictTestExitCode); delete the unused shardRunLooksTruncated predicate. - delete skill-coverage-matrix registry + its gate (nothing reads it; the floor already iterates skillCensus()). - delete touchfiles-facade export-parity tests (Bun fails missing imports at link time) and the duplicated E2E_TIERS tier-value test. - delete brain-cache-spec TRANSPORT_DEFAULT_POLICY, SKILL_RUN_RETENTION_DAYS and the now-unused BrainTrustPolicy type with their literal tests. AUTOPLAN_PREFLIGHT_BUDGET_BYTES stays: skill-preflight-budget enforces it against real resolver output. - delete audit-compliance's JSDoc-comment grep. * test: replace product tests that fake the product with real-boundary tests (F) - design: serve.test.ts drove an inline mirror server; now two tests run the real serve() on an ephemeral port (reload confinement, submit exit 0). - setup-gbrain: rollback + voyage tests execute the template-extracted init blocks (3 sites) instead of drifted local bash copies. - terminal-agent: internalHandler source greps replaced by a behavioral /internal/grant + /internal/revoke auth matrix (no/wrong/valid token). - /health: server-security-surface and the server-auth / security-audit-r2 / sidebar-tabs source greps fold into one liveness-only check on the real body; the L4 sidecar wiring gets a behavioral /pty-inject-scan test. - delete tautologies (browser-manager onDisconnect, memory-command #12), ios swiftui tap fixture self-check, memory-ingest put_page grep, detach source greps, sidebar-agent absence pins, dead-CSS pins + the dead CSS, security-audit-r2 Task 1 + the test-only meta-commands re-export, duplicate generated-SKILL.md checks. - make-pdf coverage-gaps cases move into their owner test files. * test: delete tests of dead eval code (A) - A1: the retired Eng lexical oracle (evaluateEngSeedCoverage, isEngSeedDecisionAUQ), the completion-handoff detector and the retained corpus had no paid caller since v1.87.6; delete their 26 replay files, ~2.6k helper LOC and fixtures, and the dead blocks in 8 mixed files (live hasNativePlanTerminal / batching assertions stay). - A2: dead viewport approvers in autoplan-artifact-permission and their 11 replay files + fixtures; recorder/launcher cases stay. - A3: never-wired oracles and seeders (autoplan-phase-order, eng-finding-fixture, ceo-paired-fixture, design-ui-scope, plan-skill-completion, pty-current-screen, required-reads, transcript-section-logger); plan-seed-submission now decodes through the production createPtyScreen; section manifests name their actual guard. - A4: zero-reference helper exports, plus execGit and invokeAndObserve found by the reachability pass. - 52 fixtures orphaned by the deletions; touchfile and selection-table entries for every deleted path. * test: clean up the paid eval lane (B1-B4, B6, B7) - B1: delete paid files that assert nothing or cannot pass meaningfully: skill-llm-eval-spec and skill-e2e-spec-execute (test.todo), gemini-e2e (+ gemini-session-runner; no gemini CLI in CI), ship-idempotency (red since v1.63), the two opus-4-7 *-sonnet overlay wrappers, conductor-prose (+ its source-evaluation replay), codex-e2e-plan-format; drop their keys, scripts and census rows. - B2: skill-llm-eval grades browse/sections/command-list.md with one union judge that also carries the baseline score pin; regression-vs-baseline deleted (paid run: pass, c4/c4/a4). - B3: memory-pipeline, ios-qa, ios-qa-swift-build and plan-tune-cathedral make no model calls; renamed out of the paid glob so they run on every PR. Swift builds need GSTACK_TEST_SWIFT=1; device stub deleted. - B4: codex-e2e*, outside-voice, aside and ios-device cannot run in the CI image; excluded from the weekly lane with a tracked re-entry condition. - B6: fold opus-47's negative routing controls into skill-routing-e2e journey-negatives (paid run: 3/3 unrouted) and delete the file. - B7: delete the never-green brain-privacy-gate eval; a free gstack-skill-start test now proves consent precedes artifacts egress. * test: retire the finding-count cluster and trim its helpers (C) - C0/C1: the five never-green evals (skill-e2e-autoplan-chain and skill-e2e-plan-{ceo,eng,design,devex}-finding-count) failed on harness and budget, never on skill behavior; delete them, their touchfile/tier ids, AUTOPLAN_CHAIN_BUDGET and the dedicated eighth periodic slice (--slices 7). - C2: delete the helper groups whose only paid consumers were those files (11 modules), trim claude-pty-runner and eng-seeded-coverage to the paid closure, and delete the free replay tests whose assertions exercised only that dead code (89 files, 135 orphaned fixtures). Blocks that used dead code only as input for a live subject keep their assertions: the multiSelect default moved to plan-review-decisions, runner PTY tests use inline caller policies, and the timer-safe budget checks moved to eng-finding-retry-budget. - The eight production-touching files stay except ceo-current-decision-record (its template read only feeds the retired counter). - CARVE_GUARDS.autoplan is behavioral 'none'; TODOS records the lost chain and per-finding cadence coverage with their re-entry tests. * test: fold per-incident replay series into their detector owners (D) Twelve detector families move into one owner test each: 73 incident files become describe blocks in ceo-section-loading-fixture (stale-fill race), model-overlays, coverage-audit-evidence, autoplan-phase-observer, native-auto-decide, outside-voice-evidence, eng-first-review, plan-count-completion, plan-count-file-permission, ceo-mode-option, plan-scope-selection and plan-count-prerequisite. Each block keeps its original code and fixture, so every case still runs; only tests asserting the incident file's own touchfile registration are dropped (41). Touchfile lists that named an incident now name its owner. * test: start the plan-count history PTY on its readiness marker (H) The fake CLI prints a startup marker and the runner waits for it instead of the fixed 8 s startup sleep (8.6 s -> 0.9 s locally). eng-semantic-terminal's sleeping registration cases went with C; plan-count-timeout keeps the fixed wait because it asserts deadline behavior. * test: derive paid touchfiles from each eval's static closure (E) touchfiles.test.ts now checks, per key, that the paid file's static test/helpers and test/fixtures closure (plus fixture paths it names in string literals) is covered, and names the file, path, chain and key to fix when it is not. Free *.test.ts files are no longer touchfiles, so editing a free replay test stops selecting paid evals: 950 entries removed, 653 real closure paths added. The hand-copied inventories go: periodic-fixture-selection, fake-impeccable-touchfiles and 45 per-file selection examples. Selection for the sample edits (plan-eng-review template, claude-pty-runner, plan-count-fixture, gstack-config) loses no case under either profile. CONTRIBUTING documents the rule and its lower bound. * test: skip hollow tier shards and census judges in the paid planner (B5) A paid file is now skipped for a tier lane only when every E2E id it registers is known statically and none has that tier; ids come from the touchfile registrations and literal testName/*IfSelected arguments, so a comment or skill path that quotes another id cannot unschedule it, and computed names keep today's scheduling. --list and the manifest show each skip as "skipped: no E2E_TIERS id has tier <tier>". The weekly gate census drops the LLM judges (--skip-judges); they still run in the periodic census and PR gate lanes. Gate lane 52 -> 42 files, census 41; periodic 77 -> 69. * test: run seven paid evals on the current default capture model (B8) skill-e2e-{auq-matrix,plan-format,qa-bugs,retro,workflow} pinned claude-opus-4-7 and skill-e2e-office-hours plus -brain-writeback pinned claude-sonnet-4-6; none tests a historical model, so they now capture with resolveEvalModel('capture'), and the free harness tests that execute these registrations receive the same resolver. The paid re-pin run passed all of them. skill-e2e-{design,office-hours-phase4,plan-prosons,plan} keep claude-opus-4-7: six of their cases failed on the default model (three timeouts, a missing report file, a format miss and a posture score of 3), so per the plan's fallback they keep their pins with a TODOS entry. The pre-spend estimate and drop threshold are in docs/test-audit-2026-09.md. * test: guard the reduced suite against new test-of-test files - test/test-of-test-ratchet.test.ts records the 228 free tests that import only test/ code and fails on a new one, naming the owner test to extend instead; a stale baseline entry fails with the remove instruction. - test/helpers/resolve-repo-path.ts is the one specifier/literal resolver for the ratchet and the touchfile closure invariant, with its own unit tests. - CONTRIBUTING "Test tiers" describes the paid-failure workflow (fix, then one row in the detector's owner test) and the ratchet; TEST_PORTFOLIO gains the detector -> owner-test table and no longer claims an Autoplan chain eval. - TODOS: automatic exclusion policy for chronically red periodic files (P3), the deferred native-completion table collapse, the unused CEO payment seeder; the PTY readiness item is narrowed to the paid runner. - docs/test-audit-2026-09.md collects the triage, security mapping, inventories, selection proof, behavior-commit decisions and retained false positives. * v1.91.8.0 test: smaller suite, derived paid selection, retired never-green evals Release metadata for the test-reduction branch: VERSION 1.91.8.0 (1.91.7.0 is claimed by #2983), CHANGELOG with the measured before/after table and a contributor section, durations re-recorded on Ubicloud standard-16 (857 files, 0 failures), the agents digest, CONTRIBUTING's after-measurement row, the B8 fallback TODOS entry, and the after metrics, kept-vs-plan notes, B8 run and census estimate in docs/test-audit-2026-09.md. * fix(ubicloud): skip retrieval globs that match nothing instead of reporting a failed pull * test: count issue-numbered Design findings in the UI-scope gate eval
351 lines
20 KiB
TypeScript
351 lines
20 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
import * as fs from 'node:fs';
|
|
import * as os from 'node:os';
|
|
import * as path from 'node:path';
|
|
import { EvalCollector } from './helpers/eval-store';
|
|
import { claudeOutsideExecutions, codexOutsideExecutions, foundInvoiceAuthorizationDefect, outsideExecutionTranscript } from './helpers/outside-voice-evidence';
|
|
import captured_outside_background_ai from './fixtures/outside-background-ai.json';
|
|
import { parseNDJSON } from './helpers/session-runner';
|
|
import captured_outside_voice_async from './fixtures/outside-async-task-m-events.json';
|
|
|
|
const finding = '[P1] invoice.ts removed the owner check, allowing unauthorized access to private invoices.';
|
|
|
|
describe('cross-harness live eval evidence', () => {
|
|
test('Claude prose claiming Codex ran is not evidence', () => {
|
|
const transcript = [{ type: 'assistant', message: { content: [{ type: 'text', text: `codex exec: ${finding}` }] } }];
|
|
expect(foundInvoiceAuthorizationDefect(claudeOutsideExecutions(transcript), 'codex')).toBe(false);
|
|
});
|
|
test('Claude tool results must match the actual outside tool invocation', () => {
|
|
const transcript = [
|
|
{ type: 'assistant', message: { content: [{ type: 'tool_use', id: 'outside', name: 'Bash', input: { command: 'codex exec --json -' } }] } },
|
|
{ type: 'user', message: { content: [{ type: 'tool_result', tool_use_id: 'native', content: finding }] } },
|
|
];
|
|
expect(foundInvoiceAuthorizationDefect(claudeOutsideExecutions(transcript), 'codex')).toBe(false);
|
|
transcript.push({ type: 'user', message: { content: [{ type: 'tool_result', tool_use_id: 'outside', content: finding }] } } as any);
|
|
expect(foundInvoiceAuthorizationDefect(claudeOutsideExecutions(transcript), 'codex')).toBe(true);
|
|
});
|
|
test('Codex requires completed, successful command execution with findings in its output', () => {
|
|
const event = { type: 'item.completed', item: { type: 'command_execution', command: '"/runtime/bin/gstack-claude-code" --cwd /repo --access none --timeout-ms 1000', aggregated_output: finding, exit_code: 0 } };
|
|
expect(foundInvoiceAuthorizationDefect(codexOutsideExecutions([JSON.stringify(event)]), 'claude-code')).toBe(true);
|
|
for (const invalid of [
|
|
{ ...event, type: 'item.started' },
|
|
{ ...event, item: { ...event.item, exit_code: 124 } },
|
|
{ ...event, item: { ...event.item, aggregated_output: 'OUTSIDE_STATUS: unavailable\n' + finding } },
|
|
{ type: 'item.completed', item: { type: 'agent_message', text: finding } },
|
|
]) expect(foundInvoiceAuthorizationDefect(codexOutsideExecutions([JSON.stringify(invalid)]), 'claude-code')).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('outside execution artifact retention', () => {
|
|
for (const provider of ['codex', 'claude-code'] as const) {
|
|
test(`${provider} persists full successful and failed results before cleanup`, () => {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'outside-evidence-'));
|
|
try {
|
|
const command = provider === 'codex' ? 'codex exec --json -'
|
|
: '"/runtime/bin/gstack-claude-code" --cwd /repo --access none --timeout-ms 1000';
|
|
const output = 'Review detail\n'.repeat(300) + finding;
|
|
const failedOutput = 'OUTSIDE_STATUS: unavailable\nprovider exited before final response';
|
|
const executions = [
|
|
{ command: 'cat /owned/auth.json /owned/config.toml', output: 'UNRELATED_CONFIG_CONTENT', succeeded: true },
|
|
{ command, output: failedOutput, succeeded: false },
|
|
{ command, output, succeeded: true, unrelated: 'UNRELATED_EVENT_FIELD' },
|
|
];
|
|
const transcript = outsideExecutionTranscript(executions, provider);
|
|
const collector = new EvalCollector('e2e', dir);
|
|
collector.addTest({ name: `outside-${provider}`, suite: 'outside-voice', tier: 'e2e',
|
|
passed: true, duration_ms: 1, cost_usd: 0, transcript });
|
|
|
|
// addTest writes immediately, before disposable host homes/repositories disappear.
|
|
const stored = fs.readFileSync(path.join(dir, '_partial-e2e.json'), 'utf8');
|
|
const entries = JSON.parse(stored).tests[0].transcript;
|
|
expect(entries).toEqual([
|
|
{ type: 'outside_execution', provider, command, output: failedOutput, succeeded: false },
|
|
{ type: 'outside_execution', provider, command, output, succeeded: true },
|
|
]);
|
|
expect(entries[1].output.length).toBeGreaterThan(2000);
|
|
expect(stored).not.toContain('UNRELATED_CONFIG_CONTENT');
|
|
expect(stored).not.toContain('UNRELATED_EVENT_FIELD');
|
|
} finally {
|
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
}
|
|
|
|
test('unrelated providers and host prose never become retained outside executions', () => {
|
|
const unrelated = [{ command: 'codex exec --json -', output: finding, succeeded: true }];
|
|
expect(outsideExecutionTranscript(unrelated, 'claude-code')).toEqual([]);
|
|
expect(outsideExecutionTranscript(claudeOutsideExecutions([
|
|
{ type: 'assistant', message: { content: [{ type: 'text', text: `codex exec: ${finding}` }] } },
|
|
]), 'codex')).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('outside-background-ai', () => {
|
|
const captured = captured_outside_background_ai;
|
|
const events = () => structuredClone(captured.events) as any[];
|
|
const block = (input: any[], index: number) => input[index].message.content[0];
|
|
const outputFile = /<output-file>([^<]+)<\/output-file>/.exec(captured.events[2].attachment!.prompt!)![1]!;
|
|
const finding = 'The missing invoice owner authorization check allows another user to access the invoice.';
|
|
const detected = (input: any[]) => foundInvoiceAuthorizationDefect(claudeOutsideExecutions(input), 'codex');
|
|
|
|
function rejects(mutations: Array<(input: any[]) => void>) {
|
|
for (const mutate of mutations) {
|
|
const input = events();
|
|
mutate(input);
|
|
expect(detected(input)).toBe(false);
|
|
}
|
|
}
|
|
|
|
describe('native completed outside task read through literal Bash cat', () => {
|
|
test('the exact five public events retain the completed Codex finding', () => {
|
|
expect(captured.events).toHaveLength(5);
|
|
const executions = claudeOutsideExecutions(events());
|
|
expect(foundInvoiceAuthorizationDefect(executions, 'codex')).toBe(true);
|
|
const completed = outsideExecutionTranscript(executions, 'codex').filter(row => row.succeeded);
|
|
expect(completed).toHaveLength(1);
|
|
expect(completed[0]!.background).toEqual({
|
|
toolUseId: block(events(), 0).id, taskId: 'bdie078em', outputFile,
|
|
outputToolUseId: block(events(), 3).id, completion: 'task_notification',
|
|
});
|
|
expect(completed[0]!.output).toContain('Missing ownership check exposes private financial data');
|
|
});
|
|
|
|
test('equivalent literal quoting and optional cat delimiter keep exact path ownership', () => {
|
|
for (const path of [outputFile, `'${outputFile}'`, `"${outputFile}"`]) {
|
|
for (const delimiter of ['', '-- ']) {
|
|
const input = events();
|
|
block(input, 3).input.command = `cat ${delimiter}${path}`;
|
|
expect(detected(input)).toBe(true);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('completion requires the owned launch, acknowledgment, native notice and paired output', () => {
|
|
rejects([
|
|
e => { e.splice(0, 1); }, e => { e.splice(1, 1); }, e => { e.splice(2, 1); },
|
|
e => { e.splice(3, 1); }, e => { e.pop(); },
|
|
e => { block(e, 1).is_error = true; },
|
|
e => { block(e, 4).tool_use_id = 'foreign-output'; },
|
|
e => { e[2].attachment.prompt = e[2].attachment.prompt.replace('<task-id>bdie078em', '<task-id>other'); },
|
|
e => { e[2].attachment.prompt = e[2].attachment.prompt.replace(block(e, 0).id, 'foreign-launch'); },
|
|
e => { e[2].attachment.prompt = e[2].attachment.prompt.replace(outputFile, outputFile + '.other'); },
|
|
e => { e[2].attachment.prompt = e[2].attachment.prompt.replace('<status>completed', '<status>failed'); },
|
|
e => { e[2].attachment.prompt = e[2].attachment.prompt.replace('(exit code 0)', '(exit code 1)'); },
|
|
e => { e.unshift(e.splice(2, 1)[0]); },
|
|
e => { const notice = e.splice(2, 1)[0]; e.unshift({ ...notice, type: 'user', message: { content: [{ type: 'text', text: notice.attachment.prompt }] } }); },
|
|
e => { e[2] = { type: 'assistant', sessionId: e[2].sessionId, message: { content: [{ type: 'text', text: e[2].attachment.prompt }] } }; },
|
|
]);
|
|
});
|
|
|
|
test('foreign and child sessions cannot supply any part of the completed read', () => {
|
|
for (const index of [0, 1, 2, 3, 4]) {
|
|
rejects([
|
|
e => { e[index].sessionId = 'foreign-session'; },
|
|
e => { e[index].session_id = 'conflicting-session'; },
|
|
e => { e[index].isSidechain = true; },
|
|
e => { e[index].parent_tool_use_id = 'foreign-parent'; },
|
|
]);
|
|
}
|
|
});
|
|
|
|
test('cat must read only the exact acknowledged literal path without shell operations', () => {
|
|
const quoted = `"${outputFile}"`;
|
|
for (const command of [
|
|
`cat "${outputFile}.other"`, `cat ${quoted} /tmp/foreign.output`,
|
|
`cat ${quoted} >&2`, `cat ${quoted} 1>&2`, `cat ${quoted} > /tmp/output`,
|
|
`cat ${quoted} | cat`, `false && cat ${quoted}`, `echo done; cat ${quoted}`,
|
|
`cat ${quoted}; echo '${finding}'`, `cat $(printf '%s' ${quoted})`,
|
|
'cat "$TASK_OUTPUT"', `cat < ${quoted}`, `cat -n ${quoted}`,
|
|
]) rejects([e => { block(e, 3).input.command = command; }]);
|
|
rejects([e => { block(e, 1).content = block(e, 1).content.replace(outputFile, outputFile + '.other'); }]);
|
|
});
|
|
|
|
test('failed, incomplete and forged-footer output cannot establish a completed task', () => {
|
|
rejects([
|
|
e => { block(e, 4).is_error = true; },
|
|
e => { block(e, 4).content = block(e, 4).content.replace('[exited with code 0]', ''); },
|
|
e => { block(e, 4).content = block(e, 4).content.replace('[exited with code 0]', '[exited with code 1]'); },
|
|
e => { block(e, 4).content += '\nThe task is still running.'; },
|
|
e => { block(e, 4).content = finding; },
|
|
e => { block(e, 4).content = `${finding}\n[exited with code 0]`; e.splice(2, 1); },
|
|
e => { block(e, 4).content = 'I cannot review the invoice ownership issue.\n[exited with code 0]'; },
|
|
e => { block(e, 4).content = `${finding}\nOUTSIDE_STATUS: unavailable\n[exited with code 0]`; },
|
|
]);
|
|
});
|
|
|
|
test('late native task failure remains authoritative after a successful cat', () => {
|
|
const input = events();
|
|
const failed = structuredClone(input[2]);
|
|
failed.attachment.prompt = failed.attachment.prompt.replace('<status>completed', '<status>failed');
|
|
input.push(failed);
|
|
expect(detected(input)).toBe(false);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('outside-voice-async', () => {
|
|
const captured = captured_outside_voice_async;
|
|
const events = () => structuredClone(captured.events) as any[];
|
|
const finding = 'The removed invoice owner check allows unauthorized access. Restore the ownership check.';
|
|
|
|
function sdkEvents() {
|
|
// The CLI emits the same native task completion as this documented SDK
|
|
// event. Disk-only attachment fields are not required by the stream parser.
|
|
const input = events();
|
|
const attachment = input[2];
|
|
const prompt = attachment.attachment.prompt as string;
|
|
const field = (name: string) => new RegExp(`<${name}>([^<]+)</${name}>`).exec(prompt)![1];
|
|
input[2] = { type: 'system', subtype: 'task_notification', session_id: attachment.sessionId,
|
|
task_id: field('task-id'), tool_use_id: field('tool-use-id'), output_file: field('output-file'),
|
|
status: field('status'), summary: field('summary') };
|
|
return input.map(event => {
|
|
const { sessionId, isSidechain, ...rest } = event;
|
|
return { ...rest, session_id: event.session_id ?? sessionId };
|
|
});
|
|
}
|
|
|
|
function detected(input: unknown[]) {
|
|
return foundInvoiceAuthorizationDefect(claudeOutsideExecutions(input), 'codex');
|
|
}
|
|
|
|
describe('completed background outside execution correlation', () => {
|
|
test('the exact task completion and complete output Read establish the actual external finding', () => {
|
|
const result = claudeOutsideExecutions(events());
|
|
expect(result).toHaveLength(2);
|
|
expect(result[0]!.succeeded).toBe(false);
|
|
expect(result[0]!.background?.completion).toBe('pending');
|
|
expect(result[1]!.succeeded).toBe(true);
|
|
expect(result[1]!.background).toEqual({
|
|
toolUseId: 'toolu_016PugkAqmFq5DjPFmvDA3DB', taskId: 'bn8jkc52l',
|
|
outputFile: events()[3].message.content[0].input.file_path,
|
|
outputToolUseId: 'toolu_01J2PNv3YyETiCWXKkHxFVxa', completion: 'task_notification',
|
|
});
|
|
expect(result[1]!.output).toContain('Removing the ownership check lets any authenticated caller retrieve any invoice');
|
|
expect(detected(events())).toBe(true);
|
|
expect(outsideExecutionTranscript(result, 'codex')[1]!.background).toEqual(result[1]!.background);
|
|
});
|
|
|
|
test('SDK NDJSON retains the same exact identity and output instead of borrowing host prose', () => {
|
|
const stream = sdkEvents().map(event => JSON.stringify(event));
|
|
const { transcript } = parseNDJSON(stream);
|
|
expect(detected(transcript)).toBe(true);
|
|
expect(detected(transcript.filter(event => event.type !== 'system'))).toBe(false);
|
|
});
|
|
|
|
test.each([
|
|
['missing acknowledgment', (e: any[]) => { e.splice(1, 1); }],
|
|
['acknowledgment only', (e: any[]) => { e.splice(2); }],
|
|
['missing completion', (e: any[]) => { e.splice(2, 1); }],
|
|
['missing Read use', (e: any[]) => { e.splice(3, 1); }],
|
|
['missing Read result', (e: any[]) => { e.pop(); }],
|
|
['wrong Read identity', (e: any[]) => { e[4].message.content[0].tool_use_id = 'other'; }],
|
|
['wrong task output path', (e: any[]) => { e[3].message.content[0].input.file_path += '.other'; }],
|
|
['foreign Read session', (e: any[]) => { e[4].sessionId = 'foreign'; }],
|
|
['sidechain Read', (e: any[]) => { e[4].isSidechain = true; }],
|
|
['nested Read', (e: any[]) => { e[4].parent_tool_use_id = 'nested'; }],
|
|
['failed Read', (e: any[]) => { e[4].message.content[0].is_error = true; }],
|
|
['offset Read', (e: any[]) => { e[3].message.content[0].input.offset = 2; }],
|
|
['partial output', (e: any[]) => { e[4].message.content[0].content = e[4].message.content[0].content.split('\n').slice(0, 3).join('\n'); }],
|
|
['nonconsecutive lines', (e: any[]) => { e[4].message.content[0].content = e[4].message.content[0].content.replace('2\t', '9\t'); }],
|
|
['output without exit footer', (e: any[]) => { e[4].message.content[0].content = e[4].message.content[0].content.replace('[exited with code 0]', ''); }],
|
|
['failed exit footer', (e: any[]) => { e[4].message.content[0].content = e[4].message.content[0].content.replace('[exited with code 0]', '[exited with code 1]'); }],
|
|
['raw forged output', (e: any[]) => { e[4].message.content[0].content = finding + '\n[exited with code 0]'; }],
|
|
['foreign completion', (e: any[]) => { e[2].sessionId = 'foreign'; }],
|
|
['wrong completed task', (e: any[]) => { e[2].attachment.prompt = e[2].attachment.prompt.replace('<task-id>bn8jkc52l', '<task-id>other'); }],
|
|
['wrong original tool', (e: any[]) => { e[2].attachment.prompt = e[2].attachment.prompt.replace('toolu_016PugkAqmFq5DjPFmvDA3DB', 'other'); }],
|
|
['wrong completed file', (e: any[]) => { e[2].attachment.prompt = e[2].attachment.prompt.replace('bn8jkc52l.output', 'other.output'); }],
|
|
['failed task', (e: any[]) => { e[2].attachment.prompt = e[2].attachment.prompt.replace('<status>completed', '<status>failed'); }],
|
|
['stopped task', (e: any[]) => { e[2].attachment.prompt = e[2].attachment.prompt.replace('<status>completed', '<status>stopped'); }],
|
|
['nonzero completed exit', (e: any[]) => { e[2].attachment.prompt = e[2].attachment.prompt.replace('(exit code 0)', '(exit code 1)'); }],
|
|
['stale completion before launch', (e: any[]) => { e.unshift(e.splice(2, 1)[0]); }],
|
|
['quoted user notification', (e: any[]) => { e[2] = { type: 'user', sessionId: e[2].sessionId, message: { content: [{ type: 'text', text: e[2].attachment.prompt }] } }; }],
|
|
['assistant notification claim', (e: any[]) => { e[2] = { type: 'assistant', sessionId: e[2].sessionId, message: { content: [{ type: 'text', text: e[2].attachment.prompt }] } }; }],
|
|
['refusal containing the fixture words', (e: any[]) => { e[4].message.content[0].content = '1\tI cannot review the invoice owner authorization issue.\n2\t[exited with code 0]'; }],
|
|
['unavailable provider', (e: any[]) => { e[4].message.content[0].content = `1\t${finding}\n2\tOUTSIDE_STATUS: unavailable\n3\t[exited with code 0]`; }],
|
|
])('rejects %s despite a matching finding elsewhere', (_name, mutate) => {
|
|
const input = events();
|
|
mutate(input);
|
|
expect(detected(input)).toBe(false);
|
|
});
|
|
|
|
test('a terminal failure overrides an earlier completion and an output containing a finding', () => {
|
|
for (const terminal of [
|
|
{ status: 'failed', summary: 'Background command failed (exit code 1)' },
|
|
{ status: 'completed', summary: 'Background command "Run Codex adversarial review" completed (exit code 1)' },
|
|
]) {
|
|
const input = sdkEvents();
|
|
input.push({ ...input[2], ...terminal });
|
|
expect(detected(input)).toBe(false);
|
|
}
|
|
});
|
|
|
|
test('replayed acknowledgments preserve task state and reject conflicting launch identities', () => {
|
|
const original = sdkEvents();
|
|
const failed = { ...original[2], status: 'failed', summary: 'Background command failed (exit code 1)' };
|
|
expect(detected([
|
|
...original.slice(0, 3), failed, original[1], ...original.slice(2),
|
|
])).toBe(false);
|
|
expect(detected([...original, original[1]])).toBe(true);
|
|
|
|
const plain = structuredClone(original[1]);
|
|
plain.message.content[0].content = finding;
|
|
expect(detected([...original.slice(0, 2), plain])).toBe(false);
|
|
const retained = claudeOutsideExecutions([...original, plain]);
|
|
expect(retained.filter(result => result.succeeded)).toHaveLength(1);
|
|
expect(retained.find(result => result.output === finding)?.succeeded).toBe(false);
|
|
plain.message.content[0].is_error = true;
|
|
plain.message.content[0].content = 'The background launch failed.';
|
|
expect(detected([...original, plain])).toBe(false);
|
|
|
|
for (const alter of [
|
|
(ack: any) => { ack.message.content[0].content = ack.message.content[0].content.replaceAll('bn8jkc52l', 'other-task'); },
|
|
(ack: any) => { ack.session_id = 'foreign'; },
|
|
(ack: any) => { ack.message.content[0].is_error = true; },
|
|
]) {
|
|
const acknowledgment = structuredClone(original[1]);
|
|
alter(acknowledgment);
|
|
expect(detected([...original, acknowledgment])).toBe(false);
|
|
}
|
|
});
|
|
|
|
test('partial and failed exact-path Reads remain diagnostic output without earning completion', () => {
|
|
for (const fail of [false, true]) {
|
|
const input = events();
|
|
input[4].message.content[0].content = finding;
|
|
input[4].message.content[0].is_error = fail;
|
|
const retained = outsideExecutionTranscript(claudeOutsideExecutions(input), 'codex');
|
|
expect(retained.at(-1)!.output).toBe(finding);
|
|
expect(retained.at(-1)!.succeeded).toBe(false);
|
|
expect(detected(input)).toBe(false);
|
|
}
|
|
});
|
|
|
|
test('an unsupported background acknowledgment cannot pass as a foreground result', () => {
|
|
const input = events().slice(0, 2);
|
|
input[1].message.content[0].content += '\n' + finding;
|
|
expect(detected(input)).toBe(false);
|
|
});
|
|
|
|
test('TaskOutput requires the exact launched task and native completed exit-zero envelope', () => {
|
|
const input = sdkEvents().slice(0, 2);
|
|
const session_id = input[0].session_id;
|
|
const result = `<retrieval_status>success</retrieval_status>\n\n<task_id>bn8jkc52l</task_id>\n\n<task_type>local_bash</task_type>\n\n<status>completed</status>\n\n<exit_code>0</exit_code>\n\n<output>\n${finding}\n</output>`;
|
|
input.push({ type: 'assistant', session_id, message: { content: [{ type: 'tool_use', name: 'TaskOutput', id: 'task-output', input: { task_id: 'bn8jkc52l' } }] } });
|
|
input.push({ type: 'user', session_id, message: { content: [{ type: 'tool_result', tool_use_id: 'task-output', content: result }] } });
|
|
expect(detected(input)).toBe(true);
|
|
for (const content of [
|
|
result.replace('>success<', '>not_ready<'), result.replace('>completed<', '>running<'),
|
|
result.replace('>0<', '>1<'), result.replace('>bn8jkc52l<', '>other<'),
|
|
result.replace('>local_bash<', '>local_agent<'), finding + result,
|
|
]) {
|
|
const invalid = structuredClone(input);
|
|
invalid[3].message.content[0].content = content;
|
|
expect(detected(invalid)).toBe(false);
|
|
}
|
|
const invalid = structuredClone(input);
|
|
invalid[3].message.content[0].is_error = true;
|
|
expect(detected(invalid)).toBe(false);
|
|
});
|
|
});
|
|
});
|