Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

test(mcp): share receipt and artifact recovery fixtures (#1973)

Michael D'Angelo5bd723c867a2
diff --git a/plugins/codex-security/mcp-app/tests/deep_scan_coverage_fixture.ts b/plugins/codex-security/mcp-app/tests/deep_scan_coverage_fixture.ts
index 7ae56363e..f0602288b 100644
--- a/plugins/codex-security/mcp-app/tests/deep_scan_coverage_fixture.ts
+++ b/plugins/codex-security/mcp-app/tests/deep_scan_coverage_fixture.ts
@@ -32,20 +32,14 @@ interface CoverageFixtureOptions {
sameNamedNewSurface?: boolean;
closeRetriedSurface?: boolean;
receiptOwnershipRetry?: "ordinary" | "candidate" | "unrelated";
- receiptSpelling?:
- | "worker"
- | "scan"
- | "equivalent scan"
- | "active scan"
- | "equivalent active scan"
- | "shared scan"
- | "equivalent shared scan";
+ receiptSpelling?: "worker" | "scan" | "active scan" | "shared scan";
activeReceiptSpelling?: "worker" | "scan" | "equivalent scan";
sharedReceipt?: boolean;
receiptCollision?: boolean;
emptyReceipt?: boolean;
retryPending?: boolean;
retryCoverage?: JsonObject[];
+ otherWorkerCandidateIds?: string[];
retryFindings?: JsonObject[][];
questionRows?: (string | JsonObject)[];
interruptPublication?: boolean;
@@ -139,6 +133,7 @@ export async function publishCoverageFixture(
emptyReceipt = false,
retryPending = false,
retryCoverage,
+ otherWorkerCandidateIds = ["candidate-1"],
retryFindings,
questionRows,
interruptPublication = false,
@@ -162,6 +157,7 @@ export async function publishCoverageFixture(
path.join(codexHome, "codex-security", "config.toml"),
`[deep_scan]\nworkers = 1\nsubagents = 0\nstop_after_no_new = ${statuses.length}\nmax_discovery_runs = ${statuses.length}\n`,
);
+ const workbenchAbort = new AbortController();
const runWorkbench = async (args: string[]) => {
const workbenchPath = path.join(pluginRoot, "scripts", "workbench_db.py");
const command = [workbenchPath, ...args];
@@ -183,6 +179,7 @@ runpy.run_path(sys.argv[0], run_name="__main__")
);
}
const { stdout } = await exec(process.env.PYTHON || "python3", command, {
+ signal: workbenchAbort.signal,
env: {
...process.env,
CODEX_HOME: codexHome,
@@ -235,10 +232,7 @@ runpy.run_path(sys.argv[0], run_name="__main__")
}
const archivedRef = `${path.relative(run.scanDir, path.dirname(artifactDir)).split(path.sep).join("/")}/attempts/attempt-01/artifacts/prior.txt`;
const sharedPrior = "artifacts/01_context/false_positive_feedback.json";
- const sharedPriorReceipt =
- receiptSpelling === "shared scan" ||
- receiptSpelling === "equivalent shared scan";
- if (sharedPriorReceipt) {
+ if (receiptSpelling === "shared scan") {
await mkdir(path.dirname(path.join(run.scanDir, sharedPrior)), {
recursive: true,
});
@@ -247,25 +241,14 @@ runpy.run_path(sys.argv[0], run_name="__main__")
emptyReceipt ? "" : "Archived receipt.\n",
);
}
- const receiptRef = sharedPriorReceipt
- ? sharedPrior.replace(
- "artifacts/",
- receiptSpelling === "equivalent shared scan"
- ? "artifacts/./"
- : "artifacts/",
- )
- : receiptSpelling === "worker"
- ? "artifacts/prior.txt"
- : receiptSpelling === "scan"
- ? archivedRef
- : receiptSpelling === "equivalent scan"
- ? archivedRef.replace("artifacts/", "artifacts/./")
- : `${path.relative(run.scanDir, artifactDir).split(path.sep).join("/")}/artifacts/prior.txt`.replace(
- "artifacts/",
- receiptSpelling === "equivalent active scan"
- ? "artifacts/./"
- : "artifacts/",
- );
+ const receiptRef =
+ receiptSpelling === "shared scan"
+ ? sharedPrior
+ : receiptSpelling === "worker"
+ ? "artifacts/prior.txt"
+ : receiptSpelling === "scan"
+ ? archivedRef
+ : `${path.relative(run.scanDir, artifactDir).split(path.sep).join("/")}/artifacts/prior.txt`;
if (receiptOwnershipRetry) {
await recordCodexSecurityWorkerScanDraft(
{
@@ -388,7 +371,11 @@ runpy.run_path(sys.argv[0], run_name="__main__")
label: "Prior second surface",
disposition: "needs_follow_up",
candidateId: "shared-prior-candidate",
- receiptRefs: [receiptRef],
+ receiptRefs: [
+ receiptSpelling === "worker"
+ ? receiptRef
+ : receiptRef.replace("artifacts/", "artifacts/./"),
+ ],
},
],
explicitExclusions: [],
@@ -542,18 +529,16 @@ runpy.run_path(sys.argv[0], run_name="__main__")
{ pattern: "vendor/", reason: "External dependency." },
],
deferred: pending
- ? [
- {
- id: "same-id",
- candidateId: "candidate-1",
- reason:
- index === 0
- ? "Verify entry boundaries."
- : "Verify symbolic links.",
- paths: ["source.py"],
- surfaceIds: ["shared-surface"],
- },
- ]
+ ? otherWorkerCandidateIds.map((candidateId, gapIndex) => ({
+ id: gapIndex === 0 ? "same-id" : `same-id-${gapIndex}`,
+ candidateId,
+ reason:
+ index === 0
+ ? "Verify entry boundaries."
+ : "Verify symbolic links.",
+ paths: ["source.py"],
+ surfaceIds: ["shared-surface"],
+ }))
: [],
openQuestions:
questionRows ??
@@ -592,12 +577,7 @@ runpy.run_path(sys.argv[0], run_name="__main__")
"Synthetic unrelated parent review.\n",
);
}
- if (
- receiptRetry &&
- receiptCollision &&
- (receiptSpelling === "shared scan" ||
- receiptSpelling === "equivalent shared scan")
- ) {
+ if (receiptRetry && receiptCollision && receiptSpelling === "shared scan") {
const collision = path.join(
artifactDir,
"artifacts",
@@ -956,13 +936,19 @@ runpy.run_path(sys.argv[0], run_name="__main__")
},
});
coordinator.start();
- const terminal = await coordinator.wait(undefined, 30_000);
+ // A loaded runner may take over 30 seconds to publish through the workbench.
+ const terminal = await coordinator.wait(undefined, 120_000);
+ if (!terminal) {
+ coordinator.cancel("Coverage fixture timed out.");
+ workbenchAbort.abort();
+ await coordinator.wait(undefined, 5_000).catch(() => undefined);
+ assert.fail("The coverage fixture did not finish within 120 seconds.");
+ }
assert.equal(
- terminal?.status,
+ terminal.status,
stopBeforeDraft ? "failed" : "succeeded",
- terminal?.error ?? "Deep Scan did not reach the expected terminal state.",
+ terminal.error ?? "Unexpected Deep Scan terminal status.",
);
- assert.ok(terminal);
if (!retryFindings) {
assert.equal(
terminal.noNewStreak,
@@ -1057,6 +1043,13 @@ runpy.run_path(sys.argv[0], run_name="__main__")
stopAfterDraft || stopBeforeDraft ? ["scan-stopped"] : [],
);
if (sameAttemptCloseout) {
+ assert.deepEqual(
+ coverage.resolvedDeferred,
+ coverage.reviews.map(({ workerId, attempt }) => ({
+ id: `${workerId}-attempt-${attempt}-resolved-first-gap`,
+ reason: "The same boundary is verified.",
+ })),
+ );
const surface = coverage.surfaces.find(
(row) => row.label === "First checkpoint",
);
@@ -1217,23 +1210,20 @@ runpy.run_path(sys.argv[0], run_name="__main__")
"Verify the same candidate's second boundary.",
].sort(),
);
- if (
- receiptSpelling === "shared scan" ||
- receiptSpelling === "equivalent shared scan"
- )
+ for (const surface of prior) {
+ const [ref] = surface.receiptRefs;
+ if (receiptSpelling === "shared scan")
+ assert.equal(ref, "artifacts/01_context/false_positive_feedback.json");
+ else
+ assert.match(
+ ref,
+ /\/(?:attempts|archived-receipts)\/attempt-01\/artifacts\/prior\.txt$/,
+ );
assert.equal(
- prior[0].receiptRefs[0],
- "artifacts/01_context/false_positive_feedback.json",
- );
- else
- assert.match(
- prior[0].receiptRefs[0],
- /\/(?:attempts|archived-receipts)\/attempt-01\/artifacts\/prior\.txt$/,
+ await readFile(path.join(run.scanDir, ref), "utf8"),
+ emptyReceipt ? "" : "Archived receipt.\n",
);
- assert.equal(
- await readFile(path.join(run.scanDir, prior[0].receiptRefs[0]), "utf8"),
- emptyReceipt ? "" : "Archived receipt.\n",
- );
+ }
}
return { scanDir: run.scanDir, threadId, terminal };
}
diff --git a/plugins/codex-security/mcp-app/tests/support/reducer-paging/controlled-code-mode.ts b/plugins/codex-security/mcp-app/tests/support/reducer-paging/controlled-code-mode.ts
index 28140470a..332b11900 100644
--- a/plugins/codex-security/mcp-app/tests/support/reducer-paging/controlled-code-mode.ts
+++ b/plugins/codex-security/mcp-app/tests/support/reducer-paging/controlled-code-mode.ts
@@ -126,12 +126,15 @@ export async function runControlledCodeMode({
const config = [
'model_provider="controlled"',
`model_providers.controlled={name="controlled",base_url="http://127.0.0.1:${port}/v1",wire_api="responses",requires_openai_auth=false,supports_websockets=false}`,
+ "mcp_servers.cs_artifacts.required=true",
"features.code_mode.enabled=true",
"features.code_mode_host.enabled=true",
"features.code_mode_host.disable_in_process_fallback=true",
...("url" in mcpServer
? [`mcp_servers.cs_artifacts.url=${JSON.stringify(mcpServer.url)}`]
: [
+ // Wait for the bundled fixture's tools before the scripted first call.
+ "mcp_servers.cs_artifacts.startup_timeout_sec=60",
`mcp_servers.cs_artifacts.command=${JSON.stringify(mcpServer.command)}`,
`mcp_servers.cs_artifacts.args=${JSON.stringify(mcpServer.args)}`,
]),
diff --git a/plugins/codex-security/mcp-app/tests/support/reducer-paging/deep-reducer-paging-fixture.ts b/plugins/codex-security/mcp-app/tests/support/reducer-paging/deep-reducer-paging-fixture.ts
index c263e1109..2d8877778 100644
--- a/plugins/codex-security/mcp-app/tests/support/reducer-paging/deep-reducer-paging-fixture.ts
+++ b/plugins/codex-security/mcp-app/tests/support/reducer-paging/deep-reducer-paging-fixture.ts
@@ -6,12 +6,21 @@ import { mkdir, realpath } from "node:fs/promises";
import path from "node:path";
import { sourceReferences } from "../source-references.ts";
-// This is the existing code-mode transport ceiling, used only to size the eval.
+// These are the real ceilings reported by the respective transports.
const IPC_FRAME_LIMIT_BYTES = 64 * 1024 * 1024;
+const STDIO_LINE_LIMIT_BYTES = 16 * 1024 * 1024;
const SCAN_ID = "7fc17317-9594-49e0-b06a-d72fd7e14bba";
/** Generate one reducer assignment; no repository scan or external service runs. */
-export async function createReducerPagingFixture(root: string) {
+export async function createReducerPagingFixture(
+ root: string,
+ transport: "stdio" | "http",
+ mode: "deterministic" | "model",
+) {
+ const responseLimitBytes =
+ transport === "stdio" ? STDIO_LINE_LIMIT_BYTES : IPC_FRAME_LIMIT_BYTES;
+ const fixtureLimitBytes =
+ mode === "model" ? IPC_FRAME_LIMIT_BYTES : responseLimitBytes;
const fixtureRoot = await realpath(root);
const scanRoot = path.join(fixtureRoot, "scan");
const deepRoot = path.join(scanRoot, "artifacts", "deep_discovery");
@@ -26,7 +35,7 @@ export async function createReducerPagingFixture(root: string) {
const freshHtml = finding("reflected-html", {
title: "Request text reaches an HTML response without encoding",
- summary: paddedSummary(IPC_FRAME_LIMIT_BYTES / 2),
+ summary: paddedSummary(fixtureLimitBytes / 2),
remediation: "HTML-encode request text at the response rendering boundary.",
});
const freshArchive = finding("archive-path", {
@@ -116,7 +125,7 @@ export async function createReducerPagingFixture(root: string) {
}),
) - Buffer.byteLength("null");
const legacyResponseBytes = envelopeBytes + bytes * 2 + stringEscapes;
- assert.ok(legacyResponseBytes > IPC_FRAME_LIMIT_BYTES);
+ assert.ok(legacyResponseBytes > fixtureLimitBytes);
return {
context: {
root: outputRoot,
@@ -140,6 +149,7 @@ export async function createReducerPagingFixture(root: string) {
},
measurements: {
ipcFrameLimitBytes: IPC_FRAME_LIMIT_BYTES,
+ responseLimitBytes,
largeSemanticFieldBytes: Buffer.byteLength(freshHtml.summary),
logicalInputBytes: bytes,
legacyResponseBytes,
diff --git a/plugins/codex-security/mcp-app/tests/support/reducer-paging/deep-reducer-paging.ts b/plugins/codex-security/mcp-app/tests/support/reducer-paging/deep-reducer-paging.ts
index 82a4fad25..fbeb2c971 100644
--- a/plugins/codex-security/mcp-app/tests/support/reducer-paging/deep-reducer-paging.ts
+++ b/plugins/codex-security/mcp-app/tests/support/reducer-paging/deep-reducer-paging.ts
@@ -53,7 +53,7 @@ async function runReducer({
transport: protocol = "stdio",
}: ReducerPagingEvalOptions) {
assert.ok(mode === "deterministic" || mode === "model");
- const fixture = await createReducerPagingFixture(root);
+ const fixture = await createReducerPagingFixture(root, protocol, mode);
const tracePath = path.join(root, "tool-trace.jsonl");
const serverConfigPath = path.join(root, "server-config.json");
const serverPath = path.join(root, "artifact-server.cjs");
@@ -173,7 +173,7 @@ async function runReducer({
...fixture.measurements,
...gradeReducerPagingTrace(
trace,
- fixture.measurements.ipcFrameLimitBytes,
+ fixture.measurements.responseLimitBytes,
),
...(transport
? {
@@ -194,7 +194,7 @@ async function runReducer({
/** Grade the captured I/O independently of model wording or another model run. */
export function gradeReducerPagingTrace(
trace: ReducerTraceEvent[],
- ipcFrameLimitBytes: number,
+ responseLimitBytes: number,
) {
assert.ok(trace.length > 0, "The reducer produced no tool trace.");
const reads = trace.filter(
@@ -205,7 +205,7 @@ export function gradeReducerPagingTrace(
const readsById = new Map(reads.map((event) => [event.id, event]));
const injected = trace.filter((event) => event.injected);
assert.equal(injected.length, 1);
- assert.ok(injected[0].bytes! > ipcFrameLimitBytes);
+ assert.ok(injected[0].bytes! > responseLimitBytes);
const failed = reads.find((event) => event.id === injected[0].id);
const retried = reads.find((event) => event.id > failed!.id);
assert.ok(retried, "the reducer must recover from the oversized response");
diff --git a/plugins/codex-security/mcp-app/tests/test_artifact_scan_identity.ts b/plugins/codex-security/mcp-app/tests/test_artifact_scan_identity.ts
index b21d174e9..b75bf799b 100644
--- a/plugins/codex-security/mcp-app/tests/test_artifact_scan_identity.ts
+++ b/plugins/codex-security/mcp-app/tests/test_artifact_scan_identity.ts
@@ -369,37 +369,35 @@ for (const [label, metadata, count] of [
}
for (const layout of ["standard", "diff", "deep"] as const) {
- for (const [label, candidateId] of Object.entries({
- bom: "\ufeff",
- nextLine: "\u0085",
- controlSeparators: "\u001c\u001f",
- spaces: " \u00a0\u2003\u3000",
- })) {
- test(`${layout}: ${label} candidate metadata matches recovered identity`, async (t) => {
- const normal = await fixture(t, layout);
- const recovered = await fixture(t, layout);
- const findings = [
- finding("Synthetic review", {
- provenance: { source: "local_plugin", candidateId },
- }),
- ];
- await normal.write({ ...normal.draft(), findings });
- await draftApi.saveScanDraftCheckpoint(
- recovered.context,
- { ...recovered.draft(), findings },
- false,
- );
- const result = await recoverAndFinalize(
- normal,
- recovered,
- [],
- true,
- true,
- );
- assert.deepEqual(result.recovered, result.normal);
- assert.deepEqual(result.warnings, []);
- });
- }
+ test(`${layout}: Unicode whitespace candidate IDs match recovered identities`, async (t) => {
+ const normal = await fixture(t, layout);
+ const recovered = await fixture(t, layout);
+ const candidates = {
+ bom: "\ufeff",
+ "next-line": "\u0085",
+ "control-separators": "\u001c\u001f",
+ spaces: " \u00a0\u2003\u3000",
+ };
+ const findings = Object.entries(candidates).map(([label, candidateId]) =>
+ finding(label, {
+ ruleId: `fixture.${label}`,
+ provenance: { source: "local_plugin", candidateId },
+ }),
+ );
+ await normal.write({ ...normal.draft(), findings });
+ await draftApi.saveScanDraftCheckpoint(
+ recovered.context,
+ { ...recovered.draft(), findings },
+ false,
+ );
+ const result = await recoverAndFinalize(normal, recovered, [], true, true);
+ assert.deepEqual(
+ result.normal.map((row) => row.title).sort(),
+ Object.keys(candidates).sort(),
+ );
+ assert.deepEqual(result.recovered, result.normal);
+ assert.deepEqual(result.warnings, []);
+ });
}
for (const layout of ["standard", "diff", "deep"] as const) {
diff --git a/plugins/codex-security/mcp-app/tests/test_compact_artifact_server.ts b/plugins/codex-security/mcp-app/tests/test_compact_artifact_server.ts
index bd306d6f8..910b9d49b 100644
--- a/plugins/codex-security/mcp-app/tests/test_compact_artifact_server.ts
+++ b/plugins/codex-security/mcp-app/tests/test_compact_artifact_server.ts
@@ -46,6 +46,7 @@ import {
writeFile,
} from "node:fs/promises";
import path from "node:path";
+import test from "node:test";
import { pathToFileURL } from "node:url";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
@@ -71,20 +72,27 @@ try {
target: "node20",
});
- for (const [bundle, runtimeLabel] of [
+ const shipped = path.join(bundledPluginRoot, "mcp", "server.mjs");
+ for (const [bundle, label] of [
[runtimeBundle, "source"],
- [path.join(bundledPluginRoot, "mcp", "server.mjs"), "shipped"],
+ [shipped, "shipped"],
]) {
- await testParentToolList(bundle);
- await testClaimedParentArtifactOperations(bundle, runtimeLabel);
- await testSemanticScanDraftCompletion(bundle, runtimeLabel);
- for (const artifactWriter of [false, true]) {
- await testLargeScanDraftCheckpoints(bundle, runtimeLabel, artifactWriter);
- }
- await testCompactDiffScanCompletion(bundle, runtimeLabel);
- await testDiscoveryWorkerToolList(bundle);
- await testReducerWorkerToolList(bundle);
+ await test(`${label}: parent, discovery, and reducer tool registration and worker writes`, async () => {
+ await testParentToolList(bundle);
+ await testDiscoveryWorkerToolList(bundle);
+ await testReducerWorkerToolList(bundle);
+ });
+ }
+ await test("shipped: claimed parent operations", () =>
+ testClaimedParentArtifactOperations(shipped, "shipped"));
+ await test("shipped: semantic scan draft completion", () =>
+ testSemanticScanDraftCompletion(shipped, "shipped"));
+ for (const artifactWriter of [false, true]) {
+ await test(`shipped: large ${artifactWriter ? "worker" : "parent"} draft checkpoints`, () =>
+ testLargeScanDraftCheckpoints(shipped, "shipped", artifactWriter));
}
+ await test("shipped: compact diff scan completion", () =>
+ testCompactDiffScanCompletion(shipped, "shipped"));
} finally {
await rm(temporaryRoot, { recursive: true, force: true });
}
diff --git a/plugins/codex-security/mcp-app/tests/test_coverage_provenance.ts b/plugins/codex-security/mcp-app/tests/test_coverage_provenance.ts
index aad77b53a..a74da9937 100644
--- a/plugins/codex-security/mcp-app/tests/test_coverage_provenance.ts
+++ b/plugins/codex-security/mcp-app/tests/test_coverage_provenance.ts
@@ -5,33 +5,20 @@ import path from "node:path";
import { test } from "node:test";
import {
publishCoverageFixture,
+ publishReceiptFixture,
readFixtureCoverage,
} from "./deep_scan_coverage_fixture.ts";
for (const resume of [false, true]) {
- for (const outcome of ["completion", "recovery", "no parent"]) {
- test(`resolved generic tasks survive ${resume ? "resumed" : "live"} ${outcome}`, async () => {
- const root = await mkdtemp(path.join(tmpdir(), "resolved-coverage-"));
- try {
- const { scanDir } = await publishCoverageFixture(root, "complete", {
- resume,
- firstCheckpointReceipt: "worker",
- sameAttemptCloseout: true,
- stopAfterDraft: outcome === "recovery",
- stopBeforeDraft: outcome === "no parent",
- });
- const coverage = await readFixtureCoverage(scanDir);
- assert.deepEqual(
- coverage.resolvedDeferred,
- coverage.reviews.map(({ workerId, attempt }) => ({
- id: `${workerId}-attempt-${attempt}-resolved-first-gap`,
- reason: "The same boundary is verified.",
- })),
- );
- } finally {
- await rm(root, { recursive: true, force: true });
- }
- });
+ for (const outcome of ["recovery", "no parent"]) {
+ test(`worker-local same-attempt closeout survives ${resume ? "resumed" : "live"} ${outcome}`, () =>
+ publishReceiptFixture({
+ resume,
+ firstCheckpointReceipt: "worker",
+ sameAttemptCloseout: true,
+ stopAfterDraft: outcome === "recovery",
+ stopBeforeDraft: outcome === "no parent",
+ }));
}
}
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_reducer_paging_eval.ts b/plugins/codex-security/mcp-app/tests/test_deep_reducer_paging_eval.ts
index 40f002119..4eea8c0c2 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_reducer_paging_eval.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_reducer_paging_eval.ts
@@ -17,7 +17,11 @@ for (const transport of ["stdio", "http"] as const) {
const { report, fixture } = await runReducerPagingEval({ root, transport });
assert.equal(report.realIpcErrorObserved, transport === "http");
assert.equal(report.stdioResponseErrorObserved, transport === "stdio");
- assert.ok(report.actualOversizedResponseBytes! > report.ipcFrameLimitBytes);
+ assert.equal(
+ report.responseLimitBytes,
+ (transport === "stdio" ? 16 : 64) * 1024 * 1024,
+ );
+ assert.ok(report.actualOversizedResponseBytes! > report.responseLimitBytes);
assert.ok(report.recoveryBudget < report.firstBudget);
assert.ok(report.successfulPages > 1);
assert.equal(report.referenceReads, 2);
@@ -26,6 +30,9 @@ for (const transport of ["stdio", "http"] as const) {
assert.equal(report.previousIdentityPreserved, true);
assert.equal(report.synthesizedHistoryPreserved, true);
+ // The trace and evidence graders are shared by both transports.
+ if (transport !== "stdio") return;
+
const trace = await readJsonLines(path.join(root, "tool-trace.jsonl"));
const rootPages = trace.filter(
(event) =>
@@ -41,7 +48,7 @@ for (const transport of ["stdio", "http"] as const) {
(event) =>
!(event.event === "response" && event.id === missingPage),
),
- report.ipcFrameLimitBytes,
+ report.responseLimitBytes,
),
/read every assigned-input page/,
);
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_publication_integration.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_publication_integration.ts
index b826f2f2f..8b07dfadf 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_publication_integration.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_publication_integration.ts
@@ -445,52 +445,48 @@ for (const [claimed, outputFailure] of [
});
}
-for (const complete of [false, true]) {
- test(`legacy terminal aggregate rejects late public drafts with complete=${complete}`, async (t) => {
- const fixture = await createFixture(t);
- const { run, store, call, runWorkbench } = fixture;
- await commitReducers(fixture, [1, 2], [highId, lowId]);
- const context = await createScanArtifactContext(run.scanId, runWorkbench, {
- requireRunning: true,
- });
- const draft: ScanDraftInput = {
- scanId: run.scanId,
- complete: true,
- findings: [],
- coverage,
- threatModel: { summary: "Selected aggregate" },
- };
- await assert.rejects(
- recordCodexSecurityScanDraftViaWorkbench(context, draft, async (args) => {
- await runWorkbench(args);
- throw new Error("Synthetic lost publication response");
- }),
- /lost publication response/,
- );
- const published = await snapshot(run);
- await recordCodexSecurityScanDraftViaWorkbench(
- context,
- draft,
- runWorkbench,
- );
- assert.deepEqual(await snapshot(run), published);
- await assertInterleavedProgressRetained(fixture);
- const terminal = await store.finish({
- scanId: run.scanId,
- reason: "saturated",
- manifestPath: path.join(run.scanDir, "scan-manifest.json"),
- omittedWorkerIds: [],
- });
- assert.equal(terminal.status, "succeeded");
- assert.equal(terminal.coordinatorGeneration, 1);
- const report = path.join(run.scanDir, "report.html");
- await mkdir(report);
- assertToolError(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- /report\.html/,
- );
- await rm(report, { recursive: true });
- const interrupted = await snapshot(run);
+test("legacy terminal aggregate rejects late public drafts with both complete flags", async (t) => {
+ const fixture = await createFixture(t);
+ const { run, store, call, runWorkbench } = fixture;
+ await commitReducers(fixture, [1, 2], [highId, lowId]);
+ const context = await createScanArtifactContext(run.scanId, runWorkbench, {
+ requireRunning: true,
+ });
+ const draft: ScanDraftInput = {
+ scanId: run.scanId,
+ complete: true,
+ findings: [],
+ coverage,
+ threatModel: { summary: "Selected aggregate" },
+ };
+ await assert.rejects(
+ recordCodexSecurityScanDraftViaWorkbench(context, draft, async (args) => {
+ await runWorkbench(args);
+ throw new Error("Synthetic lost publication response");
+ }),
+ /lost publication response/,
+ );
+ const published = await snapshot(run);
+ await recordCodexSecurityScanDraftViaWorkbench(context, draft, runWorkbench);
+ assert.deepEqual(await snapshot(run), published);
+ await assertInterleavedProgressRetained(fixture);
+ const terminal = await store.finish({
+ scanId: run.scanId,
+ reason: "saturated",
+ manifestPath: path.join(run.scanDir, "scan-manifest.json"),
+ omittedWorkerIds: [],
+ });
+ assert.equal(terminal.status, "succeeded");
+ assert.equal(terminal.coordinatorGeneration, 1);
+ const report = path.join(run.scanDir, "report.html");
+ await mkdir(report);
+ assertToolError(
+ await call("complete_codex_security_scan", { scanId: run.scanId }),
+ /report\.html/,
+ );
+ await rm(report, { recursive: true });
+ const interrupted = await snapshot(run);
+ for (const complete of [false, true]) {
assertToolError(
await call("record_codex_security_scan_draft", {
...partial(run, "late-progress"),
@@ -500,22 +496,21 @@ for (const complete of [false, true]) {
/terminal|publication/,
);
assert.deepEqual(await snapshot(run), interrupted);
- assertSuccess(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- );
- const completed = await snapshot(run);
- assert.deepEqual(
- JSON.parse(completed.files["coverage.json"]),
- JSON.parse(interrupted.files["coverage.json"]),
- );
- assert.equal(
- JSON.parse(completed.files["scan-manifest.json"]).scan.threatModel
- .summary,
- "Selected aggregate",
- );
- assert.deepEqual(completed.checkpoints, interrupted.checkpoints);
- });
-}
+ }
+ assertSuccess(
+ await call("complete_codex_security_scan", { scanId: run.scanId }),
+ );
+ const completed = await snapshot(run);
+ assert.deepEqual(
+ JSON.parse(completed.files["coverage.json"]),
+ JSON.parse(interrupted.files["coverage.json"]),
+ );
+ assert.equal(
+ JSON.parse(completed.files["scan-manifest.json"]).scan.threatModel.summary,
+ "Selected aggregate",
+ );
+ assert.deepEqual(completed.checkpoints, interrupted.checkpoints);
+});
for (const claimed of [false, true]) {
test(`partial drafts retain a capped publication with claimed=${claimed}`, async (t) => {
diff --git a/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts b/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
index 071a1c3e9..3a6ed7e4f 100644
--- a/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
+++ b/plugins/codex-security/mcp-app/tests/test_mcp_app_smoke.ts
@@ -105,39 +105,6 @@ assert.deepEqual(
],
"The MCP process and SDK workers must inherit Codex, external-provider, and Bedrock authentication, AWS credential-chain settings, runtime paths, and enterprise proxy/certificate configuration.",
);
-const serverSource = await readFile(path.join(mcpAppRoot, "server.ts"), "utf8");
-const authenticatedArtifactClaimSource = serverSource.match(
- /if \(\s*handoffClaimToken\s*&&\s*threadId[\s\S]*?authenticatedArtifactClaims\.set\(scanId,[\s\S]*?\n\s*\}/,
-)?.[0];
-assert.ok(
- authenticatedArtifactClaimSource,
- "Expected artifact claim authentication to require a handoff token and trusted request thread.",
-);
-assert.match(
- authenticatedArtifactClaimSource,
- /scan\?\.handoffStatus === "delivered"/,
- "Artifact claims must be cached only after durable handoff delivery.",
-);
-assert.match(
- authenticatedArtifactClaimSource,
- /scan\.handoffClaimToken === handoffClaimToken/,
- "Artifact claims must match the current persisted handoff token exactly.",
-);
-assert.match(
- authenticatedArtifactClaimSource,
- /scan\.continuationThreadId === threadId/,
- "Ordinary artifact claims must remain bound to the owning Codex thread.",
-);
-assert.match(
- authenticatedArtifactClaimSource,
- /recoveryHandoffClaimTokenSchema\.safeParse\(handoffClaimToken\)\.success/,
- "Cross-thread artifact recovery must require an exact recovery-token schema match.",
-);
-assert.match(
- await readFile(path.join(mcpAppRoot, "src", "workbench-client.ts"), "utf8"),
- /throw new Error\(error\.stderr\.trim\(\),\s*\{\s*cause:\s*error\s*\}\)/,
- "Workbench failures must preserve subprocess exit, signal, and stderr diagnostics.",
-);
const target = await temporaryDirectory("codex-security-target-");
const replacementTarget = await temporaryDirectory(
"codex-security-replacement-",
@@ -540,9 +507,7 @@ async function assertWorkspaceWorksWithoutUiCapability(scope: string) {
}
}
-async function assertHeadlessStandardScanWorksWithoutUiCapability(
- threadSource?: string,
-) {
+async function assertHeadlessStandardScanWorksWithoutUiCapability() {
const headlessStateDir = path.join(tmpdir(), randomUUID());
const headlessScanRoot = path.join(tmpdir(), randomUUID());
const headlessServer = startTestServer({
@@ -681,58 +646,75 @@ async function assertHeadlessStandardScanWorksWithoutUiCapability(
"threat_model",
);
- await writeCompletedContract(
- result.scanDir,
- result.scanId,
- result.scan.contract.target.requiredSnapshotDigest,
- );
- const completed = await headlessServer.callTool(9, {
- name: "complete_codex_security_scan",
- arguments: {
- scanId: result.scanId,
- handoffClaimToken: result.handoffClaimToken,
- },
- _meta: {
- "x-codex-turn-metadata": {
- thread_id: ownerThread,
- turn_id: "fixture-completion-turn",
- thread_source: threadSource,
- },
- },
- });
- assertNoError(completed);
- assert.equal(
- completed.result.structuredContent.scan.progress.status,
- "complete",
- );
- if (threadSource === "security_scan") {
- assert.deepEqual(
- completed.result.structuredContent.scan.usage.completion,
- {
- threadId: ownerThread,
- turnId: "fixture-completion-turn",
- finalized: false,
- },
+ for (const threadSource of [undefined, "security_scan"]) {
+ let scan = result;
+ if (threadSource) {
+ const usageScan = await headlessServer.callTool(83, {
+ name: "start_codex_security_standard_scan",
+ arguments: {
+ targetPath: target,
+ userContext: "Check completion usage.",
+ },
+ _meta: { "openai/threadId": ownerThread },
+ });
+ assertNoError(usageScan);
+ scan = usageScan.result.structuredContent;
+ assert.equal(scan.startDisposition, "created");
+ assert.notEqual(scan.scanId, result.scanId);
+ }
+ await writeCompletedContract(
+ scan.scanDir,
+ scan.scanId,
+ scan.scan.contract.target.requiredSnapshotDigest,
);
- const finalizedUsage = await headlessServer.callTool(10, {
- name: "finalize_codex_security_scan_usage",
+ const completed = await headlessServer.callTool(threadSource ? 90 : 9, {
+ name: "complete_codex_security_scan",
arguments: {
- scanId: result.scanId,
- threadId: ownerThread,
- turnId: "fixture-completion-turn",
- turnStatus: "completed",
+ scanId: scan.scanId,
+ handoffClaimToken: scan.handoffClaimToken,
+ },
+ _meta: {
+ "x-codex-turn-metadata": {
+ thread_id: ownerThread,
+ turn_id: "fixture-completion-turn",
+ thread_source: threadSource,
+ },
},
});
- assertNoError(finalizedUsage);
- assert.deepEqual(
- finalizedUsage.result.structuredContent.scan.usage,
- completed.result.structuredContent.scan.usage,
- );
- } else {
+ assertNoError(completed);
assert.equal(
- completed.result.structuredContent.scan.usage.completion,
- undefined,
+ completed.result.structuredContent.scan.progress.status,
+ "complete",
);
+ if (threadSource === "security_scan") {
+ assert.deepEqual(
+ completed.result.structuredContent.scan.usage.completion,
+ {
+ threadId: ownerThread,
+ turnId: "fixture-completion-turn",
+ finalized: false,
+ },
+ );
+ const finalizedUsage = await headlessServer.callTool(10, {
+ name: "finalize_codex_security_scan_usage",
+ arguments: {
+ scanId: scan.scanId,
+ threadId: ownerThread,
+ turnId: "fixture-completion-turn",
+ turnStatus: "completed",
+ },
+ });
+ assertNoError(finalizedUsage);
+ assert.deepEqual(
+ finalizedUsage.result.structuredContent.scan.usage,
+ completed.result.structuredContent.scan.usage,
+ );
+ } else {
+ assert.equal(
+ completed.result.structuredContent.scan.usage.completion,
+ undefined,
+ );
+ }
}
} finally {
await headlessServer.stop();
@@ -1493,7 +1475,6 @@ try {
])
await assertWorkspaceWorksWithoutUiCapability(scope);
await assertHeadlessStandardScanWorksWithoutUiCapability();
- await assertHeadlessStandardScanWorksWithoutUiCapability("security_scan");
await assertDeepScanPersistsRetryableWorkerStartupError();
await assertUserInputFailureLogging();
if (process.platform !== "win32") {
@@ -3147,6 +3128,37 @@ try {
unclaimedContext.result.content[0].text,
/Claim the pending Codex Security scan handoff/,
);
+ const unattachedToken = randomUUID();
+ const unattachedClaim = await testServer.callTool(20180, {
+ name: "claim_codex_security_scan_handoff_delivery",
+ arguments: { claimToken: unattachedToken, scanId: canceledScanId },
+ });
+ assertNoError(unattachedClaim);
+ const unattachedContext = await testServer.callTool(20181, {
+ name: "get_codex_security_scan_context",
+ arguments: { handoffClaimToken: unattachedToken, scanId: canceledScanId },
+ _meta: { "openai/threadId": "fixture-thread" },
+ });
+ assertNoError(unattachedContext);
+ assert.equal(
+ unattachedContext.result.structuredContent.scan.handoffStatus,
+ "delivered",
+ );
+ assert.equal(
+ unattachedContext.result.structuredContent.scan.continuationThreadId,
+ null,
+ );
+ const unattachedRead = await testServer.callTool(20182, {
+ name: "list_codex_security_review_items",
+ arguments: { scanId: canceledScanId },
+ _meta: { "openai/threadId": "fixture-thread" },
+ });
+ assert.equal(unattachedRead.result.isError, true);
+ assert.match(
+ unattachedRead.result.content[0].text,
+ /current continuation claim/,
+ );
+
const rejectedWrongThreadCancel = await testServer.callTool(1169, {
name: "cancel_codex_security_scan",
arguments: { scanId: canceledScanId },
@@ -3233,6 +3245,16 @@ try {
.continuationThreadId,
"fixture-recovery-thread",
);
+ const malformedRecovery = await testServer.callTool(20170, {
+ name: "get_codex_security_scan_context",
+ arguments: {
+ handoffClaimToken: `${fallbackClaimToken}-extra`,
+ scanId: fallbackScanId,
+ },
+ _meta: { "openai/threadId": "fixture-replacement-recovery-thread" },
+ });
+ assert.equal(malformedRecovery.result.isError, true);
+ assert.match(malformedRecovery.result.content[0].text, /invalid/i);
const wrongRecoveryContext = await testServer.callTool(20171, {
name: "get_codex_security_scan_context",
arguments: {
@@ -3267,6 +3289,18 @@ try {
.handoffClaimToken,
undefined,
);
+ const recoveryArtifactRead = (id: number) =>
+ testServer.callTool(id, {
+ name: "list_codex_security_review_items",
+ arguments: { scanId: fallbackScanId },
+ _meta: { "openai/threadId": "fixture-replacement-recovery-thread" },
+ });
+ const beforeRecovery = await recoveryArtifactRead(20174);
+ assert.equal(beforeRecovery.result.isError, true);
+ assert.match(
+ beforeRecovery.result.content[0].text,
+ /current continuation claim/,
+ );
const recoveredThreadContext = await testServer.callTool(20172, {
name: "get_codex_security_scan_context",
arguments: {
@@ -3293,6 +3327,12 @@ try {
.handoffClaimToken,
undefined,
);
+ const afterRecovery = await recoveryArtifactRead(20175);
+ assert.equal(afterRecovery.result.isError, true);
+ assert.match(
+ afterRecovery.result.content[0].text,
+ /only available for Deep or diff scans/,
+ );
const fallbackAppAcknowledgement = await testServer.callTool(2014, {
name: "mark_codex_security_scan_handoff_delivered",
arguments: { claimToken: fallbackClaimToken, scanId: fallbackScanId },
diff --git a/plugins/codex-security/mcp-app/tests/test_retry_coverage_dispositions.ts b/plugins/codex-security/mcp-app/tests/test_retry_coverage_dispositions.ts
index 594b8f922..071cd7044 100644
--- a/plugins/codex-security/mcp-app/tests/test_retry_coverage_dispositions.ts
+++ b/plugins/codex-security/mcp-app/tests/test_retry_coverage_dispositions.ts
@@ -10,87 +10,90 @@ import {
for (const surfaceOnly of [false, true]) {
for (const resume of [false, true]) {
- for (const disposition of ["rejected", "not_applicable", "reported"]) {
+ for (const dispositions of [["rejected", "not_applicable"], ["reported"]]) {
for (const resolveOnRetry of [false, true]) {
- test(`${resume ? "resumed" : "live"} ${surfaceOnly ? "surface-only" : "deferred"} stopped recovery preserves ${resolveOnRetry ? "the later disposition" : "newer gaps"} after a ${disposition} retry`, async () => {
+ test(`${resume ? "resumed" : "live"} ${surfaceOnly ? "surface-only" : "deferred"} stopped recovery preserves ${resolveOnRetry ? "the later disposition" : "newer gaps"} after ${dispositions.join(" and ")} retries`, async () => {
const root = await mkdtemp(path.join(tmpdir(), "retry-disposition-"));
try {
+ const cases = dispositions.map((disposition) => ({
+ disposition,
+ candidateId: `candidate-${disposition}`,
+ label: `Retry boundary: ${disposition}`,
+ gapReasons: ["First", "Second"].map(
+ (boundary) =>
+ `${boundary} ${disposition} boundary needs proof.`,
+ ),
+ }));
const resolved = {
completeness: "complete",
- surfaces: [
- {
- id: "disposition",
- label: "Candidate disposition",
- candidateId: "candidate-1",
- disposition,
- receiptRefs: [],
- },
- ],
+ surfaces: cases.map(({ candidateId, disposition }) => ({
+ id: `disposition-${disposition}`,
+ label: `Disposition: ${disposition}`,
+ candidateId,
+ disposition,
+ receiptRefs: [],
+ })),
explicitExclusions: [],
deferred: [],
openQuestions: [],
};
const pending = {
completeness: "partial",
- surfaces: [
- {
- id: "follow-up",
- label: "Retry boundary review",
- candidateId: "candidate-1",
- disposition: "needs_follow_up",
- receiptRefs: [],
- },
- ],
+ surfaces: cases.flatMap(({ candidateId, disposition, label }) =>
+ (surfaceOnly ? ["first", "second"] : ["first"]).map(
+ (suffix) => ({
+ id: `follow-up-${disposition}-${suffix}`,
+ label,
+ candidateId,
+ disposition: "needs_follow_up",
+ receiptRefs: [],
+ }),
+ ),
+ ),
explicitExclusions: [],
- deferred: [
- "First boundary needs proof.",
- "Second boundary needs proof.",
- ].map((reason, index) => ({
- id: `retry-gap-${index}`,
- candidateId: "candidate-1",
- reason,
- surfaceIds: ["follow-up"],
- })),
+ deferred: surfaceOnly
+ ? []
+ : cases.flatMap(({ candidateId, disposition, gapReasons }) =>
+ gapReasons.map((reason, index) => ({
+ id: `retry-gap-${disposition}-${index}`,
+ candidateId,
+ reason,
+ surfaceIds: [`follow-up-${disposition}-first`],
+ })),
+ ),
openQuestions: [],
};
- if (surfaceOnly) {
- pending.deferred = [];
- pending.surfaces.push({
- ...pending.surfaces[0]!,
- id: "follow-up-second",
- });
- }
- const findings =
- disposition === "reported"
- ? [
- {
- ruleId: "synthetic.retained-boundary",
- title: "Synthetic boundary finding",
- summary: "A finding retained from an earlier review.",
- severity: {
- level: "high",
- score: 8.1,
- scoringSystem: "CVSS:3.1",
- },
- confidence: {
- level: "high",
- rationale: "Synthetic evidence.",
- },
- taxonomy: { category: "path-traversal", cwe: ["CWE-22"] },
- locations: [
- { path: "source.py", startLine: 1, endLine: 1 },
- ],
- remediation: "Review the synthetic boundary.",
- provenance: {
- source: "local_plugin",
- candidateId: "candidate-1",
- },
+ const findings = dispositions.includes("reported")
+ ? [
+ {
+ ruleId: "synthetic.retained-boundary",
+ title: "Synthetic boundary finding",
+ summary: "A finding retained from an earlier review.",
+ severity: {
+ level: "high",
+ score: 8.1,
+ scoringSystem: "CVSS:3.1",
+ },
+ confidence: {
+ level: "high",
+ rationale: "Synthetic evidence.",
+ },
+ taxonomy: { category: "path-traversal", cwe: ["CWE-22"] },
+ locations: [
+ { path: "source.py", startLine: 1, endLine: 1 },
+ ],
+ remediation: "Review the synthetic boundary.",
+ provenance: {
+ source: "local_plugin",
+ candidateId: "candidate-reported",
},
- ]
- : undefined;
+ },
+ ]
+ : undefined;
const { scanDir } = await publishCoverageFixture(root, "partial", {
stopBeforeDraft: true,
resume,
+ otherWorkerCandidateIds: cases.map((row) => row.candidateId),
retryCoverage: resolveOnRetry
? [pending, resolved]
: [resolved, pending],
@@ -98,9 +101,6 @@ for (const surfaceOnly of [false, true]) {
findings && (resolveOnRetry ? [[], findings] : [findings, []]),
});
const coverage = await readFixtureCoverage(scanDir);
- const retryGaps = coverage.deferred.filter((item) =>
- pending.deferred.some((gap) => gap.reason === item.reason),
- );
if (findings) {
const retained = JSON.parse(
await readFile(path.join(scanDir, "findings.json"), "utf8"),
@@ -108,37 +108,51 @@ for (const surfaceOnly of [false, true]) {
assert.equal(retained.findings.length, 1);
assert.equal(retained.findings[0].ruleId, findings[0].ruleId);
}
- assert.deepEqual(
- retryGaps.map((item) => item.reason),
- resolveOnRetry ? [] : pending.deferred.map((item) => item.reason),
- );
- assert.equal(
- coverage.surfaces.filter(
- (item) => item.label === "Retry boundary review",
- ).length,
- resolveOnRetry ? 0 : pending.surfaces.length,
- );
- assert.equal(
- coverage.surfaces.filter(
+ for (const {
+ candidateId,
+ disposition,
+ label,
+ gapReasons,
+ } of cases) {
+ const retryGaps = coverage.deferred.filter((item) =>
+ gapReasons.includes(item.reason),
+ );
+ assert.deepEqual(
+ retryGaps.map((item) => item.reason),
+ resolveOnRetry || surfaceOnly ? [] : gapReasons,
+ );
+ assert.equal(
+ coverage.surfaces.filter((row) => row.label === label).length,
+ resolveOnRetry ? 0 : surfaceOnly ? 2 : 1,
+ );
+ const dispositionRows = coverage.surfaces.filter(
(item) => item.disposition === disposition,
- ).length,
- resolveOnRetry || (surfaceOnly && disposition !== "reported")
- ? 1
- : 0,
- );
- assert.ok(
- coverage.deferred.some(
- (item) => item.reason === "Verify symbolic links.",
- ),
- "another worker's same-candidate gap remains independent",
- );
- for (const gap of retryGaps) {
+ );
assert.equal(
- coverage.surfaces.find(
- (surface) => surface.id === gap.surfaceIds[0],
- )?.label,
- "Retry boundary review",
+ dispositionRows.length,
+ resolveOnRetry || (surfaceOnly && disposition !== "reported")
+ ? 1
+ : 0,
+ );
+ for (const row of dispositionRows) {
+ assert.equal(row.provenance?.candidateId, candidateId);
+ }
+ assert.ok(
+ coverage.deferred.some(
+ (item) =>
+ item.reason === "Verify symbolic links." &&
+ item.provenance?.candidateId === candidateId,
+ ),
+ `another worker's gap for ${candidateId} remains independent`,
);
+ for (const gap of retryGaps) {
+ assert.equal(
+ coverage.surfaces.find(
+ (surface) => surface.id === gap.surfaceIds[0],
+ )?.label,
+ label,
+ );
+ }
}
} finally {
await rm(root, { recursive: true, force: true });
diff --git a/plugins/codex-security/mcp-app/tests/test_retry_coverage_receipts_namespaces.ts b/plugins/codex-security/mcp-app/tests/test_retry_coverage_receipts_namespaces.ts
index 868924474..3fb6d2956 100644
--- a/plugins/codex-security/mcp-app/tests/test_retry_coverage_receipts_namespaces.ts
+++ b/plugins/codex-security/mcp-app/tests/test_retry_coverage_receipts_namespaces.ts
@@ -13,49 +13,16 @@ for (const resume of [false, true]) {
resume,
}));
}
- }
-}
-
-for (const resume of [false, true]) {
- for (const outcome of ["completion", "recovery", "no parent"]) {
- for (const receiptSpelling of ["scan", "equivalent scan"] as const) {
- test(`receipt namespace survives ${resume ? "reconstruction" : "live retry"} and ${outcome} with ${receiptSpelling} spelling`, () =>
- publishReceiptFixture({
- receiptRetry: true,
- receiptSpelling,
- stopAfterDraft: outcome === "recovery",
- stopBeforeDraft: outcome === "no parent",
- resume,
- }));
- }
- }
-}
-for (const resume of [false, true]) {
- for (const outcome of ["completion", "recovery", "no parent"]) {
- for (const activeReceiptSpelling of ["scan", "equivalent scan"] as const) {
- test(`active receipt namespace survives ${resume ? "reconstruction" : "live retry"} and ${outcome} with ${activeReceiptSpelling} spelling`, () =>
- publishReceiptFixture({
- receiptRetry: true,
- activeReceiptSpelling,
- stopAfterDraft: outcome === "recovery",
- stopBeforeDraft: outcome === "no parent",
- resume,
- }));
- }
- }
-}
-
-for (const resume of [false, true]) {
- for (const outcome of ["completion", "recovery", "no parent"]) {
- for (const receiptSpelling of [
- "active scan",
- "equivalent active scan",
+ for (const [receiptSpelling, activeReceiptSpelling] of [
+ ["scan", "scan"],
+ ["active scan", "equivalent scan"],
] as const) {
- test(`linked archived receipts survive ${resume ? "reconstruction" : "live retry"} and ${outcome} with ${receiptSpelling} spelling`, () =>
+ test(`archived ${receiptSpelling} and current ${activeReceiptSpelling} receipts survive ${resume ? "reconstruction" : "live retry"} and ${outcome}`, () =>
publishReceiptFixture({
receiptRetry: true,
receiptSpelling,
+ activeReceiptSpelling,
stopAfterDraft: outcome === "recovery",
stopBeforeDraft: outcome === "no parent",
resume,
diff --git a/plugins/codex-security/mcp-app/tests/test_retry_coverage_receipts_shared.ts b/plugins/codex-security/mcp-app/tests/test_retry_coverage_receipts_shared.ts
index 0fa19383d..405e20890 100644
--- a/plugins/codex-security/mcp-app/tests/test_retry_coverage_receipts_shared.ts
+++ b/plugins/codex-security/mcp-app/tests/test_retry_coverage_receipts_shared.ts
@@ -11,29 +11,16 @@ for (const resume of [false, true]) {
stopBeforeDraft: outcome === "no parent",
resume,
}));
- }
-}
-for (const resume of [false, true]) {
- for (const outcome of ["completion", "recovery", "no parent"]) {
- for (const receiptSpelling of [
- "shared scan",
- "equivalent shared scan",
- ] as const) {
- test(`archived shared receipts survive ${resume ? "reconstruction" : "live retry"} and ${outcome} with ${receiptSpelling} spelling`, () =>
- publishReceiptFixture({
- receiptRetry: true,
- receiptSpelling,
- stopAfterDraft: outcome === "recovery",
- stopBeforeDraft: outcome === "no parent",
- resume,
- }));
- }
- }
-}
+ test(`archived shared receipts survive ${resume ? "reconstruction" : "live retry"} and ${outcome} with both spellings`, () =>
+ publishReceiptFixture({
+ receiptRetry: true,
+ receiptSpelling: "shared scan",
+ stopAfterDraft: outcome === "recovery",
+ stopBeforeDraft: outcome === "no parent",
+ resume,
+ }));
-for (const resume of [false, true]) {
- for (const outcome of ["completion", "recovery", "no parent"]) {
for (const sharedReceipt of [false, true]) {
test(`empty receipt survives ${resume ? "reconstruction" : "live retry"} and ${outcome} with ${sharedReceipt ? "shared" : "worker"} current evidence`, () =>
publishReceiptFixture({
@@ -45,25 +32,16 @@ for (const resume of [false, true]) {
resume,
}));
}
- for (const receiptSpelling of [
- "shared scan",
- "equivalent shared scan",
- ] as const) {
- test(`empty receipt survives ${resume ? "reconstruction" : "live retry"} and ${outcome} with archived ${receiptSpelling} evidence`, () =>
- publishReceiptFixture({
- receiptRetry: true,
- receiptSpelling,
- emptyReceipt: true,
- stopAfterDraft: outcome === "recovery",
- stopBeforeDraft: outcome === "no parent",
- resume,
- }));
- }
- }
-}
+ test(`empty receipt survives ${resume ? "reconstruction" : "live retry"} and ${outcome} with both archived shared spellings`, () =>
+ publishReceiptFixture({
+ receiptRetry: true,
+ receiptSpelling: "shared scan",
+ emptyReceipt: true,
+ stopAfterDraft: outcome === "recovery",
+ stopBeforeDraft: outcome === "no parent",
+ resume,
+ }));
-for (const resume of [false, true]) {
- for (const outcome of ["completion", "recovery", "no parent"]) {
test(`worker-local receipts win parent collisions during ${resume ? "reconstruction" : "live retry"} and ${outcome}`, () =>
publishReceiptFixture({
receiptRetry: true,
@@ -72,11 +50,7 @@ for (const resume of [false, true]) {
stopBeforeDraft: outcome === "no parent",
resume,
}));
- }
-}
-for (const resume of [false, true]) {
- for (const outcome of ["completion", "recovery", "no parent"]) {
test(`inherited shared receipts retain their owner across retry collisions during ${resume ? "reconstruction" : "live retry"} and ${outcome}`, () =>
publishReceiptFixture({
receiptRetry: true,
diff --git a/plugins/codex-security/mcp-app/tests/test_workbench_process.ts b/plugins/codex-security/mcp-app/tests/test_workbench_process.ts
index 494c93bcd..34b4a7e6e 100644
--- a/plugins/codex-security/mcp-app/tests/test_workbench_process.ts
+++ b/plugins/codex-security/mcp-app/tests/test_workbench_process.ts
@@ -114,7 +114,7 @@ try {
delete globalThis.workbenchProcessFixture;
}
-const { executeWorkbench } = await loadWorkbenchProcess();
+const { executeWorkbench, runWorkbench } = await loadWorkbenchProcess();
const { workbenchArgs } = await importSource(
path.join(import.meta.dirname, "../src/workbench-arguments.ts"),
);
@@ -397,14 +397,21 @@ await test("large saved context retains cancellation results and diagnostics", a
"canceled",
);
await assert.rejects(
- executeWorkbench(python, [
+ runWorkbench([
"cancel-scan",
"--scan-id",
"00000000-0000-4000-8000-000000000000",
]),
(error: unknown) => {
- assert.ok(error instanceof Error && "stderr" in error);
- assert.match(String(error.stderr), /Codex Security scan not found/);
+ assert.ok(error instanceof Error);
+ assert.match(error.message, /Codex Security scan not found/);
+ assert.ok(
+ error.cause instanceof Error &&
+ "stderr" in error.cause &&
+ "code" in error.cause,
+ );
+ assert.equal(error.message, String(error.cause.stderr).trim());
+ assert.ok(typeof error.cause.code === "number" && error.cause.code > 0);
return true;
},
);