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

refactor(mcp): simplify lifecycle and protocol test fixtures (#2186)

Michael D'Angelo47d7f0229598
diff --git a/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts b/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts
index 19a27dabb..c1a18ced4 100644
--- a/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts
+++ b/plugins/codex-security/mcp-app/src/deep-scan/coordinator.ts
@@ -108,7 +108,6 @@ export class DeepScanCoordinator {
private readonly cancellationReady = Promise.withResolvers<void>();
private cancellationPersistence?: {
promise: Promise<void>;
- resolve: () => void;
failure?: { error: unknown };
};
private started = false;
@@ -266,18 +265,12 @@ export class DeepScanCoordinator {
this.state.status === "interrupted"
)
return await this.settled();
- let resolve!: () => void;
- let reject!: (error: unknown) => void;
- const promise = new Promise<void>((resolvePromise, rejectPromise) => {
- resolve = resolvePromise;
- reject = rejectPromise;
- });
+ const { promise, resolve, reject } = Promise.withResolvers<void>();
// Cancellation callers share operation errors; terminal waiters inspect only
// persistence failures below. Handle a rejection even with no joined caller.
void promise.catch(() => {});
const persistence: NonNullable<typeof this.cancellationPersistence> = {
promise,
- resolve,
};
this.cancellationPersistence = persistence;
try {
@@ -324,7 +317,7 @@ export class DeepScanCoordinator {
} finally {
// Cleanup still inspects durable state and preserves results when the
// process lost a committed response, then reports the persistence failure.
- persistence.resolve();
+ resolve();
}
const settled = await this.settled();
if (persistence.failure) throw persistence.failure.error;
diff --git a/plugins/codex-security/mcp-app/tests/deep_scan_context_snapshot_cases.ts b/plugins/codex-security/mcp-app/tests/deep_scan_context_snapshot_cases.ts
index 26daaf94e..8eed702e6 100644
--- a/plugins/codex-security/mcp-app/tests/deep_scan_context_snapshot_cases.ts
+++ b/plugins/codex-security/mcp-app/tests/deep_scan_context_snapshot_cases.ts
@@ -1,3 +1,7 @@
+import {
+ CodexSdkWorkerExecutor,
+ fakeCodexFixture,
+} from "./deep_scan_executor_fixture.ts";
import assert from "node:assert/strict";
import { execFile } from "node:child_process";
import { promisify } from "node:util";
@@ -10,22 +14,13 @@ import { importModule } from "./import-module.ts";
import type { WorkbenchDeepScanStore as Store } from "../src/deep-scan/store.js";
import type { DeepScanWorkerRunner as Runner } from "../src/deep-scan/worker-runner.js";
import type { createDeepScanArtifacts as Artifacts } from "../src/deep-scan/artifacts.js";
-import type { DeepWorkerParentSandbox } from "../src/deep-scan/parent-sandbox.js";
-import type { CodexSdkWorkerExecutor as WorkerExecutor } from "../src/deep-scan/executor.js";
+import { trustedParentSandbox as parentSandbox } from "./support/fake-codex-fixture.ts";
import type {
CodexWorkerRequest,
DeepScanWorkerKind,
} from "../src/deep-scan/types.js";
-export async function testDeepScanContextSnapshots({
- CodexSdkWorkerExecutor,
- fakeCodexFixture,
- parentSandbox,
-}: {
- CodexSdkWorkerExecutor: typeof WorkerExecutor;
- fakeCodexFixture: () => Promise<{ root: string; executablePath: string }>;
- parentSandbox: DeepWorkerParentSandbox;
-}) {
+export async function testDeepScanContextSnapshots() {
const pluginRoot = fileURLToPath(new URL("../../", import.meta.url));
const {
WorkbenchDeepScanStore,
diff --git a/plugins/codex-security/mcp-app/tests/deep_scan_coordinator_fixture.ts b/plugins/codex-security/mcp-app/tests/deep_scan_coordinator_fixture.ts
index 85079ff15..1244530d1 100644
--- a/plugins/codex-security/mcp-app/tests/deep_scan_coordinator_fixture.ts
+++ b/plugins/codex-security/mcp-app/tests/deep_scan_coordinator_fixture.ts
@@ -93,6 +93,19 @@ export type StoreInput<Method extends keyof DeepScanStore> = Parameters<
DeepScanStore[Method]
>[0];
+export function pausePoint() {
+ const entered = Promise.withResolvers<void>();
+ const released = Promise.withResolvers<void>();
+ return {
+ entered: entered.promise,
+ release: released.resolve,
+ pause() {
+ entered.resolve();
+ return released.promise;
+ },
+ };
+}
+
export class FakeStore {
run: DeepScanRunState;
declare failProgressAt: number | undefined;
@@ -112,8 +125,7 @@ export class FakeStore {
replacementManifestBeforeFinishRejection: string | undefined = undefined;
iterationResponseGate?: PromiseWithResolvers<void>;
blockDiscoveryUpdate?: "failed" | "succeeded";
- discoveryBlocked = Promise.withResolvers<void>();
- discoveryGate = Promise.withResolvers<void>();
+ discoveryUpdate = pausePoint();
iterationCommitted = Promise.withResolvers<void>();
failNextTerminalGet = false;
publicationFailureMessages: string[] = [];
@@ -145,8 +157,7 @@ export class FakeStore {
update.kind === "discovery" &&
update.status === this.blockDiscoveryUpdate
) {
- this.discoveryBlocked.resolve();
- await this.discoveryGate.promise;
+ await this.discoveryUpdate.pause();
if (update.status === "succeeded" && this.run.status !== "running") {
throw new Error(
"Only a running Deep Scan can update orchestration state.",
@@ -529,10 +540,16 @@ type CoordinatorFinding = ReturnType<
provenance: { sourceFindingIds?: string[] };
};
-export function runCoordinator(...args: Parameters<typeof createCoordinator>) {
+export function startCoordinator(
+ ...args: Parameters<typeof createCoordinator>
+) {
const coordinator = createCoordinator(...args);
coordinator.start();
- return coordinator.wait(undefined, 5_000);
+ return coordinator;
+}
+
+export function runCoordinator(...args: Parameters<typeof createCoordinator>) {
+ return startCoordinator(...args).wait(undefined, 5_000);
}
export function recordingClock(sleeps: number[]): DeepScanClock {
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 4565bb8c9..4e13e9022 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
@@ -9,7 +9,6 @@ import { promisify } from "node:util";
import type { JsonObject } from "../src/types.js";
import type { CodexWorkerRequest } from "../src/deep-scan/types.js";
import { importModule } from "./import-module.ts";
-import { readJson } from "./support/json.ts";
import { temporaryDirectory } from "./support/temporary-directories.ts";
type FixtureRuntime = typeof import("../src/deep-scan/artifacts.js") &
diff --git a/plugins/codex-security/mcp-app/tests/deep_scan_executable_alias_cases.ts b/plugins/codex-security/mcp-app/tests/deep_scan_executable_alias_cases.ts
index 36e36f0fb..1a5f88a16 100644
--- a/plugins/codex-security/mcp-app/tests/deep_scan_executable_alias_cases.ts
+++ b/plugins/codex-security/mcp-app/tests/deep_scan_executable_alias_cases.ts
@@ -1,32 +1,17 @@
+import {
+ CodexSdkWorkerExecutor,
+ fakeCodexFixture,
+ bundledCodexSdkEnvironment,
+ assertReadOnlyWorkerPolicy,
+} from "./deep_scan_executor_fixture.ts";
import assert from "node:assert/strict";
import { mkdir, readFile, symlink, writeFile } from "node:fs/promises";
import path from "node:path";
-import type { DeepWorkerParentSandbox } from "../src/deep-scan/parent-sandbox.js";
-import type { CodexSdkWorkerExecutor as WorkerExecutor } from "../src/deep-scan/executor.js";
+import { trustedParentSandbox as parentSandbox } from "./support/fake-codex-fixture.ts";
import { readJson } from "./support/json.ts";
import { assertConfigOverrides } from "./assertions.ts";
-export async function testConcurrentWorkerExecutableAliases({
- CodexSdkWorkerExecutor,
- fakeCodexFixture,
- parentSandbox,
- bundledCodexSdkEnvironment,
- assertReadOnlyWorkerPolicy,
-}: {
- CodexSdkWorkerExecutor: typeof WorkerExecutor;
- fakeCodexFixture: () => Promise<{
- root: string;
- executablePath: string;
- markerPath: string;
- preflightMarkerPath: string;
- }>;
- parentSandbox: DeepWorkerParentSandbox;
- bundledCodexSdkEnvironment: (
- command: string,
- environment: Record<string, string>,
- ) => Record<string, string>;
- assertReadOnlyWorkerPolicy: (args: readonly string[]) => void;
-}) {
+export async function testConcurrentWorkerExecutableAliases() {
const saved = [
"CODEX_CLI_PATH",
"CODEX_HOME",
diff --git a/plugins/codex-security/mcp-app/tests/deep_scan_executor_fixture.ts b/plugins/codex-security/mcp-app/tests/deep_scan_executor_fixture.ts
new file mode 100644
index 000000000..217c5a1bd
--- /dev/null
+++ b/plugins/codex-security/mcp-app/tests/deep_scan_executor_fixture.ts
@@ -0,0 +1,132 @@
+import assert from "node:assert/strict";
+import { readFile } from "node:fs/promises";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+import type { CodexSdkWorkerExecutor as Executor } from "../src/deep-scan/executor.js";
+import type { CodexWorkerRequest } from "../src/deep-scan/types.js";
+import { assertConfigOverrides } from "./assertions.ts";
+import { importModule, importSource } from "./import-module.ts";
+import { createFakeCodexFixture } from "./support/fake-codex-fixture.ts";
+import { createTemporaryDirectories } from "./support/temporary-directories.ts";
+
+const executorSource = new URL("../src/deep-scan/executor.ts", import.meta.url);
+export const {
+ bundledCodexSdkEnvironment,
+}: {
+ bundledCodexSdkEnvironment(
+ command: string,
+ environment: Record<string, string>,
+ ): Record<string, string>;
+} =
+ process.platform === "win32"
+ ? {}
+ : await importSource(
+ path.join(
+ import.meta.dirname,
+ "../../../../sdk/typescript/src/codex-sdk-environment.ts",
+ ),
+ );
+
+const executor = await importModule({
+ define: {
+ "import.meta.url": JSON.stringify(executorSource.href),
+ },
+ stdin: {
+ // Expose the environment snapshot only for tests.
+ contents: `${await readFile(executorSource, "utf8")}
+export { snapshotWorkerEnvironment, appendItemDiagnostic };
+export { isCodexCybersecurityPolicyRefusal } from "./errors.js";
+export { parseDeepScan } from "./response.js";`,
+ loader: "ts",
+ resolveDir: path.dirname(fileURLToPath(executorSource)),
+ sourcefile: fileURLToPath(executorSource),
+ },
+});
+
+export const {
+ resolveCodexPath,
+ snapshotWorkerEnvironment,
+ appendItemDiagnostic,
+ isCodexCybersecurityPolicyRefusal,
+ parseDeepScan,
+} = executor;
+export const CodexSdkWorkerExecutor: typeof Executor =
+ executor.CodexSdkWorkerExecutor;
+
+export const temporaryDirectories = createTemporaryDirectories(true);
+export const fakeCodexFixture = createFakeCodexFixture.bind(
+ null,
+ temporaryDirectories,
+);
+
+export function workerRequest(
+ promptPath: string,
+ workingDirectory: string,
+ options: Partial<CodexWorkerRequest> = {},
+): CodexWorkerRequest {
+ return {
+ kind: "discovery",
+ promptPath,
+ workingDirectory,
+ subagents: 0,
+ signal: new AbortController().signal,
+ ...options,
+ };
+}
+
+export function assertReadOnlyWorkerPolicy(args: readonly string[]) {
+ assert.equal(args.includes("--sandbox"), false);
+ assert.equal(args.includes("--add-dir"), false);
+ assert.deepEqual(
+ args.filter((arg: string) => arg.startsWith("approval_policy=")),
+ ['approval_policy="never"'],
+ );
+ assert.equal(
+ args.some((arg: string) => arg.includes("network_access")),
+ false,
+ );
+ const override = workerPermissionProfileOverride(args);
+ assertConfigOverrides(args, {
+ "permissions.codex_security_deep_scan_worker.extends": ":read-only",
+ "permissions.codex_security_deep_scan_worker.filesystem.:root": "read",
+ "permissions.codex_security_deep_scan_worker.network.enabled": false,
+ });
+ assert.equal(override.includes('"write"'), false);
+}
+
+export function workerPermissionProfileOverride(args: readonly string[]) {
+ assert.deepEqual(
+ args.filter((arg: string) => arg.startsWith("default_permissions=")),
+ ['default_permissions="codex_security_deep_scan_worker"'],
+ );
+ const overrides = args.filter((arg: string) =>
+ arg.startsWith("permissions.codex_security_deep_scan_worker="),
+ );
+ assert.equal(overrides.length, 1);
+ return overrides[0];
+}
+
+export function assertWorkerSubagentPolicy(
+ args: readonly string[],
+ subagents: number,
+ codeMode?: { enabled: boolean; excluded_tool_namespaces: string[] },
+) {
+ assertConfigOverrides(args, {
+ "features.multi_agent_v2.enabled": false,
+ "features.multi_agent_v2.max_concurrent_threads_per_session": subagents + 1,
+ "features.multi_agent": undefined,
+ "features.code_mode.excluded_tool_namespaces":
+ codeMode?.excluded_tool_namespaces,
+ ...(subagents === 0
+ ? {
+ "agents.max_threads": undefined,
+ "features.enable_fanout": false,
+ "features.code_mode.enabled": codeMode?.enabled,
+ }
+ : {
+ "agents.max_threads": subagents,
+ "features.enable_fanout": undefined,
+ }),
+ });
+ assert.equal(args.includes("features.multi_agent_v2.enabled=true"), false);
+}
diff --git a/plugins/codex-security/mcp-app/tests/deep_scan_lifecycle_cases.ts b/plugins/codex-security/mcp-app/tests/deep_scan_lifecycle_cases.ts
index f03b8d01c..adfeb0d41 100644
--- a/plugins/codex-security/mcp-app/tests/deep_scan_lifecycle_cases.ts
+++ b/plugins/codex-security/mcp-app/tests/deep_scan_lifecycle_cases.ts
@@ -1,8 +1,15 @@
+import type { TestContext } from "node:test";
import { readJson, writeJson } from "./support/json.ts";
import type { ScanDraftInput } from "../src/artifact-scan-draft.js";
import {
coordinatorFixture,
+ startCoordinator,
+ DeepScanCoordinatorRegistry,
FakeExecutor,
+ FakeStore,
+ pausePoint,
+ fixtureRun,
+ immediateClock,
runCoordinator,
} from "./deep_scan_coordinator_fixture.ts";
import assert from "node:assert/strict";
@@ -10,36 +17,17 @@ import { execFileSync } from "node:child_process";
import { randomUUID } from "node:crypto";
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
import path from "node:path";
-import { fileURLToPath } from "node:url";
-import { importModule } from "./import-module.ts";
+import { importCoordinatorServer } from "./import-module.ts";
import type { DeepScanRunState } from "../src/deep-scan/types.js";
-type LifecycleFixtures = Pick<
- typeof import("./deep_scan_coordinator_fixture.ts"),
- | "fixtureRun"
- | "FakeStore"
- | "FakeExecutor"
- | "createCoordinator"
- | "DeepScanCoordinatorRegistry"
- | "immediateClock"
->;
-
-export async function testDeepScanLifecycle({
- fixtureRun,
- FakeStore,
- FakeExecutor,
- createCoordinator,
- DeepScanCoordinatorRegistry,
- immediateClock,
-}: LifecycleFixtures) {
+export async function testDeepScanLifecycle(context: TestContext) {
const config = {
workers: 1,
subagents: 0,
stopAfterNoNew: 1,
maxDiscoveryRuns: 1,
};
- const errors = [];
- for (const test of [
+ for (const check of [
lateCancellationWaitsForPersistence,
failedParentCancellationStopsActiveWorker,
canceledPublicationWaitsForHeartbeat,
@@ -54,14 +42,8 @@ export async function testDeepScanLifecycle({
orphanWorkerDirectoriesAreNotReused,
ancestorNamesDoNotChooseWorkerSequence,
]) {
- try {
- await test();
- } catch (error) {
- errors.push(new Error(test.name, { cause: error }));
- }
+ await context.test(check.name, check);
}
- if (errors.length)
- throw new AggregateError(errors, "Deep Scan lifecycle regressions");
async function failedParentCancellationStopsActiveWorker() {
for (const terminalReadFails of [false, true]) {
@@ -127,7 +109,7 @@ export async function testDeepScanLifecycle({
}
}
- async function lateCancellationWaitsForPersistence() {
+ async function lateCancellationWaitsForPersistence(context: TestContext) {
const completedParentStatus: string = JSON.parse(
execFileSync(
process.env.PYTHON || "python3",
@@ -146,21 +128,15 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
saved = run_workbench(state, "get-scan", "--scan-id", scan_id)
print(json.dumps(saved["workspace"]["results"]["progress"]["status"]))
`,
- fileURLToPath(new URL("../../tests/", import.meta.url)),
+ path.join(import.meta.dirname, "../../tests"),
],
{ encoding: "utf8" },
),
);
- const applicationRoot = fileURLToPath(new URL("../", import.meta.url));
- const source = await readFile(
- new URL("../server.ts", import.meta.url),
- "utf8",
- );
let current: {
- registry: InstanceType<LifecycleFixtures["DeepScanCoordinatorRegistry"]>;
- store: InstanceType<LifecycleFixtures["FakeStore"]>;
- persistEntered: PromiseWithResolvers<void>;
- persistRelease: PromiseWithResolvers<void>;
+ registry: InstanceType<typeof DeepScanCoordinatorRegistry>;
+ store: FakeStore;
+ persistence: ReturnType<typeof pausePoint>;
rejectPersistence: boolean;
calls: string[];
readParent?: () => Promise<{ workspace: typeof current.workspace }>;
@@ -200,8 +176,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
.length > 1
)
throw new Error("synthetic duplicate cancellation persistence");
- current.persistEntered.resolve();
- await current.persistRelease.promise;
+ await current.persistence.pause();
if (current.rejectPersistence)
throw new Error("synthetic cancellation persistence failure");
current.store.run.status = "canceled";
@@ -210,33 +185,20 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
},
},
});
- const { createCodexSecurityServer } = await importModule({
- stdin: {
- contents: source
- .replace(
- "const deepScanCoordinators = new DeepScanCoordinatorRegistry();",
- "const deepScanCoordinators = globalThis.deepScanCancellationFixture.registry;",
- )
- .replace(
- 'import { PLUGIN_ROOT, runWorkbench, scanRoot } from "./src/workbench-client.js";',
- 'import { PLUGIN_ROOT, scanRoot } from "./src/workbench-client.js";\nconst runWorkbench = (...args) => globalThis.deepScanCancellationFixture.workbench(...args);',
- ),
- loader: "ts",
- resolveDir: applicationRoot,
- },
- define: {
- __dirname: JSON.stringify(applicationRoot),
- "import.meta.url": JSON.stringify(
- new URL("../server.ts", import.meta.url).href,
- ),
- },
- loader: { ".md": "text" },
- });
+ const { createCodexSecurityServer } = await importCoordinatorServer(
+ "deepScanCancellationFixture",
+ );
const server = createCodexSecurityServer();
- const cancel =
- server._registeredTools.cancel_codex_security_scan_from_app.handler;
- const fail = server._registeredTools.fail_codex_security_scan.handler;
- const failures = [];
+ const tools = server._registeredTools;
+ const cancel = (scanId: string) =>
+ tools.cancel_codex_security_scan_from_app.handler({ scanId });
+ const failExternally = (scanId: string) =>
+ tools.fail_codex_security_scan.handler(
+ { scanId, message: "synthetic external failure" },
+ {},
+ );
+ const parentStatus = (result: Awaited<ReturnType<typeof cancel>>) =>
+ result.structuredContent.workspace.results.progress.status;
try {
for (const stage of [
"final read",
@@ -260,534 +222,458 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
"onComplete external failure during cleanup",
]) {
for (const rejectPersistence of [false, true]) {
- const fixture = await fixtureRun(config);
- fixture.run.coordinatorGeneration = 1;
- const store = new FakeStore(fixture.run);
- const registry = new DeepScanCoordinatorRegistry();
- const entered = Promise.withResolvers<void>();
- const release = Promise.withResolvers<void>();
- const persistEntered = Promise.withResolvers<void>();
- const persistRelease = Promise.withResolvers<void>();
- const failureEntered = Promise.withResolvers<void>();
- const failureRelease = Promise.withResolvers<void>();
- const failureSaved = Promise.withResolvers<void>();
- const admissionEntered = Promise.withResolvers<void>();
- const admissionRelease = Promise.withResolvers<void>();
- const heartbeatRead = Promise.withResolvers<void>();
- const heartbeatRelease = Promise.withResolvers<void>();
- let publications = 0;
- let cancellation: ReturnType<typeof cancel> | undefined;
- let repeatedCancellation: ReturnType<typeof cancel> | undefined;
- let coordinator:
- | ReturnType<
- InstanceType<
- LifecycleFixtures["DeepScanCoordinatorRegistry"]
- >["start"]
- >
- | undefined;
- let gateHeartbeat = false;
- const concurrentFailure = stage.endsWith("external failure");
- const failureDuringCleanup =
- stage === "onComplete external failure during cleanup";
- const completedParent = stage.includes("completed parent");
- const completesDuringAdmission = stage.includes(
- "completes during admission",
+ await context.test(
+ `${stage}; persistence rejects=${rejectPersistence}`,
+ () => runStage(stage, rejectPersistence),
);
- const pendingFailureRead = stage.includes("pending-read");
- const unavailableRead = stage.startsWith("unavailable");
- const lostResponse =
- stage.startsWith("lost-response") || unavailableRead;
- const interrupted = stage === "observed interrupted";
- const stoppedStatus = interrupted ? "interrupted" : "failed";
- const observeFailure = stage === "observed failure" || interrupted;
- const publicationGate =
- stage === "lost-response failure" ||
- stage === "stale heartbeat failure";
- const durableFailure =
- stage === "persisted failure" ||
- observeFailure ||
- publicationGate ||
- lostResponse ||
- unavailableRead ||
- concurrentFailure ||
- failureDuringCleanup;
- current = {
- store,
- registry,
- persistEntered,
- persistRelease,
- rejectPersistence,
- calls: [],
- workspace: {
- setup: { submitted: true },
- results: {
- progress: {
- status: completedParent ? completedParentStatus : "running",
- },
- },
+ }
+ }
+ for (const joined of [false, true]) {
+ await context.test(`Admission read failure; joined=${joined}`, () =>
+ runAdmissionFailure(joined),
+ );
+ }
+ } finally {
+ await server.close();
+ Reflect.deleteProperty(globalThis, "deepScanCancellationFixture");
+ }
+
+ async function runStage(stage: string, rejectPersistence: boolean) {
+ const fixture = await fixtureRun(config);
+ fixture.run.coordinatorGeneration = 1;
+ const store = new FakeStore(fixture.run);
+ const registry = new DeepScanCoordinatorRegistry();
+ const entered = Promise.withResolvers<void>();
+ const release = Promise.withResolvers<void>();
+ const persistence = pausePoint();
+ const failureWrite = pausePoint();
+ const failureSaved = Promise.withResolvers<void>();
+ const admission = pausePoint();
+ const heartbeatOwnershipRead = pausePoint();
+ let publications = 0;
+ let cancellation: ReturnType<typeof cancel> | undefined;
+ let repeatedCancellation: ReturnType<typeof cancel> | undefined;
+ let coordinator:
+ | ReturnType<InstanceType<typeof DeepScanCoordinatorRegistry>["start"]>
+ | undefined;
+ let gateHeartbeat = false;
+ const concurrentFailure = stage.endsWith("external failure");
+ const failureDuringCleanup =
+ stage === "onComplete external failure during cleanup";
+ const completedParent = stage.includes("completed parent");
+ const completesDuringAdmission = stage.includes(
+ "completes during admission",
+ );
+ const pendingFailureRead = stage.includes("pending-read");
+ const unavailableRead = stage.startsWith("unavailable");
+ const lostResponse = stage.startsWith("lost-response") || unavailableRead;
+ const interrupted = stage === "observed interrupted";
+ const stoppedStatus = interrupted ? "interrupted" : "failed";
+ const observeFailure = stage === "observed failure" || interrupted;
+ const publicationGate =
+ stage === "lost-response failure" ||
+ stage === "stale heartbeat failure";
+ const durableFailure =
+ stage === "persisted failure" ||
+ observeFailure ||
+ publicationGate ||
+ lostResponse ||
+ unavailableRead ||
+ concurrentFailure ||
+ failureDuringCleanup;
+ current = {
+ store,
+ registry,
+ persistence,
+ rejectPersistence,
+ calls: [],
+ workspace: {
+ setup: { submitted: true },
+ results: {
+ progress: {
+ status: completedParent ? completedParentStatus : "running",
},
- };
- let admissionPaused = false;
- current.readParent = async () => {
- const workspace = structuredClone(current.workspace);
- if (workspace.results.progress.status === "failed")
- workspace.results.failureMessage = current.store.run.error;
- if (pendingFailureRead && !admissionPaused) {
- admissionPaused = true;
- admissionEntered.resolve();
- await admissionRelease.promise;
- if (unavailableRead)
- throw new Error("synthetic terminal state unavailable");
- }
- if (completesDuringAdmission)
- queueMicrotask(() => {
- current.workspace.results.progress.status =
- completedParentStatus;
- });
- return { workspace };
- };
+ },
+ },
+ };
+ let admissionPaused = false;
+ current.readParent = async () => {
+ const workspace = structuredClone(current.workspace);
+ if (workspace.results.progress.status === "failed")
+ workspace.results.failureMessage = current.store.run.error;
+ if (pendingFailureRead && !admissionPaused) {
+ admissionPaused = true;
+ await admission.pause();
+ if (unavailableRead)
+ throw new Error("synthetic terminal state unavailable");
+ }
+ if (completesDuringAdmission)
+ queueMicrotask(() => {
+ current.workspace.results.progress.status = completedParentStatus;
+ });
+ return { workspace };
+ };
+ if (
+ stage.startsWith("final read") ||
+ observeFailure ||
+ publicationGate ||
+ pendingFailureRead
+ ) {
+ const get = store.get.bind(store);
+ let paused = false;
+ store.get = async () => {
+ const snapshot = await get();
+ if (concurrentFailure && paused && !admissionPaused) {
+ admissionPaused = true;
+ await admission.pause();
+ }
+ if (gateHeartbeat) {
+ gateHeartbeat = false;
+ await heartbeatOwnershipRead.pause();
+ }
if (
- stage.startsWith("final read") ||
- observeFailure ||
- publicationGate ||
- pendingFailureRead
+ !paused &&
+ (observeFailure || pendingFailureRead
+ ? coordinator?.snapshot().status === stoppedStatus
+ : snapshot.status === "succeeded")
) {
- const get = store.get.bind(store);
- let paused = false;
- store.get = async () => {
- const snapshot = await get();
- if (concurrentFailure && paused && !admissionPaused) {
- admissionPaused = true;
- admissionEntered.resolve();
- await admissionRelease.promise;
- }
- if (gateHeartbeat) {
- gateHeartbeat = false;
- heartbeatRead.resolve();
- await heartbeatRelease.promise;
- }
- if (
- !paused &&
- (observeFailure || pendingFailureRead
- ? coordinator?.snapshot().status === stoppedStatus
- : snapshot.status === "succeeded")
- ) {
- paused = true;
- entered.resolve();
- await release.promise;
- }
- return snapshot;
- };
+ paused = true;
+ entered.resolve();
+ await release.promise;
}
- if (stage.startsWith("unpersisted"))
- store.fail = async () => {
- throw new Error("synthetic failure persistence unavailable");
- };
- if (publicationGate || lostResponse) {
- const fail = store.fail.bind(store);
- store.fail = async (...args) => {
- if (stage === "stale heartbeat failure") {
- failureEntered.resolve();
- await failureRelease.promise;
- }
- const result = await fail(...args);
- current.workspace.results.progress.status = "failed";
- if (lostResponse)
- throw new Error("synthetic committed failure response lost");
- return result;
- };
+ return snapshot;
+ };
+ }
+ if (stage.startsWith("unpersisted"))
+ store.fail = async () => {
+ throw new Error("synthetic failure persistence unavailable");
+ };
+ if (publicationGate || lostResponse) {
+ const fail = store.fail.bind(store);
+ store.fail = async (...args) => {
+ if (stage === "stale heartbeat failure") {
+ await failureWrite.pause();
}
- const executor = new FakeExecutor(
- observeFailure
- ? { blockDiscoveryAfterCalls: 0 }
- : stage.endsWith("failure")
- ? {
- nonRetryableDiscoveryMessage: "synthetic worker failure",
- }
- : {},
- );
- coordinator = registry.start({
- run: fixture.run,
- store,
- executor,
- pluginRoot: fixture.pluginRoot,
- clock: immediateClock,
- threadId:
- stage === "unpersisted unowned failure"
- ? undefined
- : "fixture-owner",
- heartbeatIntervalMs: 60_000,
- onComplete: async () => {
- if (stage.startsWith("onComplete")) {
- entered.resolve();
- await release.promise;
- }
- },
- onStopped: async () => {
- publications++;
- if (publicationGate) {
- entered.resolve();
- await release.promise;
- }
- },
- log: (event: { event: string }) => {
- if (
- failureDuringCleanup &&
- event.event === "coordinator_cancel_requested"
- )
- void fail(
- {
- scanId: fixture.run.scanId,
- message: "synthetic external failure",
- },
- {},
- ).then(() => failureSaved.resolve());
- if (
- stage.endsWith("microtask") &&
- event.event === "coordinator_cleanup_settled"
- )
- queueMicrotask(() => {
- cancellation = cancel({ scanId: fixture.run.scanId });
- void cancellation.catch(() => {});
- });
- if (
- !stage.endsWith("failure") ||
- event.event !== "coordinator_failed"
- )
- return;
- if (publicationGate || pendingFailureRead) {
- failureSaved.resolve();
- return;
+ const result = await fail(...args);
+ current.workspace.results.progress.status = "failed";
+ if (lostResponse)
+ throw new Error("synthetic committed failure response lost");
+ return result;
+ };
+ }
+ const executor = new FakeExecutor(
+ observeFailure
+ ? { blockDiscoveryAfterCalls: 0 }
+ : stage.endsWith("failure")
+ ? {
+ nonRetryableDiscoveryMessage: "synthetic worker failure",
}
- if (stage === "persisted failure")
- current.workspace.results.progress.status = "failed";
- entered.resolve();
- cancellation = cancel({ scanId: fixture.run.scanId });
- void cancellation.catch(() => {});
- },
- });
- const terminal = coordinator.settled();
- void terminal.catch(() => {});
- try {
- if (stage === "stale heartbeat failure") {
- await failureEntered.promise;
- gateHeartbeat = true;
- const heartbeat = coordinator.renewHeartbeat();
- await heartbeatRead.promise;
- failureRelease.resolve();
- await failureSaved.promise;
- heartbeatRelease.resolve();
- await heartbeat;
- }
- if (observeFailure) {
- await executor.discoveryStarted.promise;
- store.run.status = stoppedStatus;
- current.workspace.results.progress.status = "failed";
- await coordinator.renewHeartbeat();
- }
- await entered.promise;
- if (stage.startsWith("final read heartbeat"))
- await coordinator.renewHeartbeat();
- if (!stage.endsWith("microtask")) {
- cancellation ??= cancel({ scanId: fixture.run.scanId });
+ : {},
+ );
+ coordinator = registry.start({
+ run: fixture.run,
+ store,
+ executor,
+ pluginRoot: fixture.pluginRoot,
+ clock: immediateClock,
+ threadId:
+ stage === "unpersisted unowned failure" ? undefined : "fixture-owner",
+ heartbeatIntervalMs: 60_000,
+ onComplete: async () => {
+ if (stage.startsWith("onComplete")) {
+ entered.resolve();
+ await release.promise;
+ }
+ },
+ onStopped: async () => {
+ publications++;
+ if (publicationGate) {
+ entered.resolve();
+ await release.promise;
+ }
+ },
+ log: (event: { event: string }) => {
+ if (
+ failureDuringCleanup &&
+ event.event === "coordinator_cancel_requested"
+ )
+ void failExternally(fixture.run.scanId).then(() =>
+ failureSaved.resolve(),
+ );
+ if (
+ stage.endsWith("microtask") &&
+ event.event === "coordinator_cleanup_settled"
+ )
+ queueMicrotask(() => {
+ cancellation = cancel(fixture.run.scanId);
void cancellation.catch(() => {});
- }
- if (stage === "final read repeated cancellation") {
- await coordinator.renewHeartbeat();
- repeatedCancellation = cancel({ scanId: fixture.run.scanId });
- void repeatedCancellation.catch(() => {});
- }
- if (pendingFailureRead) {
- const admitted = await Promise.race([
- admissionEntered.promise.then(() => true),
- persistEntered.promise.then(() => false),
- cancellation.then(
- () => false,
- () => false,
- ),
- coordinator.wait(undefined, 25).then(() => false),
- ]);
- if (admitted) {
- if (concurrentFailure)
- await fail(
- {
- scanId: fixture.run.scanId,
- message: "synthetic external failure",
- },
- {},
- );
- repeatedCancellation = cancel({ scanId: fixture.run.scanId });
- void repeatedCancellation.catch(() => {});
- assert.equal(await coordinator.wait(undefined, 25), undefined);
- admissionRelease.resolve();
- }
- }
- if (failureDuringCleanup) await failureSaved.promise;
- release.resolve();
- if (completedParent || completesDuringAdmission) {
- persistRelease.resolve();
- assert.equal((await terminal).status, "succeeded");
- if (completesDuringAdmission)
- await assert.rejects(
- cancellation,
- /Only a running scan can be canceled/,
- );
- else
- assert.equal(
- (await cancellation).structuredContent.workspace.results
- .progress.status,
- completedParentStatus,
- );
- assert.equal(store.run.status, "succeeded");
- assert.equal(
- current.workspace.results.progress.status,
- completedParentStatus,
- );
- assert.equal(
- current.calls.filter((command) => command === "cancel-scan")
- .length,
- completesDuringAdmission ? 1 : 0,
- );
- continue;
- }
- if (durableFailure) {
- assert.equal((await terminal).status, stoppedStatus);
- if (unavailableRead)
- await assert.rejects(
- cancellation,
- /synthetic terminal state unavailable/,
- );
- else
- assert.equal(
- (await cancellation).structuredContent.workspace.results
- .progress.status,
- "failed",
- );
- assert.equal(current.calls.includes("cancel-scan"), false);
- if (concurrentFailure || failureDuringCleanup)
- assert.match(
- (await terminal).error,
- /synthetic external failure/,
- );
- assert.equal(publications, interrupted ? 0 : 1);
- if (unavailableRead)
- assert.match(
- (await terminal).error,
- /synthetic worker failure/,
- );
- if (repeatedCancellation) {
- if (unavailableRead)
- await assert.rejects(
- repeatedCancellation,
- /synthetic terminal state unavailable/,
- );
- else
- assert.equal(
- (await repeatedCancellation).structuredContent.workspace
- .results.progress.status,
- "failed",
- );
- }
- continue;
- }
- await persistEntered.promise;
- const waiting = await coordinator.wait(undefined, 25);
- persistRelease.resolve();
- if (stage.endsWith("microtask")) {
- assert.equal(
- waiting?.status,
- "succeeded",
- "settlement must finish before admitting another cancellation",
- );
- if (rejectPersistence)
- await assert.rejects(
- cancellation,
- /synthetic cancellation persistence failure/,
- );
- else
- assert.equal(
- (await cancellation).structuredContent.workspace.results
- .progress.status,
- "canceled",
- );
- assert.equal((await terminal).status, "succeeded");
- assert.equal(publications, 0);
- assert.deepEqual(current.calls, ["get-scan", "cancel-scan"]);
- continue;
- }
- assert.equal(
- waiting,
- undefined,
- "start waiter must await durable cancellation",
+ });
+ if (
+ !stage.endsWith("failure") ||
+ event.event !== "coordinator_failed"
+ )
+ return;
+ if (publicationGate || pendingFailureRead) {
+ failureSaved.resolve();
+ return;
+ }
+ if (stage === "persisted failure")
+ current.workspace.results.progress.status = "failed";
+ entered.resolve();
+ cancellation = cancel(fixture.run.scanId);
+ void cancellation.catch(() => {});
+ },
+ });
+ const terminal = coordinator.settled();
+ void terminal.catch(() => {});
+ try {
+ if (stage === "stale heartbeat failure") {
+ await failureWrite.entered;
+ gateHeartbeat = true;
+ const heartbeat = coordinator.renewHeartbeat();
+ await heartbeatOwnershipRead.entered;
+ failureWrite.release();
+ await failureSaved.promise;
+ heartbeatOwnershipRead.release();
+ await heartbeat;
+ }
+ if (observeFailure) {
+ await executor.discoveryStarted.promise;
+ store.run.status = stoppedStatus;
+ current.workspace.results.progress.status = "failed";
+ await coordinator.renewHeartbeat();
+ }
+ await entered.promise;
+ if (stage.startsWith("final read heartbeat"))
+ await coordinator.renewHeartbeat();
+ if (!stage.endsWith("microtask")) {
+ cancellation ??= cancel(fixture.run.scanId);
+ void cancellation.catch(() => {});
+ }
+ if (stage === "final read repeated cancellation") {
+ await coordinator.renewHeartbeat();
+ repeatedCancellation = cancel(fixture.run.scanId);
+ void repeatedCancellation.catch(() => {});
+ }
+ if (pendingFailureRead) {
+ const admitted = await Promise.race([
+ admission.entered.then(() => true),
+ persistence.entered.then(() => false),
+ cancellation.then(
+ () => false,
+ () => false,
+ ),
+ coordinator.wait(undefined, 25).then(() => false),
+ ]);
+ if (admitted) {
+ if (concurrentFailure) await failExternally(fixture.run.scanId);
+ repeatedCancellation = cancel(fixture.run.scanId);
+ void repeatedCancellation.catch(() => {});
+ assert.equal(await coordinator.wait(undefined, 25), undefined);
+ admission.release();
+ }
+ }
+ if (failureDuringCleanup) await failureSaved.promise;
+ release.resolve();
+ if (completedParent || completesDuringAdmission) {
+ persistence.release();
+ assert.equal((await terminal).status, "succeeded");
+ if (completesDuringAdmission)
+ await assert.rejects(
+ cancellation,
+ /Only a running scan can be canceled/,
);
- if (rejectPersistence) {
- await assert.rejects(
- cancellation,
- /synthetic cancellation persistence failure/,
- );
- await assert.rejects(
- terminal,
- /synthetic cancellation persistence failure/,
- );
- if (repeatedCancellation)
- await assert.rejects(
- repeatedCancellation,
- /synthetic cancellation persistence failure/,
- );
- assert.equal(publications, 0);
- } else {
- assert.equal(
- (await cancellation).structuredContent.workspace.results
- .progress.status,
- "canceled",
- );
- assert.equal((await terminal).status, "canceled");
- assert.equal(store.run.status, "canceled");
- assert.equal(
- publications,
- stage === "unpersisted unowned failure" ? 0 : 1,
- );
- if (repeatedCancellation)
- assert.equal(
- (await repeatedCancellation).structuredContent.workspace
- .results.progress.status,
- "canceled",
- );
- }
- assert.equal(current.calls[0], "get-scan");
+ else
assert.equal(
- current.calls.filter((command) => command === "cancel-scan")
- .length,
- 1,
- );
- } catch (error) {
- failures.push(
- new Error(
- `${stage}; persistence rejects=${rejectPersistence}: ${error instanceof Error ? error.message : String(error)}`,
- { cause: error },
- ),
+ parentStatus(await cancellation),
+ completedParentStatus,
);
- } finally {
- release.resolve();
- persistRelease.resolve();
- failureRelease.resolve();
- heartbeatRelease.resolve();
- admissionRelease.resolve();
- registry.shutdown("fixture cleanup");
- await Promise.allSettled([
- terminal,
- cancellation,
- repeatedCancellation,
- ]);
- }
- }
- }
- for (const joined of [false, true]) {
- const fixture = await fixtureRun(config);
- const store = new FakeStore(fixture.run);
- const registry = new DeepScanCoordinatorRegistry();
- const executor = new FakeExecutor({ blockDiscoveryAfterCalls: 0 });
- const readEntered = Promise.withResolvers<void>();
- const readRelease = Promise.withResolvers<void>();
- const persistEntered = Promise.withResolvers<void>();
- const persistRelease = Promise.withResolvers<void>();
- let reads = 0;
- current = {
- store,
- registry,
- persistEntered,
- persistRelease,
- rejectPersistence: false,
- calls: [],
- workspace: {
- setup: { submitted: true },
- results: { progress: { status: "running" } },
- },
- readParent: async () => {
- if (reads++ === 0) {
- readEntered.resolve();
- await readRelease.promise;
- throw new Error("synthetic temporary parent read failure");
- }
- return { workspace: structuredClone(current.workspace) };
- },
- };
- const coordinator = registry.start({
- run: fixture.run,
- store,
- executor,
- pluginRoot: fixture.pluginRoot,
- clock: immediateClock,
- threadId: "fixture-owner",
- heartbeatIntervalMs: 60_000,
- });
- const outcome = (operation: ReturnType<typeof cancel>) =>
- operation.then(
- () => undefined,
- (error: Error) => error,
+ assert.equal(store.run.status, "succeeded");
+ assert.equal(
+ current.workspace.results.progress.status,
+ completedParentStatus,
);
- let first: Promise<Error | undefined> | undefined;
- let second: Promise<Error | undefined> | undefined;
- let retry: ReturnType<typeof cancel> | undefined;
- try {
- await executor.discoveryStarted.promise;
- first = outcome(cancel({ scanId: fixture.run.scanId }));
- await readEntered.promise;
- if (joined) second = outcome(cancel({ scanId: fixture.run.scanId }));
- readRelease.resolve();
- assert.match(
- (await first)?.message ?? "",
- /temporary parent read failure/,
+ assert.equal(
+ current.calls.filter((command) => command === "cancel-scan").length,
+ completesDuringAdmission ? 1 : 0,
);
- if (second) {
- const result = await Promise.race([
- second,
- coordinator.wait(undefined, 25).then(() => undefined),
- ]);
- assert.match(
- result?.message ?? "",
- /temporary parent read failure/,
+ return;
+ }
+ if (durableFailure) {
+ assert.equal((await terminal).status, stoppedStatus);
+ if (unavailableRead)
+ await assert.rejects(
+ cancellation,
+ /synthetic terminal state unavailable/,
);
+ else assert.equal(parentStatus(await cancellation), "failed");
+ assert.equal(current.calls.includes("cancel-scan"), false);
+ if (concurrentFailure || failureDuringCleanup)
+ assert.match((await terminal).error, /synthetic external failure/);
+ assert.equal(publications, interrupted ? 0 : 1);
+ if (unavailableRead)
+ assert.match((await terminal).error, /synthetic worker failure/);
+ if (repeatedCancellation) {
+ if (unavailableRead)
+ await assert.rejects(
+ repeatedCancellation,
+ /synthetic terminal state unavailable/,
+ );
+ else
+ assert.equal(parentStatus(await repeatedCancellation), "failed");
}
- assert.equal(coordinator.snapshot().status, "running");
- assert.equal(await coordinator.wait(undefined, 25), undefined);
- retry = cancel({ scanId: fixture.run.scanId });
- void retry.catch(() => {});
- await persistEntered.promise;
- assert.equal(await coordinator.wait(undefined, 25), undefined);
- persistRelease.resolve();
+ return;
+ }
+ await persistence.entered;
+ const waiting = await coordinator.wait(undefined, 25);
+ persistence.release();
+ if (stage.endsWith("microtask")) {
assert.equal(
- (await retry).structuredContent.workspace.results.progress.status,
- "canceled",
+ waiting?.status,
+ "succeeded",
+ "settlement must finish before admitting another cancellation",
);
- assert.equal((await coordinator.settled()).status, "canceled");
- assert.equal(
- current.calls.filter((command) => command === "cancel-scan").length,
- 1,
+ if (rejectPersistence)
+ await assert.rejects(
+ cancellation,
+ /synthetic cancellation persistence failure/,
+ );
+ else assert.equal(parentStatus(await cancellation), "canceled");
+ assert.equal((await terminal).status, "succeeded");
+ assert.equal(publications, 0);
+ assert.deepEqual(current.calls, ["get-scan", "cancel-scan"]);
+ return;
+ }
+ assert.equal(
+ waiting,
+ undefined,
+ "start waiter must await durable cancellation",
+ );
+ if (rejectPersistence) {
+ await assert.rejects(
+ cancellation,
+ /synthetic cancellation persistence failure/,
);
- } catch (error) {
- failures.push(
- new Error(`Admission read failure; joined=${joined}`, {
- cause: error,
- }),
+ await assert.rejects(
+ terminal,
+ /synthetic cancellation persistence failure/,
);
- } finally {
- readRelease.resolve();
- persistRelease.resolve();
- registry.shutdown("fixture cleanup");
- await Promise.allSettled([
- first,
+ if (repeatedCancellation)
+ await assert.rejects(
+ repeatedCancellation,
+ /synthetic cancellation persistence failure/,
+ );
+ assert.equal(publications, 0);
+ } else {
+ assert.equal(parentStatus(await cancellation), "canceled");
+ assert.equal((await terminal).status, "canceled");
+ assert.equal(store.run.status, "canceled");
+ assert.equal(
+ publications,
+ stage === "unpersisted unowned failure" ? 0 : 1,
+ );
+ if (repeatedCancellation)
+ assert.equal(parentStatus(await repeatedCancellation), "canceled");
+ }
+ assert.equal(current.calls[0], "get-scan");
+ assert.equal(
+ current.calls.filter((command) => command === "cancel-scan").length,
+ 1,
+ );
+ } finally {
+ release.resolve();
+ persistence.release();
+ failureWrite.release();
+ heartbeatOwnershipRead.release();
+ admission.release();
+ registry.shutdown("fixture cleanup");
+ await Promise.allSettled([
+ terminal,
+ cancellation,
+ repeatedCancellation,
+ ]);
+ }
+ }
+
+ async function runAdmissionFailure(joined: boolean) {
+ const fixture = await fixtureRun(config);
+ const store = new FakeStore(fixture.run);
+ const registry = new DeepScanCoordinatorRegistry();
+ const executor = new FakeExecutor({ blockDiscoveryAfterCalls: 0 });
+ const admissionRead = pausePoint();
+ const persistence = pausePoint();
+ let reads = 0;
+ current = {
+ store,
+ registry,
+ persistence,
+ rejectPersistence: false,
+ calls: [],
+ workspace: {
+ setup: { submitted: true },
+ results: { progress: { status: "running" } },
+ },
+ readParent: async () => {
+ if (reads++ === 0) {
+ await admissionRead.pause();
+ throw new Error("synthetic temporary parent read failure");
+ }
+ return { workspace: structuredClone(current.workspace) };
+ },
+ };
+ const coordinator = registry.start({
+ run: fixture.run,
+ store,
+ executor,
+ pluginRoot: fixture.pluginRoot,
+ clock: immediateClock,
+ threadId: "fixture-owner",
+ heartbeatIntervalMs: 60_000,
+ });
+ const outcome = (operation: ReturnType<typeof cancel>) =>
+ operation.then(
+ () => undefined,
+ (error: Error) => error,
+ );
+ let first: Promise<Error | undefined> | undefined;
+ let second: Promise<Error | undefined> | undefined;
+ let retry: ReturnType<typeof cancel> | undefined;
+ try {
+ await executor.discoveryStarted.promise;
+ first = outcome(cancel(fixture.run.scanId));
+ await admissionRead.entered;
+ if (joined) second = outcome(cancel(fixture.run.scanId));
+ admissionRead.release();
+ assert.match(
+ (await first)?.message ?? "",
+ /temporary parent read failure/,
+ );
+ if (second) {
+ const result = await Promise.race([
second,
- retry,
- coordinator.settled(),
+ coordinator.wait(undefined, 25).then(() => undefined),
]);
+ assert.match(result?.message ?? "", /temporary parent read failure/);
}
+ assert.equal(coordinator.snapshot().status, "running");
+ assert.equal(await coordinator.wait(undefined, 25), undefined);
+ retry = cancel(fixture.run.scanId);
+ void retry.catch(() => {});
+ await persistence.entered;
+ assert.equal(await coordinator.wait(undefined, 25), undefined);
+ persistence.release();
+ assert.equal(parentStatus(await retry), "canceled");
+ assert.equal((await coordinator.settled()).status, "canceled");
+ assert.equal(
+ current.calls.filter((command) => command === "cancel-scan").length,
+ 1,
+ );
+ } finally {
+ admissionRead.release();
+ persistence.release();
+ registry.shutdown("fixture cleanup");
+ await Promise.allSettled([first, second, retry, coordinator.settled()]);
}
- if (failures.length)
- throw new AggregateError(failures, "Late cancellation responses");
- } finally {
- await server.close();
- Reflect.deleteProperty(globalThis, "deepScanCancellationFixture");
}
}
@@ -796,21 +682,16 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
fixture.run.coordinatorGeneration = 1;
const store = new FakeStore(fixture.run);
const executor = new FakeExecutor({ blockDiscoveryAfterCalls: 0 });
- const publishing = Promise.withResolvers<void>();
- const release = Promise.withResolvers<void>();
- const coordinator = createCoordinator(fixture, store, executor, {
+ const publication = pausePoint();
+ const coordinator = startCoordinator(fixture, store, executor, {
threadId: "fixture-owner",
heartbeatIntervalMs: 60_000,
- onStopped: async () => {
- publishing.resolve();
- await release.promise;
- },
+ onStopped: async () => await publication.pause(),
});
- coordinator.start();
await executor.discoveryStarted.promise;
store.run.status = "canceled";
coordinator.cancel("fixture cancellation");
- await publishing.promise;
+ await publication.entered;
try {
await coordinator.renewHeartbeat();
assert.equal(
@@ -819,7 +700,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
"heartbeat must not release waiters while saved results are being published",
);
} finally {
- release.resolve();
+ publication.release();
await coordinator.settled();
}
}
@@ -829,29 +710,21 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
const fixture = await fixtureRun(config);
fixture.run.coordinatorGeneration = 1;
const store = new FakeStore(fixture.run);
- const committed = Promise.withResolvers<void>();
- const release = Promise.withResolvers<void>();
+ const commitResponse = pausePoint();
const commit = store.recordIteration.bind(store);
store.recordIteration = async (input) => {
const response = await commit(input);
- committed.resolve();
- await release.promise;
+ await commitResponse.pause();
return response;
};
- const coordinator = createCoordinator(
- fixture,
- store,
- new FakeExecutor(),
- {
- threadId: "fixture-owner",
- heartbeatIntervalMs: 60_000,
- },
- );
- coordinator.start();
- await committed.promise;
+ const coordinator = startCoordinator(fixture, store, new FakeExecutor(), {
+ threadId: "fixture-owner",
+ heartbeatIntervalMs: 60_000,
+ });
+ await commitResponse.entered;
store.run.status = status;
await coordinator.renewHeartbeat();
- release.resolve();
+ commitResponse.release();
assert.equal((await coordinator.settled()).status, status);
}
}
@@ -863,7 +736,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
const executor = new FakeExecutor({ blockDiscoveryAfterCalls: 0 });
const observing = Promise.withResolvers<void>();
const replacement = Promise.withResolvers<DeepScanRunState>();
- const coordinator = createCoordinator(fixture, store, executor, {
+ const coordinator = startCoordinator(fixture, store, executor, {
threadId: "fixture-owner",
heartbeatIntervalMs: 60_000,
observeReplacement: async () => {
@@ -871,7 +744,6 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
return await replacement.promise;
},
});
- coordinator.start();
await executor.discoveryStarted.promise;
store.run.coordinatorGeneration = 2;
const heartbeat = coordinator.renewHeartbeat();
@@ -902,8 +774,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
const fixture = await fixtureRun(config);
fixture.run.coordinatorGeneration = 2;
const store = new FakeStore(fixture.run);
- const preparing = Promise.withResolvers<void>();
- const failProgress = Promise.withResolvers<void>();
+ const progressWrite = pausePoint();
const heartbeatReadStarted = Promise.withResolvers<void>();
const failureReadStarted = Promise.withResolvers<void>();
const heartbeatRead = Promise.withResolvers<DeepScanRunState>();
@@ -915,8 +786,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
let failureCalls = 0;
let observations = 0;
store.updateProgress = async () => {
- preparing.resolve();
- await failProgress.promise;
+ await progressWrite.pause();
throw new Error(
leaseLossConfirmed
? "Deep Scan coordinator lease belongs to a newer generation."
@@ -939,25 +809,19 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
"Deep Scan coordinator lease belongs to a newer generation.",
);
};
- const coordinator = createCoordinator(
- fixture,
- store,
- new FakeExecutor(),
- {
- threadId: "fixture-owner",
- heartbeatIntervalMs: 60_000,
- observeReplacement: async () => {
- observations += 1;
- observing.resolve();
- return await replacement.promise;
- },
+ const coordinator = startCoordinator(fixture, store, new FakeExecutor(), {
+ threadId: "fixture-owner",
+ heartbeatIntervalMs: 60_000,
+ observeReplacement: async () => {
+ observations += 1;
+ observing.resolve();
+ return await replacement.promise;
},
- );
- coordinator.start();
- await preparing.promise;
+ });
+ await progressWrite.entered;
const heartbeat = coordinator.renewHeartbeat();
await heartbeatReadStarted.promise;
- failProgress.resolve();
+ progressWrite.release();
await failureReadStarted.promise;
const newer = { ...store.run, coordinatorGeneration: 3 };
store.run = newer;
@@ -992,20 +856,18 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
fixture.run.coordinatorGeneration = 2;
const store = new FakeStore(fixture.run);
store.failProgressAt = 1;
- const failing = Promise.withResolvers<void>();
- const release = Promise.withResolvers<void>();
+ const failureWrite = pausePoint();
store.fail = async (_scanId, message) => {
const stale = {
...store.run,
status: "failed" as const,
error: message,
};
- failing.resolve();
- await release.promise;
+ await failureWrite.pause();
if (rejectFailure) throw new Error("fixture stale failure rejected");
return stale;
};
- const coordinator = createCoordinator(
+ const coordinator = startCoordinator(
fixture,
store,
new FakeExecutor(),
@@ -1019,8 +881,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
}),
},
);
- coordinator.start();
- await failing.promise;
+ await failureWrite.entered;
try {
if (status === "succeeded") {
store.run.coordinatorGeneration = 3;
@@ -1033,7 +894,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
coordinator.failExternallyPersisted("fixture external failure");
}
} finally {
- release.resolve();
+ failureWrite.release();
}
const terminal = await coordinator.settled();
assert.equal(terminal.status, status);
@@ -1081,19 +942,16 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
const fixture = await fixtureRun(config);
const store = new FakeStore(fixture.run);
const executor = new FakeExecutor({ blockDiscoveryAfterCalls: 0 });
- const publishing = Promise.withResolvers<void>();
- const release = Promise.withResolvers<void>();
+ const publication = pausePoint();
let publications = 0;
let cancellationSettled = false;
- const coordinator = createCoordinator(fixture, store, executor, {
+ const coordinator = startCoordinator(fixture, store, executor, {
threadId: "fixture-owner",
onStopped: async () => {
- publishing.resolve();
- await release.promise;
+ await publication.pause();
publications += 1;
},
});
- coordinator.start();
const terminal = coordinator.settled().catch((error: Error) => error);
await executor.discoveryStarted.promise;
const cancellation = coordinator
@@ -1109,7 +967,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
cancellationSettled = true;
return error;
});
- await publishing.promise;
+ await publication.entered;
await new Promise<void>((resolve) => setImmediate(resolve));
try {
assert.equal(
@@ -1118,7 +976,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
"lost response must wait for saved result publication",
);
} finally {
- release.resolve();
+ publication.release();
await terminal;
}
assert.match((await cancellation).message, /response lost/);
@@ -1135,21 +993,16 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
const fixture = await fixtureRun(config);
const store = new FakeStore(fixture.run);
const executor = new FakeExecutor({ blockDiscoveryAfterCalls: 0 });
- const publishing = Promise.withResolvers<void>();
- const release = Promise.withResolvers<void>();
+ const publication = pausePoint();
let cancellations = 0;
- const coordinator = createCoordinator(fixture, store, executor, {
+ const coordinator = startCoordinator(fixture, store, executor, {
threadId: "fixture-owner",
- onStopped: async () => {
- publishing.resolve();
- await release.promise;
- },
+ onStopped: async () => await publication.pause(),
});
- coordinator.start();
await executor.discoveryStarted.promise;
store.run.status = "failed";
coordinator.failExternallyPersisted("fixture worker failure");
- await publishing.promise;
+ await publication.entered;
const cancellation = coordinator.cancelAfterPersistence(
"late cancellation",
async () => {
@@ -1157,7 +1010,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
},
async () => ({ status: "running" }),
);
- release.resolve();
+ publication.release();
const result = await cancellation;
assert.equal(
cancellations,
@@ -1173,14 +1026,12 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
const store = new FakeStore(fixture.run);
store.failFinish = status === "failed";
store.rejectFailurePersistence = status === "failed";
- let coordinator: ReturnType<typeof createCoordinator>;
- const finalRead = Promise.withResolvers<void>();
- const release = Promise.withResolvers<void>();
+ let coordinator: ReturnType<typeof startCoordinator>;
+ const finalRead = pausePoint();
const originalGet = store.get.bind(store);
store.get = async (...args) => {
if (coordinator?.snapshot().status === status) {
- finalRead.resolve();
- await release.promise;
+ await finalRead.pause();
}
return await originalGet(...args);
};
@@ -1194,7 +1045,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
threadId: "fixture-owner",
onStopped: async () => {},
});
- await finalRead.promise;
+ await finalRead.entered;
let persisted = false;
let resolved = false;
const cancellation = registry
@@ -1217,7 +1068,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
false,
"wait for all coordinator cleanup before durable parent cancellation",
);
- release.resolve();
+ finalRead.release();
assert.equal(
await cancellation,
true,
@@ -1254,8 +1105,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
}
const store = new FakeStore(fixture.run);
const executor = new FakeExecutor();
- const coordinator = createCoordinator(fixture, store, executor);
- coordinator.start();
+ const coordinator = startCoordinator(fixture, store, executor);
const terminal = await coordinator.wait(undefined, 5_000);
assert.equal(terminal?.status, "succeeded", terminal?.error);
const next = String(BigInt(suffix) + 1n).padStart(4, "0");
@@ -1306,8 +1156,7 @@ with tempfile.TemporaryDirectory(prefix="deep-scan-completion-contract-") as roo
},
];
const store = new FakeStore(fixture.run);
- const coordinator = createCoordinator(fixture, store, new FakeExecutor());
- coordinator.start();
+ const coordinator = startCoordinator(fixture, store, new FakeExecutor());
const terminal = await coordinator.wait(undefined, 5_000);
assert.equal(terminal?.status, "succeeded", terminal?.error);
assert.ok(
diff --git a/plugins/codex-security/mcp-app/tests/deep_scan_worker_settings_cases.ts b/plugins/codex-security/mcp-app/tests/deep_scan_worker_settings_cases.ts
index 724e0b0a0..7329bd287 100644
--- a/plugins/codex-security/mcp-app/tests/deep_scan_worker_settings_cases.ts
+++ b/plugins/codex-security/mcp-app/tests/deep_scan_worker_settings_cases.ts
@@ -1,44 +1,22 @@
+import {
+ CodexSdkWorkerExecutor,
+ fakeCodexFixture,
+ workerRequest,
+ assertReadOnlyWorkerPolicy,
+ assertWorkerSubagentPolicy,
+} from "./deep_scan_executor_fixture.ts";
+import { restoreEnv } from "./support/fake-codex-source.ts";
import assert from "node:assert/strict";
import childProcess, { type SpawnOptions } from "node:child_process";
import { writeFile } from "node:fs/promises";
import { syncBuiltinESMExports } from "node:module";
import path from "node:path";
import { stringify as stringifyToml } from "smol-toml";
-import type { CodexSdkWorkerExecutor as Executor } from "../src/deep-scan/executor.js";
-import type { DeepWorkerParentSandbox } from "../src/deep-scan/parent-sandbox.js";
-import type { CodexWorkerRequest } from "../src/deep-scan/types.js";
-import { assertFlagPair } from "./assertions.ts";
+import { trustedParentSandbox as parentSandbox } from "./support/fake-codex-fixture.ts";
+import { assertFlagPair, assertConfigOverrides } from "./assertions.ts";
import { readJson } from "./support/json.ts";
-export async function testWorkerCyberAccessSettings({
- CodexSdkWorkerExecutor,
- fakeCodexFixture,
- parentSandbox,
- workerRequest,
- assertConfigOverrides,
- assertReadOnlyWorkerPolicy,
- assertWorkerSubagentPolicy,
- restoreEnv,
-}: {
- CodexSdkWorkerExecutor: typeof Executor;
- fakeCodexFixture: () => Promise<{ root: string; executablePath: string }>;
- parentSandbox: DeepWorkerParentSandbox;
- workerRequest: (
- promptPath: string,
- workingDirectory: string,
- options: Partial<CodexWorkerRequest>,
- ) => CodexWorkerRequest;
- assertConfigOverrides: (
- args: readonly string[],
- values: Record<string, string | number | boolean | undefined>,
- ) => void;
- assertReadOnlyWorkerPolicy: (args: readonly string[]) => void;
- assertWorkerSubagentPolicy: (
- args: readonly string[],
- subagents: number,
- ) => void;
- restoreEnv: (name: string, value: string | undefined) => void;
-}) {
+export async function testWorkerCyberAccessSettings() {
const cases: {
name: string;
configuration?: string;
diff --git a/plugins/codex-security/mcp-app/tests/import-module.ts b/plugins/codex-security/mcp-app/tests/import-module.ts
index 997e07d0a..6e552e316 100644
--- a/plugins/codex-security/mcp-app/tests/import-module.ts
+++ b/plugins/codex-security/mcp-app/tests/import-module.ts
@@ -1,9 +1,10 @@
import { build, type BuildOptions } from "esbuild";
import { createHash } from "node:crypto";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { readFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
-import { pathToFileURL } from "node:url";
+import { fileURLToPath, pathToFileURL } from "node:url";
const moduleDirectory = mkdtempSync(
join(tmpdir(), "codex-security-test-modules-"),
@@ -39,3 +40,29 @@ export async function importModule(options: BuildOptions) {
export function importSource(entryPoint: string, options: BuildOptions = {}) {
return importModule({ entryPoints: [entryPoint], ...options });
}
+
+export async function importCoordinatorServer(fixture: string) {
+ const applicationRoot = fileURLToPath(new URL("../", import.meta.url));
+ const server = new URL("../server.ts", import.meta.url);
+ const source = await readFile(server, "utf8");
+ return importModule({
+ stdin: {
+ contents: source
+ .replace(
+ "const deepScanCoordinators = new DeepScanCoordinatorRegistry();",
+ `const deepScanCoordinators = globalThis.${fixture}.registry;`,
+ )
+ .replace(
+ 'import { PLUGIN_ROOT, runWorkbench, scanRoot } from "./src/workbench-client.js";',
+ `import { PLUGIN_ROOT, scanRoot } from "./src/workbench-client.js";\nconst runWorkbench = (...args) => globalThis.${fixture}.workbench(...args);`,
+ ),
+ loader: "ts",
+ resolveDir: applicationRoot,
+ },
+ define: {
+ __dirname: JSON.stringify(applicationRoot),
+ "import.meta.url": JSON.stringify(server.href),
+ },
+ loader: { ".md": "text" },
+ });
+}
diff --git a/plugins/codex-security/mcp-app/tests/scan-draft-recovery-fixture.ts b/plugins/codex-security/mcp-app/tests/scan-draft-recovery-fixture.ts
index 8e9246e82..ebc44d028 100644
--- a/plugins/codex-security/mcp-app/tests/scan-draft-recovery-fixture.ts
+++ b/plugins/codex-security/mcp-app/tests/scan-draft-recovery-fixture.ts
@@ -183,6 +183,14 @@ export function draftFixture(root: string, layout: Layout) {
context,
draft,
findingsDraft,
+ findingsPath: path.join(
+ root,
+ layout === "worker" ? "result.json" : "findings.json",
+ ),
+ readComplete: async () =>
+ layout === "worker"
+ ? (await readJson(root, "result.json")).complete
+ : (await readJson(root, "scan-manifest.json")).scan.complete,
write,
writeReviewState: (...args: Parameters<typeof draft>) =>
write(draft(...args)),
diff --git a/plugins/codex-security/mcp-app/tests/support/fake-codex-source.ts b/plugins/codex-security/mcp-app/tests/support/fake-codex-source.ts
index ad8e9b62b..7bea514e5 100644
--- a/plugins/codex-security/mcp-app/tests/support/fake-codex-source.ts
+++ b/plugins/codex-security/mcp-app/tests/support/fake-codex-source.ts
@@ -222,9 +222,3 @@ export function restoreEnv(name: string, value: string | undefined) {
if (value === undefined) delete process.env[name];
else process.env[name] = value;
}
-
-export function nativeConfigOverrides(args: readonly string[]) {
- return args.flatMap((arg, index) =>
- arg === "--config" || arg === "-c" ? [args[index + 1]] : [],
- );
-}
diff --git a/plugins/codex-security/mcp-app/tests/support/rpc-server.ts b/plugins/codex-security/mcp-app/tests/support/rpc-server.ts
index d3b98d8d1..08b3a3aac 100644
--- a/plugins/codex-security/mcp-app/tests/support/rpc-server.ts
+++ b/plugins/codex-security/mcp-app/tests/support/rpc-server.ts
@@ -1,3 +1,4 @@
+import { assertNoError } from "../assertions.ts";
import { spawn } from "node:child_process";
import { EventEmitter, once } from "node:events";
import { consumeStreamLines, writeMessage } from "./streams.ts";
@@ -86,6 +87,8 @@ export function startRpcServer(
send({ id, method, params });
return waitForResponse(id);
};
+ const callTool = (id: number, params: Record<string, unknown>) =>
+ request(id, "tools/call", params);
return {
pid: child.pid,
notify: (method: string, params = {}) => send({ method, params }),
@@ -98,15 +101,21 @@ export function startRpcServer(
waitForMessage,
waitForResponse,
response,
- initialize(name: string, capabilities: Record<string, unknown> = {}) {
- return request(1, "initialize", {
+ async initialize(name: string, capabilities: Record<string, unknown> = {}) {
+ const response = await request(1, "initialize", {
protocolVersion: "2025-11-25",
capabilities,
clientInfo: { name, version: "0.1.0" },
});
+ assertNoError(response);
+ return response;
+ },
+ callTool,
+ async callSuccessfulTool(id: number, params: Record<string, unknown>) {
+ const response = await callTool(id, params);
+ assertNoError(response);
+ return response.result;
},
- callTool: (id: number, params: Record<string, unknown>) =>
- request(id, "tools/call", params),
stderrEvents: () => [...stderrEvents],
stderrText: () => stderrLines.join("\n"),
async stop() {
diff --git a/plugins/codex-security/mcp-app/tests/test_artifact_attack_path.ts b/plugins/codex-security/mcp-app/tests/test_artifact_attack_path.ts
index 61d074bac..a20e9a645 100644
--- a/plugins/codex-security/mcp-app/tests/test_artifact_attack_path.ts
+++ b/plugins/codex-security/mcp-app/tests/test_artifact_attack_path.ts
@@ -1,3 +1,4 @@
+import { after, test } from "node:test";
import { jsonLines, readJson, readJsonLines } from "./support/json.ts";
import { createTemporaryDirectories } from "./support/temporary-directories.ts";
import type { RawDiscoveryCandidate } from "../src/artifact-discovery.js";
@@ -17,20 +18,9 @@ const {
const scanId = "11111111-1111-4111-8111-111111111111";
const temporaryDirectories = createTemporaryDirectories(true);
-try {
- await testSchemaMatchesDocumentedAttackPathDecisions();
- await testEligibleRowsKeepDiscoveryValidationAndOrder();
- await testUnknownAndDuplicateCandidatesDoNotChangeLedger();
- await testMissingEligibleCandidateDoesNotChangeLedger();
- await testIneligibleCandidatesDoNotChangeLedger();
- await testDuplicateStoredCandidatesDoNotChangeLedger();
- await testMalformedLedgerIsNotReplaced();
- await testEmptyLedgerAcceptsAnEmptyBatch();
-} finally {
- await temporaryDirectories.cleanup();
-}
+after(() => temporaryDirectories.cleanup());
-async function testSchemaMatchesDocumentedAttackPathDecisions() {
+test(async function testSchemaMatchesDocumentedAttackPathDecisions() {
const schema = await readJson(
import.meta.dirname,
"../../schemas/tools/candidate-attack-paths.schema.json",
@@ -86,9 +76,9 @@ async function testSchemaMatchesDocumentedAttackPathDecisions() {
}).success,
false,
);
-}
+});
-async function testEligibleRowsKeepDiscoveryValidationAndOrder() {
+test(async function testEligibleRowsKeepDiscoveryValidationAndOrder() {
const fixture = await createFixture("eligible candidates", [
candidate("candidate-reportable", "reportable"),
candidate("candidate-suppressed", "suppressed"),
@@ -123,9 +113,9 @@ async function testEligibleRowsKeepDiscoveryValidationAndOrder() {
fixture.originalRows[3],
]);
assert.deepEqual(Object.keys(result), ["kind", "operation", "rowsWritten"]);
-}
+});
-async function testUnknownAndDuplicateCandidatesDoNotChangeLedger() {
+test(async function testUnknownAndDuplicateCandidatesDoNotChangeLedger() {
const fixture = await createFixture("unknown and duplicate", [
candidate("candidate-1", "reportable"),
]);
@@ -150,9 +140,9 @@ async function testUnknownAndDuplicateCandidatesDoNotChangeLedger() {
/repeats candidate candidate-1/,
);
await assertUnchanged(fixture);
-}
+});
-async function testMissingEligibleCandidateDoesNotChangeLedger() {
+test(async function testMissingEligibleCandidateDoesNotChangeLedger() {
const fixture = await createFixture("missing eligible candidate", [
candidate("candidate-reportable", "reportable"),
candidate("candidate-deferred", "deferred"),
@@ -170,9 +160,9 @@ async function testMissingEligibleCandidateDoesNotChangeLedger() {
/missing candidate-deferred/,
);
await assertUnchanged(fixture);
-}
+});
-async function testIneligibleCandidatesDoNotChangeLedger() {
+test(async function testIneligibleCandidatesDoNotChangeLedger() {
const fixture = await createFixture("ineligible candidates", [
candidate("candidate-suppressed", "suppressed"),
candidate("candidate-not-applicable", "not_applicable"),
@@ -190,9 +180,9 @@ async function testIneligibleCandidatesDoNotChangeLedger() {
);
await assertUnchanged(fixture);
}
-}
+});
-async function testDuplicateStoredCandidatesDoNotChangeLedger() {
+test(async function testDuplicateStoredCandidatesDoNotChangeLedger() {
const fixture = await createFixture("duplicate ledger rows", [
candidate("candidate-1", "reportable"),
candidate("candidate-1", "deferred"),
@@ -205,9 +195,9 @@ async function testDuplicateStoredCandidatesDoNotChangeLedger() {
/ledger repeats candidate candidate-1/,
);
await assertUnchanged(fixture);
-}
+});
-async function testMalformedLedgerIsNotReplaced() {
+test(async function testMalformedLedgerIsNotReplaced() {
const fixture = await createFixture("malformed ledger", []);
const malformed = "{not valid JSON}\n";
await writeFile(fixture.ledgerPath, malformed, "utf8");
@@ -218,9 +208,9 @@ async function testMalformedLedgerIsNotReplaced() {
}),
);
assert.equal(await readFile(fixture.ledgerPath, "utf8"), malformed);
-}
+});
-async function testEmptyLedgerAcceptsAnEmptyBatch() {
+test(async function testEmptyLedgerAcceptsAnEmptyBatch() {
const fixture = await createFixture("no candidates", []);
assert.deepEqual(
@@ -243,7 +233,7 @@ async function testEmptyLedgerAcceptsAnEmptyBatch() {
/scan-bound artifact context/,
);
assert.equal(await readFile(fixture.ledgerPath, "utf8"), "");
-}
+});
async function createFixture(
label: string,
diff --git a/plugins/codex-security/mcp-app/tests/test_artifact_foundation.ts b/plugins/codex-security/mcp-app/tests/test_artifact_foundation.ts
index aead4545b..45e673c00 100644
--- a/plugins/codex-security/mcp-app/tests/test_artifact_foundation.ts
+++ b/plugins/codex-security/mcp-app/tests/test_artifact_foundation.ts
@@ -1,3 +1,4 @@
+import { after, before, test } from "node:test";
import * as z from "zod/v4";
import { Ajv2020 } from "ajv/dist/2020.js";
import { readJson } from "./support/json.ts";
@@ -56,22 +57,13 @@ const context = {
};
const components = ["artifacts", "02_discovery", "candidate_ledger.jsonl"];
-try {
- await testSchemaSourceOfTruth();
- await testScanContext();
- await testWorkerStandardLayout();
- await testSafeJsonAndJsonl();
- await testAtomicReplacementAfterInterruptedWriter();
- await testAtomicReplacement();
- await testBoundedPagination();
- await testUnsafeArtifacts();
-} finally {
- await rm(fixture, { force: true, recursive: true });
-}
+after(() => rm(fixture, { force: true, recursive: true }));
+before(async () => {
+ await mkdir(context.root, { recursive: true });
+ await mkdir(context.repoRoot, { recursive: true });
+});
-console.log("Codex Security compact artifact foundation tests passed");
-
-async function testSchemaSourceOfTruth() {
+test(async function testSchemaSourceOfTruth() {
const common =
schemas.artifactSchemaDocuments["definitions/artifact-common"].$defs;
const validator = z.strictObject({
@@ -146,13 +138,11 @@ async function testSchemaSourceOfTruth() {
candidateId,
);
}
-}
+});
-async function testScanContext() {
+test(async function testScanContext() {
const root = path.join(fixture, "scan");
const repoRoot = path.join(fixture, "repository");
- await mkdir(root, { recursive: true });
- await mkdir(repoRoot, { recursive: true });
const scanId = "61a20957-1be8-4ccf-8de8-eab4061e8cc3";
const contract = {
target: {
@@ -231,9 +221,9 @@ async function testScanContext() {
})),
/requested scan identity/,
);
-}
+});
-async function testWorkerStandardLayout() {
+test(async function testWorkerStandardLayout() {
const root = path.join(fixture, "worker", "output");
const repoRoot = path.join(fixture, "repository");
await mkdir(root, { recursive: true });
@@ -275,32 +265,9 @@ async function testWorkerStandardLayout() {
);
assert.equal(context.layout, "worker");
assert.equal(context.scope, ".");
-}
-
-async function testAtomicReplacementAfterInterruptedWriter() {
- const destination = await io.artifactDestination(
- context,
- ["interrupted.json"],
- "interrupted artifact",
- );
- const child = spawn(process.execPath, [
- "-e",
- 'require("node:fs").openSync(process.argv[1], "wx", 0o600); process.stdout.write("locked"); setInterval(() => {}, 1000);',
- destination + ".lock",
- ]);
- await once(child.stdout, "data");
- child.kill("SIGKILL");
- await once(child, "close");
- await io.replaceArtifactText(destination, "recovered\n");
- assert.equal(await readFile(destination, "utf8"), "recovered\n");
- const values = ["a", "b", "c"].map((value) => value.repeat(32_000));
- await Promise.all(
- values.map((value) => io.replaceArtifactText(destination, value)),
- );
- assert.ok(values.includes(await readFile(destination, "utf8")));
-}
+});
-async function testSafeJsonAndJsonl() {
+test(async function testSafeJsonAndJsonl() {
const destination = await io.artifactDestination(
context,
components,
@@ -394,9 +361,32 @@ async function testSafeJsonAndJsonl() {
await chmod(destination, 0o600);
}
}
-}
+});
+
+test(async function testAtomicReplacementAfterInterruptedWriter() {
+ const destination = await io.artifactDestination(
+ context,
+ ["interrupted.json"],
+ "interrupted artifact",
+ );
+ const child = spawn(process.execPath, [
+ "-e",
+ 'require("node:fs").openSync(process.argv[1], "wx", 0o600); process.stdout.write("locked"); setInterval(() => {}, 1000);',
+ destination + ".lock",
+ ]);
+ await once(child.stdout, "data");
+ child.kill("SIGKILL");
+ await once(child, "close");
+ await io.replaceArtifactText(destination, "recovered\n");
+ assert.equal(await readFile(destination, "utf8"), "recovered\n");
+ const values = ["a", "b", "c"].map((value) => value.repeat(32_000));
+ await Promise.all(
+ values.map((value) => io.replaceArtifactText(destination, value)),
+ );
+ assert.ok(values.includes(await readFile(destination, "utf8")));
+});
-async function testAtomicReplacement() {
+test(async function testAtomicReplacement() {
const destination = await io.artifactDestination(
context,
components,
@@ -419,9 +409,9 @@ async function testAtomicReplacement() {
assert.deepEqual(await readdir(path.dirname(destination)), [
"candidate_ledger.jsonl",
]);
-}
+});
-async function testBoundedPagination() {
+test(async function testBoundedPagination() {
const rows = [
{ path: "./src/first.ts" },
{ path: "scope with spaces/café.ts" },
@@ -442,9 +432,9 @@ async function testBoundedPagination() {
() => io.paginateArtifactRows(rows, { cursor: "4" }, "review_items"),
/outside the available rows/,
);
-}
+});
-async function testUnsafeArtifacts() {
+test(async function testUnsafeArtifacts() {
for (const components of [
[],
["..", "outside.json"],
@@ -499,4 +489,4 @@ async function testUnsafeArtifacts() {
),
/safe regular directory|escaped|context/i,
);
-}
+});
diff --git a/plugins/codex-security/mcp-app/tests/test_artifact_inventory.ts b/plugins/codex-security/mcp-app/tests/test_artifact_inventory.ts
index 2c3f085eb..a4469b422 100644
--- a/plugins/codex-security/mcp-app/tests/test_artifact_inventory.ts
+++ b/plugins/codex-security/mcp-app/tests/test_artifact_inventory.ts
@@ -1,3 +1,4 @@
+import { after, test } from "node:test";
import { createTemporaryDirectories } from "./support/temporary-directories.ts";
import assert from "node:assert/strict";
import { execFile as nodeExecFile } from "node:child_process";
@@ -45,33 +46,9 @@ const EUC_JP_PERL_HEAD = Buffer.from(
"hex",
);
-try {
- await testSchemasAreBoundAndExact();
- await testPrepareUsesTheExistingStandardGenerator();
- if (!["win32", "darwin"].includes(process.platform))
- await testNonUtf8InventoryPaths();
- await testPrepareWithIgnoredTrackedFiles();
- await testPrepareExcludesGitMetadata();
- await testPrepareUsesOnlyAuthoritativeDiffChanges();
- await testPrepareIncludesPerlSourceWithMixedEncodings();
- await testPrepareIncludesStagedAndUnstagedChanges();
- await testInventoryChildPreservesSettingsAndCwd();
- if (process.platform !== "win32") await testInventoryChildPreservesRawPaths();
- await testInventoryChildFailuresPreserveOutput();
- await testWorkerReadsItsOwnBoundInventory();
- await testCursorDoesNotExceedInventory();
- await testEmptyInventoryIsValid();
- await testUnsafeInventoryRowsAreRejected();
- await testSymlinkedInventoryIsRejected();
- await testInventoryReadErrorsAreReported();
- await testWorkersCannotPrepareInventory();
- await testBoundScopeFailurePreservesPreviousInventory();
- await testInvalidDiffTargetPreservesPreviousInventory();
-} finally {
- await temporaryDirectories.cleanup();
-}
+after(() => temporaryDirectories.cleanup());
-async function testSchemasAreBoundAndExact() {
+test(async function testSchemasAreBoundAndExact() {
const scanId = "f84c8312-a602-4660-8e01-518a176cd75a";
const prepare = inventory.prepareReviewItemsInputSchema;
const parent = inventory.reviewItemsReaderInputSchema;
@@ -91,9 +68,9 @@ async function testSchemasAreBoundAndExact() {
assert.equal(parent.safeParse({ scanId, limit: 0 }).success, false);
assert.equal(parent.safeParse({ scanId, limit: 1001 }).success, false);
assert.equal(parent.safeParse({ scanId, cursor: "-1" }).success, false);
-}
+});
-async function testPrepareUsesTheExistingStandardGenerator() {
+test(async function testPrepareUsesTheExistingStandardGenerator() {
const fixture = await createFixture("standard repository");
// Sandbox writable roots can have empty .git placeholders above an ordinary directory.
await mkdir(path.join(fixture.root, ".git"));
@@ -190,209 +167,10 @@ async function testPrepareUsesTheExistingStandardGenerator() {
{ reviewItemsTotal: 1 },
);
assert.equal(await readFile(fixture.scanInventory, "utf8"), "-source.py\n");
-}
-
-async function testInventoryChildPreservesSettingsAndCwd() {
- const fixture = await createFixture("inventory child settings");
- await runGit(fixture.repoRoot, "init", "-q");
- await runGit(fixture.repoRoot, "commit", "--allow-empty", "-qm", "base");
- const baseRevision = await runGit(fixture.repoRoot, "rev-parse", "HEAD");
- await fixture.writeRepositoryFile("visible.py", "visible\n");
- await fixture.writeRepositoryFile("hidden.py", "hidden\n");
- const home = path.join(fixture.root, "selected home");
- const tools = path.join(fixture.root, "selected tools");
- await mkdir(home);
- await mkdir(tools);
- const ignores = path.join(fixture.root, "global-ignore");
- const config = path.join(fixture.root, "global-config");
- await writeFile(ignores, "hidden.py\n");
- await writeFile(
- config,
- `[core]\nexcludesFile = ${JSON.stringify(ignores)}\n`,
- );
- const marker = path.join(fixture.root, "child.jsonl");
- const preload = path.join(fixture.root, "preload.cjs");
- const names = [
- "HOME",
- "PATH",
- "GIT_CONFIG_GLOBAL",
- "NODE_OPTIONS",
- "CODEX_MCP_NODE_PATH",
- "LD_LIBRARY_PATH",
- "DYLD_LIBRARY_PATH",
- ];
- await writeFile(
- preload,
- `require('node:fs').appendFileSync(${JSON.stringify(marker)}, JSON.stringify({pid:process.pid,node:process.execPath,cwd:process.cwd(),argv:process.argv,env:Object.fromEntries(${JSON.stringify(names)}.map(name=>[name,process.env[name]]))})+'\\n');`,
- );
- const saved = names.map((name) => [name, process.env[name]] as const);
- const selected = {
- HOME: home,
- PATH: tools + path.delimiter + (process.env.PATH ?? ""),
- GIT_CONFIG_GLOBAL: config,
- NODE_OPTIONS: `--require ${JSON.stringify(path.relative(process.cwd(), preload).split(path.sep).join("/"))}`,
- CODEX_MCP_NODE_PATH: path.join(fixture.root, "unused-node"),
- LD_LIBRARY_PATH: path.join(fixture.root, "selected libraries"),
- DYLD_LIBRARY_PATH: path.join(fixture.root, "selected dylibs"),
- };
- Object.assign(process.env, selected);
- try {
- const context = {
- ...fixture.scan,
- mode: "diff",
- targetContract: {
- diffTarget: {
- kind: "working_tree",
- baseRevision,
- headRevision: "HEAD",
- },
- },
- };
- assert.deepEqual(await inventory.prepareCodexSecurityReviewItems(context), {
- reviewItemsTotal: 1,
- });
- assert.deepEqual(await inventory.listCodexSecurityReviewItems(context), {
- items: [{ path: "visible.py" }],
- });
- const records = (await readFile(marker, "utf8"))
- .trim()
- .split("\n")
- .map((line) => JSON.parse(line));
- const child = records.find(
- (record) =>
- record.argv[1] ===
- path.join(fixture.scan.pluginRoot, "mcp", "helpers.mjs"),
- );
- assert.ok(child);
- assert.notEqual(child.pid, process.pid);
- assert.equal(child.node, process.execPath);
- assert.equal(child.cwd, process.cwd());
- assert.deepEqual(child.env, selected);
- for (const [name, value] of Object.entries(selected))
- assert.equal(process.env[name], value);
- } finally {
- for (const [name, value] of saved) {
- if (value === undefined) delete process.env[name];
- else process.env[name] = value;
- }
- }
-}
+});
-async function testInventoryChildPreservesRawPaths() {
- const fixture = await createFixture("inventory raw child paths");
- await runGit(fixture.repoRoot, "init", "-q");
- await runGit(fixture.repoRoot, "commit", "--allow-empty", "-qm", "base");
- const baseRevision = await runGit(fixture.repoRoot, "rev-parse", "HEAD");
- await fixture.writeRepositoryFile("visible.py", "visible\n");
- await fixture.writeRepositoryFile("hidden.py", "hidden\n");
- // APFS requires valid UTF-8 names; Linux also permits undecodable bytes.
- const suffix =
- process.platform === "darwin" ? Buffer.from("雪") : Buffer.from([0xff]);
- const suffixText = process.platform === "darwin" ? "雪" : "\udcff";
- const rawPath = (name: string) =>
- Buffer.concat([Buffer.from(path.join(fixture.root, name)), suffix]);
- const repo = rawPath("repository-");
- await rename(fixture.repoRoot, repo);
- const ignore = path.join(fixture.root, "global-ignore");
- await writeFile(ignore, "hidden.py\n");
- const config = rawPath("global-config-");
- await writeFile(config, `[core]\nexcludesFile = ${JSON.stringify(ignore)}\n`);
- const git = rawPath("selected-git-");
- await writeFile(git, '#!/bin/sh\nexec git "$@"\n', { mode: 0o700 });
- const context = {
- ...fixture.scan,
- repoRoot: path.join(fixture.root, "repository-") + suffixText,
- mode: "diff",
- targetContract: {
- diffTarget: { kind: "working_tree", baseRevision, headRevision: "HEAD" },
- },
- };
- const marker = path.join(fixture.root, "child.json");
- const preload = path.join(fixture.root, "preload.cjs");
- const loaderSettings = {
- LD_LIBRARY_PATH: path.join(fixture.root, "selected libraries"),
- DYLD_LIBRARY_PATH: path.join(fixture.root, "selected dylibs"),
- };
- await writeFile(
- preload,
- `const fs = require('node:fs'); fs.writeFileSync(${JSON.stringify(marker)}, JSON.stringify({stdin:fs.readFileSync(0).length,env:Object.fromEntries(${JSON.stringify(Object.keys(loaderSettings))}.map(name=>[name,process.env[name]]))}));`,
- );
- const driver = path.join(fixture.root, "prepare.mjs");
- await build({
- stdin: {
- contents: `import { prepareCodexSecurityReviewItems } from ${JSON.stringify(path.resolve(import.meta.dirname, "../src/artifact-inventory.ts"))}; Object.assign(process.env, ${JSON.stringify({ ...loaderSettings, NODE_OPTIONS: `--require ${JSON.stringify(preload)}` })}); console.log(JSON.stringify(await prepareCodexSecurityReviewItems(${JSON.stringify(context)})));`,
- loader: "ts",
- resolveDir: import.meta.dirname,
- },
- bundle: true,
- platform: "node",
- format: "esm",
- outfile: driver,
- define: {
- "import.meta.url": JSON.stringify(
- new URL(
- "../../../../sdk/typescript/_bundled_plugin/mcp/helpers.mjs",
- import.meta.url,
- ).href,
- ),
- },
- });
- const octal = (value: Buffer) =>
- [...value]
- .map((byte) => `\\0${byte.toString(8).padStart(3, "0")}`)
- .join("");
- const { stdout } = await execFile(
- "/bin/sh",
- [
- "-c",
- [
- // Raw environment bytes are valid on macOS even though APFS names are UTF-8.
- 'HOME=$(printf "/fixture/home-\\377"); export HOME',
- `GIT_CONFIG_GLOBAL=$(printf '%b' '${octal(config)}'); export GIT_CONFIG_GLOBAL`,
- `CODEX_SECURITY_GIT=$(printf '%b' '${octal(git)}'); export CODEX_SECURITY_GIT`,
- 'exec "$1" "$2"',
- ].join("\n"),
- "inventory-fixture",
- process.execPath,
- driver,
- ],
- { encoding: "utf8" },
- );
- assert.deepEqual(JSON.parse(stdout), { reviewItemsTotal: 1 });
- assert.equal(await readFile(fixture.scanInventory, "utf8"), "visible.py\n");
- assert.deepEqual(JSON.parse(await readFile(marker, "utf8")), {
- stdin: 0,
- env: loaderSettings,
- });
-}
-
-async function testInventoryChildFailuresPreserveOutput() {
- for (const signal of process.platform === "win32" ? [false] : [false, true]) {
- const fixture = await createFixture("inventory child failure");
- const pluginRoot = path.join(fixture.root, "failing plugin");
- await mkdir(path.join(pluginRoot, "mcp"), { recursive: true });
- await writeFile(
- path.join(pluginRoot, "mcp", "helpers.mjs"),
- signal
- ? 'process.kill(process.pid, "SIGTERM");'
- : 'process.stderr.write("synthetic inventory failure\\n"); process.exitCode = 23;',
- );
- await writeInventory(fixture.scanInventory, "previous.py\n");
- await assert.rejects(
- inventory.prepareCodexSecurityReviewItems({
- ...fixture.scan,
- pluginRoot,
- }),
- signal ? /SIGTERM/u : /synthetic inventory failure/u,
- );
- assert.equal(
- await readFile(fixture.scanInventory, "utf8"),
- "previous.py\n",
- );
- }
-}
-
-async function testNonUtf8InventoryPaths() {
+test(async function testNonUtf8InventoryPaths(t) {
+ if (["win32", "darwin"].includes(process.platform)) return t.skip();
const fixture = await createFixture("non-UTF-8 repository names");
const rawPath = Buffer.concat([
Buffer.from(path.join(fixture.repoRoot, "name-")),
@@ -424,9 +202,9 @@ async function testNonUtf8InventoryPaths() {
assert.deepEqual(await inventory.listCodexSecurityReviewItems(fixture.scan), {
items: [{ path: "./name-�.ts" }],
});
-}
+});
-async function testPrepareWithIgnoredTrackedFiles() {
+test(async function testPrepareWithIgnoredTrackedFiles() {
const fixture = await createFixture("ignored tracked files");
await runGit(fixture.repoRoot, "init", "-q");
await fixture.writeRepositoryFile(".gitignore", "-generated/\n");
@@ -477,9 +255,9 @@ async function testPrepareWithIgnoredTrackedFiles() {
if (savedGit === undefined) delete process.env.CODEX_SECURITY_GIT;
else process.env.CODEX_SECURITY_GIT = savedGit;
}
-}
+});
-async function testPrepareExcludesGitMetadata() {
+test(async function testPrepareExcludesGitMetadata() {
const fixture = await createFixture("nested repositories");
await runGit(fixture.repoRoot, "init", "-q");
for (const [name, source] of [
@@ -520,9 +298,9 @@ async function testPrepareExcludesGitMetadata() {
items: [],
},
);
-}
+});
-async function testPrepareUsesOnlyAuthoritativeDiffChanges() {
+test(async function testPrepareUsesOnlyAuthoritativeDiffChanges() {
const fixture = await createFixture("selected committed changes");
await runGit(fixture.repoRoot, "init", "-q");
await fixture.writeRepositoryFile(
@@ -576,9 +354,9 @@ async function testPrepareUsesOnlyAuthoritativeDiffChanges() {
{ path: "tests/example.ts" },
],
});
-}
+});
-async function testPrepareIncludesPerlSourceWithMixedEncodings() {
+test(async function testPrepareIncludesPerlSourceWithMixedEncodings() {
const fixture = await createFixture("perl source extensions");
await runGit(fixture.repoRoot, "init", "-q");
const perlSources = [
@@ -640,9 +418,9 @@ async function testPrepareIncludesPerlSourceWithMixedEncodings() {
{ path: "www/cgi-bin/legacy.cgi" },
],
});
-}
+});
-async function testPrepareIncludesStagedAndUnstagedChanges() {
+test(async function testPrepareIncludesStagedAndUnstagedChanges() {
const fixture = await createFixture("selected working tree changes");
await runGit(fixture.repoRoot, "init", "-q");
await fixture.writeRepositoryFile(
@@ -688,9 +466,212 @@ async function testPrepareIncludesStagedAndUnstagedChanges() {
{ path: "src/untracked.ts" },
],
});
-}
+});
+
+test(async function testInventoryChildPreservesSettingsAndCwd() {
+ const fixture = await createFixture("inventory child settings");
+ await runGit(fixture.repoRoot, "init", "-q");
+ await runGit(fixture.repoRoot, "commit", "--allow-empty", "-qm", "base");
+ const baseRevision = await runGit(fixture.repoRoot, "rev-parse", "HEAD");
+ await fixture.writeRepositoryFile("visible.py", "visible\n");
+ await fixture.writeRepositoryFile("hidden.py", "hidden\n");
+ const home = path.join(fixture.root, "selected home");
+ const tools = path.join(fixture.root, "selected tools");
+ await mkdir(home);
+ await mkdir(tools);
+ const ignores = path.join(fixture.root, "global-ignore");
+ const config = path.join(fixture.root, "global-config");
+ await writeFile(ignores, "hidden.py\n");
+ await writeFile(
+ config,
+ `[core]\nexcludesFile = ${JSON.stringify(ignores)}\n`,
+ );
+ const marker = path.join(fixture.root, "child.jsonl");
+ const preload = path.join(fixture.root, "preload.cjs");
+ const names = [
+ "HOME",
+ "PATH",
+ "GIT_CONFIG_GLOBAL",
+ "NODE_OPTIONS",
+ "CODEX_MCP_NODE_PATH",
+ "LD_LIBRARY_PATH",
+ "DYLD_LIBRARY_PATH",
+ ];
+ await writeFile(
+ preload,
+ `require('node:fs').appendFileSync(${JSON.stringify(marker)}, JSON.stringify({pid:process.pid,node:process.execPath,cwd:process.cwd(),argv:process.argv,env:Object.fromEntries(${JSON.stringify(names)}.map(name=>[name,process.env[name]]))})+'\\n');`,
+ );
+ const saved = names.map((name) => [name, process.env[name]] as const);
+ const selected = {
+ HOME: home,
+ PATH: tools + path.delimiter + (process.env.PATH ?? ""),
+ GIT_CONFIG_GLOBAL: config,
+ NODE_OPTIONS: `--require ${JSON.stringify(path.relative(process.cwd(), preload).split(path.sep).join("/"))}`,
+ CODEX_MCP_NODE_PATH: path.join(fixture.root, "unused-node"),
+ LD_LIBRARY_PATH: path.join(fixture.root, "selected libraries"),
+ DYLD_LIBRARY_PATH: path.join(fixture.root, "selected dylibs"),
+ };
+ Object.assign(process.env, selected);
+ try {
+ const context = {
+ ...fixture.scan,
+ mode: "diff",
+ targetContract: {
+ diffTarget: {
+ kind: "working_tree",
+ baseRevision,
+ headRevision: "HEAD",
+ },
+ },
+ };
+ assert.deepEqual(await inventory.prepareCodexSecurityReviewItems(context), {
+ reviewItemsTotal: 1,
+ });
+ assert.deepEqual(await inventory.listCodexSecurityReviewItems(context), {
+ items: [{ path: "visible.py" }],
+ });
+ const records = (await readFile(marker, "utf8"))
+ .trim()
+ .split("\n")
+ .map((line) => JSON.parse(line));
+ const child = records.find(
+ (record) =>
+ record.argv[1] ===
+ path.join(fixture.scan.pluginRoot, "mcp", "helpers.mjs"),
+ );
+ assert.ok(child);
+ assert.notEqual(child.pid, process.pid);
+ assert.equal(child.node, process.execPath);
+ assert.equal(child.cwd, process.cwd());
+ assert.deepEqual(child.env, selected);
+ for (const [name, value] of Object.entries(selected))
+ assert.equal(process.env[name], value);
+ } finally {
+ for (const [name, value] of saved) {
+ if (value === undefined) delete process.env[name];
+ else process.env[name] = value;
+ }
+ }
+});
-async function testWorkerReadsItsOwnBoundInventory() {
+test(async function testInventoryChildPreservesRawPaths(t) {
+ if (process.platform === "win32") return t.skip();
+ const fixture = await createFixture("inventory raw child paths");
+ await runGit(fixture.repoRoot, "init", "-q");
+ await runGit(fixture.repoRoot, "commit", "--allow-empty", "-qm", "base");
+ const baseRevision = await runGit(fixture.repoRoot, "rev-parse", "HEAD");
+ await fixture.writeRepositoryFile("visible.py", "visible\n");
+ await fixture.writeRepositoryFile("hidden.py", "hidden\n");
+ // APFS requires valid UTF-8 names; Linux also permits undecodable bytes.
+ const suffix =
+ process.platform === "darwin" ? Buffer.from("雪") : Buffer.from([0xff]);
+ const suffixText = process.platform === "darwin" ? "雪" : "\udcff";
+ const rawPath = (name: string) =>
+ Buffer.concat([Buffer.from(path.join(fixture.root, name)), suffix]);
+ const repo = rawPath("repository-");
+ await rename(fixture.repoRoot, repo);
+ const ignore = path.join(fixture.root, "global-ignore");
+ await writeFile(ignore, "hidden.py\n");
+ const config = rawPath("global-config-");
+ await writeFile(config, `[core]\nexcludesFile = ${JSON.stringify(ignore)}\n`);
+ const git = rawPath("selected-git-");
+ await writeFile(git, '#!/bin/sh\nexec git "$@"\n', { mode: 0o700 });
+ const context = {
+ ...fixture.scan,
+ repoRoot: path.join(fixture.root, "repository-") + suffixText,
+ mode: "diff",
+ targetContract: {
+ diffTarget: { kind: "working_tree", baseRevision, headRevision: "HEAD" },
+ },
+ };
+ const marker = path.join(fixture.root, "child.json");
+ const preload = path.join(fixture.root, "preload.cjs");
+ const loaderSettings = {
+ LD_LIBRARY_PATH: path.join(fixture.root, "selected libraries"),
+ DYLD_LIBRARY_PATH: path.join(fixture.root, "selected dylibs"),
+ };
+ await writeFile(
+ preload,
+ `const fs = require('node:fs'); fs.writeFileSync(${JSON.stringify(marker)}, JSON.stringify({stdin:fs.readFileSync(0).length,env:Object.fromEntries(${JSON.stringify(Object.keys(loaderSettings))}.map(name=>[name,process.env[name]]))}));`,
+ );
+ const driver = path.join(fixture.root, "prepare.mjs");
+ await build({
+ stdin: {
+ contents: `import { prepareCodexSecurityReviewItems } from ${JSON.stringify(path.resolve(import.meta.dirname, "../src/artifact-inventory.ts"))}; Object.assign(process.env, ${JSON.stringify({ ...loaderSettings, NODE_OPTIONS: `--require ${JSON.stringify(preload)}` })}); console.log(JSON.stringify(await prepareCodexSecurityReviewItems(${JSON.stringify(context)})));`,
+ loader: "ts",
+ resolveDir: import.meta.dirname,
+ },
+ bundle: true,
+ platform: "node",
+ format: "esm",
+ outfile: driver,
+ define: {
+ "import.meta.url": JSON.stringify(
+ new URL(
+ "../../../../sdk/typescript/_bundled_plugin/mcp/helpers.mjs",
+ import.meta.url,
+ ).href,
+ ),
+ },
+ });
+ const octal = (value: Buffer) =>
+ [...value]
+ .map((byte) => `\\0${byte.toString(8).padStart(3, "0")}`)
+ .join("");
+ const { stdout } = await execFile(
+ "/bin/sh",
+ [
+ "-c",
+ [
+ // Raw environment bytes are valid on macOS even though APFS names are UTF-8.
+ 'HOME=$(printf "/fixture/home-\\377"); export HOME',
+ 'GIT_CONFIG_GLOBAL=$(printf "%b" "$3"); export GIT_CONFIG_GLOBAL',
+ 'CODEX_SECURITY_GIT=$(printf "%b" "$4"); export CODEX_SECURITY_GIT',
+ 'exec "$1" "$2"',
+ ].join("\n"),
+ "inventory-fixture",
+ process.execPath,
+ driver,
+ octal(config),
+ octal(git),
+ ],
+ { encoding: "utf8" },
+ );
+ assert.deepEqual(JSON.parse(stdout), { reviewItemsTotal: 1 });
+ assert.equal(await readFile(fixture.scanInventory, "utf8"), "visible.py\n");
+ assert.deepEqual(JSON.parse(await readFile(marker, "utf8")), {
+ stdin: 0,
+ env: loaderSettings,
+ });
+});
+
+test(async function testInventoryChildFailuresPreserveOutput() {
+ for (const signal of process.platform === "win32" ? [false] : [false, true]) {
+ const fixture = await createFixture("inventory child failure");
+ const pluginRoot = path.join(fixture.root, "failing plugin");
+ await mkdir(path.join(pluginRoot, "mcp"), { recursive: true });
+ await writeFile(
+ path.join(pluginRoot, "mcp", "helpers.mjs"),
+ signal
+ ? 'process.kill(process.pid, "SIGTERM");'
+ : 'process.stderr.write("synthetic inventory failure\\n"); process.exitCode = 23;',
+ );
+ await writeInventory(fixture.scanInventory, "previous.py\n");
+ await assert.rejects(
+ inventory.prepareCodexSecurityReviewItems({
+ ...fixture.scan,
+ pluginRoot,
+ }),
+ signal ? /SIGTERM/u : /synthetic inventory failure/u,
+ );
+ assert.equal(
+ await readFile(fixture.scanInventory, "utf8"),
+ "previous.py\n",
+ );
+ }
+});
+
+test(async function testWorkerReadsItsOwnBoundInventory() {
const fixture = await createFixture("isolated worker inventory");
await writeInventory(fixture.scanInventory, "./src/parent.ts\n");
await writeInventory(fixture.workerInventory, "./src/worker.ts\n");
@@ -702,9 +683,9 @@ async function testWorkerReadsItsOwnBoundInventory() {
await inventory.listCodexSecurityReviewItems(fixture.worker),
{ items: [{ path: "./src/worker.ts" }] },
);
-}
+});
-async function testCursorDoesNotExceedInventory() {
+test(async function testCursorDoesNotExceedInventory() {
const fixture = await createFixture("inventory paging");
await writeInventory(fixture.scanInventory, "./src/a.ts\n./src/b.ts\n");
@@ -712,9 +693,9 @@ async function testCursorDoesNotExceedInventory() {
inventory.listCodexSecurityReviewItems(fixture.scan, { cursor: "3" }),
/cursor/i,
);
-}
+});
-async function testEmptyInventoryIsValid() {
+test(async function testEmptyInventoryIsValid() {
const fixture = await createFixture("empty repository");
assert.deepEqual(
@@ -725,9 +706,9 @@ async function testEmptyInventoryIsValid() {
assert.deepEqual(await inventory.listCodexSecurityReviewItems(fixture.scan), {
items: [],
});
-}
+});
-async function testUnsafeInventoryRowsAreRejected() {
+test(async function testUnsafeInventoryRowsAreRejected() {
for (const unsafe of [
"../outside.ts",
"/absolute.ts",
@@ -741,9 +722,9 @@ async function testUnsafeInventoryRowsAreRejected() {
/inventory row 1 has an unsafe repository path/,
);
}
-}
+});
-async function testSymlinkedInventoryIsRejected() {
+test(async function testSymlinkedInventoryIsRejected() {
const fixture = await createFixture("symlinked artifact");
const outside = path.join(fixture.root, "outside.txt");
await writeFile(outside, "src/outside.ts\n");
@@ -754,9 +735,9 @@ async function testSymlinkedInventoryIsRejected() {
inventory.listCodexSecurityReviewItems(fixture.scan),
/safe|regular|symlink/i,
);
-}
+});
-async function testInventoryReadErrorsAreReported() {
+test(async function testInventoryReadErrorsAreReported() {
const fixture = await createFixture("missing inventory");
await assert.rejects(
@@ -788,18 +769,18 @@ async function testInventoryReadErrorsAreReported() {
},
);
}
-}
+});
-async function testWorkersCannotPrepareInventory() {
+test(async function testWorkersCannotPrepareInventory() {
const fixture = await createFixture("worker cannot prepare");
await assert.rejects(
inventory.prepareCodexSecurityReviewItems(fixture.worker),
/only a parent scan/i,
);
-}
+});
-async function testBoundScopeFailurePreservesPreviousInventory() {
+test(async function testBoundScopeFailurePreservesPreviousInventory() {
const fixture = await createFixture("invalid bound scope");
await writeInventory(fixture.scanInventory, "./src/original.ts\n");
const invalid = { ...fixture.scan, scope: "../outside" };
@@ -812,9 +793,9 @@ async function testBoundScopeFailurePreservesPreviousInventory() {
await readFile(fixture.scanInventory, "utf8"),
"./src/original.ts\n",
);
-}
+});
-async function testInvalidDiffTargetPreservesPreviousInventory() {
+test(async function testInvalidDiffTargetPreservesPreviousInventory() {
const fixture = await createFixture("invalid selected changes");
await writeInventory(fixture.scanInventory, "src/original.ts\n");
@@ -850,7 +831,7 @@ async function testInvalidDiffTargetPreservesPreviousInventory() {
await readFile(fixture.scanInventory, "utf8"),
"src/original.ts\n",
);
-}
+});
async function createFixture(label: string) {
const root = await temporaryDirectories.create(
@@ -919,5 +900,3 @@ async function runGit(repository: string, ...arguments_: string[]) {
);
return stdout.trim();
}
-
-console.log("compact artifact inventory tests passed");
diff --git a/plugins/codex-security/mcp-app/tests/test_artifact_scan_draft_recovery.ts b/plugins/codex-security/mcp-app/tests/test_artifact_scan_draft_recovery.ts
index 38ff2134c..2b4928512 100644
--- a/plugins/codex-security/mcp-app/tests/test_artifact_scan_draft_recovery.ts
+++ b/plugins/codex-security/mcp-app/tests/test_artifact_scan_draft_recovery.ts
@@ -59,6 +59,36 @@ const findingFor = (candidateId: string): FixtureFinding => ({
provenance: { source: "local_plugin", candidateId },
});
+async function finalizeParentFindings({
+ root,
+ context,
+}: Awaited<ReturnType<typeof fixture>>) {
+ const manifestPath = path.join(root, "scan-manifest.json");
+ const manifest = await readJson(manifestPath);
+ Object.assign(manifest.scan, {
+ id: context.scanId,
+ producer: { name: "codex-security-plugin", version: "0.1.0" },
+ status: "completed",
+ startedAt: "2026-05-31T18:00:00Z",
+ completedAt: "2026-05-31T18:09:00Z",
+ });
+ await writeJson(manifestPath, manifest);
+ for (const file of ["findings.json", "coverage.json"]) {
+ const filePath = path.join(root, file);
+ const document = await readJson(filePath);
+ document.scanId = context.scanId;
+ await writeJson(filePath, document);
+ }
+ await execFileAsync(process.env.PYTHON?.trim() || "python3", [
+ fileURLToPath(
+ new URL("../../scripts/finalize_scan_contract.py", import.meta.url),
+ ),
+ "--scan-dir",
+ root,
+ ]);
+ return (await readJson(root, "findings.json")).findings;
+}
+
// Finding reconciliation is shared by failed and canceled scans. Exercise both
// terminal bindings without repeating every identity case for each status.
for (const [layout, status] of [
@@ -226,10 +256,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
await f.write(submitted);
await f.write(submitted);
await f.writeReviewState({}, true);
- const saved = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "findings.json",
- );
+ const saved = await readJson(f.findingsPath);
assert.equal(saved.findings.length, 1);
});
}
@@ -238,41 +265,14 @@ for (const layout of ["standard", "diff", "worker"] as const) {
for (const candidate of ["first", "second", "third"])
await f.writeFindings([findingFor(candidate)]);
await f.writeReviewState({}, true);
- const saved = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "findings.json",
- );
+ const saved = await readJson(f.findingsPath);
assert.equal(saved.findings.length, 3);
if (layout !== "worker") {
assert.equal(
new Set(saved.findings.map(draftApi.scanFindingIdentity)).size,
3,
);
- const manifestPath = path.join(f.root, "scan-manifest.json");
- const manifest = await readJson(manifestPath);
- Object.assign(manifest.scan, {
- id: f.context.scanId!,
- producer: { name: "codex-security-plugin", version: "0.1.0" },
- status: "completed",
- startedAt: "2026-05-31T18:00:00Z",
- completedAt: "2026-05-31T18:09:00Z",
- });
- await writeFile(manifestPath, JSON.stringify(manifest));
- for (const file of ["findings.json", "coverage.json"]) {
- const filePath = path.join(f.root, file);
- const document = await readJson(filePath);
- document.scanId = f.context.scanId;
- await writeFile(filePath, JSON.stringify(document));
- }
- await execFileAsync(process.env.PYTHON?.trim() || "python3", [
- fileURLToPath(
- new URL("../../scripts/finalize_scan_contract.py", import.meta.url),
- ),
- "--scan-dir",
- f.root,
- ]);
- const completed = await readJson(f.root, "findings.json");
- assert.equal(completed.findings.length, 3);
+ assert.equal((await finalizeParentFindings(f)).length, 3);
}
assert.deepEqual(
new Set(
@@ -1658,13 +1658,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
});
const original = structuredClone(input);
if (interrupted) {
- await interruptDraftWrite(
- path.join(
- f.root,
- layout === "worker" ? "result.json" : "findings.json",
- ),
- () => f.write(input),
- );
+ await interruptDraftWrite(f.findingsPath, () => f.write(input));
}
const initial = await f.write(input);
const [surface] = initial.reviewState.surfaces;
@@ -1973,14 +1967,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
await f.writeReviewState({ resolvedDeferred: [close(task.id)] }, true);
for (const input of [f.draft({ deferred: [task] }), f.draft()]) {
await f.write(input);
- const published = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "scan-manifest.json",
- );
- assert.equal(
- layout === "worker" ? published.complete : published.scan.complete,
- false,
- );
+ assert.equal(await f.readComplete(), false);
if (layout === "worker") {
const head = await readJson(f.root, "checkpoint-head.json");
const checkpoint = await readJson(
@@ -1993,14 +1980,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
}
}
await f.writeReviewState({ resolvedDeferred: [close(task.id)] }, true);
- const finished = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "scan-manifest.json",
- );
- assert.notEqual(
- layout === "worker" ? finished.complete : finished.scan.complete,
- false,
- );
+ assert.notEqual(await f.readComplete(), false);
});
}
@@ -2097,12 +2077,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
),
pendingBefore ? followUp : reviewed,
);
- const published = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "scan-manifest.json",
- );
- const complete =
- layout === "worker" ? published.complete : published.scan.complete;
+ const complete = await f.readComplete();
if (pendingBefore || pendingAfter) assert.equal(complete, false);
else assert.notEqual(complete, false);
}
@@ -2119,14 +2094,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
const finished = await f.read();
assert.deepEqual(finished.deferred, []);
assert.equal(finished.surfaces[0].disposition, "no_issue_found");
- const published = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "scan-manifest.json",
- );
- assert.notEqual(
- layout === "worker" ? published.complete : published.scan.complete,
- false,
- );
+ assert.notEqual(await f.readComplete(), false);
});
}
}
@@ -2135,14 +2103,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
const f = await fixture(t, layout);
await f.writeReviewState({}, true);
await f.writeReviewState({ deferred: [{ id: "late", ...generic }] });
- const published = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "scan-manifest.json",
- );
- assert.equal(
- layout === "worker" ? published.complete : published.scan.complete,
- false,
- );
+ assert.equal(await f.readComplete(), false);
const pending = (await f.read()).deferred;
assert.deepEqual(pending, [{ id: "late", ...generic }]);
await f.writeReviewState({}, true);
@@ -2326,14 +2287,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
otherPending,
);
assert.equal(result.reviewState.completeness, undefined);
- const document = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "scan-manifest.json",
- );
- assert.equal(
- layout === "worker" ? document.complete : document.scan.complete,
- false,
- );
+ assert.equal(await f.readComplete(), false);
}
});
}
@@ -2375,10 +2329,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
const input = f.findingsDraft([reported], { complete: true });
await f.write(input);
await f.write(input);
- const saved = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "findings.json",
- );
+ const saved = await readJson(f.findingsPath);
assert.equal(saved.findings.length, 1);
const provenance = saved.findings[0].provenance;
for (const field of ["sourceFindingIds", "sourceFindings"] as const) {
@@ -2398,32 +2349,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
const parent = layout === "worker" ? await fixture(t, "deep") : f;
if (layout === "worker")
await parent.writeFindings(saved.findings, { complete: true });
- const manifestPath = path.join(parent.root, "scan-manifest.json");
- const manifest = await readJson(manifestPath);
- Object.assign(manifest.scan, {
- id: parent.context.scanId,
- producer: { name: "codex-security-plugin", version: "0.1.0" },
- status: "completed",
- startedAt: "2026-05-31T18:00:00Z",
- completedAt: "2026-05-31T18:09:00Z",
- });
- await writeFile(manifestPath, JSON.stringify(manifest));
- for (const file of ["findings.json", "coverage.json"]) {
- const document = await readJson(parent.root, file);
- document.scanId = parent.context.scanId;
- await writeFile(path.join(parent.root, file), JSON.stringify(document));
- }
- await execFileAsync(process.env.PYTHON?.trim() || "python3", [
- fileURLToPath(
- new URL("../../scripts/finalize_scan_contract.py", import.meta.url),
- ),
- "--scan-dir",
- parent.root,
- ]);
- assert.equal(
- (await readJson(parent.root, "findings.json")).findings.length,
- 1,
- );
+ assert.equal((await finalizeParentFindings(parent)).length, 1);
});
}
}
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 7579e84c8..1c3d8a63e 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
@@ -33,6 +33,29 @@ import {
const execFileAsync = promisify(execFile);
+async function createWorker(parent: DraftFixture, id = "reviewer") {
+ const root = path.join(parent.root, id);
+ await mkdir(root);
+ return draftFixture(root, "worker");
+}
+
+async function recoveryWriters(
+ t: Parameters<typeof fixture>[0],
+ layout: Parameters<typeof fixture>[1],
+) {
+ const { normal, recovered, recover } = await recoveryPair(
+ t,
+ layout === "worker" ? "deep" : layout,
+ );
+ const normalWriter =
+ layout === "worker" ? await createWorker(normal) : normal;
+ const recoveredWriter =
+ layout === "worker" ? await createWorker(recovered) : recovered;
+ const workers =
+ layout === "worker" ? [savedWorker(recoveredWriter.root)] : [];
+ return { normal, normalWriter, recoveredWriter, workers, recover };
+}
+
function withWorkerId(rows: FixtureFinding[], workerId: string) {
return rows.map((row) => ({
...row,
@@ -103,11 +126,10 @@ for (const variant of [
for (const reversed of [false, true]) {
test(`worker ${variant} identity survives recovery (reversed=${reversed})`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const workerRoot = path.join(normal.root, "worker");
- const interruptedRoot = path.join(recovered.root, "worker");
- await Promise.all([mkdir(workerRoot), mkdir(interruptedRoot)]);
- const worker = draftFixture(workerRoot, "worker");
- const interrupted = draftFixture(interruptedRoot, "worker");
+ const [worker, interrupted] = await Promise.all([
+ createWorker(normal, "worker"),
+ createWorker(recovered, "worker"),
+ ]);
const locations = [
{ path: "src/first.py", startLine: 1 },
{ path: "src/second.py", startLine: 2 },
@@ -135,10 +157,10 @@ for (const variant of [
}
await worker.writeFindings([rows[1]]);
await interrupted.checkpoint(interrupted.findingsDraft([rows[1]]));
- const saved = await readJson(workerRoot, "result.json");
+ const saved = await readJson(worker.root, "result.json");
await normal.writeFindings(withWorkerId(saved.findings, "worker"));
const result = await recover({
- workers: [savedWorker(interruptedRoot, "worker", "succeeded")],
+ workers: [savedWorker(interrupted.root, "worker", "succeeded")],
details: true,
replay: true,
provenanceDetails: true,
@@ -216,11 +238,10 @@ for (const observations of [
]) {
test(`worker checkpoints preserve reordered JSON identities ${observations.join("/")}`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const workerRoot = path.join(normal.root, "worker");
- const interruptedRoot = path.join(recovered.root, "worker");
- await Promise.all([mkdir(workerRoot), mkdir(interruptedRoot)]);
- const worker = draftFixture(workerRoot, "worker");
- const interrupted = draftFixture(interruptedRoot, "worker");
+ const [worker, interrupted] = await Promise.all([
+ createWorker(normal, "worker"),
+ createWorker(recovered, "worker"),
+ ]);
const findings = observations.map((value) =>
finding("Synthetic review", {
extensions: { observations: [{ value }] },
@@ -241,21 +262,21 @@ for (const observations of [
const name =
createHash("sha256").update(contents).digest("hex") + ".json";
await writeFile(
- path.join(interruptedRoot, "checkpoints", name),
+ path.join(interrupted.root, "checkpoints", name),
contents,
);
} else {
await interrupted.checkpoint(snapshot);
}
if (index === 0) {
- await dateDraftFiles(workerRoot, 100);
- await dateDraftFiles(interruptedRoot, 100);
+ await dateDraftFiles(worker.root, 100);
+ await dateDraftFiles(interrupted.root, 100);
}
}
- const saved = await readJson(workerRoot, "result.json");
+ const saved = await readJson(worker.root, "result.json");
await normal.writeFindings(withWorkerId(saved.findings, "worker"));
const result = await recover({
- workers: [savedWorker(interruptedRoot, "worker")],
+ workers: [savedWorker(interrupted.root, "worker")],
details: true,
replay: true,
});
@@ -454,11 +475,10 @@ const terminalDraftCases: Array<{
for (const { variant, expectedCount, observation } of terminalDraftCases) {
test(`worker: a newer terminal draft reconciles ${variant} observations`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const workerRoot = path.join(normal.root, "worker");
- const interruptedRoot = path.join(recovered.root, "worker");
- await Promise.all([mkdir(workerRoot), mkdir(interruptedRoot)]);
- const worker = draftFixture(workerRoot, "worker");
- const interrupted = draftFixture(interruptedRoot, "worker");
+ const [worker, interrupted] = await Promise.all([
+ createWorker(normal, "worker"),
+ createWorker(recovered, "worker"),
+ ]);
const plain = finding(
"Synthetic review",
observation
@@ -557,10 +577,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
provenance: { source: "local_plugin", candidateId: "candidate-1" },
},
]);
- const saved = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "findings.json",
- );
+ const saved = await readJson(f.findingsPath);
assert.equal(saved.findings.length, 1);
assert.equal(saved.findings[0].provenance.candidateId, "candidate-1");
});
@@ -644,9 +661,7 @@ for (const variant of [
const workers = [];
const findings = [];
for (const [index, id] of ["reviewer-a", "reviewer-b"].entries()) {
- const root = path.join(recovered.root, id);
- await mkdir(root);
- const worker = draftFixture(root, "worker");
+ const worker = await createWorker(recovered, id);
const value = finding(
variant === "same title" || index === 0
? "First review"
@@ -666,7 +681,7 @@ for (const variant of [
if (variant === "authored anchor" && index === 0)
value.identity = { anchor: "established-review" };
await worker.writeFindings([value]);
- const result = await readJson(root, "result.json");
+ const result = await readJson(worker.root, "result.json");
if (variant === "rejected sibling" && index === 1) {
await worker.writeReviewState(
{
@@ -684,7 +699,7 @@ for (const variant of [
} else {
findings.push(...withWorkerId(result.findings, id));
}
- workers.push(savedWorker(root, id));
+ workers.push(savedWorker(worker.root, id));
}
await normal.writeFindings(findings);
const result = await recover({ workers });
@@ -708,12 +723,8 @@ for (const [kind, metadata, identifier] of [
]) {
test(`deep: ${kind} via ${metadata}/${identifier ?? "plain"} matches published worker identities`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const normalRoot = path.join(normal.root, "reviewer");
- const recoveryRoot = path.join(recovered.root, "reviewer");
- await mkdir(normalRoot);
- await mkdir(recoveryRoot);
- const publishedWorker = draftFixture(normalRoot, "worker");
- const interruptedWorker = draftFixture(recoveryRoot, "worker");
+ const publishedWorker = await createWorker(normal);
+ const interruptedWorker = await createWorker(recovered);
const first = finding("First review", {
...(kind === "candidate enrichment"
? {}
@@ -746,9 +757,11 @@ for (const [kind, metadata, identifier] of [
await interruptedWorker.checkpoint(
interruptedWorker.findingsDraft([second]),
);
- const result = await readJson(normalRoot, "result.json");
+ const result = await readJson(publishedWorker.root, "result.json");
await normal.writeFindings(withWorkerId(result.findings, "reviewer"));
- const comparison = await recover({ workers: [savedWorker(recoveryRoot)] });
+ const comparison = await recover({
+ workers: [savedWorker(interruptedWorker.root)],
+ });
assert.equal(
comparison.normal.length,
kind === "candidate aliases" ? 2 : 1,
@@ -794,12 +807,8 @@ for (const variant of [
for (const reversed of [false, true]) {
test(`deep: explicit worker identity survives ${variant} revision (reverse=${reversed})`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const nwroot = path.join(normal.root, "reviewer"),
- rwroot = path.join(recovered.root, "reviewer");
- await mkdir(nwroot);
- await mkdir(rwroot);
- const nw = draftFixture(nwroot, "worker"),
- rw = draftFixture(rwroot, "worker");
+ const nw = await createWorker(normal);
+ const rw = await createWorker(recovered);
const first = finding("First review", {
identity: { anchor: "authored-review" },
});
@@ -828,9 +837,9 @@ for (const variant of [
await rw.writeFindings(ordered(first));
await nw.writeFindings(ordered(second));
await rw.checkpoint(rw.findingsDraft(ordered(second)));
- const result = await readJson(nwroot, "result.json");
+ const result = await readJson(nw.root, "result.json");
await normal.writeFindings(withWorkerId(result.findings, "reviewer"));
- const comparison = await recover({ workers: [savedWorker(rwroot)] });
+ const comparison = await recover({ workers: [savedWorker(rw.root)] });
assert.equal(comparison.normal.length, withSibling ? 2 : 1);
assert.deepEqual(comparison.recovered, comparison.normal);
assert.deepEqual(comparison.warnings, []);
@@ -868,26 +877,8 @@ for (const layout of ["standard", "diff", "worker"] as const) {
"retained sibling",
]) {
test(`${layout}: checkpoint reconciliation preserves ${variant}`, async (t) => {
- const { normal, recovered, recover } = await recoveryPair(
- t,
- layout === "worker" ? "deep" : layout,
- );
- let normalSource = normal,
- recoveredSource = recovered;
- const workers = [];
- if (layout === "worker") {
- for (const f of [normal, recovered])
- await mkdir(path.join(f.root, "reviewer"));
- normalSource = draftFixture(
- path.join(normal.root, "reviewer"),
- "worker",
- );
- recoveredSource = draftFixture(
- path.join(recovered.root, "reviewer"),
- "worker",
- );
- workers.push(savedWorker(recoveredSource.root));
- }
+ const { normal, normalWriter, recoveredWriter, workers, recover } =
+ await recoveryWriters(t, layout);
const first = finding("First review", {
provenance: { source: "local_plugin", candidateId: "candidate-1" },
});
@@ -906,14 +897,14 @@ for (const layout of ["standard", "diff", "worker"] as const) {
if (variant === "retained sibling") second.title = "Second review";
const initial =
variant === "retained sibling" ? [first, second] : [first];
- for (const f of [normalSource, recoveredSource])
+ for (const f of [normalWriter, recoveredWriter])
await f.writeFindings(initial);
- await normalSource.writeFindings([second], { complete: true });
- await recoveredSource.checkpoint(
- recoveredSource.findingsDraft([second], { complete: true }),
+ await normalWriter.writeFindings([second], { complete: true });
+ await recoveredWriter.checkpoint(
+ recoveredWriter.findingsDraft([second], { complete: true }),
);
if (layout === "worker") {
- const saved = await readJson(normalSource.root, "result.json");
+ const saved = await readJson(normalWriter.root, "result.json");
await normal.writeFindings(withWorkerId(saved.findings, "reviewer"));
}
const result = await recover({
@@ -1045,12 +1036,8 @@ for (const layout of ["standard", "diff", "deep"] as const) {
for (const field of ["reportId", "ledgerRowId"]) {
test(`deep: worker blank ${field} enrichment retains publication identity`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const normalRoot = path.join(normal.root, "reviewer");
- const recoveredRoot = path.join(recovered.root, "reviewer");
- await mkdir(normalRoot);
- await mkdir(recoveredRoot);
- const normalWorker = draftFixture(normalRoot, "worker");
- const recoveredWorker = draftFixture(recoveredRoot, "worker");
+ const normalWorker = await createWorker(normal);
+ const recoveredWorker = await createWorker(recovered);
const first = finding("Synthetic worker review", {
provenance: { source: "local_plugin", candidateId: "candidate-1" },
extensions: { [field]: " \t " },
@@ -1060,9 +1047,11 @@ for (const field of ["reportId", "ledgerRowId"]) {
await normalWorker.writeFindings([value]);
await recoveredWorker.checkpoint(recoveredWorker.findingsDraft([value]));
}
- const saved = await readJson(normalRoot, "result.json");
+ const saved = await readJson(normalWorker.root, "result.json");
await normal.writeFindings(withWorkerId(saved.findings, "reviewer"));
- const result = await recover({ workers: [savedWorker(recoveredRoot)] });
+ const result = await recover({
+ workers: [savedWorker(recoveredWorker.root)],
+ });
assert.equal(result.normal.length, 1);
assert.equal(result.recovered.length, 1);
assert.deepEqual(result.warnings, []);
@@ -1149,12 +1138,8 @@ for (const layout of ["standard", "diff", "deep"] as const) {
test("deep: refined candidate retains independent cross-location report", async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const normalRoot = path.join(normal.root, "reviewer");
- const recoveredRoot = path.join(recovered.root, "reviewer");
- await mkdir(normalRoot);
- await mkdir(recoveredRoot);
- const normalWorker = draftFixture(normalRoot, "worker");
- const recoveredWorker = draftFixture(recoveredRoot, "worker");
+ const normalWorker = await createWorker(normal);
+ const recoveredWorker = await createWorker(recovered);
const first = finding("First review", {
severity: { level: "high" },
provenance: { source: "local_plugin", candidateId: "candidate-1" },
@@ -1173,10 +1158,10 @@ test("deep: refined candidate retains independent cross-location report", async
await normalWorker.writeFindings(findings);
await recoveredWorker.checkpoint(recoveredWorker.findingsDraft(findings));
}
- const saved = await readJson(normalRoot, "result.json");
+ const saved = await readJson(normalWorker.root, "result.json");
await normal.writeFindings(withWorkerId(saved.findings, "reviewer"));
const result = await recover({
- workers: [savedWorker(recoveredRoot)],
+ workers: [savedWorker(recoveredWorker.root)],
details: true,
});
@@ -1300,9 +1285,7 @@ for (const authored of [false, true]) {
const workers = [],
findings = [];
for (const id of ["worker-a", "worker-b"]) {
- const workerRoot = path.join(recovered.root, id);
- await mkdir(workerRoot);
- const worker = draftFixture(workerRoot, "worker");
+ const worker = await createWorker(recovered, id);
const value = finding("Synthetic bound owner review", {
provenance: { source: "local_plugin", candidateId: "candidate-1" },
...(authored ? { identity: { anchor: "authored-review" } } : {}),
@@ -1317,7 +1300,7 @@ for (const authored of [false, true]) {
...value,
provenance: { ...value.provenance, workerId: id },
});
- workers.push(savedWorker(workerRoot, id));
+ workers.push(savedWorker(worker.root, id));
}
await normal.writeFindings(findings);
const result = await recover({ workers });
@@ -1332,11 +1315,8 @@ for (const order of ["earlier-first", "later-first"]) {
for (const initialLevel of ["low", "high"]) {
test(`worker revised raw checkpoint retains ${metadata} enrichment (${order}, ${initialLevel} to low)`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const normalRoot = path.join(normal.root, "reviewer"),
- recoveredRoot = path.join(recovered.root, "reviewer");
- for (const root of [normalRoot, recoveredRoot]) await mkdir(root);
- const worker = draftFixture(normalRoot, "worker"),
- recoveryWorker = draftFixture(recoveredRoot, "worker");
+ const worker = await createWorker(normal);
+ const recoveryWorker = await createWorker(recovered);
const initial = {
...finding("Synthetic review"),
summary: "Initial assessment.",
@@ -1365,14 +1345,14 @@ for (const order of ["earlier-first", "later-first"]) {
await worker.write(draft);
await saveCheckpointAt(recoveryWorker, draft, 100 + index * 100);
}
- const saved = await readJson(normalRoot, "result.json");
+ const saved = await readJson(worker.root, "result.json");
assert.equal(saved.findings.length, 1);
assert.equal(saved.findings[0].summary, revised.summary);
assert.equal(saved.findings[0].severity.level, "low");
assert.equal(saved.findings[0][metadata].candidateId, "candidate-1");
await normal.writeFindings(withWorkerId(saved.findings, "reviewer"));
const result = await recover({
- workers: [savedWorker(recoveredRoot)],
+ workers: [savedWorker(recoveryWorker.root)],
details: true,
});
assert.deepEqual(result.warnings, []);
@@ -1444,9 +1424,7 @@ for (const sameTitle of [false, true]) {
const workers = [],
findings = [];
for (const [index, id] of ["worker-a", "worker-b"].entries()) {
- const workerRoot = path.join(recovered.root, id);
- await mkdir(workerRoot);
- const worker = draftFixture(workerRoot, "worker");
+ const worker = await createWorker(recovered, id);
const value = finding(
sameTitle
? "Synthetic shared review"
@@ -1460,9 +1438,9 @@ for (const sameTitle of [false, true]) {
},
);
await worker.writeFindings([value]);
- const saved = await readJson(workerRoot, "result.json");
+ const saved = await readJson(worker.root, "result.json");
findings.push(...saved.findings);
- workers.push(savedWorker(workerRoot, id));
+ workers.push(savedWorker(worker.root, id));
}
await normal.writeFindings(findings);
const result = await recover({ workers });
@@ -1474,12 +1452,8 @@ for (const sameTitle of [false, true]) {
for (const authored of [false, true]) {
test(`bound owner keeps same worker metadata revision authored=${authored}`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const workerRoot = path.join(recovered.root, "worker-a"),
- normalWorkerRoot = path.join(normal.root, "worker-a");
- await mkdir(workerRoot);
- await mkdir(normalWorkerRoot);
- const worker = draftFixture(workerRoot, "worker"),
- normalWorker = draftFixture(normalWorkerRoot, "worker");
+ const worker = await createWorker(recovered, "worker-a");
+ const normalWorker = await createWorker(normal, "worker-a");
for (const alias of ["discovery", "refined"]) {
const value = finding("Synthetic shared review", {
provenance: {
@@ -1492,10 +1466,10 @@ for (const authored of [false, true]) {
await normalWorker.writeFindings([value]);
await worker.checkpoint(worker.findingsDraft([value]));
}
- const saved = await readJson(normalWorkerRoot, "result.json");
+ const saved = await readJson(normalWorker.root, "result.json");
await normal.writeFindings(saved.findings);
const result = await recover({
- workers: [savedWorker(workerRoot, "worker-a")],
+ workers: [savedWorker(worker.root, "worker-a")],
});
assert.equal(result.normal.length, 1);
assert.deepEqual(result.recovered, result.normal);
@@ -1507,11 +1481,8 @@ for (const metadata of ["provenance", "extensions"] as const) {
for (const shape of ["shared siblings", "reportId", "ledgerRowId"]) {
test(`raw group authority preserves ${shape} with ${metadata} candidates`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const normalRoot = path.join(normal.root, "reviewer"),
- recoveredRoot = path.join(recovered.root, "reviewer");
- for (const root of [normalRoot, recoveredRoot]) await mkdir(root);
- const writer = draftFixture(normalRoot, "worker"),
- interrupted = draftFixture(recoveredRoot, "worker");
+ const writer = await createWorker(normal);
+ const interrupted = await createWorker(recovered);
const first = finding("First review");
first[metadata] = { ...first[metadata], candidateId: "candidate-1" };
if (shape === "shared siblings")
@@ -1531,20 +1502,20 @@ for (const metadata of ["provenance", "extensions"] as const) {
};
for (const worker of [writer, interrupted])
await worker.writeFindings(initial);
- await dateDraftFiles(recoveredRoot, 100);
+ await dateDraftFiles(interrupted.root, 100);
const update = writer.findingsDraft([revised]);
await writer.write(update);
await interrupted.checkpoint(update);
await utimes(
- path.join(recoveredRoot, "checkpoints", checkpointName(update)),
+ path.join(interrupted.root, "checkpoints", checkpointName(update)),
200,
200,
);
- const saved = await readJson(normalRoot, "result.json");
+ const saved = await readJson(writer.root, "result.json");
assert.equal(saved.findings.length, initial.length);
await normal.writeFindings(withWorkerId(saved.findings, "reviewer"));
const result = await recover({
- workers: [savedWorker(recoveredRoot)],
+ workers: [savedWorker(interrupted.root)],
details: true,
replay: true,
});
@@ -1630,9 +1601,7 @@ const revisionFinding = (level: string, summary: string) =>
for (const source of ["selected checkpoint", "published result"]) {
test(`finding precedence retains ${source} at tied timestamps`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const output = path.join(recovered.root, "reviewer");
- await mkdir(output);
- const worker = draftFixture(output, "worker");
+ const worker = await createWorker(recovered);
const initial = worker.findingsDraft(
[revisionFinding("low", "Initial evidence.")],
{ complete: true },
@@ -1643,24 +1612,24 @@ for (const source of ["selected checkpoint", "published result"]) {
);
await worker.write(initial);
await worker.write(latest);
- const saved = await readJson(output, "result.json");
+ const saved = await readJson(worker.root, "result.json");
await normal.writeFindings(saved.findings, { complete: true });
// Valid JSON whitespace controls filename order without changing the evidence.
- const names = await readdir(path.join(output, "checkpoints"));
+ const names = await readdir(path.join(worker.root, "checkpoints"));
let contents = JSON.stringify(initial),
name = "";
do {
contents += "\n";
name = createHash("sha256").update(contents).digest("hex") + ".json";
} while (names.some((existing) => existing > name));
- await writeFile(path.join(output, "checkpoints", name), contents);
+ await writeFile(path.join(worker.root, "checkpoints", name), contents);
if (source === "published result") {
const { rm } = await import("node:fs/promises");
- await rm(path.join(output, "checkpoint-head.json"));
+ await rm(path.join(worker.root, "checkpoint-head.json"));
}
- await dateDraftFiles(output, 100);
+ await dateDraftFiles(worker.root, 100);
const result = await recover({
- workers: [savedWorker(output)],
+ workers: [savedWorker(worker.root)],
details: true,
replay: true,
});
@@ -1714,9 +1683,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
}
test("finding precedence compares parent and worker observation times", async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const workerRoot = path.join(recovered.root, "reviewer");
- await mkdir(workerRoot);
- const worker = draftFixture(workerRoot, "worker");
+ const worker = await createWorker(recovered);
await worker.writeFindings(
[revisionFinding("low", "Earlier worker evidence.")],
{ complete: true },
@@ -1727,9 +1694,9 @@ test("finding precedence compares parent and worker observation times", async (t
);
for (const f of [normal, recovered]) await f.write(latest);
await dateDraftFiles(recovered.root, 200);
- await dateDraftFiles(workerRoot, 100);
+ await dateDraftFiles(worker.root, 100);
const result = await recover({
- workers: [savedWorker(workerRoot)],
+ workers: [savedWorker(worker.root)],
details: true,
replay: true,
});
@@ -1750,9 +1717,7 @@ for (const revised of [false, true]) {
},
}),
);
- const workerRoot = path.join(recovered.root, "reviewer");
- await mkdir(workerRoot);
- const worker = draftFixture(workerRoot, "worker");
+ const worker = await createWorker(recovered);
await worker.writeFindings(findings, { complete: true });
for (const f of [normal, recovered])
await f.writeFindings(findings, { complete: true });
@@ -1768,7 +1733,7 @@ for (const revised of [false, true]) {
});
if (revised) await normal.writeFindings(latest, { complete: true });
const result = await recover({
- workers: [savedWorker(workerRoot)],
+ workers: [savedWorker(worker.root)],
details: true,
replay: true,
});
@@ -1971,9 +1936,7 @@ for (const [field, value] of Object.entries({
findings = [];
for (const index of reservedFirst ? [2, 0, 1] : [0, 1, 2]) {
const id = `worker-${index}`;
- const workerRoot = path.join(recovered.root, id);
- await mkdir(workerRoot);
- const worker = draftFixture(workerRoot, "worker");
+ const worker = await createWorker(recovered, id);
const row = finding(`Review ${index}`, {
identity: {
anchor: "shared",
@@ -1988,7 +1951,7 @@ for (const [field, value] of Object.entries({
});
await worker.writeFindings([row]);
findings.push(row);
- workers.push(savedWorker(workerRoot, id));
+ workers.push(savedWorker(worker.root, id));
}
await normal.writeFindings(findings);
const result = await recover({ workers, details: true, replay: true });
@@ -2098,9 +2061,7 @@ for (const field of ["description", "source", "version"]) {
for (const candidate of [false, true]) {
test(`worker identity ${field} annotation revision keeps one report (candidate=${candidate})`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const workerRoot = path.join(recovered.root, "reviewer");
- await mkdir(workerRoot);
- const worker = draftFixture(workerRoot, "worker");
+ const worker = await createWorker(recovered);
const first = finding("Synthetic review", {
identity: {
anchor: "authored",
@@ -2114,15 +2075,15 @@ for (const field of ["description", "source", "version"]) {
},
});
await worker.writeFindings([first]);
- await dateDraftFiles(workerRoot, 100);
+ await dateDraftFiles(worker.root, 100);
const revised = {
...first,
identity: { ...first.identity, [field]: "revised" },
};
await worker.writeFindings([revised]);
- const saved = await readJson(workerRoot, "result.json");
+ const saved = await readJson(worker.root, "result.json");
await normal.writeFindings(saved.findings);
- const workers = [savedWorker(workerRoot)];
+ const workers = [savedWorker(worker.root)];
const result = await recover({ workers, details: true, replay: true });
assert.equal(result.normal.length, 1);
assert.equal(result.recovered.length, 1);
@@ -2136,25 +2097,23 @@ for (const metadata of ["extensions", "provenance"] as const) {
for (const malformedFirst of [false, true]) {
test(`discarded ${metadata} sibling cannot change a valid identity (malformed first=${malformedFirst})`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const workerRoot = path.join(recovered.root, "reviewer");
- await mkdir(workerRoot);
- const worker = draftFixture(workerRoot, "worker");
+ const worker = await createWorker(recovered);
const row = finding("Synthetic review");
row[metadata] = { ...row[metadata], candidateId: "candidate-1" };
row.provenance = { ...row.provenance, workerId: "reviewer" };
await worker.writeFindings([row]);
- await dateDraftFiles(workerRoot, 100);
+ await dateDraftFiles(worker.root, 100);
await normal.writeFindings([row]);
const { summary: _summary, ...malformed } = {
...structuredClone(row),
locations: [{ path: "src/example.py", startLine: 2 }],
};
- const resultFile = path.join(workerRoot, "result.json");
+ const resultFile = path.join(worker.root, "result.json");
const saved = await readJson(resultFile);
saved.findings = malformedFirst ? [malformed, row] : [row, malformed];
await writeFile(resultFile, JSON.stringify(saved));
await utimes(resultFile, 200, 200);
- const workers = [savedWorker(workerRoot)];
+ const workers = [savedWorker(worker.root)];
const result = await recover({ workers, details: true, replay: true });
assert.equal(result.normal.length, 1);
assert.equal(result.recovered.length, 1);
@@ -2169,11 +2128,8 @@ for (const field of ["description", "source", "version"]) {
for (const order of ["earlier-first", "later-first"]) {
test(`worker identity ${field} annotation revision survives checkpoint order (${order}, candidate=${candidate})`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const normalRoot = path.join(normal.root, "reviewer"),
- recoveredRoot = path.join(recovered.root, "reviewer");
- for (const root of [normalRoot, recoveredRoot]) await mkdir(root);
- const worker = draftFixture(normalRoot, "worker"),
- recoveryWorker = draftFixture(recoveredRoot, "worker");
+ const worker = await createWorker(normal);
+ const recoveryWorker = await createWorker(recovered);
const first = finding("Synthetic review", {
identity: {
anchor: "authored",
@@ -2209,11 +2165,11 @@ for (const field of ["description", "source", "version"]) {
await worker.write(draft);
await saveCheckpointAt(recoveryWorker, draft, 100 + index * 100);
}
- const saved = await readJson(normalRoot, "result.json");
+ const saved = await readJson(worker.root, "result.json");
assert.equal(saved.findings.length, 1);
assert.equal(saved.findings[0].identity[field], "revised");
await normal.writeFindings(saved.findings);
- const workers = [savedWorker(recoveredRoot)];
+ const workers = [savedWorker(recoveryWorker.root)];
const result = await recover({ workers, details: true, replay: true });
assert.equal(result.normal.length, 1);
assert.equal(result.recovered.length, 1);
@@ -2255,9 +2211,7 @@ for (const sameLocation of [false, true]) {
for (const level of ["low", "high"]) {
test(`absorbed worker report keeps independent candidate sibling (same location=${sameLocation}, ${level})`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const workerRoot = path.join(recovered.root, "reviewer");
- await mkdir(workerRoot);
- const worker = draftFixture(workerRoot, "worker");
+ const worker = await createWorker(recovered);
const first = finding("First review", {
summary: "Original first assessment.",
severity: { level: "medium" },
@@ -2287,16 +2241,16 @@ for (const sameLocation of [false, true]) {
},
};
await worker.writeFindings([first], { complete: true });
- await dateDraftFiles(workerRoot, 100);
+ await dateDraftFiles(worker.root, 100);
for (const f of [normal, recovered])
await f.writeFindings([parent], { complete: true });
await dateDraftFiles(recovered.root, 200);
- await dateDraftFiles(workerRoot, 100);
+ await dateDraftFiles(worker.root, 100);
const checkpoint = worker.findingsDraft([first, second]);
await saveCheckpointAt(worker, checkpoint, 300);
await normal.writeFindings([parent, second], { complete: true });
const result = await recover({
- workers: [savedWorker(workerRoot)],
+ workers: [savedWorker(worker.root)],
details: true,
replay: true,
});
@@ -2309,21 +2263,8 @@ for (const sameLocation of [false, true]) {
for (const layout of ["standard", "diff", "deep", "worker"] as const) {
for (const update of ["omitted", "partial"] as const) {
test(`${layout}: accepted provenance arrays survive ${update} checkpoint details`, async (t) => {
- const { normal, recovered, recover } = await recoveryPair(
- t,
- layout === "worker" ? "deep" : layout,
- );
- let normalWriter = normal,
- recoveredWriter = recovered;
- const workers: Record<string, unknown>[] = [];
- if (layout === "worker") {
- const normalRoot = path.join(normal.root, "reviewer"),
- recoveredRoot = path.join(recovered.root, "reviewer");
- for (const root of [normalRoot, recoveredRoot]) await mkdir(root);
- normalWriter = draftFixture(normalRoot, "worker");
- recoveredWriter = draftFixture(recoveredRoot, "worker");
- workers.push(savedWorker(recoveredRoot));
- }
+ const { normal, normalWriter, recoveredWriter, workers, recover } =
+ await recoveryWriters(t, layout);
const raw = finding("Synthetic finding", {
identity: { anchor: "stable" },
provenance: {
@@ -2402,21 +2343,8 @@ for (const layout of ["standard", "diff", "deep", "worker"] as const) {
for (const layout of ["standard", "diff", "deep", "worker"] as const) {
for (const field of ["reportId", "ledgerRowId"] as const) {
test(`${layout}: revised sibling keeps identity through ${field} enrichment`, async (t) => {
- const { normal, recovered, recover } = await recoveryPair(
- t,
- layout === "worker" ? "deep" : layout,
- );
- let normalWriter = normal,
- recoveredWriter = recovered;
- const workers: Record<string, unknown>[] = [];
- if (layout === "worker") {
- const normalRoot = path.join(normal.root, "reviewer"),
- recoveredRoot = path.join(recovered.root, "reviewer");
- for (const root of [normalRoot, recoveredRoot]) await mkdir(root);
- normalWriter = draftFixture(normalRoot, "worker");
- recoveredWriter = draftFixture(recoveredRoot, "worker");
- workers.push(savedWorker(recoveredRoot));
- }
+ const { normal, normalWriter, recoveredWriter, workers, recover } =
+ await recoveryWriters(t, layout);
const first = finding(
"First review",
layout === "worker"
@@ -2518,10 +2446,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
let saved: { findings: FixtureFinding[] };
for (let replay = 0; replay < 2; replay++) {
await f.writeFindings([revised]);
- saved = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "findings.json",
- );
+ saved = await readJson(f.findingsPath);
assert.ok(
containsAncestor(saved.findings),
"Saved ancestry must survive the published revision and replay.",
@@ -2671,21 +2596,8 @@ for (const layout of ["standard", "diff", "deep"] as const) {
for (const layout of ["standard", "diff", "deep", "worker"] as const) {
for (const candidate of [false, true]) {
test(`${layout}: live revisions inherit the published identity from retained history (candidate=${candidate})`, async (t) => {
- const { normal, recovered, recover } = await recoveryPair(
- t,
- layout === "worker" ? "deep" : layout,
- );
- let normalWriter = normal,
- recoveredWriter = recovered;
- const workers: Record<string, unknown>[] = [];
- if (layout === "worker") {
- const normalRoot = path.join(normal.root, "reviewer"),
- recoveredRoot = path.join(recovered.root, "reviewer");
- for (const root of [normalRoot, recoveredRoot]) await mkdir(root);
- normalWriter = draftFixture(normalRoot, "worker");
- recoveredWriter = draftFixture(recoveredRoot, "worker");
- workers.push(savedWorker(recoveredRoot));
- }
+ const { normal, normalWriter, recoveredWriter, workers, recover } =
+ await recoveryWriters(t, layout);
const original = finding("Synthetic historical revision", {
identity: { anchor: "stable-report" },
summary: "Original evidence.",
@@ -2702,12 +2614,8 @@ for (const layout of ["standard", "diff", "deep", "worker"] as const) {
await writer.writeFindings([original]);
for (let replay = 0; replay < 2; replay++) {
await normalWriter.writeFindings([revised]);
- await interruptDraftWrite(
- path.join(
- recoveredWriter.root,
- layout === "worker" ? "result.json" : "findings.json",
- ),
- () => recoveredWriter.writeFindings([revised]),
+ await interruptDraftWrite(recoveredWriter.findingsPath, () =>
+ recoveredWriter.writeFindings([revised]),
);
if (layout === "worker") {
const saved = await readJson(normalWriter.root, "result.json");
@@ -2758,10 +2666,7 @@ for (const layout of ["standard", "diff", "deep", "worker"] as const) {
let previous: unknown;
for (let replay = 0; replay < 2; replay++) {
await f.writeFindings([revised]);
- const saved = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "findings.json",
- );
+ const saved = await readJson(f.findingsPath);
assert.equal(
saved.findings.length,
2,
@@ -2786,9 +2691,7 @@ for (const evidence of ["identical", "distinct", "reordered"] as const) {
for (const includeResult of [false, true]) {
test(`unchanged worker batch retains ${evidence} provenance (result=${includeResult})`, async (t) => {
const { normal, recovered, recover } = await recoveryPair(t, "deep");
- const workerRoot = path.join(recovered.root, "reviewer");
- await mkdir(workerRoot);
- const worker = draftFixture(workerRoot, "worker");
+ const worker = await createWorker(recovered);
const findings = ["first", "second"].map((id) =>
finding("Synthetic saved review", {
provenance: {
@@ -2803,14 +2706,14 @@ for (const evidence of ["identical", "distinct", "reordered"] as const) {
await worker.writeFindings(findings, { complete: true });
if (evidence === "reordered")
await worker.writeFindings([...findings].reverse(), { complete: true });
- const saved = await readJson(workerRoot, "result.json");
+ const saved = await readJson(worker.root, "result.json");
assert.equal(saved.findings.length, 2);
await normal.writeFindings(withWorkerId(saved.findings, "reviewer"), {
complete: true,
});
- if (!includeResult) await rm(path.join(workerRoot, "result.json"));
+ if (!includeResult) await rm(path.join(worker.root, "result.json"));
const result = await recover({
- workers: [savedWorker(workerRoot)],
+ workers: [savedWorker(worker.root)],
details: true,
replay: true,
provenanceDetails: true,
@@ -2836,21 +2739,8 @@ for (const layout of ["standard", "diff", "worker"] as const) {
},
})) {
test(`${layout}: preserved identity metadata ${metadata} survives ${cut} interruption`, async (t) => {
- const { normal, recovered, recover } = await recoveryPair(
- t,
- layout === "worker" ? "deep" : layout,
- );
- let writer: DraftFixture = normal,
- recoveryWriter: DraftFixture = recovered;
- if (layout === "worker") {
- for (const f of [normal, recovered])
- await mkdir(path.join(f.root, "reviewer"));
- writer = draftFixture(path.join(normal.root, "reviewer"), "worker");
- recoveryWriter = draftFixture(
- path.join(recovered.root, "reviewer"),
- "worker",
- );
- }
+ const { normal, normalWriter, recoveredWriter, workers, recover } =
+ await recoveryWriters(t, layout);
const initial = finding("Synthetic preserved identity review", {
identity:
metadata === "valid" ? preservedIdentity : { anchor: "authored" },
@@ -2861,27 +2751,25 @@ for (const layout of ["standard", "diff", "worker"] as const) {
...(layout === "worker" ? { workerId: "reviewer" } : {}),
},
});
- for (const f of [writer, recoveryWriter])
+ for (const f of [normalWriter, recoveredWriter])
await f.writeFindings([initial]);
- await dateDraftFiles(recoveryWriter.root, 100);
+ await dateDraftFiles(recoveredWriter.root, 100);
const revised = {
...initial,
summary: "Revised synthetic assessment.",
severity: { level: "high" },
};
delete revised.identity;
- await writer.writeFindings([revised]);
- const filename = layout === "worker" ? "result.json" : "findings.json";
+ await normalWriter.writeFindings([revised]);
if (cut === "raw")
- await recoveryWriter.checkpoint(
- recoveryWriter.findingsDraft([revised]),
+ await recoveredWriter.checkpoint(
+ recoveredWriter.findingsDraft([revised]),
);
else
- await interruptDraftWrite(
- path.join(recoveryWriter.root, filename),
- () => recoveryWriter.writeFindings([revised]),
+ await interruptDraftWrite(recoveredWriter.findingsPath, () =>
+ recoveredWriter.writeFindings([revised]),
);
- const saved = await readJson(writer.root, filename);
+ const saved = await readJson(normalWriter.findingsPath);
assert.equal(saved.findings.length, 1);
assert.equal(saved.findings[0].severity.level, "high");
assert.deepEqual(
@@ -2890,8 +2778,7 @@ for (const layout of ["standard", "diff", "worker"] as const) {
);
if (layout === "worker") await normal.writeFindings(saved.findings);
const result = await recover({
- workers:
- layout === "worker" ? [savedWorker(recoveryWriter.root)] : [],
+ workers,
details: true,
replay: true,
});
@@ -3101,16 +2988,14 @@ for (const missing of [false, true]) {
delete saved.findings[0].identity;
await writeFile(file, JSON.stringify(saved));
}
- const workerRoot = path.join(recovered.root, "reviewer");
- await mkdir(workerRoot);
- const worker = draftFixture(workerRoot, "worker");
+ const worker = await createWorker(recovered);
await worker.writeFindings([source], { complete: true });
for (const name of ["scan-manifest.json", "findings.json", "coverage.json"])
await utimes(path.join(recovered.root, name), 2, 2);
for (const name of await readdir(path.join(recovered.root, "checkpoints")))
await utimes(path.join(recovered.root, "checkpoints", name), 1.5, 1.5);
- await utimes(path.join(workerRoot, "result.json"), 1, 1);
- const result = await recover({ workers: [savedWorker(workerRoot)] });
+ await utimes(path.join(worker.root, "result.json"), 1, 1);
+ const result = await recover({ workers: [savedWorker(worker.root)] });
assert.equal(result.normal.length, 1);
assert.deepEqual(result.recovered, result.normal);
assert.deepEqual(result.warnings, []);
@@ -3161,10 +3046,7 @@ for (const reversed of [false, true]) {
? { ...raw, extensions: { reportId: "report-1" } }
: raw;
await f.writeFindings([update], { complete: true });
- const saved = await readJson(
- f.root,
- layout === "worker" ? "result.json" : "findings.json",
- );
+ const saved = await readJson(f.findingsPath);
assert.equal(saved.findings.length, 2);
assert.deepEqual(
saved.findings
diff --git a/plugins/codex-security/mcp-app/tests/test_artifact_scan_publication_recovery.ts b/plugins/codex-security/mcp-app/tests/test_artifact_scan_publication_recovery.ts
index 3a53d60c2..4ec8d91ea 100644
--- a/plugins/codex-security/mcp-app/tests/test_artifact_scan_publication_recovery.ts
+++ b/plugins/codex-security/mcp-app/tests/test_artifact_scan_publication_recovery.ts
@@ -11,6 +11,7 @@ import {
interruptDraftAfterRaw,
} from "./scan-draft-recovery-fixture.ts";
import {
+ type FixtureFinding,
type RecoveredFinding,
finding,
recoveryPair,
@@ -18,11 +19,61 @@ import {
dateDraftFiles,
} from "./scan-identity-recovery-fixture.ts";
+const replayWithProvenance = {
+ details: true,
+ replay: true,
+ provenanceDetails: true,
+};
+
+// Publish independently so a location-dependent identity remains observable.
+async function publishedPair(
+ t: Parameters<typeof recoveryPair>[0],
+ layout: "standard" | "deep",
+ findings: FixtureFinding[],
+ { complete = false, scoped = false, time = 100 } = {},
+) {
+ const pair = await recoveryPair(t, layout);
+ const { normal, recovered } = pair;
+ for (const target of [normal, recovered]) {
+ if (scoped) {
+ target.context.scope = "src";
+ (
+ target.context.targetContract!.scope as Record<string, unknown>
+ ).requiredIncludePaths = ["src"];
+ }
+ await target.writeFindings(findings, { complete });
+ await dateDraftFiles(target.root, time);
+ }
+ return pair;
+}
+
+async function terminalAt(
+ { normal, recovered, recover }: Awaited<ReturnType<typeof recoveryPair>>,
+ findings: FixtureFinding[],
+ time: number,
+ cut: "raw input" | "committed head",
+) {
+ const checkpoints = path.join(recovered.root, "checkpoints");
+ const original = new Set(await readdir(checkpoints));
+ await normal.writeFindings(findings, { complete: true });
+ const input = recovered.findingsDraft(findings, { complete: true });
+ if (cut === "raw input") await recovered.checkpoint(input);
+ else
+ await interruptDraftWrite(recovered.findingsPath, () =>
+ recovered.write(input),
+ );
+ for (const name of await readdir(checkpoints))
+ if (!original.has(name))
+ await utimes(path.join(checkpoints, name), time, time);
+ if (cut === "committed head")
+ await utimes(path.join(recovered.root, "checkpoint-head.json"), time, time);
+ return recover(replayWithProvenance);
+}
+
for (const authored of [false, true]) {
for (const owner of [undefined, "reviewer"]) {
for (const changedCandidate of [false, true]) {
test(`parent and moved worker keep publication identities on frozen retry (authored=${authored}, owner=${owner ?? "omitted"}, changedCandidate=${changedCandidate})`, async (t) => {
- const { normal, recovered, recover } = await recoveryPair(t, "deep");
const first = finding("Review", {
...(authored ? { identity: { anchor: "review" } } : {}),
provenance: {
@@ -37,10 +88,9 @@ for (const authored of [false, true]) {
locations: [{ path: "src/example.py", startLine: 2 }],
provenance: { source: "local_plugin", candidateId: "candidate-b" },
};
- for (const target of [normal, recovered]) {
- await target.writeFindings([first]);
- await dateDraftFiles(target.root, 100);
- }
+ const { normal, recovered, recover } = await publishedPair(t, "deep", [
+ first,
+ ]);
const workerRoot = path.join(recovered.root, "reviewer");
await mkdir(workerRoot);
const worker = draftFixture(workerRoot, "worker");
@@ -90,14 +140,6 @@ for (const layout of ["standard", "deep"] as const) {
"authored owned",
]) {
test(`${layout}: terminal replacement ${variant} matches frozen recovery (scoped=${scoped})`, async (t) => {
- const { normal, recovered, recover } = await recoveryPair(t, layout);
- if (scoped)
- for (const target of [normal, recovered]) {
- target.context.scope = "src";
- (
- target.context.targetContract!.scope as Record<string, unknown>
- ).requiredIncludePaths = ["src"];
- }
const initial = finding("First review", {
...(variant.includes("authored")
? { identity: { anchor: "authored-review" } }
@@ -121,19 +163,17 @@ for (const layout of ["standard", "deep"] as const) {
: {}),
},
};
- for (const target of [normal, recovered]) {
- await target.writeFindings([initial], { complete: true });
- await dateDraftFiles(target.root, 100);
- }
+ const { normal, recovered, recover } = await publishedPair(
+ t,
+ layout,
+ [initial],
+ { complete: true, scoped },
+ );
await normal.writeFindings([revised], { complete: true });
await recovered.checkpoint(
recovered.findingsDraft([revised], { complete: true }),
);
- const result = await recover({
- details: true,
- replay: true,
- provenanceDetails: true,
- });
+ const result = await recover(replayWithProvenance);
const byEvidence = (rows: RecoveredFinding[]) =>
new Map(
rows.map(({ evidenceProvenance, ...row }) => [row.summary, row]),
@@ -161,48 +201,14 @@ for (const scoped of [false, true]) {
for (const time of [99, 100, 101]) {
for (const cut of ["raw input", "committed head"] as const) {
test(`terminal Deep identity follows producer context at time ${time} (scoped=${scoped}, cut=${cut})`, async (t) => {
- const { normal, recovered, recover } = await recoveryPair(t, "deep");
- if (scoped)
- for (const f of [normal, recovered]) {
- f.context.scope = "src";
- (
- f.context.targetContract!.scope as Record<string, unknown>
- ).requiredIncludePaths = ["src"];
- }
const first = finding("First review");
const revised = {
...first,
title: "Revised review",
summary: "Revised synthetic evidence.",
};
- for (const f of [normal, recovered]) {
- await f.writeFindings([first]);
- await dateDraftFiles(f.root, 100);
- }
- const checkpoints = path.join(recovered.root, "checkpoints");
- const original = new Set(await readdir(checkpoints));
- await normal.writeFindings([revised], { complete: true });
- const input = recovered.findingsDraft([revised], { complete: true });
- if (cut === "raw input") await recovered.checkpoint(input);
- else
- await interruptDraftWrite(
- path.join(recovered.root, "findings.json"),
- () => recovered.write(input),
- );
- for (const name of await readdir(checkpoints))
- if (!original.has(name))
- await utimes(path.join(checkpoints, name), time, time);
- if (cut === "committed head")
- await utimes(
- path.join(recovered.root, "checkpoint-head.json"),
- time,
- time,
- );
- const result = await recover({
- details: true,
- replay: true,
- provenanceDetails: true,
- });
+ const pair = await publishedPair(t, "deep", [first], { scoped });
+ const result = await terminalAt(pair, [revised], time, cut);
assert.equal(result.normal.length, 1);
assert.deepEqual(result.recovered, result.normal);
assert.deepEqual(result.warnings, []);
@@ -232,11 +238,7 @@ for (const cut of ["raw input", "committed head"] as const) {
else
await recovered.write({ ...recovered.draft(pending), findings: [later] });
for (const f of [normal, recovered]) await dateDraftFiles(f.root, 100);
- const result = await recover({
- details: true,
- replay: true,
- provenanceDetails: true,
- });
+ const result = await recover(replayWithProvenance);
const byId = (rows: RecoveredFinding[]) =>
new Map(rows.map((row) => [row.findingId, row]));
assert.equal(result.normal.length, 2);
@@ -348,7 +350,6 @@ for (const authored of [false, true]) {
for (const time of [99, 100, 101]) {
for (const cut of ["raw input", "committed head"] as const) {
test(`terminal Deep replacement retains unchanged siblings (authored=${authored}, time=${time}, cut=${cut})`, async (t) => {
- const { normal, recovered, recover } = await recoveryPair(t, "deep");
const [unchanged, removed, added] = [
"Unchanged",
"Removed",
@@ -359,36 +360,10 @@ for (const authored of [false, true]) {
authored ? { identity: { anchor: title.toLowerCase() } } : {},
),
);
- for (const f of [normal, recovered]) {
- await f.writeFindings([unchanged, removed], { complete: true });
- await dateDraftFiles(f.root, 100);
- }
- const checkpoints = path.join(recovered.root, "checkpoints");
- const original = new Set(await readdir(checkpoints));
- await normal.writeFindings([unchanged, added], { complete: true });
- const input = recovered.findingsDraft([unchanged, added], {
+ const pair = await publishedPair(t, "deep", [unchanged, removed], {
complete: true,
});
- if (cut === "raw input") await recovered.checkpoint(input);
- else
- await interruptDraftWrite(
- path.join(recovered.root, "findings.json"),
- () => recovered.write(input),
- );
- for (const name of await readdir(checkpoints))
- if (!original.has(name))
- await utimes(path.join(checkpoints, name), time, time);
- if (cut === "committed head")
- await utimes(
- path.join(recovered.root, "checkpoint-head.json"),
- time,
- time,
- );
- const result = await recover({
- details: true,
- replay: true,
- provenanceDetails: true,
- });
+ const result = await terminalAt(pair, [unchanged, added], time, cut);
assert.equal(result.normal.length, 2);
assert.deepEqual(result.recovered, result.normal);
for (const row of result.recovered)
@@ -497,12 +472,7 @@ for (const parentState of ["absent", "partial", "terminal"] as const) {
await utimes(path.join(recovered.root, name), 104, 104);
await dateDraftFiles(path.join(recovered.root, "checkpoints"), 104);
}
- const result = await recover({
- workers,
- details: true,
- replay: true,
- provenanceDetails: true,
- });
+ const result = await recover({ workers, ...replayWithProvenance });
const byEvidence = (rows: RecoveredFinding[]) =>
new Map(rows.map((row) => [row.title, row]));
assert.equal(
@@ -534,11 +504,7 @@ for (const abandonedTime of [99, 200, 300]) {
abandonedTime,
abandonedTime,
);
- const result = await recover({
- details: true,
- replay: true,
- provenanceDetails: true,
- });
+ const result = await recover(replayWithProvenance);
assert.deepEqual(result.recovered, result.normal);
assert.equal(result.recovered[0]!.title, "Accepted replacement");
assert.deepEqual(result.warnings, []);
@@ -546,13 +512,12 @@ for (const abandonedTime of [99, 200, 300]) {
}
test("a newer file-authored canonical Deep result supersedes the accepted head", async (t) => {
- const { normal, recovered, recover } = await recoveryPair(t, "deep");
- for (const f of [normal, recovered]) {
- await f.writeFindings([finding("Earlier accepted result")], {
- complete: true,
- });
- await dateDraftFiles(f.root, 100);
- }
+ const { normal, recovered, recover } = await publishedPair(
+ t,
+ "deep",
+ [finding("Earlier accepted result")],
+ { complete: true },
+ );
await normal.writeFindings(
[
finding("File authored update", {
@@ -569,11 +534,7 @@ test("a newer file-authored canonical Deep result supersedes the accepted head",
);
await utimes(path.join(recovered.root, name), 300, 300);
}
- const result = await recover({
- details: true,
- replay: true,
- provenanceDetails: true,
- });
+ const result = await recover(replayWithProvenance);
assert.deepEqual(result.recovered, result.normal);
assert.equal(result.recovered[0]!.title, "File authored update");
assert.deepEqual(result.warnings, []);
@@ -581,16 +542,17 @@ test("a newer file-authored canonical Deep result supersedes the accepted head",
for (const reversed of [false, true]) {
test(`a raw terminal rewrite preserves authored identity collisions (reversed=${reversed})`, async (t) => {
- const { normal, recovered, recover } = await recoveryPair(t, "deep");
const findings = [
"First independent report",
"Second independent report",
].map((title) => finding(title, { identity: { anchor: "same" } }));
if (reversed) findings.reverse();
- for (const f of [normal, recovered]) {
- await f.writeFindings(findings, { complete: true });
- await dateDraftFiles(f.root, 100);
- }
+ const { normal, recovered, recover } = await publishedPair(
+ t,
+ "deep",
+ findings,
+ { complete: true },
+ );
const revised = findings.map((row) => ({
...row,
summary: `Updated ${row.title}`,
@@ -599,11 +561,7 @@ for (const reversed of [false, true]) {
await interruptDraftAfterRaw(() =>
recovered.writeFindings(revised, { complete: true }),
);
- const result = await recover({
- details: true,
- replay: true,
- provenanceDetails: true,
- });
+ const result = await recover(replayWithProvenance);
assert.equal(result.recovered.length, 2);
assert.deepEqual(result.recovered, result.normal);
assert.deepEqual(
@@ -695,11 +653,7 @@ for (const cut of ["published", "pending"] as const) {
recovered.writeFindings([revised], { complete: true }),
);
}
- const result = await recover({
- details: true,
- replay: true,
- provenanceDetails: true,
- });
+ const result = await recover(replayWithProvenance);
assert.deepEqual(result.recovered, result.normal);
assert.equal(result.recovered.length, 1);
assert.deepEqual(result.warnings, []);
@@ -707,13 +661,14 @@ for (const cut of ["published", "pending"] as const) {
}
test("a backdated legacy terminal retains both possible publication histories", async (t) => {
- const { normal, recovered, recover } = await recoveryPair(t, "deep");
const accepted = finding("Accepted review"),
unordered = finding("Unordered legacy review");
- for (const f of [normal, recovered]) {
- await f.writeFindings([accepted], { complete: true });
- await dateDraftFiles(f.root, 200);
- }
+ const { normal, recovered, recover } = await publishedPair(
+ t,
+ "deep",
+ [accepted],
+ { complete: true, time: 200 },
+ );
await normal.writeFindings([accepted, unordered], { complete: true });
// Older writers did not record whether this input preceded or followed the head.
const contents = JSON.stringify(
@@ -726,11 +681,7 @@ test("a backdated legacy terminal retains both possible publication histories",
);
await writeFile(raw, contents);
await utimes(raw, 100, 100);
- const result = await recover({
- details: true,
- replay: true,
- provenanceDetails: true,
- });
+ const result = await recover(replayWithProvenance);
const byTitle = (rows: RecoveredFinding[]) =>
new Map(rows.map((row) => [row.title, row]));
assert.equal(result.recovered.length, 2);
diff --git a/plugins/codex-security/mcp-app/tests/test_build_native_wrappers.ts b/plugins/codex-security/mcp-app/tests/test_build_native_wrappers.ts
index 2eb070ae6..b5e272159 100644
--- a/plugins/codex-security/mcp-app/tests/test_build_native_wrappers.ts
+++ b/plugins/codex-security/mcp-app/tests/test_build_native_wrappers.ts
@@ -1,5 +1,6 @@
import assert from "node:assert/strict";
import { spawn } from "node:child_process";
+import { once } from "node:events";
import test from "node:test";
const builder = new URL(
@@ -23,34 +24,21 @@ test("concurrent runtime builds preserve complete native wrapper exports", async
}
`;
await Promise.all(
- Array.from(
- { length: 3 },
- () =>
- new Promise<void>((resolve, reject) => {
- const child = spawn(
- process.execPath,
- ["--input-type=module", "--eval", source],
- {
- stdio: ["ignore", "pipe", "pipe"],
- },
- );
- let output = "";
- child.stdout.on("data", (data) => {
- output += data;
- });
- child.stderr.on("data", (data) => {
- output += data;
- });
- child.once("error", reject);
- child.once("close", (code) => {
- try {
- assert.equal(code, 0, output);
- resolve();
- } catch (error) {
- reject(error);
- }
- });
- }),
- ),
+ Array.from({ length: 3 }, async () => {
+ const child = spawn(
+ process.execPath,
+ ["--input-type=module", "--eval", source],
+ {
+ stdio: ["ignore", "pipe", "pipe"],
+ },
+ );
+ let output = "";
+ for (const stream of [child.stdout, child.stderr])
+ stream.on("data", (chunk) => {
+ output += chunk;
+ });
+ const [code] = await once(child, "close");
+ assert.equal(code, 0, output);
+ }),
);
});
diff --git a/plugins/codex-security/mcp-app/tests/test_canonical_artifact_contracts.ts b/plugins/codex-security/mcp-app/tests/test_canonical_artifact_contracts.ts
index 83ec49fca..3f5efc614 100644
--- a/plugins/codex-security/mcp-app/tests/test_canonical_artifact_contracts.ts
+++ b/plugins/codex-security/mcp-app/tests/test_canonical_artifact_contracts.ts
@@ -1,4 +1,7 @@
import assert from "node:assert/strict";
+import { createHash } from "node:crypto";
+import { readFile } from "node:fs/promises";
+import { join } from "node:path";
import Ajv2020 from "ajv/dist/2020.js";
import * as z from "zod/v4";
import { readJson } from "./support/json.ts";
@@ -128,22 +131,24 @@ for (const kind of [
document.scan.target.snapshotDigest = `codex-security-snapshot/v1:sha256:${"a".repeat(64)}`;
assert.equal(manifest.validate(document), true);
}
-for (const example of [
- manifest.example,
- await readJson(
- import.meta.dirname,
- "../../examples/legacy-completed-scan/scan-manifest.json",
- ),
-]) {
+for (const directory of ["completed-scan", "legacy-completed-scan"]) {
+ const root = join(import.meta.dirname, "../../examples", directory);
+ const example = await readJson(root, "scan-manifest.json");
assert.equal(manifest.validate(example), true);
- for (const path of [
- "findings.json",
- ...(example.scan.coverageRef ? ["coverage.json"] : []),
- ]) {
+ const paths = ["findings.json"];
+ assert.equal(example.scan.findingsRef, "findings.json");
+ if (example.scan.coverageRef) paths.push("coverage.json");
+ for (const path of paths) {
const document = structuredClone(example);
const artifact = document.scan.artifacts.find(
(entry: { path: string }) => entry.path === path,
);
+ const bytes = await readFile(join(root, path));
+ assert.equal(JSON.parse(bytes.toString("utf8")).scanId, document.scan.id);
+ assert.equal(
+ createHash("sha256").update(bytes).digest("hex"),
+ artifact.sha256,
+ );
document.scan.artifacts = document.scan.artifacts.filter(
(entry: { path: string }) => entry.path !== path,
);
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 6653e9bbe..f0e4b5bea 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
@@ -2,7 +2,7 @@ import { readJson, snapshotScanDraft, writeJson } from "./support/json.ts";
import { workerDraft, finding } from "./scan-draft-fixture.ts";
import { gitText } from "../scripts/git.mjs";
import { temporaryDirectory } from "./support/temporary-directories.ts";
-import type { TextContent } from "@modelcontextprotocol/sdk/types.js";
+import type { TextContent, Tool } from "@modelcontextprotocol/sdk/types.js";
type CompletedResult = {
scanId: string;
manifest: {
@@ -523,28 +523,11 @@ async function testSemanticScanDraftCompletion(
candidate_id: "candidate-0123456789abcdef",
cwe_ids: ["CWE-89"],
};
- await assert.rejects(
- readFile(
- path.join(
- scanDirectory,
- "artifacts",
- "02_discovery",
- "in_scope_files.txt",
- ),
- ),
- { code: "ENOENT" },
- );
- await assert.rejects(
- readFile(
- path.join(
- scanDirectory,
- "artifacts",
- "02_discovery",
- "candidate_ledger.jsonl",
- ),
- ),
- { code: "ENOENT" },
- );
+ for (const name of ["in_scope_files.txt", "candidate_ledger.jsonl"])
+ await assert.rejects(
+ readFile(path.join(scanDirectory, "artifacts", "02_discovery", name)),
+ { code: "ENOENT" },
+ );
const codeEvidence = {
id: "fixture-sql-sink",
@@ -912,82 +895,46 @@ async function testSemanticScanDraftCompletion(
assert.ok(results.manifest.scan.sealedAt);
assert.ok(results.manifest.scan.artifacts.length > 0);
assert.equal(results.findings.findings.length, 1);
- assert.equal(results.findings.findings[0].ruleId, finding.ruleId);
- assert.deepEqual(results.findings.findings[0].taxonomy, finding.taxonomy);
- assert.deepEqual(
- results.findings.findings[0].provenance,
- finding.provenance,
- );
- assert.equal(results.findings.findings[0].remediation, finding.remediation);
- assert.deepEqual(
- results.findings.findings[0].remediationTests,
- finding.remediationTests,
- );
- assert.deepEqual(
- results.findings.findings[0].preventiveControls,
- finding.preventiveControls,
- );
- assert.equal(
- results.findings.findings[0].extensions.candidateId,
- candidate.candidate_id,
- );
- assert.ok(results.findings.findings[0].findingId);
- assert.ok(results.findings.findings[0].occurrenceId);
- assert.ok(results.findings.findings[0].fingerprints.primary);
+ const savedFinding = results.findings.findings[0];
+ assert.equal(savedFinding.ruleId, finding.ruleId);
+ assert.equal(savedFinding.remediation, finding.remediation);
+ for (const field of [
+ "taxonomy",
+ "provenance",
+ "remediationTests",
+ "preventiveControls",
+ ] as const)
+ assert.deepEqual(savedFinding[field], finding[field]);
+ assert.equal(savedFinding.extensions.candidateId, candidate.candidate_id);
+ assert.ok(savedFinding.findingId);
+ assert.ok(savedFinding.occurrenceId);
+ assert.ok(savedFinding.fingerprints.primary);
assert.equal(results.manifest.scan.target.kind, "directory_snapshot");
assert.equal(results.manifest.scan.mode, "repository");
assert.deepEqual(results.manifest.scan.scope.includePaths, ["."]);
assert.deepEqual(results.manifest.scan.scope.excludePaths, []);
assert.deepEqual(results.review, { excludedPaths: [] });
- const head = JSON.parse(
- await readFile(path.join(scanDirectory, "checkpoint-head.json"), "utf8"),
- );
- const retained = JSON.parse(
- await readFile(
- path.join(scanDirectory, "checkpoints", head.checkpoint),
- "utf8",
- ),
+ const head = await readJson(scanDirectory, "checkpoint-head.json");
+ const retained = (
+ await readJson(scanDirectory, "checkpoints", head.checkpoint)
).reviewState;
assert.equal(retained.surfaces[0].disposition, "reported");
+ const withId = (row: Record<string, unknown>, id: string) => ({
+ ...row,
+ id,
+ });
assert.deepEqual(retained.deferred, [
- {
- ...reviewState.deferred[0],
- id: "candidate-deferred-query",
- },
- {
- ...reviewState.deferred[1],
- id: "candidate-reserved-query-2",
- },
+ withId(reviewState.deferred[0], "candidate-deferred-query"),
+ withId(reviewState.deferred[1], "candidate-reserved-query-2"),
reviewState.deferred[2],
- {
- ...reviewState.deferred[3],
- id: "candidate-deferred-query-2",
- },
- {
- ...reviewState.deferred[4],
- id: "candidate-reserved-query-3",
- },
- {
- ...reasonOnlyDeferred,
- id: generatedIds[0],
- },
- {
- ...reasonOnlyDeferred,
- id: generatedIds[1],
- },
- {
- ...explicitCollisionDeferred,
- id: generatedIds[2],
- },
- {
- ...candidateCollisionDeferred,
- id: generatedIds[3],
- },
+ withId(reviewState.deferred[3], "candidate-deferred-query-2"),
+ withId(reviewState.deferred[4], "candidate-reserved-query-3"),
+ withId(reasonOnlyDeferred, generatedIds[0]),
+ withId(reasonOnlyDeferred, generatedIds[1]),
+ withId(explicitCollisionDeferred, generatedIds[2]),
+ withId(candidateCollisionDeferred, generatedIds[3]),
reviewState.deferred[9],
- {
- ...reviewState.deferred[10],
- id: candidateCollisionDeferredId,
- },
+ withId(reviewState.deferred[10], candidateCollisionDeferredId),
]);
assert.deepEqual(retained.openQuestions, savedCoverage.openQuestions);
assert.ok(
@@ -1297,19 +1244,21 @@ function requireToolError(
);
}
+async function listSandboxAwareTools(client: Client, role: string) {
+ assert.deepEqual(
+ client.getServerCapabilities()?.experimental?.["codex/sandbox-state-meta"],
+ {},
+ `The ${role} MCP must advertise actual parent sandbox-state metadata.`,
+ );
+ return (await client.listTools()).tools;
+}
+
async function testParentToolList(bundle: string) {
const client = await startClient(bundle, {
CODEX_SECURITY_STATE_DIR: path.join(temporaryRoot, randomUUID()),
});
try {
- assert.deepEqual(
- client.getServerCapabilities()?.experimental?.[
- "codex/sandbox-state-meta"
- ],
- {},
- "The parent MCP must advertise actual parent sandbox-state metadata.",
- );
- const tools = (await client.listTools()).tools;
+ const tools = await listSandboxAwareTools(client, "parent");
for (const tool of tools) {
if (
(
@@ -1329,7 +1278,7 @@ async function testParentToolList(bundle: string) {
false,
"The parent MCP must not expose a bound discovery worker's threat-model tool.",
);
- for (const name of [
+ const scanTools = [
"prepare_codex_security_review_items",
"list_codex_security_review_items",
"record_codex_security_discovery_candidates",
@@ -1338,6 +1287,9 @@ async function testParentToolList(bundle: string) {
"record_candidate_attack_paths",
"record_codex_security_scan_draft",
"get_codex_security_completed_scan",
+ ];
+ for (const name of [
+ ...scanTools,
"get_codex_security_finding_issues",
"record_codex_security_finding_issues",
"complete_codex_security_scan",
@@ -1357,35 +1309,14 @@ async function testParentToolList(bundle: string) {
}
for (const tool of tools.filter((entry) =>
- [
- "prepare_codex_security_review_items",
- "list_codex_security_review_items",
- "record_codex_security_discovery_candidates",
- "list_codex_security_candidates",
- "record_codex_security_candidate_validations",
- "record_candidate_attack_paths",
- "record_codex_security_scan_draft",
- "get_codex_security_completed_scan",
- ].includes(entry.name),
+ scanTools.includes(entry.name),
)) {
assert.equal(
tool.inputSchema.required?.includes("scanId"),
true,
`${tool.name} must require the authoritative workbench scan identity.`,
);
- for (const forbidden of [
- "path",
- "artifactPath",
- "outputPath",
- "root",
- "operation",
- ]) {
- assert.equal(
- Object.hasOwn(tool.inputSchema.properties ?? {}, forbidden),
- false,
- `${tool.name} must not accept a model-selected artifact destination.`,
- );
- }
+ assertNoArtifactDestination(tool);
if (tool.name === "record_codex_security_scan_draft")
assertSemanticInputProperties(tool.inputSchema);
}
@@ -1465,14 +1396,7 @@ async function testDiscoveryWorkerToolList(bundle: string) {
CODEX_SECURITY_PLUGIN_ROOT: bundledPluginRoot,
});
try {
- assert.deepEqual(
- client.getServerCapabilities()?.experimental?.[
- "codex/sandbox-state-meta"
- ],
- {},
- "The discovery worker MCP must advertise actual parent sandbox-state metadata.",
- );
- const tools = (await client.listTools()).tools;
+ const tools = await listSandboxAwareTools(client, "discovery worker");
assert.deepEqual(
tools.map((tool) => tool.name),
["record_codex_security_scan_draft"],
@@ -1486,19 +1410,7 @@ async function testDiscoveryWorkerToolList(bundle: string) {
"reviewState",
]);
assert.equal(tool.inputSchema.additionalProperties, false);
- for (const forbidden of [
- "path",
- "artifactPath",
- "outputPath",
- "root",
- "operation",
- ]) {
- assert.equal(
- Object.hasOwn(tool.inputSchema.properties ?? {}, forbidden),
- false,
- `${tool.name} must not accept a model-selected ${forbidden}.`,
- );
- }
+ assertNoArtifactDestination(tool);
const input = {
scanId,
@@ -1569,6 +1481,22 @@ async function testDiscoveryWorkerToolList(bundle: string) {
}
}
+function assertNoArtifactDestination(tool: Tool) {
+ for (const forbidden of [
+ "path",
+ "artifactPath",
+ "outputPath",
+ "root",
+ "operation",
+ ]) {
+ assert.equal(
+ Object.hasOwn(tool.inputSchema.properties ?? {}, forbidden),
+ false,
+ `${tool.name} must not accept a model-selected artifact destination (${forbidden}).`,
+ );
+ }
+}
+
function assertSemanticInputProperties(schema: Record<string, unknown>) {
const properties = schema.properties as Record<
string,
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_cancel_response.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_cancel_response.ts
index 53b37175e..38988259a 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_cancel_response.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_cancel_response.ts
@@ -1,11 +1,11 @@
import assert from "node:assert/strict";
import { randomUUID } from "node:crypto";
-import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
+import { mkdir, rm, writeFile } from "node:fs/promises";
import { execFileSync } from "node:child_process";
import { join } from "node:path";
import { temporaryDirectory } from "./support/temporary-directories.ts";
import { fileURLToPath } from "node:url";
-import { importModule } from "./import-module.ts";
+import { importCoordinatorServer } from "./import-module.ts";
interface FixtureScanResults {
scanId?: string;
@@ -52,8 +52,6 @@ interface CancelResponseModule {
};
}
-const applicationRoot = fileURLToPath(new URL("../", import.meta.url));
-const source = await readFile(new URL("../server.ts", import.meta.url), "utf8");
const calls: string[][] = [];
let workspace: FixtureWorkspace;
const scanId = randomUUID();
@@ -91,28 +89,9 @@ const fixture: CancelResponseFixture = {
};
globalThis.cancelResponseFixture = fixture;
try {
- const { createCodexSecurityServer } = (await importModule({
- stdin: {
- contents: source
- .replace(
- "const deepScanCoordinators = new DeepScanCoordinatorRegistry();",
- "const deepScanCoordinators = globalThis.cancelResponseFixture.registry;",
- )
- .replace(
- 'import { PLUGIN_ROOT, runWorkbench, scanRoot } from "./src/workbench-client.js";',
- 'import { PLUGIN_ROOT, scanRoot } from "./src/workbench-client.js";\nconst runWorkbench = (...args) => globalThis.cancelResponseFixture.workbench(...args);',
- ),
- loader: "ts",
- resolveDir: applicationRoot,
- },
- define: {
- __dirname: JSON.stringify(applicationRoot),
- "import.meta.url": JSON.stringify(
- new URL("../server.ts", import.meta.url).href,
- ),
- },
- loader: { ".md": "text" },
- })) as CancelResponseModule;
+ const { createCodexSecurityServer } = (await importCoordinatorServer(
+ "cancelResponseFixture",
+ )) as CancelResponseModule;
const server = createCodexSecurityServer();
const cancel =
server._registeredTools.cancel_codex_security_scan_from_app.handler;
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts
index 2f4e4d71e..bc834a0e4 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_coordinator.ts
@@ -12,7 +12,7 @@ import type {
CodexWorkerRequest,
CodexWorkerResult,
} from "../src/deep-scan/types.js";
-import { mock } from "node:test";
+import { after, mock, test } from "node:test";
import assert from "node:assert/strict";
import { randomUUID } from "node:crypto";
import {
@@ -1056,13 +1056,13 @@ async function testCancellationDuringDiscoveryAcceptanceRejectsLateSuccess() {
},
});
coordinator.start();
- await store.discoveryBlocked.promise;
+ await store.discoveryUpdate.entered;
// The real cancel command persists this state before signaling the coordinator.
store.run.status = "canceled";
for (const worker of store.workers.values()) worker.status = "canceled";
coordinator.cancel("fixture persisted cancellation");
- store.discoveryGate.resolve();
+ store.discoveryUpdate.release();
let terminalSettled = false;
const terminalPromise = coordinator
@@ -2657,83 +2657,84 @@ async function testQuotaFailureStopsDispatchBeforeWorkerShutdown() {
}
}
-try {
- await testDeepScanLifecycle({
- fixtureRun,
- FakeStore,
- FakeExecutor,
- createCoordinator,
- DeepScanCoordinatorRegistry,
- immediateClock,
- });
- await testQuotaFailureStopsDispatchBeforeWorkerShutdown();
- await testStandardWorkersReceiveExistingFalsePositiveFeedback();
- await testConcurrentCheckpointKeepsExistingIteration();
- await testDiscoveryWorkersKeepOneContextAfterPersistedUpdate();
- await testPersistedContextDoesNotChangeAnotherProcessDiscoverySnapshot();
- await testWorkerScopedCandidateSourceAggregation();
- await testRetryKeepsLogicalWorker();
- await testSandboxDiagnosticSurvivesArtifactRetries();
- await testSuccessfulDeepCoverageRetainsIndependentWorkerReviewStatus();
- await testDiscoveryDeadlineReducesSingleBufferedFinding();
- await testDiscoveryAcceptedAtDeadlineIsReduced();
- await testDiscoveryDeadlineWithoutAcceptedWorkersReturnsPartialEvidence();
- await testDiscoveryDeadlineBeforeWorkerDispatchReturnsPartialEvidence();
- await testSingletonHardCapReduction();
- await testExhaustedRetryFailsScan();
- await testPolicyRefusalReplacesDiscoveryImmediately();
- await testTransientDiscoveryErrorsRetainRecovery();
- await testConsecutiveCybersecurityRefusalsFailAtConfiguredThreshold();
- await testRecoverableWorkerErrorsCannotFailScan();
- await testSuccessfulDiscoveryResetsConsecutiveFailureThreshold();
- await testExhaustedInvalidDiscoveryArtifactsAreReplaced();
- await testExhaustedMalformedDiscoveryDoesNotRemainPublishable();
- await testTransientExecutionFailureResumesWorkerThread();
- await testConfigurationFailureDoesNotRetry();
- await testConfigurationFailureDoesNotRetry("Request blocked by cyberPolicy.");
- await testFailureManifestWriteDoesNotMaskOriginalError();
- await testFinishPersistenceFailureRewritesManifestAsFailure();
- await testLongWorkerErrorIsPreservedAtPersistenceBoundary();
- await testDiscoveryPhasePersistenceFailureStopsDispatch();
- await testCancellationClearsRetryWait();
- await testGenericDiagnosticsPreserveMissingResultRetries();
- await testMissingDiscoveryResultResumesExistingThread();
- await testMissingDiscoveryResultResumesExistingThread(true);
- await testInvalidArtifactsRetry();
- await testSharedReceiptSurvivesWorkerRetry();
- await testCancellationAfterCommittedAggregateRemainsCanceled();
- await testRejectedFinishDoesNotOverwriteReplacementManifest();
- await testWaiterDetachAndCancellation();
- await testCancellationDropsUnvalidatedDiscoveryResult();
- await testCancellationDuringDiscoveryAcceptanceRejectsLateSuccess();
- await testRegistryEvictionAndExternalFailure();
- await testStoppedPublicationFailurePreservesOriginalDiagnostic();
- await testStoppedPublicationFailurePreservesPrefixedDiagnostic();
- await testTerminalReadFailureIsNotRecordedAsPublicationFailure();
- await testStaleMutationObservesReplacement();
- await testStoreConfirmedReplacementSurvivesReadFailure();
- await testStoreConfirmationSurvivesReplayAndThreadMetadata();
- await testCoordinatorHeartbeatsStopAfterOwnershipChanges();
- await testCoordinatorHeartbeatsContinueDuringBlockedOwnershipRead();
- await testRemoteObserverRetriesTransientPersistenceFailures();
- await testJoinAndOrphanRules();
- await testResumeDoesNotRequireHistoricalWorkerPrompt("failed");
- await testResumeDoesNotRequireHistoricalWorkerPrompt("canceled");
- await testPausedDiscoverySurvivesCoordinatorRestart(false);
- await testPausedDiscoverySurvivesCoordinatorRestart();
- await testResumedDiscoveryDeadlineUsesPersistedCreationTime();
- await testResumedDiscoveryDeadlineUsesPersistedCreationTime(true);
- await testResumedDiscoveryDeadlineUsesPersistedCreationTime(false, 2.5);
- await testResumedDiscoveryDeadlineUsesPersistedCreationTime(true, 96);
- await testResumedManifestPreservesCompletedReducer(false, false);
- await testResumedManifestPreservesCompletedReducer();
- await testResumedManifestPreservesCompletedReducer(true);
- await testResumedManifestPreservesCompletedReducer(false, true, [
- "api",
- "background jobs",
- ]);
- await testPersistedErrorLimitStopsBeforeRescheduling();
- await testRestartRestoresDispatchOrderAfterMixedResults();
-} finally {
- await temporaryDirectories.cleanup();
+function registerCases<T extends unknown[]>(
+ check: (...args: T) => Promise<void>,
+ cases: T[],
+) {
+ for (const args of cases)
+ test(`${check.name} ${JSON.stringify(args)}`, () => check(...args));
}
+
+after(() => temporaryDirectories.cleanup());
+test("Deep Scan lifecycle", testDeepScanLifecycle);
+test(testQuotaFailureStopsDispatchBeforeWorkerShutdown);
+test(testStandardWorkersReceiveExistingFalsePositiveFeedback);
+test(testConcurrentCheckpointKeepsExistingIteration);
+test(testDiscoveryWorkersKeepOneContextAfterPersistedUpdate);
+test(testPersistedContextDoesNotChangeAnotherProcessDiscoverySnapshot);
+test(testWorkerScopedCandidateSourceAggregation);
+test(testRetryKeepsLogicalWorker);
+test(testSandboxDiagnosticSurvivesArtifactRetries);
+test(testSuccessfulDeepCoverageRetainsIndependentWorkerReviewStatus);
+test(testDiscoveryDeadlineReducesSingleBufferedFinding);
+test(testDiscoveryAcceptedAtDeadlineIsReduced);
+test(testDiscoveryDeadlineWithoutAcceptedWorkersReturnsPartialEvidence);
+test(testDiscoveryDeadlineBeforeWorkerDispatchReturnsPartialEvidence);
+test(testSingletonHardCapReduction);
+test(testExhaustedRetryFailsScan);
+test(testPolicyRefusalReplacesDiscoveryImmediately);
+test(testTransientDiscoveryErrorsRetainRecovery);
+test(testConsecutiveCybersecurityRefusalsFailAtConfiguredThreshold);
+test(testRecoverableWorkerErrorsCannotFailScan);
+test(testSuccessfulDiscoveryResetsConsecutiveFailureThreshold);
+test(testExhaustedInvalidDiscoveryArtifactsAreReplaced);
+test(testExhaustedMalformedDiscoveryDoesNotRemainPublishable);
+test(testTransientExecutionFailureResumesWorkerThread);
+registerCases(testConfigurationFailureDoesNotRetry, [
+ [],
+ ["Request blocked by cyberPolicy."],
+]);
+test(testFailureManifestWriteDoesNotMaskOriginalError);
+test(testFinishPersistenceFailureRewritesManifestAsFailure);
+test(testLongWorkerErrorIsPreservedAtPersistenceBoundary);
+test(testDiscoveryPhasePersistenceFailureStopsDispatch);
+test(testCancellationClearsRetryWait);
+test(testGenericDiagnosticsPreserveMissingResultRetries);
+registerCases(testMissingDiscoveryResultResumesExistingThread, [[], [true]]);
+test(testInvalidArtifactsRetry);
+test(testSharedReceiptSurvivesWorkerRetry);
+test(testCancellationAfterCommittedAggregateRemainsCanceled);
+test(testRejectedFinishDoesNotOverwriteReplacementManifest);
+test(testWaiterDetachAndCancellation);
+test(testCancellationDropsUnvalidatedDiscoveryResult);
+test(testCancellationDuringDiscoveryAcceptanceRejectsLateSuccess);
+test(testRegistryEvictionAndExternalFailure);
+test(testStoppedPublicationFailurePreservesOriginalDiagnostic);
+test(testStoppedPublicationFailurePreservesPrefixedDiagnostic);
+test(testTerminalReadFailureIsNotRecordedAsPublicationFailure);
+test(testStaleMutationObservesReplacement);
+test(testStoreConfirmedReplacementSurvivesReadFailure);
+test(testStoreConfirmationSurvivesReplayAndThreadMetadata);
+test(testCoordinatorHeartbeatsStopAfterOwnershipChanges);
+test(testCoordinatorHeartbeatsContinueDuringBlockedOwnershipRead);
+test(testRemoteObserverRetriesTransientPersistenceFailures);
+test(testJoinAndOrphanRules);
+registerCases(testResumeDoesNotRequireHistoricalWorkerPrompt, [
+ ["failed"],
+ ["canceled"],
+]);
+registerCases(testPausedDiscoverySurvivesCoordinatorRestart, [[false], []]);
+registerCases(testResumedDiscoveryDeadlineUsesPersistedCreationTime, [
+ [],
+ [true],
+ [false, 2.5],
+ [true, 96],
+]);
+registerCases(testResumedManifestPreservesCompletedReducer, [
+ [false, false],
+ [],
+ [true],
+ [false, true, ["api", "background jobs"]],
+]);
+test(testPersistedErrorLimitStopsBeforeRescheduling);
+test(testRestartRestoresDispatchOrderAfterMixedResults);
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_errors.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_errors.ts
index 573f57ab4..454e4c6db 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_errors.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_errors.ts
@@ -1,3 +1,4 @@
+import { test } from "node:test";
import assert from "node:assert/strict";
import { fileURLToPath } from "node:url";
import { importModule } from "./import-module.ts";
@@ -13,21 +14,16 @@ const {
],
});
-testOsErrorCodesRemainRetryable();
-testTextualMissingPathErrorsRemainRetryable();
-testWorkerErrorClassificationPreservesExplicitFailures();
-testUsageLimitClassification();
-
-function testOsErrorCodesRemainRetryable() {
+test(function testOsErrorCodesRemainRetryable() {
for (const code of ["ENOENT", "EACCES", "ENOEXEC", "EPERM"]) {
const original = Object.assign(new Error(`spawn codex ${code}`), { code });
const classified = classifyCodexWorkerError(original);
assert.equal(classified, original);
assert.equal(classified.name, "Error");
}
-}
+});
-function testTextualMissingPathErrorsRemainRetryable() {
+test(function testTextualMissingPathErrorsRemainRetryable() {
for (const diagnostic of [
"Error: No such file or directory (os error 2)",
"Error: The system cannot find the file specified. (os error 2)",
@@ -38,9 +34,9 @@ function testTextualMissingPathErrorsRemainRetryable() {
const classified = classifyCodexWorkerError(original);
assert.equal(classified, original);
}
-}
+});
-function testWorkerErrorClassificationPreservesExplicitFailures() {
+test(function testWorkerErrorClassificationPreservesExplicitFailures() {
const explicit = new DeepScanNonRetryableError(
"Explicitly rejected worker permission profile.",
);
@@ -102,9 +98,9 @@ function testWorkerErrorClassificationPreservesExplicitFailures() {
});
assert.equal(classifyCodexWorkerError(original), original);
}
-}
+});
-function testUsageLimitClassification() {
+test(function testUsageLimitClassification() {
for (const message of [
"Quota exceeded. Check your plan and billing details.",
"To use Codex with your ChatGPT plan, upgrade to Plus: https://chatgpt.com/explore/plus.",
@@ -129,4 +125,4 @@ function testUsageLimitClassification() {
assert.equal(error.name, "Error");
assert.equal(error.message, message);
}
-}
+});
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts
index 3db039286..c72612f46 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_executor.ts
@@ -1,3 +1,18 @@
+import {
+ CodexSdkWorkerExecutor,
+ resolveCodexPath,
+ snapshotWorkerEnvironment,
+ appendItemDiagnostic,
+ isCodexCybersecurityPolicyRefusal,
+ parseDeepScan,
+ temporaryDirectories,
+ fakeCodexFixture,
+ bundledCodexSdkEnvironment,
+ workerRequest,
+ assertReadOnlyWorkerPolicy,
+ workerPermissionProfileOverride,
+ assertWorkerSubagentPolicy,
+} from "./deep_scan_executor_fixture.ts";
import {
mockWorkerSpawn,
testWorkerCancellation,
@@ -12,7 +27,6 @@ import {
} from "./support/fake-codex-source.ts";
import { windowsAcl } from "./support/windows-output-fixture.ts";
import {
- createFakeCodexFixture,
deniedWorkerPermissionProfile,
emptyWorkerPermissionProfile,
trustedParentSandbox,
@@ -25,7 +39,6 @@ import {
assertFlagPair,
nativeConfigOverrides,
} from "./assertions.ts";
-import { createTemporaryDirectories } from "./support/temporary-directories.ts";
import { mock, test, type TestContext } from "node:test";
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
import assert from "node:assert/strict";
@@ -35,7 +48,6 @@ import childProcess, {
type ChildProcess,
} from "node:child_process";
import {
- chmod,
copyFile,
mkdir,
readFile,
@@ -49,7 +61,6 @@ import { createRequire, syncBuiltinESMExports } from "node:module";
import path from "node:path";
import { createInterface } from "node:readline";
import { rootCertificates } from "node:tls";
-import { fileURLToPath } from "node:url";
import { importModule } from "./import-module.ts";
import type {
@@ -62,49 +73,6 @@ import { testDeepScanContextSnapshots } from "./deep_scan_context_snapshot_cases
import { workerTelemetryFixture } from "./deep_scan_worker_telemetry_fixture.ts";
import { testWorkerCyberAccessSettings } from "./deep_scan_worker_settings_cases.ts";
-const executorSource = new URL("../src/deep-scan/executor.ts", import.meta.url);
-const { bundledCodexSdkEnvironment } =
- process.platform === "win32"
- ? {}
- : await importModule({
- entryPoints: [
- fileURLToPath(
- new URL(
- "../../../../sdk/typescript/src/codex-sdk-environment.ts",
- import.meta.url,
- ),
- ),
- ],
- });
-
-const {
- CodexSdkWorkerExecutor,
- resolveCodexPath,
- snapshotWorkerEnvironment,
- appendItemDiagnostic,
- isCodexCybersecurityPolicyRefusal,
- parseDeepScan,
-} = await importModule({
- define: {
- "import.meta.url": JSON.stringify(executorSource.href),
- },
- stdin: {
- // Expose the environment snapshot only for tests.
- contents: `${await readFile(executorSource, "utf8")}
-export { snapshotWorkerEnvironment, appendItemDiagnostic };
-export { isCodexCybersecurityPolicyRefusal } from "./errors.js";
-export { parseDeepScan } from "./response.js";`,
- loader: "ts",
- resolveDir: path.dirname(fileURLToPath(executorSource)),
- sourcefile: fileURLToPath(executorSource),
- },
-});
-
-const temporaryDirectories = createTemporaryDirectories(true);
-const fakeCodexFixture = createFakeCodexFixture.bind(
- null,
- temporaryDirectories,
-);
const previousMarker = process.env.FAKE_CODEX_MARKER;
const ipcFrameError =
"code-mode delegate response exceeds the IPC frame limit: code-mode IPC frame length 76008279 exceeds 67108864 bytes";
@@ -150,31 +118,12 @@ try {
"selected profile files",
);
await check(t, testUnsupportedProviderSnapshotFailsBeforeLaunch);
- await check(
- t,
- () =>
- testWorkerCyberAccessSettings({
- CodexSdkWorkerExecutor,
- fakeCodexFixture,
- parentSandbox: trustedParentSandbox,
- workerRequest,
- assertConfigOverrides,
- assertReadOnlyWorkerPolicy,
- assertWorkerSubagentPolicy,
- restoreEnv,
- }),
- "cyber access settings",
- );
+ await check(t, testWorkerCyberAccessSettings, "cyber access settings");
await check(t, testReportOnlyComparison);
if (process.platform !== "win32") {
await check(
t,
- () =>
- testDeepScanContextSnapshots({
- CodexSdkWorkerExecutor,
- fakeCodexFixture,
- parentSandbox: trustedParentSandbox,
- }),
+ testDeepScanContextSnapshots,
"isolated context snapshots",
);
await check(t, testMissingParentSandboxFailsBeforeWorkerLaunch);
@@ -205,14 +154,7 @@ try {
await check(t, testPreflightBindsExecutableAndHomeBeforeChangingCwd);
await check(
t,
- () =>
- testConcurrentWorkerExecutableAliases({
- CodexSdkWorkerExecutor,
- fakeCodexFixture,
- parentSandbox: trustedParentSandbox,
- bundledCodexSdkEnvironment,
- assertReadOnlyWorkerPolicy,
- }),
+ testConcurrentWorkerExecutableAliases,
"concurrent executable aliases",
);
}
@@ -3601,21 +3543,6 @@ function runWorker(
}).run(workerRequest(promptPath, workingDirectory, options));
}
-function workerRequest(
- promptPath: string,
- workingDirectory: string,
- options: Partial<CodexWorkerRequest> = {},
-): CodexWorkerRequest {
- return {
- kind: "discovery",
- promptPath,
- workingDirectory,
- subagents: 0,
- signal: new AbortController().signal,
- ...options,
- };
-}
-
async function runFixtureWorker(prompt: string, subagents = 0) {
return withWorkerFixture(async (fixture, promptPath, workingDirectory) => {
await writeFile(promptPath, `${prompt}\n`);
@@ -3623,63 +3550,6 @@ async function runFixtureWorker(prompt: string, subagents = 0) {
});
}
-function assertReadOnlyWorkerPolicy(args: readonly string[]) {
- assert.equal(args.includes("--sandbox"), false);
- assert.equal(args.includes("--add-dir"), false);
- assert.deepEqual(
- args.filter((arg: string) => arg.startsWith("approval_policy=")),
- ['approval_policy="never"'],
- );
- assert.equal(
- args.some((arg: string) => arg.includes("network_access")),
- false,
- );
- const override = workerPermissionProfileOverride(args);
- assertConfigOverrides(args, {
- "permissions.codex_security_deep_scan_worker.extends": ":read-only",
- "permissions.codex_security_deep_scan_worker.filesystem.:root": "read",
- "permissions.codex_security_deep_scan_worker.network.enabled": false,
- });
- assert.equal(override.includes('"write"'), false);
-}
-
-function workerPermissionProfileOverride(args: readonly string[]) {
- assert.deepEqual(
- args.filter((arg: string) => arg.startsWith("default_permissions=")),
- ['default_permissions="codex_security_deep_scan_worker"'],
- );
- const overrides = args.filter((arg: string) =>
- arg.startsWith("permissions.codex_security_deep_scan_worker="),
- );
- assert.equal(overrides.length, 1);
- return overrides[0];
-}
-
-function assertWorkerSubagentPolicy(
- args: readonly string[],
- subagents: number,
- codeMode?: { enabled: boolean; excluded_tool_namespaces: string[] },
-) {
- assertConfigOverrides(args, {
- "features.multi_agent_v2.enabled": false,
- "features.multi_agent_v2.max_concurrent_threads_per_session": subagents + 1,
- "features.multi_agent": undefined,
- "features.code_mode.excluded_tool_namespaces":
- codeMode?.excluded_tool_namespaces,
- ...(subagents === 0
- ? {
- "agents.max_threads": undefined,
- "features.enable_fanout": false,
- "features.code_mode.enabled": codeMode?.enabled,
- }
- : {
- "agents.max_threads": subagents,
- "features.enable_fanout": undefined,
- }),
- });
- assert.equal(args.includes("features.multi_agent_v2.enabled=true"), false);
-}
-
async function withWorkerFixture<Result>(
action: (
fixture: Awaited<ReturnType<typeof fakeCodexFixture>>,
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_host_shutdown.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_host_shutdown.ts
index 9065cd803..18b90b0e1 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_host_shutdown.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_host_shutdown.ts
@@ -9,6 +9,7 @@ import { importModule } from "./import-module.ts";
import {
DeepScanCoordinatorRegistry,
FakeExecutor,
+ pausePoint,
FakeStore,
fixtureRun,
immediateClock,
@@ -70,18 +71,14 @@ try {
const registry = new DeepScanCoordinatorRegistry();
const store = new FakeStore(fixture.run);
const executor = new FakeExecutor({ blockDiscoveryAfterCalls: 0 });
- const entered = Promise.withResolvers<void>();
- const release = Promise.withResolvers<void>();
+ const shutdown = pausePoint();
const secondStarted = Promise.withResolvers<void>();
const handlers: Promise<unknown>[] = [];
const outcomes: unknown[] = [];
const signals: AbortSignal[] = [];
let claims = 0;
let now = 0;
- const hold = async () => {
- entered.resolve();
- await release.promise;
- };
+ const hold = async () => await shutdown.pause();
Object.assign(globalThis, {
[fixtureKey]: {
registry,
@@ -153,7 +150,7 @@ try {
const requests = [invoke()];
try {
await Promise.race([
- entered.promise,
+ shutdown.entered,
requests[0].then(() =>
assert.fail("Request settled before the held operation"),
),
@@ -164,7 +161,7 @@ try {
}
await client.close();
assert.ok(signals.every((signal) => signal.aborted));
- release.resolve();
+ shutdown.release();
// Client rejection precedes handler completion when the transport closes.
await Promise.allSettled(handlers);
assert.equal(registry.get(fixture.run.scanId), undefined);
@@ -206,7 +203,7 @@ try {
);
}
} finally {
- release.resolve();
+ shutdown.release();
await client.close();
await Promise.allSettled([...handlers, ...requests]);
const coordinator = registry.get(fixture.run.scanId);
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_logging.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_logging.ts
index 2861b9216..a61c44608 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_logging.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_logging.ts
@@ -4,7 +4,7 @@ import { test } from "node:test";
import type { DeepScanLogEvent } from "../src/deep-scan/types.js";
import {
coordinatorFixture,
- createCoordinator,
+ startCoordinator,
FakeExecutor,
runCoordinator,
temporaryDirectories,
@@ -52,7 +52,7 @@ try {
});
let workerSignal: AbortSignal | undefined;
const events: DeepScanLogEvent[] = [];
- const coordinator = createCoordinator(
+ const coordinator = startCoordinator(
fixture,
store,
{
@@ -72,7 +72,6 @@ try {
},
},
);
- coordinator.start();
await executor.discoveryStarted.promise;
const reason = "fixture cancellation\nwith diagnostic detail";
try {
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_permission_profile_preflight.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_permission_profile_preflight.ts
index 18f2d31de..68c69ffc2 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_permission_profile_preflight.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_permission_profile_preflight.ts
@@ -1,3 +1,4 @@
+import { test } from "node:test";
import { jsonLineInputSource } from "./support/json-line-input-source.ts";
import { readJson, readJsonLines } from "./support/json.ts";
import type { ChildProcess, SpawnOptions } from "node:child_process";
@@ -64,200 +65,7 @@ const unsupportedConfiguration = (error: Error) =>
error?.name === "Error" &&
error.message.includes("with this Codex configuration");
-await testAllowedProfileAndRawArgv();
-await testOpenAiApiKeyFallbackPreservesNativeAuthentication();
-await testSequentialPaginatedResponsesAcrossChunks();
-await testMalformedStreamFailsClosed();
-await testRepeatedCatalogCursorFailsClosed();
-await testDisallowedProfileGivesAdminGuidance();
-await testOtherManagedPolicyRejectionIsGeneric();
-await testMergedProfileCollisionFailsClosed();
-await testDroppedLiteralOrGlobFailsClosed();
-await testLiteralProtoKeyCollisionFailsClosed();
-await testSelectedProfileClassificationRequiresVerifiedString();
-await testMalformedAndUnsupportedResponsesFailClosed();
-await testEarlyExecutableExitIsNotVersionError();
-await testUnexpectedTerminationRemainsRetryable();
-await testStdioFailuresRemainRetryable();
-await testUnknownJsonRpcFailuresPreserveNativeDiagnostics();
-await testRuntimeFallbackWarningClassification();
-await testSpawnErrorFailsClosed();
-await testMissingWorkerDirectoryRemainsRetryable();
-await testAbortKillsPreflightChild();
-await testAbortPreservesCallerReason();
-await testDirectScanSession();
-await testParentTurnCyberAccessProgram();
-
-async function testParentTurnCyberAccessProgram() {
- const parentTurn = {
- threadId: "fixture-parent-thread",
- turnId: "fixture-current-turn",
- };
- const context = (turnId: string, program: unknown) => ({
- type: "turn_context",
- payload: {
- turn_id: turnId,
- ...(program === undefined ? {} : { cyber_access_program: program }),
- },
- });
- const read = (fixture: PreflightFixture) =>
- readDeepScanParentCyberAccessProgram({
- codexPath: fixture.codexPath,
- cwd: fixture.cwd,
- configOverrides: rawOverrides,
- parentTurn,
- signal: new AbortController().signal,
- });
- for (const program of [
- "standard",
- "daybreak_blue",
- "daybreak_red",
- "future_program",
- null,
- undefined,
- ]) {
- await withFakeCodex(
- {
- parentRollout: [
- context("fixture-older-turn", "daybreak_blue"),
- context(parentTurn.turnId, program),
- context("fixture-newer-turn", "daybreak_red"),
- ],
- },
- async (fixture) => {
- assert.equal(await read(fixture), program ?? undefined);
- const calls = await readJsonLines(fixture.callsPath);
- assert.deepEqual(
- calls.map((call) => call.method),
- ["initialize", "initialized", "thread/read"],
- );
- assert.deepEqual(calls[2].params, {
- threadId: parentTurn.threadId,
- includeTurns: false,
- });
- },
- );
- }
- for (const scenario of [
- { parentRollout: [context("fixture-other-turn", "daybreak_blue")] },
- { parentPathUnavailable: true },
- {
- returnedParentThreadId: "fixture-other-thread",
- parentRollout: [context(parentTurn.turnId, "daybreak_blue")],
- },
- ]) {
- await withFakeCodex(scenario, async (fixture) => {
- assert.equal(await read(fixture), undefined);
- });
- }
- await withFakeCodex(
- {
- methodErrors: {
- "thread/read": {
- code: -32600,
- message: `thread not loaded: ${parentTurn.threadId}`,
- },
- },
- },
- async (fixture) => {
- assert.equal(await read(fixture), undefined);
- },
- );
- await withFakeCodex(
- {
- methodErrors: {
- "thread/read": {
- code: -32000,
- message: "Synthetic native read failure",
- },
- },
- stderr: "Synthetic native stderr detail",
- },
- async (fixture) => {
- await assert.rejects(read(fixture), (error: Error) => {
- assert.match(error.message, /Synthetic native read failure/);
- assert.match(error.message, /Synthetic native stderr detail/);
- return true;
- });
- },
- );
- await withFakeCodex({}, async (fixture) => {
- await assert.rejects(read(fixture), { code: "ENOENT" });
- });
-}
-
-async function testDirectScanSession() {
- const permissionProfile = {
- type: "managed",
- file_system: {
- type: "restricted",
- entries: [
- { path: { type: "special", value: { kind: "root" } }, access: "read" },
- {
- path: {
- type: "path",
- path: path.resolve("synthetic", "private [home]"),
- },
- access: "deny",
- },
- ],
- },
- network: "restricted",
- };
- await withFakeCodex(
- { parentPermissionProfile: permissionProfile },
- async (fixture) => {
- const result = await prepareCliDeepScanSession({
- codexPath: fixture.codexPath,
- commandArgs: ["--config", 'model_provider="synthetic_provider"'],
- cwd: fixture.cwd,
- configOverrides: ['model_reasoning_effort="high"'],
- prompt: "Review the supplied synthetic repository.",
- signal: new AbortController().signal,
- });
- assert.deepEqual(result, {
- threadId: "new-scan-thread",
- model: "synthetic-model",
- reasoningEffort: "high",
- permissionProfile,
- });
- const calls = await readJsonLines(fixture.callsPath);
- assert.deepEqual(
- calls.map((call) => call.method),
- ["initialize", "initialized", "thread/start", "thread/inject_items"],
- );
- assert.deepEqual(calls[2].params, {
- cwd: fixture.cwd,
- threadSource: "security_scan",
- ephemeral: false,
- });
- assert.equal(
- calls[3].params.items[0].content[0].text,
- "Review the supplied synthetic repository.",
- );
- const argv = await readJson(fixture.argvPath);
- assert.equal(
- argv[argv.indexOf("--config") + 1],
- 'model_provider="synthetic_provider"',
- );
- assert.equal(argv.includes("--profile"), false);
- },
- );
- await withFakeCodex({ parentPermissionProfile: null }, async (fixture) => {
- await assert.rejects(
- prepareCliDeepScanSession({
- codexPath: fixture.codexPath,
- cwd: fixture.cwd,
- configOverrides: [],
- prompt: "Synthetic scan.",
- signal: new AbortController().signal,
- }),
- /effective permissions/,
- );
- });
-}
-
-async function testAllowedProfileAndRawArgv() {
+test(async function testAllowedProfileAndRawArgv() {
const codexHome = "/fixture/canonical-codex-home";
const env = Object.freeze({
...process.env,
@@ -351,9 +159,9 @@ async function testAllowedProfileAndRawArgv() {
},
{ longExecutable: true },
);
-}
+});
-async function testOpenAiApiKeyFallbackPreservesNativeAuthentication() {
+test(async function testOpenAiApiKeyFallbackPreservesNativeAuthentication() {
for (const { account, requiresOpenaiAuth, forcedLoginMethod, expected } of [
{ account: null, requiresOpenaiAuth: true, expected: true },
{ account: { type: "apiKey" }, requiresOpenaiAuth: true, expected: false },
@@ -406,9 +214,9 @@ async function testOpenAiApiKeyFallbackPreservesNativeAuthentication() {
},
);
}
-}
+});
-async function testSequentialPaginatedResponsesAcrossChunks() {
+test(async function testSequentialPaginatedResponsesAcrossChunks() {
await withFakeCodex(
{
streamResponses: true,
@@ -437,9 +245,9 @@ async function testSequentialPaginatedResponsesAcrossChunks() {
);
},
);
-}
+});
-async function testMalformedStreamFailsClosed() {
+test(async function testMalformedStreamFailsClosed() {
for (const output of [
"not JSON\n",
"[]\n",
@@ -459,9 +267,9 @@ async function testMalformedStreamFailsClosed() {
},
);
}
-}
+});
-async function testRepeatedCatalogCursorFailsClosed() {
+test(async function testRepeatedCatalogCursorFailsClosed() {
await withFakeCodex(
{
configResult: configReadResult(expectedProfile),
@@ -479,9 +287,9 @@ async function testRepeatedCatalogCursorFailsClosed() {
);
},
);
-}
+});
-async function testDisallowedProfileGivesAdminGuidance() {
+test(async function testDisallowedProfileGivesAdminGuidance() {
await withFakeCodex(
{
stderr: "SECRET_REPOSITORY_PATH=/repo/private\n",
@@ -520,9 +328,9 @@ async function testDisallowedProfileGivesAdminGuidance() {
assert.equal(Object.hasOwn(calls[4], "params"), false);
},
);
-}
+});
-async function testOtherManagedPolicyRejectionIsGeneric() {
+test(async function testOtherManagedPolicyRejectionIsGeneric() {
await withFakeCodex(
{
configResult: configReadResult(expectedProfile, "enterprise-default"),
@@ -545,9 +353,9 @@ async function testOtherManagedPolicyRejectionIsGeneric() {
);
},
);
-}
+});
-async function testMergedProfileCollisionFailsClosed() {
+test(async function testMergedProfileCollisionFailsClosed() {
await withFakeCodex(
{
configResult: configReadResult({
@@ -567,9 +375,9 @@ async function testMergedProfileCollisionFailsClosed() {
);
},
);
-}
+});
-async function testDroppedLiteralOrGlobFailsClosed() {
+test(async function testDroppedLiteralOrGlobFailsClosed() {
for (const key of ["/repo/temp[1]", "/"] as const) {
const weakened = structuredClone(expectedProfile);
delete weakened.filesystem[key];
@@ -588,9 +396,9 @@ async function testDroppedLiteralOrGlobFailsClosed() {
},
);
}
-}
+});
-async function testLiteralProtoKeyCollisionFailsClosed() {
+test(async function testLiteralProtoKeyCollisionFailsClosed() {
const profileWithLiteralProtoKey = Object.fromEntries([
...Object.entries(expectedProfile),
["__proto__", "write"],
@@ -611,9 +419,9 @@ async function testLiteralProtoKeyCollisionFailsClosed() {
);
},
);
-}
+});
-async function testSelectedProfileClassificationRequiresVerifiedString() {
+test(async function testSelectedProfileClassificationRequiresVerifiedString() {
for (const selected of [undefined, null, 17, ":read-only"]) {
const configResult = configReadResult(expectedProfile);
configResult.config.default_permissions = selected;
@@ -635,9 +443,9 @@ async function testSelectedProfileClassificationRequiresVerifiedString() {
},
);
}
-}
+});
-async function testMalformedAndUnsupportedResponsesFailClosed() {
+test(async function testMalformedAndUnsupportedResponsesFailClosed() {
await withFakeCodex(
{
configResult: configReadResult(expectedProfile),
@@ -694,9 +502,9 @@ async function testMalformedAndUnsupportedResponsesFailClosed() {
);
},
);
-}
+});
-async function testEarlyExecutableExitIsNotVersionError() {
+test(async function testEarlyExecutableExitIsNotVersionError() {
await withFakeCodex(
{
exitOnMethod: "initialize",
@@ -719,9 +527,9 @@ async function testEarlyExecutableExitIsNotVersionError() {
);
},
);
-}
+});
-async function testUnexpectedTerminationRemainsRetryable() {
+test(async function testUnexpectedTerminationRemainsRetryable() {
await withFakeCodex(
{
hangAt: "config/read",
@@ -742,9 +550,9 @@ async function testUnexpectedTerminationRemainsRetryable() {
assert.equal(children[0].signalCode, "SIGKILL");
},
);
-}
+});
-async function testStdioFailuresRemainRetryable() {
+test(async function testStdioFailuresRemainRetryable() {
for (const stream of ["stdin", "stdout", "write callback"] as const) {
await withFakeCodex(
{ hangAt: "initialize" },
@@ -793,9 +601,9 @@ async function testStdioFailuresRemainRetryable() {
},
);
}
-}
+});
-async function testUnknownJsonRpcFailuresPreserveNativeDiagnostics() {
+test(async function testUnknownJsonRpcFailuresPreserveNativeDiagnostics() {
for (const code of [-32603, -32602, -32000, undefined]) {
await withFakeCodex(
{
@@ -823,37 +631,9 @@ async function testUnknownJsonRpcFailuresPreserveNativeDiagnostics() {
},
);
}
-}
-
-async function testSpawnErrorFailsClosed() {
- const missingCodex = path.join(tmpdir(), `missing-codex-${process.pid}`);
- await assert.rejects(
- preflight(missingCodex, tmpdir()),
- (error: NodeJS.ErrnoException & { cause?: NodeJS.ErrnoException }) =>
- error?.name === "Error" &&
- error.cause?.code === "ENOENT" &&
- error.message.includes(JSON.stringify(missingCodex)) &&
- error.message.includes("could not start") &&
- error.message.includes("with --version") &&
- error.message.includes("CODEX_CLI_PATH/PATH") &&
- !error.message.includes("does not support"),
- );
-}
-
-async function testMissingWorkerDirectoryRemainsRetryable() {
- await withFakeCodex({}, async ({ codexPath, cwd, argvPath }) => {
- await assert.rejects(
- preflight(codexPath, path.join(cwd, "missing-worker-directory")),
- (error: NodeJS.ErrnoException & { cause?: NodeJS.ErrnoException }) =>
- error?.name === "Error" &&
- error.cause?.code === "ENOENT" &&
- error.message.includes("could not start"),
- );
- await assert.rejects(readFile(argvPath), { code: "ENOENT" });
- });
-}
+});
-async function testRuntimeFallbackWarningClassification() {
+test(async function testRuntimeFallbackWarningClassification() {
const warning = `Configured value for \`permission_profile\` is disallowed by requirements; falling back from \`${profileId}\` to required value \`enterprise-default\`.`;
const error = deepScanPermissionProfileFallbackError(warning);
assert.equal(error?.name, "DeepScanNonRetryableError");
@@ -887,9 +667,37 @@ async function testRuntimeFallbackWarningClassification() {
deepScanPermissionProfileFallbackError(emptyDestinationWarning)?.name,
"DeepScanNonRetryableError",
);
-}
+});
-async function testAbortKillsPreflightChild() {
+test(async function testSpawnErrorFailsClosed() {
+ const missingCodex = path.join(tmpdir(), `missing-codex-${process.pid}`);
+ await assert.rejects(
+ preflight(missingCodex, tmpdir()),
+ (error: NodeJS.ErrnoException & { cause?: NodeJS.ErrnoException }) =>
+ error?.name === "Error" &&
+ error.cause?.code === "ENOENT" &&
+ error.message.includes(JSON.stringify(missingCodex)) &&
+ error.message.includes("could not start") &&
+ error.message.includes("with --version") &&
+ error.message.includes("CODEX_CLI_PATH/PATH") &&
+ !error.message.includes("does not support"),
+ );
+});
+
+test(async function testMissingWorkerDirectoryRemainsRetryable() {
+ await withFakeCodex({}, async ({ codexPath, cwd, argvPath }) => {
+ await assert.rejects(
+ preflight(codexPath, path.join(cwd, "missing-worker-directory")),
+ (error: NodeJS.ErrnoException & { cause?: NodeJS.ErrnoException }) =>
+ error?.name === "Error" &&
+ error.cause?.code === "ENOENT" &&
+ error.message.includes("could not start"),
+ );
+ await assert.rejects(readFile(argvPath), { code: "ENOENT" });
+ });
+});
+
+test(async function testAbortKillsPreflightChild() {
for (const [ignoreTermination, inheritStdio] of [
[false, false],
[true, false],
@@ -952,9 +760,9 @@ async function testAbortKillsPreflightChild() {
},
);
}
-}
+});
-async function testAbortPreservesCallerReason() {
+test(async function testAbortPreservesCallerReason() {
for (const run of [
preflightDeepScanWorkerPermissionProfile,
readDeepScanRuntimeConfig,
@@ -1010,7 +818,176 @@ async function testAbortPreservesCallerReason() {
}
}
}
-}
+});
+
+test(async function testDirectScanSession() {
+ const permissionProfile = {
+ type: "managed",
+ file_system: {
+ type: "restricted",
+ entries: [
+ { path: { type: "special", value: { kind: "root" } }, access: "read" },
+ {
+ path: {
+ type: "path",
+ path: path.resolve("synthetic", "private [home]"),
+ },
+ access: "deny",
+ },
+ ],
+ },
+ network: "restricted",
+ };
+ await withFakeCodex(
+ { parentPermissionProfile: permissionProfile },
+ async (fixture) => {
+ const result = await prepareCliDeepScanSession({
+ codexPath: fixture.codexPath,
+ commandArgs: ["--config", 'model_provider="synthetic_provider"'],
+ cwd: fixture.cwd,
+ configOverrides: ['model_reasoning_effort="high"'],
+ prompt: "Review the supplied synthetic repository.",
+ signal: new AbortController().signal,
+ });
+ assert.deepEqual(result, {
+ threadId: "new-scan-thread",
+ model: "synthetic-model",
+ reasoningEffort: "high",
+ permissionProfile,
+ });
+ const calls = await readJsonLines(fixture.callsPath);
+ assert.deepEqual(
+ calls.map((call) => call.method),
+ ["initialize", "initialized", "thread/start", "thread/inject_items"],
+ );
+ assert.deepEqual(calls[2].params, {
+ cwd: fixture.cwd,
+ threadSource: "security_scan",
+ ephemeral: false,
+ });
+ assert.equal(
+ calls[3].params.items[0].content[0].text,
+ "Review the supplied synthetic repository.",
+ );
+ const argv = await readJson(fixture.argvPath);
+ assert.equal(
+ argv[argv.indexOf("--config") + 1],
+ 'model_provider="synthetic_provider"',
+ );
+ assert.equal(argv.includes("--profile"), false);
+ },
+ );
+ await withFakeCodex({ parentPermissionProfile: null }, async (fixture) => {
+ await assert.rejects(
+ prepareCliDeepScanSession({
+ codexPath: fixture.codexPath,
+ cwd: fixture.cwd,
+ configOverrides: [],
+ prompt: "Synthetic scan.",
+ signal: new AbortController().signal,
+ }),
+ /effective permissions/,
+ );
+ });
+});
+
+test(async function testParentTurnCyberAccessProgram() {
+ const parentTurn = {
+ threadId: "fixture-parent-thread",
+ turnId: "fixture-current-turn",
+ };
+ const context = (turnId: string, program: unknown) => ({
+ type: "turn_context",
+ payload: {
+ turn_id: turnId,
+ ...(program === undefined ? {} : { cyber_access_program: program }),
+ },
+ });
+ const read = (fixture: PreflightFixture) =>
+ readDeepScanParentCyberAccessProgram({
+ codexPath: fixture.codexPath,
+ cwd: fixture.cwd,
+ configOverrides: rawOverrides,
+ parentTurn,
+ signal: new AbortController().signal,
+ });
+ for (const program of [
+ "standard",
+ "daybreak_blue",
+ "daybreak_red",
+ "future_program",
+ null,
+ undefined,
+ ]) {
+ await withFakeCodex(
+ {
+ parentRollout: [
+ context("fixture-older-turn", "daybreak_blue"),
+ context(parentTurn.turnId, program),
+ context("fixture-newer-turn", "daybreak_red"),
+ ],
+ },
+ async (fixture) => {
+ assert.equal(await read(fixture), program ?? undefined);
+ const calls = await readJsonLines(fixture.callsPath);
+ assert.deepEqual(
+ calls.map((call) => call.method),
+ ["initialize", "initialized", "thread/read"],
+ );
+ assert.deepEqual(calls[2].params, {
+ threadId: parentTurn.threadId,
+ includeTurns: false,
+ });
+ },
+ );
+ }
+ for (const scenario of [
+ { parentRollout: [context("fixture-other-turn", "daybreak_blue")] },
+ { parentPathUnavailable: true },
+ {
+ returnedParentThreadId: "fixture-other-thread",
+ parentRollout: [context(parentTurn.turnId, "daybreak_blue")],
+ },
+ ]) {
+ await withFakeCodex(scenario, async (fixture) => {
+ assert.equal(await read(fixture), undefined);
+ });
+ }
+ await withFakeCodex(
+ {
+ methodErrors: {
+ "thread/read": {
+ code: -32600,
+ message: `thread not loaded: ${parentTurn.threadId}`,
+ },
+ },
+ },
+ async (fixture) => {
+ assert.equal(await read(fixture), undefined);
+ },
+ );
+ await withFakeCodex(
+ {
+ methodErrors: {
+ "thread/read": {
+ code: -32000,
+ message: "Synthetic native read failure",
+ },
+ },
+ stderr: "Synthetic native stderr detail",
+ },
+ async (fixture) => {
+ await assert.rejects(read(fixture), (error: Error) => {
+ assert.match(error.message, /Synthetic native read failure/);
+ assert.match(error.message, /Synthetic native stderr detail/);
+ return true;
+ });
+ },
+ );
+ await withFakeCodex({}, async (fixture) => {
+ await assert.rejects(read(fixture), { code: "ENOENT" });
+ });
+});
async function assertPreflightStopped(
children: ChildProcess[],
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 0845ae849..9355d9a53 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
@@ -110,7 +110,7 @@ const {
} = host;
test("three Standard scans publish two distinct findings with their original evidence", async (t) => {
- const { run, store, call, runWorkbench } = await createFixture(t, {
+ const { run, store, completeScan, runWorkbench } = await createFixture(t, {
deepConfig:
"[deep_scan]\nworkers = 1\nstop_after_no_new = 1\nmax_discovery_runs = 3\n",
});
@@ -178,9 +178,7 @@ test("three Standard scans publish two distinct findings with their original evi
const terminal = await coordinator.wait(undefined, 30_000);
assert.equal(terminal?.status, "succeeded");
assert.equal(terminal.dispatchedCount, 3);
- assertSuccess(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- );
+ assertSuccess(await completeScan());
const saved = JSON.parse(
(await snapshot(run)).files["findings.json"]!,
).findings;
@@ -195,13 +193,8 @@ test("three Standard scans publish two distinct findings with their original evi
test("public partial drafts retain checkpoints after coordinator adoption", async (t) => {
const fixture = await createFixture(t);
- const { run, store, call, runWorkbench } = fixture;
- assertSuccess(
- await call(
- "record_codex_security_scan_draft",
- partial(run, "generation-one"),
- ),
- );
+ const { run, store, runWorkbench } = fixture;
+ assertSuccess(await fixture.recordDraft(partial(run, "generation-one")));
const first = await checkpoints(run);
// Main retains the submitted checkpoint and normalized parent snapshot.
assert.equal(Object.keys(first).length, 2);
@@ -212,12 +205,7 @@ test("public partial drafts retain checkpoints after coordinator adoption", asyn
assert.equal(claim.acquired, true);
assert.equal(claim.run.coordinatorGeneration, 2);
- assertSuccess(
- await call(
- "record_codex_security_scan_draft",
- partial(run, "generation-two"),
- ),
- );
+ assertSuccess(await fixture.recordDraft(partial(run, "generation-two")));
const retained = await checkpoints(run);
assert.equal(Object.keys(retained).length, 4);
for (const [name, bytes] of Object.entries(first))
@@ -235,29 +223,21 @@ test("public partial drafts retain checkpoints after coordinator adoption", asyn
const before = await snapshot(run);
assertToolError(
- await call("record_codex_security_scan_draft", {
+ await fixture.recordDraft({
...partial(run, "unfenced-final"),
complete: true,
}),
/current coordinator lease/,
);
- const context = await createScanArtifactContext(run.scanId, runWorkbench, {
- requireRunning: true,
- });
+ const writeDraft = await openDraftWriter(run.scanId, runWorkbench);
await assert.rejects(
- recordCodexSecurityScanDraftViaWorkbench(
- context,
- partial(run, "stale-generation"),
- runWorkbench,
- undefined,
- { coordinatorGeneration: 1, resultPath: null },
- ),
+ writeDraft(partial(run, "stale-generation"), runWorkbench, undefined, {
+ coordinatorGeneration: 1,
+ resultPath: null,
+ }),
/newer generation/,
);
- assertToolError(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- /deep/i,
- );
+ assertToolError(await fixture.completeScan(), /deep/i);
assert.deepEqual(await snapshot(run), before);
assert.deepEqual(await readdir(path.join(run.scanDir, "drafts")), []);
});
@@ -320,12 +300,9 @@ for (const [
] of scenarios) {
test(`selected reducer survives recovery and public completion: ${label}`, async (t) => {
const fixture = await createFixture(t, paths);
- const { run, store, call, runWorkbench, instant } = fixture;
+ const { run, store, runWorkbench, instant } = fixture;
assertSuccess(
- await call(
- "record_codex_security_scan_draft",
- partial(run, "parent-checkpoint-only"),
- ),
+ await fixture.recordDraft(partial(run, "parent-checkpoint-only")),
);
const parentCheckpoints = await checkpoints(run);
assert.equal(Object.keys(parentCheckpoints).length, 2);
@@ -345,12 +322,9 @@ for (const [
.map((worker) => worker.mergeState),
Array(4).fill("merged"),
);
- const context = await createScanArtifactContext(run.scanId, runWorkbench, {
- requireRunning: true,
- });
+ const writeDraft = await openDraftWriter(run.scanId, runWorkbench);
const publish = async (index: number, coordinatorGeneration = 2) =>
- recordCodexSecurityScanDraftViaWorkbench(
- context,
+ writeDraft(
{
...JSON.parse(await readFile(results[index], "utf8")),
reviewState,
@@ -381,13 +355,7 @@ for (const [
clock: { now: () => Date.parse(instant), sleep: async () => {} },
onComplete: async (draft, signal, publication) => {
publications.push(publication);
- await recordCodexSecurityScanDraftViaWorkbench(
- context,
- draft,
- runWorkbench,
- signal,
- publication,
- );
+ await writeDraft(draft, runWorkbench, signal, publication);
await assertInterleavedProgressRetained(fixture);
},
});
@@ -404,11 +372,9 @@ for (const [
const beforeCompletion = await snapshot(run);
const lateDraft = partial(run, "late-parent-checkpoint");
- assertToolError(await call("record_codex_security_scan_draft", lateDraft));
+ assertToolError(await fixture.recordDraft(lateDraft));
assert.deepEqual(await snapshot(run), beforeCompletion);
- assertSuccess(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- );
+ assertSuccess(await fixture.completeScan());
const sealed = await snapshot(run);
const manifest = JSON.parse(sealed.files["scan-manifest.json"]);
assert.equal(
@@ -428,15 +394,13 @@ for (const [
);
}
assert.deepEqual(sealed.checkpoints, beforeCompletion.checkpoints);
- assertSuccess(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- );
+ assertSuccess(await fixture.completeScan());
assert.deepEqual(
await snapshot(run),
sealed,
"completion replay is byte-stable",
);
- assertToolError(await call("record_codex_security_scan_draft", lateDraft));
+ assertToolError(await fixture.recordDraft(lateDraft));
assert.deepEqual(
await snapshot(run),
sealed,
@@ -453,7 +417,7 @@ for (const [claimed, outputFailure] of [
]) {
test(`legacy discovery parent with claimed=${claimed} ${outputFailure ? "retains failure after an output write error" : "retains progress before first completion"}`, async (t) => {
const fixture = await createFixture(t);
- const { run, store, call, runWorkbench } = fixture;
+ const { run, store, runWorkbench } = fixture;
if (claimed) {
const claim = await store.claimCoordinator({
scanId: run.scanId,
@@ -479,22 +443,14 @@ for (const [claimed, outputFailure] of [
assert.equal(terminal.coordinatorGeneration, claimed ? 2 : 1);
assert.equal(terminal.manifestPath, manifestPath);
if (!outputFailure) {
- assertSuccess(
- await call(
- "record_codex_security_scan_draft",
- partial(run, "legacy-progress"),
- ),
- );
+ assertSuccess(await fixture.recordDraft(partial(run, "legacy-progress")));
const progress = await checkpoints(run);
assert.ok(Object.keys(progress).length > 0);
- assertToolError(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- /incomplete/,
- );
+ assertToolError(await fixture.completeScan(), /incomplete/);
assert.deepEqual(await checkpoints(run), progress);
}
assertSuccess(
- await call("record_codex_security_scan_draft", {
+ await fixture.recordDraft({
scanId: run.scanId,
complete: true,
findings: [],
@@ -504,10 +460,7 @@ for (const [claimed, outputFailure] of [
if (outputFailure) {
const report = path.join(run.scanDir, "report.html");
await mkdir(report);
- assertToolError(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- /report\.html/,
- );
+ assertToolError(await fixture.completeScan(), /report\.html/);
await rm(report, { recursive: true });
const context = await runWorkbench(["get-scan", "--scan-id", run.scanId]);
assert.equal(
@@ -516,32 +469,25 @@ for (const [claimed, outputFailure] of [
);
const interrupted = await snapshot(run);
assertToolError(
- await call("record_codex_security_scan_draft", {
+ await fixture.recordDraft({
...partial(run, "late-legacy-draft"),
complete: true,
threatModel: { summary: "Late replacement" },
}),
);
assert.deepEqual(await snapshot(run), interrupted);
- assertToolError(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- /running/,
- );
+ assertToolError(await fixture.completeScan(), /running/);
} else {
- assertSuccess(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- );
+ assertSuccess(await fixture.completeScan());
}
});
}
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;
+ const { run, store, runWorkbench } = fixture;
await commitReducers(fixture, [1, 2], [highId, lowId]);
- const context = await createScanArtifactContext(run.scanId, runWorkbench, {
- requireRunning: true,
- });
+ const writeDraft = await openDraftWriter(run.scanId, runWorkbench);
const draft: ScanDraftInput = {
scanId: run.scanId,
complete: true,
@@ -550,14 +496,14 @@ test("legacy terminal aggregate rejects late public drafts with both complete fl
threatModel: { summary: "Selected aggregate" },
};
await assert.rejects(
- recordCodexSecurityScanDraftViaWorkbench(context, draft, async (args) => {
+ writeDraft(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);
+ await writeDraft(draft, runWorkbench);
assert.deepEqual(await snapshot(run), published);
await assertInterleavedProgressRetained(fixture);
const terminal = await store.finish({
@@ -570,15 +516,12 @@ test("legacy terminal aggregate rejects late public drafts with both complete fl
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/,
- );
+ assertToolError(await fixture.completeScan(), /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", {
+ await fixture.recordDraft({
...partial(run, "late-progress"),
complete,
threatModel: { summary: "Late replacement" },
@@ -587,9 +530,7 @@ test("legacy terminal aggregate rejects late public drafts with both complete fl
);
assert.deepEqual(await snapshot(run), interrupted);
}
- assertSuccess(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- );
+ assertSuccess(await fixture.completeScan());
const completed = await snapshot(run);
assert.deepEqual(
JSON.parse(completed.files["scan-manifest.json"]).scan.review,
@@ -605,14 +546,12 @@ test("legacy terminal aggregate rejects late public drafts with both complete fl
for (const claimed of [false, true]) {
test(`partial drafts retain a capped publication with claimed=${claimed}`, async (t) => {
const fixture = await createFixture(t);
- const { run, store, call, runWorkbench, instant } = fixture;
+ const { run, store, runWorkbench, instant } = fixture;
const selectedRun = claimed
? (await store.claimCoordinator({ scanId: run.scanId, threadId: owner }))
.run
: run;
- const context = await createScanArtifactContext(run.scanId, runWorkbench, {
- requireRunning: true,
- });
+ const writeDraft = await openDraftWriter(run.scanId, runWorkbench);
const elapsedSeconds = ((run.config.maxTimeHours ?? 1) + 1) * 3_600;
fixture.setTime(elapsedSeconds);
const deadline = Date.parse(instant) + elapsedSeconds * 1_000;
@@ -627,8 +566,7 @@ for (const claimed of [false, true]) {
},
clock: { now: () => deadline, sleep: async () => {} },
onComplete: async (draft, signal, publication) => {
- await recordCodexSecurityScanDraftViaWorkbench(
- context,
+ await writeDraft(
draft,
runWorkbench,
signal,
@@ -648,24 +586,16 @@ for (const claimed of [false, true]) {
const report = path.join(run.scanDir, "report.html");
await mkdir(report);
- assertToolError(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- /report\.html/,
- );
+ assertToolError(await fixture.completeScan(), /report\.html/);
await rm(report, { recursive: true });
const interrupted = await snapshot(run);
assertToolError(
- await call(
- "record_codex_security_scan_draft",
- partial(run, "late-progress"),
- ),
+ await fixture.recordDraft(partial(run, "late-progress")),
/coordinator lease|terminal/,
);
assert.deepEqual(await snapshot(run), interrupted);
- assertSuccess(
- await call("complete_codex_security_scan", { scanId: run.scanId }),
- );
+ assertSuccess(await fixture.completeScan());
const completed = await snapshot(run);
assert.ok(JSON.parse(completed.files["scan-manifest.json"]).scan.sealedAt);
assert.deepEqual(
@@ -681,9 +611,7 @@ for (const status of ["failed", "interrupted"] as const) {
test(`selected publication retains ${status} and exact failure replay`, async (t) => {
const { run, store, runWorkbench } = await createFixture(t);
await store.claimCoordinator({ scanId: run.scanId, threadId: owner });
- const context = await createScanArtifactContext(run.scanId, runWorkbench, {
- requireRunning: true,
- });
+ const writeDraft = await openDraftWriter(run.scanId, runWorkbench);
const draft: ScanDraftInput = {
scanId: run.scanId,
findings: [],
@@ -691,8 +619,7 @@ for (const status of ["failed", "interrupted"] as const) {
};
const publication = { coordinatorGeneration: 2, resultPath: null };
await assert.rejects(
- recordCodexSecurityScanDraftViaWorkbench(
- context,
+ writeDraft(
draft,
async (args) => {
await runWorkbench(args);
@@ -703,13 +630,7 @@ for (const status of ["failed", "interrupted"] as const) {
),
/lost publication response/,
);
- await recordCodexSecurityScanDraftViaWorkbench(
- context,
- draft,
- runWorkbench,
- undefined,
- publication,
- );
+ await writeDraft(draft, runWorkbench, undefined, publication);
const message = "Synthetic failure after publication";
const failed = await store.fail(run.scanId, message, status);
assert.equal(failed.status, status);
@@ -732,7 +653,7 @@ for (const status of ["failed", "interrupted"] as const) {
}
async function assertInterleavedProgressRetained(fixture: PublicationFixture) {
- const { run, call } = fixture;
+ const { run } = fixture;
const before = await snapshot(run);
const progress = {
scanId: run.scanId,
@@ -751,7 +672,7 @@ async function assertInterleavedProgressRetained(fixture: PublicationFixture) {
},
threatModel: { summary: "Unselected progress model" },
};
- assertSuccess(await call("record_codex_security_scan_draft", progress));
+ assertSuccess(await fixture.recordDraft(progress));
const after = await snapshot(run);
assert.deepEqual(after.files, before.files);
for (const [name, contents] of Object.entries(before.checkpoints))
@@ -834,6 +755,17 @@ async function createFixture(t: TestContext, paths: FixturePaths = {}) {
});
if (transport.stderr instanceof Readable) transport.stderr.resume();
let connected: Promise<void> | undefined;
+ async function call(
+ name: string,
+ args: Record<string, unknown> | ScanDraftInput,
+ ) {
+ await (connected ??= client.connect(transport));
+ return client.callTool({
+ name,
+ arguments: { ...args },
+ _meta: { "openai/threadId": owner },
+ });
+ }
return {
run,
store,
@@ -844,17 +776,20 @@ async function createFixture(t: TestContext, paths: FixturePaths = {}) {
now = new Date(Date.parse(instant) + offset * 1_000).toISOString();
return now;
},
- async call(name: string, args: Record<string, unknown> | ScanDraftInput) {
- await (connected ??= client.connect(transport));
- return client.callTool({
- name,
- arguments: { ...args },
- _meta: { "openai/threadId": owner },
- });
- },
+ recordDraft: (draft: ScanDraftInput | Record<string, unknown>) =>
+ call("record_codex_security_scan_draft", draft),
+ completeScan: () =>
+ call("complete_codex_security_scan", { scanId: run.scanId }),
};
}
+async function openDraftWriter(scanId: string, runner: RunArtifactWorkbench) {
+ const context = await createScanArtifactContext(scanId, runner, {
+ requireRunning: true,
+ });
+ return recordCodexSecurityScanDraftViaWorkbench.bind(undefined, context);
+}
+
async function commitReducers(
fixture: PublicationFixture,
offsets: readonly [number, number],
@@ -1031,22 +966,17 @@ with sqlite3.connect(sys.argv[1]) as c:
...JSON.parse(await readFile(results[1], "utf8")),
reviewState,
};
- const context = await createScanArtifactContext(run.scanId, runWorkbench, {
- requireRunning: true,
- });
+ const writeDraft = await openDraftWriter(run.scanId, runWorkbench);
return {
...fixture,
sql,
results,
draft,
publish: (runner = runWorkbench) =>
- recordCodexSecurityScanDraftViaWorkbench(
- context,
- draft,
- runner,
- undefined,
- { coordinatorGeneration: 2, resultPath: results[1] },
- ),
+ writeDraft(draft, runner, undefined, {
+ coordinatorGeneration: 2,
+ resultPath: results[1],
+ }),
workers: async (): Promise<PublicationWorkers> =>
JSON.parse(
await sql(`import json, sqlite3, sys
@@ -1175,18 +1105,8 @@ for (const workflow of ["deep-scan-mcp/v1", "deep-security-scan/v1"]) {
coordinatorGeneration: 2,
resultPath: f.results[1],
});
- const context = await createScanArtifactContext(
- f.run.scanId,
- runner.run,
- { requireRunning: true },
- );
- await recordCodexSecurityScanDraftViaWorkbench(
- context,
- draft,
- runner.run,
- signal,
- publication,
- );
+ const writeDraft = await openDraftWriter(f.run.scanId, runner.run);
+ await writeDraft(draft, runner.run, signal, publication);
},
});
coordinator.start();
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_stdio_lifecycle.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_stdio_lifecycle.ts
index 97fc5965f..96504302c 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_stdio_lifecycle.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_stdio_lifecycle.ts
@@ -192,12 +192,7 @@ service_tier = "ultrafast"
const server = startServer(serverBundlePath, environment);
try {
- const initialized = await server.request(1, "initialize", {
- protocolVersion: "2025-11-25",
- capabilities: {},
- clientInfo: { name: "deep-scan-stdio-lifecycle", version: "0.1.0" },
- });
- assertNoError(initialized);
+ const initialized = await server.initialize("deep-scan-stdio-lifecycle");
assert.deepEqual(
initialized.result.capabilities.experimental["codex/sandbox-state-meta"],
{},
@@ -208,59 +203,43 @@ service_tier = "ultrafast"
);
assert.deepEqual(initialized.result.capabilities.logging, {});
- const missingParentSandbox = await server.request(
- 2,
- "tools/call",
- toolCall(
- "start_codex_security_deep_scan",
- {
- targetPath,
- scope: ".",
- userContext: "missing parent sandbox fixture",
- },
- threadId,
- undefined,
- null,
- ),
- );
- assert.equal(missingParentSandbox.result?.isError, true);
- assert.match(
- missingParentSandbox.result.content
- .map((item: { text: string }) => item.text)
- .join(" "),
- /parent.*sandbox|sandbox.*metadata|permission/i,
- );
-
- const unsupportedParentSandbox = await server.request(
- 3,
- "tools/call",
- toolCall(
- "start_codex_security_deep_scan",
- {
- targetPath,
- scope: ".",
- userContext: "unsupported parent sandbox fixture",
- },
- threadId,
- undefined,
+ for (const [id, reason, sandboxState] of [
+ [2, "missing", null],
+ [
+ 3,
+ "unsupported",
{
permissionProfile: { type: "disabled" },
sandboxCwd: pathToFileURL(pluginRoot).href,
},
- ),
- );
- assert.equal(unsupportedParentSandbox.result?.isError, true);
- assert.match(
- unsupportedParentSandbox.result.content
- .map((item: { text: string }) => item.text)
- .join(" "),
- /parent.*sandbox|sandbox.*metadata|permission/i,
- );
+ ],
+ ] as const) {
+ const response = await server.callTool(
+ id,
+ toolCall(
+ "start_codex_security_deep_scan",
+ {
+ targetPath,
+ scope: ".",
+ userContext: `${reason} parent sandbox fixture`,
+ },
+ threadId,
+ undefined,
+ sandboxState,
+ ),
+ );
+ assert.equal(response.result?.isError, true);
+ assert.match(
+ response.result.content
+ .map((item: { text: string }) => item.text)
+ .join(" "),
+ /parent.*sandbox|sandbox.*metadata|permission/i,
+ );
+ }
assert.deepEqual(await readLogLines(startLogPath), []);
- const missingConfig = await server.request(
+ const missingConfig = await server.callTool(
4,
- "tools/call",
toolCall(
"start_codex_security_deep_scan",
{
@@ -277,28 +256,24 @@ service_tier = "ultrafast"
[],
);
+ const targetRequest = {
+ targetPath,
+ scope: ".",
+ userContext: "stdio lifecycle fixture",
+ projectConfigPath,
+ };
server.sendRequest(
10,
"tools/call",
- toolCall(
- "start_codex_security_deep_scan",
- {
- targetPath,
- scope: ".",
- userContext: "stdio lifecycle fixture",
- projectConfigPath,
- },
- threadId,
- {
- "x-codex-turn-metadata": {
- model: "gpt-5.5",
- reasoning_effort: "xhigh",
- thread_id: threadId,
- turn_id: "active-parent-turn",
- service_tier: "default",
- },
+ toolCall("start_codex_security_deep_scan", targetRequest, threadId, {
+ "x-codex-turn-metadata": {
+ model: "gpt-5.5",
+ reasoning_effort: "xhigh",
+ thread_id: threadId,
+ turn_id: "active-parent-turn",
+ service_tier: "default",
},
- ),
+ }),
);
const scanId = await waitForScanId({ server });
@@ -314,6 +289,7 @@ service_tier = "ultrafast"
(worker: PersistedDeepScanWorker) => worker.kind === "discovery",
)?.artifactDir;
assert.equal(typeof startedArtifactRoot, "string");
+ // Another client can replace this shared install while the scan is active.
await writeFile(
path.join(installedPluginRoot, "scripts", "workbench_db.py"),
'raise RuntimeError("Installed plugin helpers replaced during another scan")\n',
@@ -364,20 +340,14 @@ service_tier = "ultrafast"
pythonWrapperPath,
);
- // Another client can replace this shared install while the scan is active.
- await writeFile(
- path.join(installedPluginRoot, "scripts", "workbench_db.py"),
- "raise RuntimeError('synthetic replacement plugin helper')\n",
- );
await rm(path.join(installedPluginRoot, "references"), {
recursive: true,
});
await rm(path.join(installedPluginRoot, "schemas"), { recursive: true });
// Discovery progress is admitted once the first complete Standard worker is active.
- const discoveryProgress = await server.request(
+ await server.callSuccessfulTool(
15,
- "tools/call",
toolCall(
"update_codex_security_scan_progress",
{
@@ -389,14 +359,9 @@ service_tier = "ultrafast"
threadId,
),
);
- assertNoError(discoveryProgress);
- const discoveryScan = await runWorkbench(environment, [
- "get-scan",
- "--scan-id",
- scanId,
- ]);
- assert.equal(discoveryScan.scan.progress.phase, "discovery");
- assert.equal(discoveryScan.scan.progress.coverage.worklistRows, 6);
+ const discoveryScan = await getScan(environment, scanId);
+ assert.equal(discoveryScan.progress.phase, "discovery");
+ assert.equal(discoveryScan.progress.coverage.worklistRows, 6);
// Stopping the original model response detaches only that long-poll waiter.
server.notify("notifications/cancelled", {
@@ -408,12 +373,6 @@ service_tier = "ultrafast"
const stillRunning = await getDeepScan({ environment, scanId, threadId });
assert.equal(stillRunning.status, "running");
assert.equal(stillRunning.cancelRequested, false);
- assert.equal(
- stillRunning.workers.some(
- (worker: PersistedDeepScanWorker) => worker.kind === "setup",
- ),
- false,
- );
assert.equal(stillRunning.workers.length, 1);
assert.equal(stillRunning.workers[0].kind, "discovery");
assert.equal(stillRunning.workers[0].status, "running");
@@ -424,16 +383,7 @@ service_tier = "ultrafast"
server.sendRequest(
11,
"tools/call",
- toolCall(
- "start_codex_security_deep_scan",
- {
- targetPath,
- scope: ".",
- userContext: "stdio lifecycle fixture",
- projectConfigPath,
- },
- threadId,
- ),
+ toolCall("start_codex_security_deep_scan", targetRequest, threadId),
);
server.sendRequest(
12,
@@ -452,9 +402,8 @@ service_tier = "ultrafast"
);
assert.equal((await readLogLines(startLogPath)).length, 1);
- const rejectedWrongThreadCancel = await server.request(
+ const rejectedWrongThreadCancel = await server.callTool(
1312,
- "tools/call",
toolCall("cancel_codex_security_scan", { scanId }, "another-thread"),
);
assert.equal(rejectedWrongThreadCancel.result?.isError, true);
@@ -468,9 +417,8 @@ service_tier = "ultrafast"
await writeFile(signalCheckpointControlPath, "write-on-signal\n");
await writeFile(cancelFailureControlPath, "fail\n");
- const failedCancel = await server.request(
+ const failedCancel = await server.callTool(
1313,
- "tools/call",
toolCall("cancel_codex_security_scan", { scanId }, threadId),
);
assert.equal(failedCancel.result?.isError, true);
@@ -494,23 +442,17 @@ service_tier = "ultrafast"
assert.equal(failedJoin.result?.structuredContent, undefined);
assert.match(failureText, /injected cancel-scan failure/);
}
- const stillDurablyRunning = await runWorkbench(environment, [
- "get-scan",
- "--scan-id",
- scanId,
- ]);
- assert.equal(stillDurablyRunning.scan.progress.status, "running");
+ const stillDurablyRunning = await getScan(environment, scanId);
+ assert.equal(stillDurablyRunning.progress.status, "running");
assert.equal(
(await getDeepScan({ environment, scanId, threadId })).cancelRequested,
false,
);
- const cancelResponse = await server.request(
+ await server.callSuccessfulTool(
1314,
- "tools/call",
toolCall("cancel_codex_security_scan", { scanId }, threadId),
);
- assertNoError(cancelResponse);
assert.equal(
(await readLogLines(cancelLogPath)).length,
2,
@@ -562,9 +504,8 @@ service_tier = "ultrafast"
true,
);
- const lateJoin = await server.request(
+ const lateJoin = await server.callTool(
14,
- "tools/call",
toolCall("start_codex_security_deep_scan", { scanId }, threadId),
);
assertCanceled(lateJoin, scanId, startedState.scanDir);
@@ -637,28 +578,20 @@ service_tier = "ultrafast"
true,
);
assertReadOnlyWorkerInvocation(failedWorker.argv, codexHome);
- assert.equal(
- activeFailureState.workers.some(
- (worker: PersistedDeepScanWorker) => worker.kind === "setup",
- ),
- false,
- );
assert.equal(activeFailureState.workers.length, 1);
assert.equal(activeFailureState.workers[0].kind, "discovery");
assert.equal(activeFailureState.workers[0].status, "running");
assertProcessAlive(failedWorker.pid);
const failureMessage = "fixture unrecoverable failure\0source";
- const failureResponse = await server.request(
+ await server.callSuccessfulTool(
21,
- "tools/call",
toolCall(
"fail_codex_security_scan",
{ scanId: failedScanId, message: failureMessage },
failureThreadId,
),
);
- assertNoError(failureResponse);
const failedWaiter = await server.waitForResponse(20);
const failureText =
@@ -669,18 +602,16 @@ service_tier = "ultrafast"
assert.equal(failedWaiter.result?.structuredContent, undefined);
assert.match(failureText, /fixture unrecoverable failure/);
assert.match(failureText, /no successful discovery manifest was returned/);
- const failedContext = await server.request(
+ const failedContext = await server.callSuccessfulTool(
211,
- "tools/call",
toolCall(
"get_codex_security_scan_context",
{ scanId: failedScanId },
failureThreadId,
),
);
- assertNoError(failedContext);
assert.equal(
- failedContext.result.structuredContent.scan.progress.status,
+ failedContext.structuredContent.scan.progress.status,
"failed",
);
const exitedWorkers = await waitForJsonLines(exitLogPath, 2);
@@ -719,9 +650,8 @@ service_tier = "ultrafast"
true,
);
- const failedLateJoin = await server.request(
+ const failedLateJoin = await server.callTool(
22,
- "tools/call",
toolCall(
"start_codex_security_deep_scan",
{ scanId: failedScanId },
@@ -752,35 +682,28 @@ service_tier = "ultrafast"
);
const resumedThreadId = "deep-scan-stdio-resumed-thread";
- const opened = await server.request(
+ const opened = await server.callSuccessfulTool(
24,
- "tools/call",
toolCall(
"open_codex_security_workspace",
{ targetPath, scope: ".", mode: "deep" },
resumedThreadId,
),
);
- assertNoError(opened);
- const sessionId = opened.result.structuredContent.workspace.id;
- assertNoError(
- await server.request(
- 25,
- "tools/call",
- toolCall(
- "submit_codex_security_setup",
- { sessionId, targetPath, scope: ".", mode: "deep" },
- resumedThreadId,
- ),
+ const sessionId = opened.structuredContent.workspace.id;
+ await server.callSuccessfulTool(
+ 25,
+ toolCall(
+ "submit_codex_security_setup",
+ { sessionId, targetPath, scope: ".", mode: "deep" },
+ resumedThreadId,
),
);
- const started = await server.request(
+ const started = await server.callSuccessfulTool(
26,
- "tools/call",
toolCall("start_codex_security_scan", { sessionId }, resumedThreadId),
);
- assertNoError(started);
- const resumedScan = started.result.structuredContent.workspace.results;
+ const resumedScan = started.structuredContent.workspace.results;
const resumedScanId = resumedScan.scanId;
await chmod(resumedScan.scanDir, 0o755);
const handoffClaimToken = randomUUID();
@@ -803,12 +726,9 @@ service_tier = "ultrafast"
},
],
] as const) {
- assertNoError(
- await server.request(
- id,
- "tools/call",
- toolCall(name, arguments_, resumedThreadId),
- ),
+ await server.callSuccessfulTool(
+ id,
+ toolCall(name, arguments_, resumedThreadId),
);
}
@@ -867,27 +787,19 @@ service_tier = "ultrafast"
() => process.kill(server.pid!, 0),
"the original MCP server must have exited",
);
- const paused = await runWorkbench(environment, [
- "get-scan",
- "--scan-id",
- resumedScanId,
- ]);
+ const paused = await getScan(environment, resumedScanId);
assert.deepEqual(
- [paused.scan.progress.status, paused.scan.progress.phase],
+ [paused.progress.status, paused.progress.phase],
["running", "discovery"],
);
- assert.deepEqual(paused.scan.progress.independentReviews, {
+ assert.deepEqual(paused.progress.independentReviews, {
completed: 1,
active: 0,
maximum: 2,
consolidating: false,
});
assert.deepEqual(
- [
- paused.scan.reportAvailable,
- paused.scan.findingCount,
- paused.scan.artifacts,
- ],
+ [paused.reportAvailable, paused.findingCount, paused.artifacts],
[false, 0, {}],
);
const manifestPath = path.join(resumedScan.scanDir, "scan-manifest.json");
@@ -912,16 +824,7 @@ service_tier = "ultrafast"
const resumedStartIndex = (await readJsonLines(startLogPath)).length;
const restartedServer = startServer(serverBundlePath, environment);
try {
- assertNoError(
- await restartedServer.request(1, "initialize", {
- protocolVersion: "2025-11-25",
- capabilities: {},
- clientInfo: {
- name: "deep-scan-restarted-artifacts",
- version: "0.1.0",
- },
- }),
- );
+ await restartedServer.initialize("deep-scan-restarted-artifacts");
restartedServer.sendRequest(
2,
"tools/call",
@@ -963,21 +866,16 @@ service_tier = "ultrafast"
return run.status === "succeeded";
}, "the detached coordinator to persist its successful aggregate");
await waitFor(async () => {
- const scan = await runWorkbench(environment, [
- "get-scan",
- "--scan-id",
- resumedScanId,
- ]);
- return scan.scan.progress.status === "complete";
+ const scan = await getScan(environment, resumedScanId);
+ return scan.progress.status === "complete";
}, "the detached coordinator to finalize without another tool call");
const sealedBeforeRejoin = await readFile(manifestPath, "utf8");
const reportBeforeRejoin = await readFile(
path.join(resumedScan.scanDir, "report.md"),
"utf8",
);
- const resumed = await restartedServer.request(
+ const resumed = await restartedServer.callSuccessfulTool(
3,
- "tools/call",
toolCall(
"start_codex_security_deep_scan",
{ scanId: resumedScanId, handoffClaimToken },
@@ -990,7 +888,6 @@ service_tier = "ultrafast"
},
),
);
- assertNoError(resumed);
const modelRows = await execFileAsync(
process.env.PYTHON?.trim() || "python3",
[
@@ -1001,16 +898,16 @@ service_tier = "ultrafast"
],
);
assert.deepEqual(JSON.parse(modelRows.stdout), ["gpt-6.1-sol", "max"]);
- const instructions = resumed.result.structuredContent.instructions;
+ const instructions = resumed.structuredContent.instructions;
assert.match(
instructions,
/Do not call complete_codex_security_scan again/,
);
- const completion = resumed.result.structuredContent.completion;
+ const completion = resumed.structuredContent.completion;
assert.deepEqual(completion, {
scan: { progress: { status: "complete" }, reportAvailable: true },
});
- assert.deepEqual(resumed.result.structuredContent, {
+ assert.deepEqual(resumed.structuredContent, {
scanId: resumedScanId,
scanDir: resumedScan.scanDir,
manifestPath,
@@ -1018,11 +915,9 @@ service_tier = "ultrafast"
instructions,
completion,
});
- assert.deepEqual(resumed.result.content, [
- { type: "text", text: instructions },
- ]);
+ assert.deepEqual(resumed.content, [{ type: "text", text: instructions }]);
assert.equal(
- resumed.result.content.some((item: { text: string }) =>
+ resumed.content.some((item: { text: string }) =>
item.text.includes(resumedScanId),
),
true,
@@ -1068,7 +963,7 @@ service_tier = "ultrafast"
(await readJson(resumedScan.scanDir, "findings.json")).findings,
[],
);
- const completedScan = resumed.result.structuredContent;
+ const completedScan = resumed.structuredContent;
const sealedManifest = await readJson(completedScan.manifestPath);
assert.equal(sealedManifest.scan.status, "completed");
assert.ok(sealedManifest.scan.sealedAt);
@@ -1141,9 +1036,8 @@ service_tier = "ultrafast"
"# Synthetic completion retry\n",
);
await writeFile(completionFailureControlPath, "fail\n");
- const completionFailed = await restartedServer.request(
+ const completionFailed = await restartedServer.callTool(
4,
- "tools/call",
toolCall(
"start_codex_security_deep_scan",
{ targetPath: retryTarget },
@@ -1167,40 +1061,34 @@ service_tier = "ultrafast"
threadId: resumedThreadId,
});
assert.equal(retryRun.status, "succeeded");
- const pending = await runWorkbench(environment, [
- "get-scan",
- "--scan-id",
- retryScanId,
- ]);
- assert.equal(pending.scan.progress.status, "running");
- assert.equal(pending.scan.reportAvailable, false);
+ const pending = await getScan(environment, retryScanId);
+ assert.equal(pending.progress.status, "running");
+ assert.equal(pending.reportAvailable, false);
const workerCountBeforeRetry = (await readLogLines(startLogPath)).length;
await writeFile(
path.join(retryTarget, "source.py"),
"# Target changed after the failed completion\n",
);
- const retry = await restartedServer.request(
+ const retry = await restartedServer.callSuccessfulTool(
5,
- "tools/call",
toolCall(
"start_codex_security_deep_scan",
{ scanId: retryScanId },
resumedThreadId,
),
);
- assertNoError(retry);
- assert.equal(retry.result.structuredContent.scanId, retryScanId);
+ assert.equal(retry.structuredContent.scanId, retryScanId);
assert.equal(
- retry.result.structuredContent.completion.scan.progress.status,
+ retry.structuredContent.completion.scan.progress.status,
"complete",
);
assert.equal(
- retry.result.structuredContent.completion.scan.reportAvailable,
+ retry.structuredContent.completion.scan.reportAvailable,
true,
);
assert.equal(
- retry.result.structuredContent.reportPath,
- path.join(retry.result.structuredContent.scanDir, "report.md"),
+ retry.structuredContent.reportPath,
+ path.join(retry.structuredContent.scanDir, "report.md"),
);
assert.equal(
(await readLogLines(startLogPath)).length,
@@ -1245,17 +1133,13 @@ async function testDetachedTargetReplay(
);
let server = startServer(serverBundlePath, environment);
try {
- assertNoError(await server.initialize("detached-target"));
+ await server.initialize("detached-target");
server.sendRequest(2, "tools/call", request);
const scanId = await waitForScanId({ server, requestId: 2 });
server.notify("notifications/cancelled", { requestId: 2 });
await waitFor(async () => {
- const state = await runWorkbench(environment, [
- "get-scan",
- "--scan-id",
- scanId,
- ]);
- return state.scan.progress.status === "complete";
+ const state = await getScan(environment, scanId);
+ return state.progress.status === "complete";
}, "the detached target request to finalize");
assert.equal(server.response(2)?.result?.structuredContent, undefined);
const { scanDir } = await getDeepScan({ environment, scanId, threadId });
@@ -1264,10 +1148,9 @@ async function testDetachedTargetReplay(
await server.stop();
server = startServer(serverBundlePath, environment);
- assertNoError(await server.initialize("detached-target-retry"));
- const replay = await server.callTool(2, request);
- assertNoError(replay);
- const completed = replay.result.structuredContent;
+ await server.initialize("detached-target-retry");
+ const replay = await server.callSuccessfulTool(2, request);
+ const completed = replay.structuredContent;
assert.equal(completed.scanId, scanId);
assert.equal(completed.scanDir, scanDir);
assert.equal(completed.completion.scan.reportAvailable, true);
@@ -1453,8 +1336,8 @@ async function testCliDeepScanEngine({
// A resumed SDK scan rejoins through the parent MCP turn after discovery.
const parent = startServer(serverBundlePath, environment);
try {
- assertNoError(await parent.initialize("sdk-parent"));
- const joined = await parent.callTool(
+ await parent.initialize("sdk-parent");
+ const joined = await parent.callSuccessfulTool(
2,
toolCall(
"start_codex_security_deep_scan",
@@ -1462,11 +1345,10 @@ async function testCliDeepScanEngine({
threadId,
),
);
- assertNoError(joined);
- assert.equal(joined.result.structuredContent.scanId, completed.scanId);
- assert.equal(joined.result.structuredContent.completion, undefined);
- assert.equal(joined.result.structuredContent.reportPath, undefined);
- assert.match(joined.result.structuredContent.instructions, /SDK/);
+ assert.equal(joined.structuredContent.scanId, completed.scanId);
+ assert.equal(joined.structuredContent.completion, undefined);
+ assert.equal(joined.structuredContent.reportPath, undefined);
+ assert.match(joined.structuredContent.instructions, /SDK/);
} finally {
await parent.stop();
}
@@ -1688,6 +1570,15 @@ async function waitForScanId({
return scanId;
}
+async function getScan(environment: NodeJS.ProcessEnv, scanId: string) {
+ const result = await runWorkbench(environment, [
+ "get-scan",
+ "--scan-id",
+ scanId,
+ ]);
+ return result.scan;
+}
+
async function getDeepScan({
environment,
scanId,
diff --git a/plugins/codex-security/mcp-app/tests/test_deep_scan_terminal_race.ts b/plugins/codex-security/mcp-app/tests/test_deep_scan_terminal_race.ts
index 2db12a766..892e7874e 100644
--- a/plugins/codex-security/mcp-app/tests/test_deep_scan_terminal_race.ts
+++ b/plugins/codex-security/mcp-app/tests/test_deep_scan_terminal_race.ts
@@ -1,6 +1,6 @@
import assert from "node:assert/strict";
import { execFile } from "node:child_process";
-import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
+import { mkdir, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { test } from "node:test";
import { fileURLToPath } from "node:url";
@@ -10,9 +10,9 @@ import type {
ScanDraftInput,
} from "../src/artifact-scan-draft.js";
import type { DeepScanRunState } from "../src/deep-scan/types.js";
-import { importModule } from "./import-module.ts";
+import { importCoordinatorServer, importModule } from "./import-module.ts";
import { temporaryDirectory } from "./support/temporary-directories.ts";
-import { FakeExecutor } from "./deep_scan_coordinator_fixture.ts";
+import { FakeExecutor, pausePoint } from "./deep_scan_coordinator_fixture.ts";
const execFileAsync = promisify(execFile);
const applicationRoot = fileURLToPath(new URL("../", import.meta.url));
@@ -32,7 +32,6 @@ export { recordCodexSecurityScanDraftViaWorkbench } from "./src/artifact-scan-dr
},
loader: { ".md": "text" },
});
-const source = await readFile(new URL("../server.ts", import.meta.url), "utf8");
for (const ordering of [
"failure response first",
@@ -60,17 +59,12 @@ for (const ordering of [
const failureDuringPublication = ordering.endsWith("during publication");
const root = await temporaryDirectory("deep-scan-terminal-race-");
const registry = new DeepScanCoordinatorRegistry();
- const cleanupEntered = Promise.withResolvers<void>();
- const cleanupRelease = Promise.withResolvers<void>();
- const cancelEntered = Promise.withResolvers<void>();
- const cancelRelease = Promise.withResolvers<void>();
- const failureCommitted = Promise.withResolvers<void>();
- const failureResponse = Promise.withResolvers<void>();
- const finishCommitted = Promise.withResolvers<void>();
- const finishResponse = Promise.withResolvers<void>();
+ const cleanup = pausePoint();
+ const cancelPersistence = pausePoint();
+ const failureCommit = pausePoint();
+ const finishCommit = pausePoint();
const admissionRead = Promise.withResolvers<void>();
- const publicationEntered = Promise.withResolvers<void>();
- const publicationRelease = Promise.withResolvers<void>();
+ const publication = pausePoint();
let server:
| ReturnType<(typeof import("../server.ts"))["createCodexSecurityServer"]>
| undefined;
@@ -107,8 +101,7 @@ for (const ordering of [
};
const workbench = async (args: string[]) => {
if (args[0] === "cancel-scan" && !canceledBeforeFailure) {
- cancelEntered.resolve();
- await cancelRelease.promise;
+ await cancelPersistence.pause();
}
const result = await runWorkbench(args);
if (
@@ -116,17 +109,14 @@ for (const ordering of [
canceledBeforeAdmission &&
!activeBeforeAdmission
) {
- finishCommitted.resolve();
- await finishResponse.promise;
+ await finishCommit.pause();
}
if (args[0] === "get-scan") admissionRead.resolve();
if (args[0] === "cancel-scan" && canceledBeforeFailure) {
- cancelEntered.resolve();
- await cancelRelease.promise;
+ await cancelPersistence.pause();
}
if (args[0] === "fail-scan") {
- failureCommitted.resolve();
- await failureResponse.promise;
+ await failureCommit.pause();
}
if (args[0] === "cancel-scan" && lostCancellation)
throw new Error("synthetic committed cancellation response lost");
@@ -135,28 +125,9 @@ for (const ordering of [
Object.assign(globalThis, {
terminalRaceFixture: { registry, workbench },
});
- const { createCodexSecurityServer } = await importModule({
- stdin: {
- contents: source
- .replace(
- "const deepScanCoordinators = new DeepScanCoordinatorRegistry();",
- "const deepScanCoordinators = globalThis.terminalRaceFixture.registry;",
- )
- .replace(
- 'import { PLUGIN_ROOT, runWorkbench, scanRoot } from "./src/workbench-client.js";',
- 'import { PLUGIN_ROOT, scanRoot } from "./src/workbench-client.js";\nconst runWorkbench = (...args) => globalThis.terminalRaceFixture.workbench(...args);',
- ),
- loader: "ts",
- resolveDir: applicationRoot,
- },
- define: {
- __dirname: JSON.stringify(applicationRoot),
- "import.meta.url": JSON.stringify(
- new URL("../server.ts", import.meta.url).href,
- ),
- },
- loader: { ".md": "text" },
- });
+ const { createCodexSecurityServer } = await importCoordinatorServer(
+ "terminalRaceFixture",
+ );
const application = createCodexSecurityServer();
server = application;
const cancel =
@@ -185,8 +156,7 @@ for (const ordering of [
!canceledBeforeAdmission
) {
held = true;
- cleanupEntered.resolve();
- await cleanupRelease.promise;
+ await cleanup.pause();
}
return result;
};
@@ -225,8 +195,7 @@ for (const ordering of [
},
onStopped: async (stopped: DeepScanRunState) => {
if (failureDuringPublication) {
- publicationEntered.resolve();
- await publicationRelease.promise;
+ await publication.pause();
}
await runWorkbench([
"preserve-scan-results",
@@ -243,7 +212,7 @@ for (const ordering of [
void terminal!.catch(() => {});
if (canceledBeforeAdmission || failedBeforeAdmission) {
if (activeBeforeAdmission) await executor.discoveryStarted.promise;
- else await finishCommitted.promise;
+ else await finishCommit.entered;
await runWorkbench([
failedBeforeAdmission ? "fail-scan" : "cancel-scan",
"--scan-id",
@@ -252,7 +221,7 @@ for (const ordering of [
? ["--message", "synthetic externally persisted failure"]
: []),
]);
- cancelRelease.resolve();
+ cancelPersistence.release();
const cancellationResult = cancel({ scanId: run.scanId });
cancellation = cancellationResult;
void cancellation!.catch(() => {});
@@ -265,7 +234,7 @@ for (const ordering of [
"accepted cancellation stops the worker before the next heartbeat",
);
}
- finishResponse.resolve();
+ finishCommit.release();
const result = await terminal!;
assert.equal(
result.status,
@@ -290,12 +259,12 @@ for (const ordering of [
await executor.discoveryStarted.promise;
cancellation = cancel({ scanId: run.scanId });
void cancellation!.catch(() => {});
- await cancelEntered.promise;
+ await cancelPersistence.entered;
if (failureDuringPublication) {
- cancelRelease.resolve();
- await publicationEntered.promise;
+ cancelPersistence.release();
+ await publication.entered;
}
- failureResponse.resolve();
+ failureCommit.release();
await fail(
{ scanId: run.scanId, message: "synthetic no-op failure" },
{},
@@ -309,8 +278,8 @@ for (const ordering of [
(await store.get(run.scanId, "fixture-owner")).status,
"canceled",
);
- cancelRelease.resolve();
- publicationRelease.resolve();
+ cancelPersistence.release();
+ publication.release();
if (lostCancellation) {
await assert.rejects(
cancellation!,
@@ -332,17 +301,17 @@ for (const ordering of [
}
return;
}
- await cleanupEntered.promise;
+ await cleanup.entered;
cancellation = cancel({ scanId: run.scanId });
void cancellation!.catch(() => {});
- await cancelEntered.promise;
+ await cancelPersistence.entered;
if (ordering !== "lost cancellation response") {
failure = fail(
{ scanId: run.scanId, message: "synthetic committed parent failure" },
{},
);
void failure!.catch(() => {});
- await failureCommitted.promise;
+ await failureCommit.entered;
assert.equal(
(
await runWorkbench([
@@ -361,12 +330,12 @@ for (const ordering of [
"failed",
);
if (ordering === "failure response first") {
- failureResponse.resolve();
+ failureCommit.release();
await failure;
}
}
- cancelRelease.resolve();
- cleanupRelease.resolve();
+ cancelPersistence.release();
+ cleanup.release();
if (ordering === "lost cancellation response") {
await assert.rejects(
cancellation!,
@@ -393,15 +362,15 @@ for (const ordering of [
);
if (ordering === "failure response first")
assert.match(stopped.error!, /synthetic committed parent failure/);
- failureResponse.resolve();
+ failureCommit.release();
await failure;
}
} finally {
- cleanupRelease.resolve();
- cancelRelease.resolve();
- failureResponse.resolve();
- finishResponse.resolve();
- publicationRelease.resolve();
+ cleanup.release();
+ cancelPersistence.release();
+ failureCommit.release();
+ finishCommit.release();
+ publication.release();
registry.shutdown("fixture cleanup");
await Promise.allSettled([terminal, cancellation, failure]);
await server?.close();
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 84d404781..ea1f11b65 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
@@ -192,6 +192,13 @@ function startTestServer({
);
}
+function entitlementContext(trustedAccess: object) {
+ return {
+ schemaVersion: 1,
+ entitlements: { cyber_trusted_access: trustedAccess },
+ };
+}
+
const testServer = startTestServer({
cwd: launchCwd,
env: {
@@ -248,13 +255,13 @@ async function assertBundledNodeLauncher() {
},
});
try {
- assertNoError(
- await bundledNodeServer.initialize("codex-security-bundled-node-smoke"),
- );
+ await bundledNodeServer.initialize("codex-security-bundled-node-smoke");
assertNoError(await bundledNodeServer.request(2, "tools/list"));
- const input = await bundledNodeServer.callTool(3, continuationQuestion);
- assertNoError(input);
- assert.deepEqual(input.result.structuredContent, { status: "unavailable" });
+ const input = await bundledNodeServer.callSuccessfulTool(
+ 3,
+ continuationQuestion,
+ );
+ assert.deepEqual(input.structuredContent, { status: "unavailable" });
if (!windows) {
assert.equal(
await readFile(path.join(emptyPath, "bundled-node-used"), "utf8"),
@@ -284,9 +291,7 @@ async function assertPythonHelperFailures() {
.join(" ");
}
try {
- assertNoError(
- await server.initialize("codex-security-python-errors-smoke"),
- );
+ await server.initialize("codex-security-python-errors-smoke");
const missingText = await inspectErrorText(2);
assert.ok(missingText.includes(`spawn ${python} ENOENT`), missingText);
assert.match(missingText, /could not start its Python 3 helper/);
@@ -344,27 +349,24 @@ async function assertWorkspaceWorksWithoutUiCapability(scope: string) {
},
});
try {
- assertNoError(await nonUiServer.initialize("codex-security-non-ui-smoke"));
- const inspected = await nonUiServer.callTool(10, {
+ await nonUiServer.initialize("codex-security-non-ui-smoke");
+ const inspected = await nonUiServer.callSuccessfulTool(10, {
name: "inspect_codex_security_target",
arguments: {
targetPath: process.platform === "win32" ? targetPath : alias,
},
});
- assertNoError(inspected);
- const canonicalTarget =
- inspected.result.structuredContent.target.targetPath;
+ const canonicalTarget = inspected.structuredContent.target.targetPath;
assert.equal(canonicalTarget, await realpath(targetPath));
- const reinspected = await nonUiServer.callTool(11, {
+ const reinspected = await nonUiServer.callSuccessfulTool(11, {
name: "inspect_codex_security_target",
arguments: { targetPath: canonicalTarget },
});
- assertNoError(reinspected);
assert.equal(
- reinspected.result.structuredContent.target.targetPath,
+ reinspected.structuredContent.target.targetPath,
canonicalTarget,
);
- const response = await nonUiServer.callTool(2, {
+ const response = await nonUiServer.callSuccessfulTool(2, {
name: "open_codex_security_workspace",
arguments: {
targetPath: canonicalTarget,
@@ -376,8 +378,7 @@ async function assertWorkspaceWorksWithoutUiCapability(scope: string) {
},
_meta: { "openai/threadId": "fixture-non-ui-thread" },
});
- assertNoError(response);
- const workspace = response.result.structuredContent.workspace;
+ const workspace = response.structuredContent.workspace;
assert.match(workspace.id, /^[0-9a-f-]{36}$/);
assert.equal(workspace.targetPath, await realpath(targetPath));
assert.equal(workspace.mode, "standard");
@@ -385,7 +386,7 @@ async function assertWorkspaceWorksWithoutUiCapability(scope: string) {
assert.equal(workspace.targetTitle, "--user-context");
assert.equal(workspace.targetSummary, "--fixture-summary");
assert.equal(workspace.userContext, userContext);
- const saved = await nonUiServer.callTool(3, {
+ const saved = await nonUiServer.callSuccessfulTool(3, {
name: "submit_codex_security_setup",
arguments: {
sessionId: workspace.id,
@@ -395,16 +396,13 @@ async function assertWorkspaceWorksWithoutUiCapability(scope: string) {
targetSummary: "",
},
});
- assertNoError(saved);
- assert.equal(saved.result.structuredContent.workspace.scope, scope);
- assert.equal(saved.result.structuredContent.workspace.targetSummary, null);
- assertNoError(
- await nonUiServer.callTool(4, {
- name: "list_codex_security_scans",
- arguments: { query: "-sub" },
- }),
- );
- const setup = await nonUiServer.callTool(12, {
+ assert.equal(saved.structuredContent.workspace.scope, scope);
+ assert.equal(saved.structuredContent.workspace.targetSummary, null);
+ await nonUiServer.callSuccessfulTool(4, {
+ name: "list_codex_security_scans",
+ arguments: { query: "-sub" },
+ });
+ const setup = await nonUiServer.callSuccessfulTool(12, {
name: "inspect_codex_security_setup",
arguments: {
targetPath: workspace.targetPath,
@@ -412,23 +410,21 @@ async function assertWorkspaceWorksWithoutUiCapability(scope: string) {
mode: workspace.mode,
},
});
- assertNoError(setup);
- assert.equal(setup.result.structuredContent.setup.scope, scope);
- const started = await nonUiServer.callTool(13, {
+ assert.equal(setup.structuredContent.setup.scope, scope);
+ const started = await nonUiServer.callSuccessfulTool(13, {
name: "start_codex_security_scan",
arguments: { sessionId: workspace.id },
});
- assertNoError(started);
assert.equal(
- started.result.structuredContent.workspace.targetPath,
+ started.structuredContent.workspace.targetPath,
canonicalTarget,
);
- assert.equal(started.result.structuredContent.workspace.scope, scope);
+ assert.equal(started.structuredContent.workspace.scope, scope);
for (const [index, name] of [
"start_codex_security_prompt_only_scan",
"start_codex_security_standard_scan",
].entries()) {
- const launched = await nonUiServer.callTool(14 + index, {
+ const launched = await nonUiServer.callSuccessfulTool(14 + index, {
name,
arguments: {
targetPath: canonicalTarget,
@@ -437,19 +433,11 @@ async function assertWorkspaceWorksWithoutUiCapability(scope: string) {
},
_meta: { "openai/threadId": `fixture-path-launch-${index}` },
});
- assertNoError(launched);
- assertScanTarget(
- launched.result._meta,
- launched.result.structuredContent.scan.scanId,
- );
- assert.equal(
- launched.result.structuredContent.scan.targetPath,
- canonicalTarget,
- );
- assert.equal(launched.result.structuredContent.scan.scope, scope);
+ assertScanTarget(launched._meta, launched.structuredContent.scan.scanId);
+ assert.equal(launched.structuredContent.scan.targetPath, canonicalTarget);
+ assert.equal(launched.structuredContent.scan.scope, scope);
assert.deepEqual(
- launched.result.structuredContent.scan.contract.scope
- .requiredIncludePaths,
+ launched.structuredContent.scan.contract.scope.requiredIncludePaths,
[scope],
);
}
@@ -502,9 +490,7 @@ async function assertHeadlessStandardScanWorksWithoutUiCapability() {
`Review https://example.test/internal. ${"Assess the HTTP boundary. ".repeat(44_000)}`.trim();
assert.ok(headlessContext.length > 1_000_000);
try {
- assertNoError(
- await headlessServer.initialize("codex-security-headless-smoke"),
- );
+ await headlessServer.initialize("codex-security-headless-smoke");
const withoutOwner = await headlessServer.callTool(2, {
name: "start_codex_security_standard_scan",
arguments: { targetPath: target },
@@ -604,7 +590,7 @@ async function assertHeadlessStandardScanWorksWithoutUiCapability() {
/only available for Deep or diff scans/,
);
- const advanced = await headlessServer.callTool(81, {
+ await headlessServer.callSuccessfulTool(81, {
name: "update_codex_security_scan_progress",
arguments: {
scanId: result.scanId,
@@ -613,8 +599,7 @@ async function assertHeadlessStandardScanWorksWithoutUiCapability() {
},
_meta: { "openai/threadId": ownerThread },
});
- assertNoError(advanced);
- const rejoinedAfterPreflight = await headlessServer.callTool(82, {
+ const rejoinedAfterPreflight = await headlessServer.callSuccessfulTool(82, {
name: "start_codex_security_standard_scan",
arguments: {
targetPath: target,
@@ -622,20 +607,19 @@ async function assertHeadlessStandardScanWorksWithoutUiCapability() {
},
_meta: { "openai/threadId": ownerThread },
});
- assertNoError(rejoinedAfterPreflight);
assert.equal(
- rejoinedAfterPreflight.result.structuredContent.startDisposition,
+ rejoinedAfterPreflight.structuredContent.startDisposition,
"joined",
);
assert.equal(
- rejoinedAfterPreflight.result.structuredContent.scan.progress.phase,
+ rejoinedAfterPreflight.structuredContent.scan.progress.phase,
"threat_model",
);
for (const threadSource of [undefined, "security_scan"]) {
let scan = result;
if (threadSource) {
- const usageScan = await headlessServer.callTool(83, {
+ const usageScan = await headlessServer.callSuccessfulTool(83, {
name: "start_codex_security_standard_scan",
arguments: {
targetPath: target,
@@ -643,8 +627,7 @@ async function assertHeadlessStandardScanWorksWithoutUiCapability() {
},
_meta: { "openai/threadId": ownerThread },
});
- assertNoError(usageScan);
- scan = usageScan.result.structuredContent;
+ scan = usageScan.structuredContent;
assert.equal(scan.startDisposition, "created");
assert.notEqual(scan.scanId, result.scanId);
}
@@ -653,40 +636,39 @@ async function assertHeadlessStandardScanWorksWithoutUiCapability() {
scan.scanId,
scan.scan.contract.target.requiredSnapshotDigest,
);
- const completed = await headlessServer.callTool(threadSource ? 90 : 9, {
- name: "complete_codex_security_scan",
- arguments: {
- scanId: scan.scanId,
- handoffClaimToken: scan.handoffClaimToken,
- },
- _meta: {
- "x-codex-turn-metadata": {
- thread_id: ownerThread,
- turn_id: "fixture-completion-turn",
- thread_source: threadSource,
+ const completed = await headlessServer.callSuccessfulTool(
+ threadSource ? 90 : 9,
+ {
+ name: "complete_codex_security_scan",
+ arguments: {
+ scanId: scan.scanId,
+ handoffClaimToken: scan.handoffClaimToken,
+ },
+ _meta: {
+ "x-codex-turn-metadata": {
+ thread_id: ownerThread,
+ turn_id: "fixture-completion-turn",
+ thread_source: threadSource,
+ },
},
},
- });
- assertNoError(completed);
- assertScanTarget(completed.result._meta, scan.scanId);
+ );
+ assertScanTarget(completed._meta, scan.scanId);
assert.equal(
- completed.result.structuredContent.scan.lifecycle.status,
+ completed.structuredContent.scan.lifecycle.status,
"completed",
);
assert.equal(
- completed.result.structuredContent.scan.progress.status,
+ completed.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, {
+ assert.deepEqual(completed.structuredContent.scan.usage.completion, {
+ threadId: ownerThread,
+ turnId: "fixture-completion-turn",
+ finalized: false,
+ });
+ const finalizedUsage = await headlessServer.callSuccessfulTool(10, {
name: "finalize_codex_security_scan_usage",
arguments: {
scanId: scan.scanId,
@@ -695,14 +677,13 @@ async function assertHeadlessStandardScanWorksWithoutUiCapability() {
turnStatus: "completed",
},
});
- assertNoError(finalizedUsage);
assert.deepEqual(
- finalizedUsage.result.structuredContent.scan.usage,
- completed.result.structuredContent.scan.usage,
+ finalizedUsage.structuredContent.scan.usage,
+ completed.structuredContent.scan.usage,
);
} else {
assert.equal(
- completed.result.structuredContent.scan.usage.completion,
+ completed.structuredContent.scan.usage.completion,
undefined,
);
}
@@ -739,9 +720,7 @@ async function assertDeepScanPersistsRetryableWorkerStartupError() {
env: fixtureEnvironment,
});
try {
- assertNoError(
- await deepServer.initialize("codex-security-deep-inventory-smoke"),
- );
+ await deepServer.initialize("codex-security-deep-inventory-smoke");
deepServer.sendRequest(2, "tools/call", {
name: "start_codex_security_deep_scan",
@@ -759,14 +738,13 @@ async function assertDeepScanPersistsRetryableWorkerStartupError() {
Date.now() - pollingStarted < 30_000;
requestId++
) {
- const listed = await deepServer.callTool(requestId, {
+ const listed = await deepServer.callSuccessfulTool(requestId, {
name: "list_codex_security_scans",
arguments: {},
});
- assertNoError(listed);
- [scan] = listed.result.structuredContent.scans;
+ [scan] = listed.structuredContent.scans;
if (scan) {
- assert.equal(listed.result.structuredContent.scans.length, 1);
+ assert.equal(listed.structuredContent.scans.length, 1);
assert.equal(scan.progress.status, "running");
const { deepScan } = JSON.parse(
execFileSync(
@@ -802,12 +780,11 @@ async function assertDeepScanPersistsRetryableWorkerStartupError() {
);
assert.equal(startupErrorWorker.status, "running");
- const canceled = await deepServer.callTool(3, {
+ await deepServer.callSuccessfulTool(3, {
name: "cancel_codex_security_scan",
arguments: { scanId: scan.scanId },
_meta: { "openai/threadId": "fixture-deep-inventory-thread" },
});
- assertNoError(canceled);
await deepServer.waitForMessage(
(message) => message.id === 2,
"Deep Scan start response after cancellation",
@@ -930,11 +907,7 @@ async function assertBundledPythonRuntime() {
},
});
try {
- assertNoError(
- await bundledPythonServer.initialize(
- "codex-security-bundled-python-smoke",
- ),
- );
+ await bundledPythonServer.initialize("codex-security-bundled-python-smoke");
// Codex can install the primary runtime after the MCP server has started.
// Creating this wrapper after initialization verifies call-time discovery.
await mkdir(path.dirname(bundledPythonPath), { recursive: true });
@@ -946,12 +919,10 @@ exec "$CODEX_SECURITY_TEST_SYSTEM_PYTHON" "$@"
`,
{ mode: 0o755 },
);
- assertNoError(
- await bundledPythonServer.callTool(2, {
- name: "inspect_codex_security_target",
- arguments: { targetPath: target },
- }),
- );
+ await bundledPythonServer.callSuccessfulTool(2, {
+ name: "inspect_codex_security_target",
+ arguments: { targetPath: target },
+ });
assert.equal(await readFile(launchMarkerPath, "utf8"), "bundled");
} finally {
await bundledPythonServer.stop();
@@ -1042,7 +1013,6 @@ try {
const initialized = await testServer.initialize("codex-security-smoke", {
elicitation: { form: {} },
});
- assertNoError(initialized);
assert.equal(initialized.result.serverInfo.name, "codex-security");
assert.equal(initialized.result.serverInfo.title, "Codex Security");
assert.equal(
@@ -1093,15 +1063,14 @@ try {
/Skip it for Amazon Bedrock scans/,
);
- const unknownTrustedAccess = await testServer.callTool(9601, {
+ const unknownTrustedAccess = await testServer.callSuccessfulTool(9601, {
name: "get_codex_security_daybreak_access",
arguments: {},
});
- assertNoError(unknownTrustedAccess);
- assert.equal(unknownTrustedAccess.result._meta, undefined);
+ assert.equal(unknownTrustedAccess._meta, undefined);
assert.deepEqual(
{
- ...unknownTrustedAccess.result.structuredContent,
+ ...unknownTrustedAccess.structuredContent,
checkedAt: undefined,
},
{
@@ -1114,11 +1083,11 @@ try {
);
assert.ok(
Number.isFinite(
- Date.parse(unknownTrustedAccess.result.structuredContent.checkedAt),
+ Date.parse(unknownTrustedAccess.structuredContent.checkedAt),
),
);
assert.doesNotMatch(
- unknownTrustedAccess.result.content[0].text,
+ unknownTrustedAccess.content[0].text,
/protected results associated with this account may not be displayable/,
);
@@ -1142,42 +1111,32 @@ try {
checkedAt: "2026-07-13T12:00:00.000Z",
stale: false,
};
- const hostedTrustedAccess = await testServer.callTool(9602, {
+ const hostedTrustedAccess = await testServer.callSuccessfulTool(9602, {
name: "get_codex_security_daybreak_access",
arguments: {},
_meta: {
threadId: "fixture-trusted-access-thread",
- "openai/entitlementContext": {
- schemaVersion: 1,
- entitlements: {
- cyber_trusted_access: grantedTrustedAccess,
- },
- },
+ "openai/entitlementContext": entitlementContext(grantedTrustedAccess),
},
});
- assertNoError(hostedTrustedAccess);
- assert.equal(hostedTrustedAccess.result._meta, undefined);
+ assert.equal(hostedTrustedAccess._meta, undefined);
assert.deepEqual(
- hostedTrustedAccess.result.structuredContent,
+ hostedTrustedAccess.structuredContent,
grantedDaybreakAccess,
);
assert.doesNotMatch(
- JSON.stringify(hostedTrustedAccess.result),
+ JSON.stringify(hostedTrustedAccess),
/\btac(?:[123])?\b/i,
);
- assert.match(hostedTrustedAccess.result.content[0].text, /Daybreak Blue/);
- assert.match(hostedTrustedAccess.result.content[0].text, /Daybreak Red/);
+ assert.match(hostedTrustedAccess.content[0].text, /Daybreak Blue/);
+ assert.match(hostedTrustedAccess.content[0].text, /Daybreak Red/);
- const isolatedOtherTrustedAccess = await testServer.callTool(9613, {
+ const isolatedOtherTrustedAccess = await testServer.callSuccessfulTool(9613, {
name: "get_codex_security_daybreak_access",
arguments: {},
_meta: { threadId: "fixture-isolated-trusted-access-other" },
});
- assertNoError(isolatedOtherTrustedAccess);
- assert.equal(
- isolatedOtherTrustedAccess.result.structuredContent.status,
- "unknown",
- );
+ assert.equal(isolatedOtherTrustedAccess.structuredContent.status, "unknown");
const invalidGrantPairs = [
{ level: "tac2", source: "project" },
@@ -1188,42 +1147,33 @@ try {
{ level: "government", source: "project" },
];
for (const [index, invalidGrant] of invalidGrantPairs.entries()) {
- const response = await testServer.callTool(9620 + index, {
+ const response = await testServer.callSuccessfulTool(9620 + index, {
name: "get_codex_security_daybreak_access",
arguments: {},
_meta: {
threadId: "fixture-invalid-grant-thread",
- "openai/entitlementContext": {
- schemaVersion: 1,
- entitlements: {
- cyber_trusted_access: {
- ...grantedTrustedAccess,
- grants: [{ level: "tac1", source: "user" }, invalidGrant],
- },
- },
- },
+ "openai/entitlementContext": entitlementContext({
+ ...grantedTrustedAccess,
+ grants: [{ level: "tac1", source: "user" }, invalidGrant],
+ }),
},
});
- assertNoError(response);
- assert.equal(response.result.structuredContent.status, "unknown");
- assert.deepEqual(response.result.structuredContent.programs, []);
+ assert.equal(response.structuredContent.status, "unknown");
+ assert.deepEqual(response.structuredContent.programs, []);
}
- const staleGrantedAccess = await testServer.callTool(9626, {
+ const staleGrantedAccess = await testServer.callSuccessfulTool(9626, {
name: "get_codex_security_daybreak_access",
arguments: {},
_meta: {
threadId: "fixture-stale-granted-thread",
- "openai/entitlementContext": {
- schemaVersion: 1,
- entitlements: {
- cyber_trusted_access: { ...grantedTrustedAccess, stale: true },
- },
- },
+ "openai/entitlementContext": entitlementContext({
+ ...grantedTrustedAccess,
+ stale: true,
+ }),
},
});
- assertNoError(staleGrantedAccess);
- assert.deepEqual(staleGrantedAccess.result.structuredContent, {
+ assert.deepEqual(staleGrantedAccess.structuredContent, {
schemaVersion: 1,
status: "unknown",
programs: [],
@@ -1231,18 +1181,17 @@ try {
stale: true,
});
assert.doesNotMatch(
- staleGrantedAccess.result.content[0].text,
+ staleGrantedAccess.content[0].text,
/protected results may not be displayable/,
);
- const untrustedReplay = await testServer.callTool(9603, {
+ const untrustedReplay = await testServer.callSuccessfulTool(9603, {
name: "get_codex_security_daybreak_access",
arguments: {},
_meta: { threadId: "fixture-trusted-access-thread" },
});
- assertNoError(untrustedReplay);
- assert.equal(untrustedReplay.result._meta, undefined);
- assert.equal(untrustedReplay.result.structuredContent.status, "unknown");
+ assert.equal(untrustedReplay._meta, undefined);
+ assert.equal(untrustedReplay.structuredContent.status, "unknown");
const deniedTrustedAccess = {
schemaVersion: 1,
@@ -1252,22 +1201,16 @@ try {
stale: false,
enrollmentUrl: "https://chatgpt.com/cyber",
};
- const refreshedTrustedAccess = await testServer.callTool(9604, {
+ const refreshedTrustedAccess = await testServer.callSuccessfulTool(9604, {
name: "get_codex_security_daybreak_access",
arguments: {},
_meta: {
threadId: "fixture-trusted-access-thread",
- "openai/entitlementContext": {
- schemaVersion: 1,
- entitlements: {
- cyber_trusted_access: deniedTrustedAccess,
- },
- },
+ "openai/entitlementContext": entitlementContext(deniedTrustedAccess),
},
});
- assertNoError(refreshedTrustedAccess);
- assert.equal(refreshedTrustedAccess.result._meta, undefined);
- assert.deepEqual(refreshedTrustedAccess.result.structuredContent, {
+ assert.equal(refreshedTrustedAccess._meta, undefined);
+ assert.deepEqual(refreshedTrustedAccess.structuredContent, {
schemaVersion: 1,
status: "not_granted",
programs: [],
@@ -1276,140 +1219,103 @@ try {
enrollmentUrl: "https://chatgpt.com/cyber",
});
assert.doesNotMatch(
- JSON.stringify(refreshedTrustedAccess.result),
+ JSON.stringify(refreshedTrustedAccess),
/\btac(?:[123])?\b/i,
);
assert.match(
- refreshedTrustedAccess.result.content[0].text,
+ refreshedTrustedAccess.content[0].text,
/protected results associated with this account may not be displayable/,
);
assert.match(
- refreshedTrustedAccess.result.content[0].text,
+ refreshedTrustedAccess.content[0].text,
/does not determine Amazon Bedrock model access/,
);
- const timestampedTrustedAccess = await testServer.callTool(9608, {
+ const timestampedTrustedAccess = await testServer.callSuccessfulTool(9608, {
name: "get_codex_security_daybreak_access",
arguments: {},
_meta: {
threadId: "fixture-timestamped-trusted-access-thread",
- "openai/entitlementContext": {
+ "openai/entitlementContext": entitlementContext({
schemaVersion: 1,
- entitlements: {
- cyber_trusted_access: {
- schemaVersion: 1,
- status: "granted",
- grants: [{ level: "tac2", source: "user" }],
- stale: false,
- },
- },
- },
+ status: "granted",
+ grants: [{ level: "tac2", source: "user" }],
+ stale: false,
+ }),
},
});
- assertNoError(timestampedTrustedAccess);
- assert.equal(
- timestampedTrustedAccess.result.structuredContent.status,
- "granted",
- );
- assert.deepEqual(timestampedTrustedAccess.result.structuredContent.programs, [
+ assert.equal(timestampedTrustedAccess.structuredContent.status, "granted");
+ assert.deepEqual(timestampedTrustedAccess.structuredContent.programs, [
"Daybreak Blue",
]);
assert.ok(
Number.isFinite(
- Date.parse(timestampedTrustedAccess.result.structuredContent.checkedAt),
+ Date.parse(timestampedTrustedAccess.structuredContent.checkedAt),
),
);
- const unownedTrustedAccess = await testServer.callTool(9605, {
+ const unownedTrustedAccess = await testServer.callSuccessfulTool(9605, {
name: "get_codex_security_daybreak_access",
arguments: {},
_meta: {
"openai/threadId": "fixture-spoofed-missing-canonical-thread",
- "openai/entitlementContext": {
- schemaVersion: 1,
- entitlements: {
- cyber_trusted_access: grantedTrustedAccess,
- },
- },
+ "openai/entitlementContext": entitlementContext(grantedTrustedAccess),
},
});
- assertNoError(unownedTrustedAccess);
- assert.equal(unownedTrustedAccess.result.structuredContent.status, "unknown");
+ assert.equal(unownedTrustedAccess.structuredContent.status, "unknown");
- const malformedTrustedAccess = await testServer.callTool(9606, {
+ const malformedTrustedAccess = await testServer.callSuccessfulTool(9606, {
name: "get_codex_security_daybreak_access",
arguments: {},
_meta: {
threadId: "fixture-malformed-trusted-access-thread",
- "openai/entitlementContext": {
- schemaVersion: 1,
- entitlements: {
- cyber_trusted_access: {
- ...grantedTrustedAccess,
- grants: [],
- },
- },
- },
+ "openai/entitlementContext": entitlementContext({
+ ...grantedTrustedAccess,
+ grants: [],
+ }),
},
});
- assertNoError(malformedTrustedAccess);
- assert.equal(
- malformedTrustedAccess.result.structuredContent.status,
- "unknown",
- );
+ assert.equal(malformedTrustedAccess.structuredContent.status, "unknown");
const argumentTrustedAccess = await testServer.callTool(9607, {
name: "get_codex_security_daybreak_access",
arguments: {
- "openai/entitlementContext": {
- schemaVersion: 1,
- entitlements: {
- cyber_trusted_access: grantedTrustedAccess,
- },
- },
+ "openai/entitlementContext": entitlementContext(grantedTrustedAccess),
},
_meta: { threadId: "fixture-argument-trusted-access-thread" },
});
assert.equal(argumentTrustedAccess.result.isError, true);
- const replayedTrustedAccess = await testServer.callTool(9609, {
+ const replayedTrustedAccess = await testServer.callSuccessfulTool(9609, {
name: "get_codex_security_daybreak_access",
arguments: {},
_meta: { threadId: "fixture-trusted-access-thread" },
});
- assertNoError(replayedTrustedAccess);
- assert.equal(
- replayedTrustedAccess.result.structuredContent.status,
- "unknown",
- );
+ assert.equal(replayedTrustedAccess.structuredContent.status, "unknown");
- const spoofedThreadTrustedAccess = await testServer.callTool(9610, {
+ const spoofedThreadTrustedAccess = await testServer.callSuccessfulTool(9610, {
name: "get_codex_security_daybreak_access",
arguments: {},
_meta: {
threadId: "fixture-trusted-access-owner",
"openai/threadId": "fixture-spoofed-trusted-access-owner",
- "openai/entitlementContext": {
- schemaVersion: 1,
- entitlements: {
- cyber_trusted_access: grantedTrustedAccess,
- },
- },
+ "openai/entitlementContext": entitlementContext(grantedTrustedAccess),
},
});
- assertNoError(spoofedThreadTrustedAccess);
assert.deepEqual(
- spoofedThreadTrustedAccess.result.structuredContent,
+ spoofedThreadTrustedAccess.structuredContent,
grantedDaybreakAccess,
);
- const canonicalThreadTrustedAccess = await testServer.callTool(9611, {
- name: "get_codex_security_daybreak_access",
- arguments: {},
- _meta: { threadId: "fixture-trusted-access-owner" },
- });
- assertNoError(canonicalThreadTrustedAccess);
+ const canonicalThreadTrustedAccess = await testServer.callSuccessfulTool(
+ 9611,
+ {
+ name: "get_codex_security_daybreak_access",
+ arguments: {},
+ _meta: { threadId: "fixture-trusted-access-owner" },
+ },
+ );
assert.equal(
- canonicalThreadTrustedAccess.result.structuredContent.status,
+ canonicalThreadTrustedAccess.structuredContent.status,
"unknown",
);
@@ -1959,7 +1865,7 @@ try {
const urlContext =
"Deployment details came from https://example.test/internal.";
- const opened = await testServer.callTool(4, {
+ const opened = await testServer.callSuccessfulTool(4, {
name: "open_codex_security_workspace",
arguments: {
targetPath: target,
@@ -1970,8 +1876,7 @@ try {
},
_meta: { "openai/threadId": "fixture-thread" },
});
- assertNoError(opened);
- const workspace = opened.result.structuredContent.workspace;
+ const workspace = opened.structuredContent.workspace;
assert.equal(workspace.setup.submitted, false);
assert.equal(workspace.mode, "standard");
assert.equal(workspace.userContext, urlContext);
@@ -1982,29 +1887,24 @@ try {
reviewChangesSupported: false,
});
- const sameThreadReopen = await testServer.callTool(1162, {
+ const sameThreadReopen = await testServer.callSuccessfulTool(1162, {
name: "open_codex_security_workspace",
arguments: { sessionId: workspace.id },
_meta: { "openai/threadId": "fixture-thread" },
});
- assertNoError(sameThreadReopen);
- assert.equal(
- sameThreadReopen.result.structuredContent.workspace.id,
- workspace.id,
- );
+ assert.equal(sameThreadReopen.structuredContent.workspace.id, workspace.id);
- const otherThreadOpened = await testServer.callTool(1163, {
+ const otherThreadOpened = await testServer.callSuccessfulTool(1163, {
name: "open_codex_security_workspace",
arguments: { targetPath: replacementTarget },
_meta: { "openai/threadId": "fixture-other-thread" },
});
- assertNoError(otherThreadOpened);
assert.notEqual(
- otherThreadOpened.result.structuredContent.workspace.id,
+ otherThreadOpened.structuredContent.workspace.id,
workspace.id,
);
assert.equal(
- otherThreadOpened.result.structuredContent.workspace.targetPath,
+ otherThreadOpened.structuredContent.workspace.targetPath,
await realpath(replacementTarget),
);
@@ -2029,48 +1929,41 @@ try {
/thread metadata is required/i,
);
- const metadataFreeCreate = await testServer.callTool(1166, {
+ const metadataFreeCreate = await testServer.callSuccessfulTool(1166, {
name: "open_codex_security_workspace",
arguments: { targetPath: target },
});
- assertNoError(metadataFreeCreate);
assert.match(
- metadataFreeCreate.result.structuredContent.workspace.id,
+ metadataFreeCreate.structuredContent.workspace.id,
/^[0-9a-f-]{36}$/,
);
- const savedOtherWorkspace = await testServer.callTool(2020, {
+ await testServer.callSuccessfulTool(2020, {
name: "submit_codex_security_setup",
arguments: {
- sessionId: otherThreadOpened.result.structuredContent.workspace.id,
+ sessionId: otherThreadOpened.structuredContent.workspace.id,
targetPath: replacementTarget,
scope: ".",
mode: "standard",
},
});
- assertNoError(savedOtherWorkspace);
testServer.notify("notifications/cancelled", {
requestId: 2021,
reason: "Smoke-test cancellation",
});
- const otherStarted = await testServer.callTool(2023, {
+ await testServer.callSuccessfulTool(2023, {
name: "start_codex_security_scan",
arguments: {
- sessionId: otherThreadOpened.result.structuredContent.workspace.id,
+ sessionId: otherThreadOpened.structuredContent.workspace.id,
},
});
- assertNoError(otherStarted);
- const absoluteScopeOpened = await testServer.callTool(150, {
+ const absoluteScopeOpened = await testServer.callSuccessfulTool(150, {
name: "open_codex_security_workspace",
arguments: { targetPath: target, scope: target, mode: "standard" },
_meta: { "openai/threadId": "fixture-aux-thread" },
});
- assertNoError(absoluteScopeOpened);
- assert.equal(
- absoluteScopeOpened.result.structuredContent.workspace.scope,
- ".",
- );
+ assert.equal(absoluteScopeOpened.structuredContent.workspace.scope, ".");
const invalidReopen = await testServer.callTool(151, {
name: "open_codex_security_workspace",
@@ -2079,16 +1972,15 @@ try {
assert.equal(invalidReopen.result.isError, true);
assert.match(invalidReopen.result.content[0].text, /sessionId only reopens/);
- const deepOpened = await testServer.callTool(44, {
+ const deepOpened = await testServer.callSuccessfulTool(44, {
name: "open_codex_security_workspace",
arguments: { targetPath: target, scope: ".", mode: "deep" },
_meta: { "openai/threadId": "fixture-aux-thread" },
});
- assertNoError(deepOpened);
- assert.equal(deepOpened.result.structuredContent.workspace.mode, "deep");
- assert.equal(deepOpened.result.structuredContent.workspace.scope, ".");
+ assert.equal(deepOpened.structuredContent.workspace.mode, "deep");
+ assert.equal(deepOpened.structuredContent.workspace.scope, ".");
- const diffOpened = await testServer.callTool(45, {
+ const diffOpened = await testServer.callSuccessfulTool(45, {
name: "open_codex_security_workspace",
arguments: {
targetPath: gitTarget,
@@ -2099,22 +1991,21 @@ try {
},
_meta: { "openai/threadId": "fixture-aux-thread" },
});
- assertNoError(diffOpened);
- assert.equal(diffOpened.result.structuredContent.workspace.mode, "diff");
+ assert.equal(diffOpened.structuredContent.workspace.mode, "diff");
assert.equal(
- diffOpened.result.structuredContent.workspace.targetSummary,
+ diffOpened.structuredContent.workspace.targetSummary,
"Latest commit · fixture",
);
assert.equal(
- diffOpened.result.structuredContent.workspace.diffTarget.headRevision,
+ diffOpened.structuredContent.workspace.diffTarget.headRevision,
gitHead,
);
assert.equal(
- diffOpened.result.structuredContent.workspace.setupValidation.valid,
+ diffOpened.structuredContent.workspace.setupValidation.valid,
true,
);
- const inferredDiffOpened = await testServer.callTool(152, {
+ const inferredDiffOpened = await testServer.callSuccessfulTool(152, {
name: "open_codex_security_workspace",
arguments: {
targetPath: gitTarget,
@@ -2123,11 +2014,7 @@ try {
},
_meta: { "openai/threadId": "fixture-aux-thread" },
});
- assertNoError(inferredDiffOpened);
- assert.equal(
- inferredDiffOpened.result.structuredContent.workspace.mode,
- "diff",
- );
+ assert.equal(inferredDiffOpened.structuredContent.workspace.mode, "diff");
const contradictoryDiffOpened = await testServer.callTool(153, {
name: "open_codex_security_workspace",
@@ -2156,7 +2043,7 @@ try {
const nestedGitTarget = path.join(gitTarget, "nested");
await mkdir(nestedGitTarget);
- const nestedDiffOpened = await testServer.callTool(155, {
+ const nestedDiffOpened = await testServer.callSuccessfulTool(155, {
name: "open_codex_security_workspace",
arguments: {
targetPath: nestedGitTarget,
@@ -2166,22 +2053,21 @@ try {
},
_meta: { "openai/threadId": "fixture-aux-thread" },
});
- assertNoError(nestedDiffOpened);
assert.equal(
- nestedDiffOpened.result.structuredContent.workspace.setupValidation.valid,
+ nestedDiffOpened.structuredContent.workspace.setupValidation.valid,
false,
);
assert.match(
- nestedDiffOpened.result.structuredContent.workspace.setupValidation.error,
+ nestedDiffOpened.structuredContent.workspace.setupValidation.error,
/repository root/,
);
assert.equal(
- nestedDiffOpened.result.structuredContent.workspace.targetMetadata
+ nestedDiffOpened.structuredContent.workspace.targetMetadata
.reviewChangesSupported,
false,
);
- const inspectedSetup = await testServer.callTool(46, {
+ const inspectedSetup = await testServer.callSuccessfulTool(46, {
name: "inspect_codex_security_setup",
arguments: {
targetPath: gitTarget,
@@ -2190,21 +2076,19 @@ try {
diffTarget: { kind: "commit", headRevision: "HEAD" },
},
});
- assertNoError(inspectedSetup);
const inspectedCommitTarget =
- inspectedSetup.result.structuredContent.setup.diffTarget;
+ inspectedSetup.structuredContent.setup.diffTarget;
assert.equal(inspectedCommitTarget.baseRevision, gitBase);
assert.equal(
- inspectedSetup.result.structuredContent.setup.diffTarget.headRevision,
+ inspectedSetup.structuredContent.setup.diffTarget.headRevision,
gitHead,
);
assert.equal(
- inspectedSetup.result.structuredContent.setup.target.targetMetadata
- .commitSubject,
+ inspectedSetup.structuredContent.setup.target.targetMetadata.commitSubject,
"update fixture",
);
- const inspectedCommitOpened = await testServer.callTool(2200, {
+ const inspectedCommitOpened = await testServer.callSuccessfulTool(2200, {
name: "open_codex_security_workspace",
arguments: {
targetPath: gitTarget,
@@ -2215,12 +2099,11 @@ try {
},
_meta: { "openai/threadId": "fixture-inspected-commit-thread" },
});
- assertNoError(inspectedCommitOpened);
- const inspectedCommitSaved = await testServer.callTool(2201, {
+ const inspectedCommitSaved = await testServer.callSuccessfulTool(2201, {
name: "submit_codex_security_setup",
arguments: {
- sessionId: inspectedCommitOpened.result.structuredContent.workspace.id,
+ sessionId: inspectedCommitOpened.structuredContent.workspace.id,
targetPath: gitTarget,
scope: ".",
mode: "diff",
@@ -2228,13 +2111,12 @@ try {
diffTarget: inspectedCommitTarget,
},
});
- assertNoError(inspectedCommitSaved);
assert.deepEqual(
- inspectedCommitSaved.result.structuredContent.workspace.diffTarget,
+ inspectedCommitSaved.structuredContent.workspace.diffTarget,
inspectedCommitTarget,
);
- const invalidOpened = await testServer.callTool(47, {
+ const invalidOpened = await testServer.callSuccessfulTool(47, {
name: "open_codex_security_workspace",
arguments: {
targetPath: path.join(target, "missing"),
@@ -2243,36 +2125,33 @@ try {
},
_meta: { "openai/threadId": "fixture-aux-thread" },
});
- assertNoError(invalidOpened);
assert.equal(
- invalidOpened.result.structuredContent.workspace.setupValidation.valid,
+ invalidOpened.structuredContent.workspace.setupValidation.valid,
false,
);
assert.equal(
- invalidOpened.result.structuredContent.workspace.targetMetadata,
+ invalidOpened.structuredContent.workspace.targetMetadata,
undefined,
);
- const inspected = await testServer.callTool(40, {
+ const inspected = await testServer.callSuccessfulTool(40, {
name: "inspect_codex_security_target",
arguments: { targetPath: target },
});
- assertNoError(inspected);
assert.equal(
- inspected.result.structuredContent.target.displayName,
+ inspected.structuredContent.target.displayName,
path.basename(target),
);
assert.equal(
- inspected.result.structuredContent.target.targetPath,
+ inspected.structuredContent.target.targetPath,
await realpath(target),
);
assert.equal(
- inspected.result.structuredContent.target.targetMetadata
- .reviewChangesSupported,
+ inspected.structuredContent.target.targetMetadata.reviewChangesSupported,
false,
);
- const saved = await testServer.callTool(5, {
+ const saved = await testServer.callSuccessfulTool(5, {
name: "submit_codex_security_setup",
arguments: {
sessionId: workspace.id,
@@ -2282,12 +2161,11 @@ try {
userContext: "Pay attention to the HTTP API.",
},
});
- assertNoError(saved);
- assert.equal(saved.result._meta, undefined);
- const savedWorkspace = saved.result.structuredContent.workspace;
+ assert.equal(saved._meta, undefined);
+ const savedWorkspace = saved.structuredContent.workspace;
assert.equal(savedWorkspace.setup.submitted, true);
assert.equal(savedWorkspace.userContext, "Pay attention to the HTTP API.");
- const started = await testServer.callTool(6, {
+ const started = await testServer.callSuccessfulTool(6, {
name: "start_codex_security_scan",
arguments: {
model: "gpt-5.6-sol",
@@ -2295,8 +2173,7 @@ try {
sessionId: workspace.id,
},
});
- assertNoError(started);
- const startedWorkspace = started.result.structuredContent.workspace;
+ const startedWorkspace = started.structuredContent.workspace;
assert.equal(startedWorkspace.results.model, "gpt-5.6-sol");
assert.equal(startedWorkspace.results.reasoningEffort, "high");
@@ -2312,7 +2189,7 @@ try {
false,
);
const scanId = startedWorkspace.results.scanId;
- assertScanTarget(started.result._meta, scanId);
+ assertScanTarget(started._meta, scanId);
assert.equal(startedWorkspace.results.progress.phase, "preflight");
assert.equal(startedWorkspace.results.progress.status, "running");
assert.equal(startedWorkspace.results.handoffStatus, "pending");
@@ -2341,18 +2218,16 @@ try {
"release_codex_security_scan_handoff_delivery",
"claim_codex_security_scan_handoff_delivery",
].entries()) {
- const claimedHandoff = await testServer.callTool(200200 + index, {
+ const claimedHandoff = await testServer.callSuccessfulTool(200200 + index, {
name,
arguments: { claimToken: handoffClaimToken, scanId },
});
- assertNoError(claimedHandoff);
assert.equal(
- claimedHandoff.result.structuredContent.workspace.results
- .handoffClaimToken,
+ claimedHandoff.structuredContent.workspace.results.handoffClaimToken,
index === 1 ? null : handoffClaimToken,
);
}
- const attachedHandoff = await testServer.callTool(20021, {
+ await testServer.callSuccessfulTool(20021, {
name: "attach_codex_security_scan_continuation_thread",
arguments: {
claimToken: handoffClaimToken,
@@ -2360,14 +2235,12 @@ try {
threadId: "fixture-thread",
},
});
- assertNoError(attachedHandoff);
- const threadOwnedScan = await testServer.callTool(2202, {
+ const threadOwnedScan = await testServer.callSuccessfulTool(2202, {
name: "get_codex_security_scan",
arguments: { scanId },
});
- assertNoError(threadOwnedScan);
assert.equal(
- threadOwnedScan.result.structuredContent.scan.continuationThreadId,
+ threadOwnedScan.structuredContent.scan.continuationThreadId,
"fixture-thread",
);
@@ -2393,33 +2266,24 @@ try {
/Pass the handoffClaimToken/,
);
- const delivered = await testServer.callTool(2003, {
+ const delivered = await testServer.callSuccessfulTool(2003, {
name: "get_codex_security_scan_context",
arguments: { handoffClaimToken, scanId },
_meta: { "openai/threadId": "fixture-thread" },
});
- assertNoError(delivered);
+ assert.equal(delivered.structuredContent.scan.handoffStatus, "delivered");
+ assert.equal(delivered.structuredContent.scan.handoffClaimToken, undefined);
assert.equal(
- delivered.result.structuredContent.scan.handoffStatus,
- "delivered",
- );
- assert.equal(
- delivered.result.structuredContent.scan.handoffClaimToken,
+ delivered.structuredContent.workspace.results.handoffClaimToken,
undefined,
);
- assert.equal(
- delivered.result.structuredContent.workspace.results.handoffClaimToken,
- undefined,
- );
- const reopenedWorkspace = await testServer.callTool(2203, {
+ const reopenedWorkspace = await testServer.callSuccessfulTool(2203, {
name: "open_codex_security_workspace",
arguments: { sessionId: workspace.id },
_meta: { "openai/threadId": "fixture-thread" },
});
- assertNoError(reopenedWorkspace);
assert.equal(
- reopenedWorkspace.result.structuredContent.workspace.results
- .handoffClaimToken,
+ reopenedWorkspace.structuredContent.workspace.results.handoffClaimToken,
undefined,
);
@@ -2434,59 +2298,51 @@ try {
/owned by another continuation/,
);
- const deliveredWithoutToken = await testServer.callTool(2007, {
+ await testServer.callSuccessfulTool(2007, {
name: "get_codex_security_scan_context",
arguments: { scanId },
_meta: { "openai/threadId": "fixture-thread" },
});
- assertNoError(deliveredWithoutToken);
const longUserContext = `${"Prioritize tenant isolation. ".repeat(120)}Read https://example.test/context.`;
- const renamedScan = await testServer.callTool(92020, {
+ const renamedScan = await testServer.callSuccessfulTool(92020, {
name: "rename_codex_security_scan",
arguments: { scanId, name: " - Release audit " },
});
- assertNoError(renamedScan);
- assert.deepEqual(renamedScan.result.structuredContent, {
+ assert.deepEqual(renamedScan.structuredContent, {
scanId,
name: "- Release audit",
});
- const reopenedScan = await testServer.callTool(92021, {
+ const reopenedScan = await testServer.callSuccessfulTool(92021, {
name: "get_codex_security_scan",
arguments: { scanId },
});
- assertNoError(reopenedScan);
- assert.equal(
- reopenedScan.result.structuredContent.scan.name,
- "- Release audit",
- );
- const updatedContext = await testServer.callTool(92010, {
+ assert.equal(reopenedScan.structuredContent.scan.name, "- Release audit");
+ const updatedContext = await testServer.callSuccessfulTool(92010, {
name: "update_codex_security_scan_context",
arguments: { handoffClaimToken, scanId, userContext: longUserContext },
_meta: { "openai/threadId": "fixture-thread" },
});
- assertNoError(updatedContext);
assert.equal(
- updatedContext.result.structuredContent.scan.userContext,
+ updatedContext.structuredContent.scan.userContext,
longUserContext,
);
assert.equal(
- updatedContext.result.structuredContent.workspace.userContext,
+ updatedContext.structuredContent.workspace.userContext,
longUserContext,
);
const appUserContext = "Focus on account recovery. ".repeat(120).trim();
- const appUpdatedContext = await testServer.callTool(92011, {
+ const appUpdatedContext = await testServer.callSuccessfulTool(92011, {
name: "update_codex_security_scan_context_from_app",
arguments: { scanId, userContext: appUserContext },
});
- assertNoError(appUpdatedContext);
assert.equal(
- appUpdatedContext.result.structuredContent.scan.userContext,
+ appUpdatedContext.structuredContent.scan.userContext,
appUserContext,
);
- const readyPreflightProgress = await testServer.callTool(90164, {
+ const readyPreflightProgress = await testServer.callSuccessfulTool(90164, {
name: "update_codex_security_scan_progress",
_meta: {
"openai/threadId": "fixture-thread",
@@ -2503,27 +2359,25 @@ try {
phaseProgressUnit: "checks",
},
});
- assertNoError(readyPreflightProgress);
assert.equal(
- readyPreflightProgress.result.structuredContent.scan.model,
+ readyPreflightProgress.structuredContent.scan.model,
"gpt-5.6-terra",
);
assert.equal(
- readyPreflightProgress.result.structuredContent.scan.reasoningEffort,
+ readyPreflightProgress.structuredContent.scan.reasoningEffort,
"low",
);
assert.deepEqual(
- readyPreflightProgress.result.structuredContent.scan.progress
- .preflightProgress,
+ readyPreflightProgress.structuredContent.scan.progress.preflightProgress,
{ completed: 4, total: 4 },
);
assert.equal(
- readyPreflightProgress.result.structuredContent.scan.userContext,
+ readyPreflightProgress.structuredContent.scan.userContext,
appUserContext,
);
const nextPhaseUserContext = "Prioritize password-reset token validation.";
- const updatedPhaseContext = await testServer.callTool(92013, {
+ await testServer.callSuccessfulTool(92013, {
name: "update_codex_security_scan_context",
arguments: {
handoffClaimToken,
@@ -2532,9 +2386,8 @@ try {
},
_meta: { "openai/threadId": "fixture-thread" },
});
- assertNoError(updatedPhaseContext);
- const updated = await testServer.callTool(8, {
+ const updated = await testServer.callSuccessfulTool(8, {
name: "update_codex_security_scan_progress",
arguments: {
scanId,
@@ -2548,59 +2401,47 @@ try {
handoffClaimToken,
},
});
- assertNoError(updated);
assert.equal(
- updated.result.structuredContent.scan.userContext,
+ updated.structuredContent.scan.userContext,
nextPhaseUserContext,
);
- assert.deepEqual(updated.result.structuredContent.scan.progress.coverage, {
+ assert.deepEqual(updated.structuredContent.scan.progress.coverage, {
closedRows: 22,
filesTotal: 1,
worklistRows: 31,
});
- assert.deepEqual(
- updated.result.structuredContent.scan.progress.phaseProgress,
- {
- completed: 1,
- total: 4,
- unit: "candidate_findings",
- },
- );
- assert.deepEqual(
- updated.result.structuredContent.scan.progress.preflightProgress,
- {
- completed: 4,
- total: 4,
- },
- );
+ assert.deepEqual(updated.structuredContent.scan.progress.phaseProgress, {
+ completed: 1,
+ total: 4,
+ unit: "candidate_findings",
+ });
+ assert.deepEqual(updated.structuredContent.scan.progress.preflightProgress, {
+ completed: 4,
+ total: 4,
+ });
await writeCompletedContract(initializedScanDir, scanId, snapshotDigest);
await writeFile(path.join(target, "src/a.py"), "changed\n");
- const completed = await testServer.callTool(802, {
+ const completed = await testServer.callSuccessfulTool(802, {
name: "complete_codex_security_scan",
arguments: { handoffClaimToken, scanId },
});
- assertNoError(completed);
- assert.deepEqual(completed.result.structuredContent.scan.warnings, [
+ assert.deepEqual(completed.structuredContent.scan.warnings, [
"Directory contents changed while the scan was running; results were saved for the original snapshot.",
]);
await writeFile(path.join(target, "src/a.py"), "vulnerable\n");
+ assert.equal(completed.structuredContent.scan.progress.status, "complete");
+ assert.equal(completed.structuredContent.scan.findings.length, 2);
assert.equal(
- completed.result.structuredContent.scan.progress.status,
+ completed.structuredContent.workspace.results.progress.status,
"complete",
);
- assert.equal(completed.result.structuredContent.scan.findings.length, 2);
- assert.equal(
- completed.result.structuredContent.workspace.results.progress.status,
- "complete",
- );
- const refreshed = await testServer.callTool(10, {
+ const refreshed = await testServer.callSuccessfulTool(10, {
name: "get_codex_security_scan",
arguments: { scanId: scanId.toUpperCase() },
});
- assertNoError(refreshed);
- assertScanTarget(refreshed.result._meta, scanId);
- const results = refreshed.result.structuredContent.scan;
+ assertScanTarget(refreshed._meta, scanId);
+ const results = refreshed.structuredContent.scan;
assert.equal(results.findings.length, 2);
assert.equal(results.findingCount, 2);
assert.deepEqual(results.severityCounts, { high: 1, informational: 1 });
@@ -2622,7 +2463,7 @@ try {
const occurrenceId = results.findings[0].occurrenceId;
const remediationRequestId = randomUUID();
- const closedFinding = await testServer.callTool(60, {
+ const closedFinding = await testServer.callSuccessfulTool(60, {
name: "set_codex_security_finding_triage",
arguments: {
occurrenceId,
@@ -2631,13 +2472,12 @@ try {
note: "The archive path is normalized before the write.",
},
});
- assertNoError(closedFinding);
assert.equal(
- closedFinding.result.structuredContent.scan.findings[0].triage.status,
+ closedFinding.structuredContent.scan.findings[0].triage.status,
"closed",
);
assert.equal(
- closedFinding.result.structuredContent.scan.findings[0].triage.closeReason,
+ closedFinding.structuredContent.scan.findings[0].triage.closeReason,
"false_positive",
);
@@ -2655,15 +2495,14 @@ try {
rejectedClosedPatch.result.content[0].text,
/Reopen this finding/,
);
- const reopenedFinding = await testServer.callTool(160, {
+ await testServer.callSuccessfulTool(160, {
name: "set_codex_security_finding_triage",
arguments: { occurrenceId, status: "open" },
});
- assertNoError(reopenedFinding);
const canceledRequestId = randomUUID();
const canceledActionToken = randomUUID();
- const requestedThenCanceledPatch = await testServer.callTool(500, {
+ await testServer.callSuccessfulTool(500, {
name: "request_codex_security_finding_remediation",
arguments: {
actionToken: canceledActionToken,
@@ -2671,8 +2510,7 @@ try {
requestId: canceledRequestId,
},
});
- assertNoError(requestedThenCanceledPatch);
- const canceledPatch = await testServer.callTool(501, {
+ const canceledPatch = await testServer.callSuccessfulTool(501, {
name: "cancel_codex_security_finding_remediation_request",
arguments: {
actionToken: canceledActionToken,
@@ -2680,9 +2518,8 @@ try {
requestId: canceledRequestId,
},
});
- assertNoError(canceledPatch);
assert.deepEqual(
- canceledPatch.result.structuredContent.scan.findings[0].remediationState,
+ canceledPatch.structuredContent.scan.findings[0].remediationState,
{
state: "idle",
},
@@ -2693,7 +2530,7 @@ try {
"release_codex_security_finding_remediation_claim",
"claim_codex_security_finding_remediation_resend",
].entries()) {
- const requestedPatch = await testServer.callTool(6100 + index, {
+ const requestedPatch = await testServer.callSuccessfulTool(6100 + index, {
name,
arguments: {
actionToken: generationActionToken,
@@ -2701,9 +2538,8 @@ try {
requestId: remediationRequestId,
},
});
- assertNoError(requestedPatch);
const remediation =
- requestedPatch.result.structuredContent.scan.findings[0].remediationState;
+ requestedPatch.structuredContent.scan.findings[0].remediationState;
assert.equal(remediation.state, "requested");
assert.equal(
remediation.actionClaimToken,
@@ -2731,7 +2567,7 @@ try {
-vulnerable
+fixed
`;
- const generatedPatch = await testServer.callTool(62, {
+ const generatedPatch = await testServer.callSuccessfulTool(62, {
name: "set_codex_security_finding_remediation",
arguments: {
actionToken: generationActionToken,
@@ -2743,9 +2579,7 @@ try {
summary: "Contain archive extraction under the output root.",
},
});
- assertNoError(generatedPatch);
- const generatedFinding =
- generatedPatch.result.structuredContent.scan.findings[0];
+ const generatedFinding = generatedPatch.structuredContent.scan.findings[0];
const remediation = generatedFinding.remediationState;
const savedPatchPath = path.join(initializedScanDir, remediation.patchPath);
assert.equal(remediation.state, "generated");
@@ -2769,7 +2603,7 @@ try {
assert.equal(generatedFinding.triage.status, "open");
const applyActionToken = randomUUID();
- const requestedApply = await testServer.callTool(65, {
+ const requestedApply = await testServer.callSuccessfulTool(65, {
name: "request_codex_security_finding_remediation_action",
arguments: {
action: "apply",
@@ -2779,18 +2613,16 @@ try {
requestId: remediationRequestId,
},
});
- assertNoError(requestedApply);
assert.equal(
- requestedApply.result.structuredContent.scan.findings[0].remediationState
+ requestedApply.structuredContent.scan.findings[0].remediationState
.pendingAction,
"apply",
);
assert.equal(
- requestedApply.result.structuredContent.scan.findings[0].remediationState
- .version,
+ requestedApply.structuredContent.scan.findings[0].remediationState.version,
3,
);
- const markedApplyDelivered = await testServer.callTool(166, {
+ const markedApplyDelivered = await testServer.callSuccessfulTool(166, {
name: "mark_codex_security_finding_remediation_delivered",
arguments: {
actionToken: applyActionToken,
@@ -2798,10 +2630,9 @@ try {
requestId: remediationRequestId,
},
});
- assertNoError(markedApplyDelivered);
assert.ok(
- markedApplyDelivered.result.structuredContent.scan.findings[0]
- .remediationState.actionDeliveredAt,
+ markedApplyDelivered.structuredContent.scan.findings[0].remediationState
+ .actionDeliveredAt,
);
execFileSync("git", ["apply", "--no-index", savedPatchPath], { cwd: target });
assert.match(
@@ -2809,7 +2640,7 @@ try {
/^fixed\r?\n$/,
);
- const appliedPatch = await testServer.callTool(66, {
+ const appliedPatch = await testServer.callSuccessfulTool(66, {
name: "set_codex_security_finding_remediation",
arguments: {
actionToken: applyActionToken,
@@ -2821,15 +2652,13 @@ try {
patchPath: remediation.patchPath,
},
});
- assertNoError(appliedPatch);
assert.equal(
- appliedPatch.result.structuredContent.scan.findings[0].remediationState
- .state,
+ appliedPatch.structuredContent.scan.findings[0].remediationState.state,
"applied",
);
const verifyActionToken = randomUUID();
- const requestedVerify = await testServer.callTool(168, {
+ const requestedVerify = await testServer.callSuccessfulTool(168, {
name: "request_codex_security_finding_remediation_action",
arguments: {
action: "verify",
@@ -2839,19 +2668,17 @@ try {
requestId: remediationRequestId,
},
});
- assertNoError(requestedVerify);
assert.equal(
- requestedVerify.result.structuredContent.scan.findings[0].remediationState
+ requestedVerify.structuredContent.scan.findings[0].remediationState
.pendingAction,
"verify",
);
assert.equal(
- requestedVerify.result.structuredContent.scan.findings[0].remediationState
- .version,
+ requestedVerify.structuredContent.scan.findings[0].remediationState.version,
5,
);
- const verifyingPatch = await testServer.callTool(169, {
+ const verifyingPatch = await testServer.callSuccessfulTool(169, {
name: "set_codex_security_finding_remediation",
arguments: {
actionToken: verifyActionToken,
@@ -2862,19 +2689,17 @@ try {
state: "verifying",
},
});
- assertNoError(verifyingPatch);
assert.equal(
- verifyingPatch.result.structuredContent.scan.findings[0].remediationState
- .state,
+ verifyingPatch.structuredContent.scan.findings[0].remediationState.state,
"verifying",
);
assert.equal(
- verifyingPatch.result.structuredContent.scan.findings[0].remediationState
+ verifyingPatch.structuredContent.scan.findings[0].remediationState
.pendingAction,
"verify",
);
- const verifiedPatch = await testServer.callTool(170, {
+ const verifiedPatch = await testServer.callSuccessfulTool(170, {
name: "set_codex_security_finding_remediation",
arguments: {
actionToken: verifyActionToken,
@@ -2886,19 +2711,17 @@ try {
verificationSummary: "Focused remediation checks passed.",
},
});
- assertNoError(verifiedPatch);
assert.equal(
- verifiedPatch.result.structuredContent.scan.findings[0].remediationState
- .state,
+ verifiedPatch.structuredContent.scan.findings[0].remediationState.state,
"verified",
);
assert.equal(
- verifiedPatch.result.structuredContent.scan.findings[0].remediationState
+ verifiedPatch.structuredContent.scan.findings[0].remediationState
.pendingAction,
null,
);
assert.equal(
- verifiedPatch.result.structuredContent.scan.findings[0].remediationState
+ verifiedPatch.structuredContent.scan.findings[0].remediationState
.verificationSummary,
"Focused remediation checks passed.",
);
@@ -2914,12 +2737,10 @@ try {
actionToken: randomUUID(),
requestId: randomUUID(),
};
- assertNoError(
- await testServer.callTool(174, {
- name: "request_codex_security_finding_remediation",
- arguments: latin1Request,
- }),
- );
+ await testServer.callSuccessfulTool(174, {
+ name: "request_codex_security_finding_remediation",
+ arguments: latin1Request,
+ });
const latin1Generation = {
...latin1Request,
expectedVersion: 1,
@@ -2934,16 +2755,15 @@ try {
malformedPatch.result.content[0].text,
/unpaired Unicode surrogate.*base64/,
);
- const generatedLatin1 = await testServer.callTool(176, {
+ const generatedLatin1 = await testServer.callSuccessfulTool(176, {
name: "set_codex_security_finding_remediation",
arguments: {
...latin1Generation,
patch: { encoding: "base64", content: latin1Patch.toString("base64") },
},
});
- assertNoError(generatedLatin1);
const { patchDigest, patchPath } =
- generatedLatin1.result.structuredContent.scan.findings[1].remediationState;
+ generatedLatin1.structuredContent.scan.findings[1].remediationState;
const latin1PatchPath = path.join(initializedScanDir, patchPath);
assert.equal(patchDigest, `sha256:${hash("sha256", latin1Patch)}`);
assert.deepEqual(await readFile(latin1PatchPath), latin1Patch);
@@ -2952,21 +2772,14 @@ try {
});
assert.match(await readFile(latin1Source, "latin1"), /^résolu\r?\n$/);
- const findingsPage = await testServer.callTool(67, {
+ const findingsPage = await testServer.callSuccessfulTool(67, {
name: "list_codex_security_findings",
arguments: { scanId, offset: 0, limit: 1 },
});
- assertNoError(findingsPage);
- assert.equal(
- findingsPage.result.structuredContent.findingsPage.findings.length,
- 1,
- );
- assert.equal(
- findingsPage.result.structuredContent.findingsPage.nextOffset,
- 1,
- );
- assert.equal(findingsPage.result.structuredContent.findingsPage.total, 2);
- const filteredFindingsPage = await testServer.callTool(94001, {
+ assert.equal(findingsPage.structuredContent.findingsPage.findings.length, 1);
+ assert.equal(findingsPage.structuredContent.findingsPage.nextOffset, 1);
+ assert.equal(findingsPage.structuredContent.findingsPage.total, 2);
+ const filteredFindingsPage = await testServer.callSuccessfulTool(94001, {
name: "list_codex_security_findings",
arguments: {
scanId,
@@ -2976,49 +2789,41 @@ try {
limit: 1,
},
});
- assertNoError(filteredFindingsPage);
assert.deepEqual(
- filteredFindingsPage.result.structuredContent.findingsPage.findings.map(
+ filteredFindingsPage.structuredContent.findingsPage.findings.map(
(finding: { occurrenceId: string }) => finding.occurrenceId,
),
[occurrenceId],
);
- assert.equal(
- filteredFindingsPage.result.structuredContent.findingsPage.total,
- 1,
- );
+ assert.equal(filteredFindingsPage.structuredContent.findingsPage.total, 1);
- const csvExport = await testServer.callTool(63, {
+ const csvExport = await testServer.callSuccessfulTool(63, {
name: "export_codex_security_findings",
arguments: { scanId, format: "csv" },
});
- assertNoError(csvExport);
assert.equal(
- csvExport.result.structuredContent.export.path,
+ csvExport.structuredContent.export.path,
path.join(initializedScanDir, "exports", "findings.csv"),
);
assert.match(
- await readFile(csvExport.result.structuredContent.export.path, "utf8"),
+ await readFile(csvExport.structuredContent.export.path, "utf8"),
/occurrence_id,finding_id,title/,
);
- const sarifExport = await testServer.callTool(64, {
+ const sarifExport = await testServer.callSuccessfulTool(64, {
name: "export_codex_security_findings",
arguments: { scanId, format: "sarif" },
});
- assertNoError(sarifExport);
assert.equal(
- sarifExport.result.structuredContent.export.path,
+ sarifExport.structuredContent.export.path,
path.join(initializedScanDir, "exports", "results.sarif"),
);
- const restarted = await testServer.callTool(171, {
+ const restarted = await testServer.callSuccessfulTool(171, {
name: "start_codex_security_scan",
arguments: { sessionId: workspace.id },
});
- assertNoError(restarted);
- const canceledScanId =
- restarted.result.structuredContent.workspace.results.scanId;
+ const canceledScanId = restarted.structuredContent.workspace.results.scanId;
const unclaimedContext = await testServer.callTool(2010, {
name: "get_codex_security_scan_context",
arguments: { scanId: canceledScanId },
@@ -3034,23 +2839,21 @@ try {
/Claim the pending Codex Security scan handoff/,
);
const unattachedToken = randomUUID();
- const unattachedClaim = await testServer.callTool(20180, {
+ await testServer.callSuccessfulTool(20180, {
name: "claim_codex_security_scan_handoff_delivery",
arguments: { claimToken: unattachedToken, scanId: canceledScanId },
});
- assertNoError(unattachedClaim);
- const unattachedContext = await testServer.callTool(20181, {
+ const unattachedContext = await testServer.callSuccessfulTool(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,
+ unattachedContext.structuredContent.scan.handoffStatus,
"delivered",
);
assert.equal(
- unattachedContext.result.structuredContent.scan.continuationThreadId,
+ unattachedContext.structuredContent.scan.continuationThreadId,
null,
);
const unattachedRead = await testServer.callTool(20182, {
@@ -3083,26 +2886,24 @@ try {
rejectedMissingThreadCancel.result.content[0].text,
/continuation thread.*Codex Security workbench/,
);
- const canceledFromNativeRoute = await testServer.callTool(2210, {
+ const canceledFromNativeRoute = await testServer.callSuccessfulTool(2210, {
name: "cancel_codex_security_scan_from_app",
arguments: { scanId: canceledScanId },
});
- assertNoError(canceledFromNativeRoute);
- assertScanTarget(canceledFromNativeRoute.result._meta, canceledScanId);
+ assertScanTarget(canceledFromNativeRoute._meta, canceledScanId);
- const canceled = await testServer.callTool(172, {
+ const canceled = await testServer.callSuccessfulTool(172, {
name: "cancel_codex_security_scan",
arguments: { scanId: canceledScanId.toUpperCase() },
_meta: { "openai/threadId": "fixture-thread" },
});
- assertNoError(canceled);
- assertScanTarget(canceled.result._meta, canceledScanId);
+ assertScanTarget(canceled._meta, canceledScanId);
assert.equal(
- canceled.result.structuredContent.workspace.results.progress.status,
+ canceled.structuredContent.workspace.results.progress.status,
"canceled",
);
assert.equal(
- typeof canceled.result.structuredContent.workspace.results.canceledAt,
+ typeof canceled.structuredContent.workspace.results.canceledAt,
"string",
);
@@ -3116,25 +2917,23 @@ try {
/Only a running scan/,
);
- const fallbackStarted = await testServer.callTool(2011, {
+ const fallbackStarted = await testServer.callSuccessfulTool(2011, {
name: "start_codex_security_scan",
arguments: { sessionId: workspace.id },
});
- assertNoError(fallbackStarted);
const fallbackScanId =
- fallbackStarted.result.structuredContent.workspace.results.scanId;
- const oldCancellation = await testServer.callTool(2211, {
+ fallbackStarted.structuredContent.workspace.results.scanId;
+ const oldCancellation = await testServer.callSuccessfulTool(2211, {
name: "cancel_codex_security_scan_from_app",
arguments: { scanId: canceledScanId },
});
- assertNoError(oldCancellation);
assert.equal(
- oldCancellation.result.structuredContent.workspace.results.scanId,
+ oldCancellation.structuredContent.workspace.results.scanId,
fallbackScanId,
);
- assertScanTarget(oldCancellation.result._meta, canceledScanId);
+ assertScanTarget(oldCancellation._meta, canceledScanId);
const fallbackClaimToken = `recovery_${randomUUID()}`;
- const fallbackClaimed = await testServer.callTool(2012, {
+ const fallbackClaimed = await testServer.callSuccessfulTool(2012, {
name: "claim_codex_security_scan_handoff_delivery",
arguments: {
claimToken: fallbackClaimToken,
@@ -3142,13 +2941,11 @@ try {
takeOverStale: true,
},
});
- assertNoError(fallbackClaimed);
assert.equal(
- fallbackClaimed.result.structuredContent.workspace.results
- .handoffClaimToken,
+ fallbackClaimed.structuredContent.workspace.results.handoffClaimToken,
fallbackClaimToken,
);
- const fallbackAttached = await testServer.callTool(2017, {
+ const fallbackAttached = await testServer.callSuccessfulTool(2017, {
name: "attach_codex_security_scan_continuation_thread",
arguments: {
claimToken: fallbackClaimToken,
@@ -3156,10 +2953,8 @@ try {
threadId: "fixture-recovery-thread",
},
});
- assertNoError(fallbackAttached);
assert.equal(
- fallbackAttached.result.structuredContent.workspace.results
- .continuationThreadId,
+ fallbackAttached.structuredContent.workspace.results.continuationThreadId,
"fixture-recovery-thread",
);
const malformedRecovery = await testServer.callTool(20170, {
@@ -3185,25 +2980,23 @@ try {
wrongRecoveryContext.result.content[0].text,
/handoff delivery could not be recorded|owned by another continuation/i,
);
- const fallbackContext = await testServer.callTool(2013, {
+ const fallbackContext = await testServer.callSuccessfulTool(2013, {
name: "get_codex_security_scan_context",
arguments: {
handoffClaimToken: fallbackClaimToken,
scanId: fallbackScanId,
},
});
- assertNoError(fallbackContext);
assert.equal(
- fallbackContext.result.structuredContent.scan.handoffStatus,
+ fallbackContext.structuredContent.scan.handoffStatus,
"delivered",
);
assert.equal(
- fallbackContext.result.structuredContent.scan.handoffClaimToken,
+ fallbackContext.structuredContent.scan.handoffClaimToken,
undefined,
);
assert.equal(
- fallbackContext.result.structuredContent.workspace.results
- .handoffClaimToken,
+ fallbackContext.structuredContent.workspace.results.handoffClaimToken,
undefined,
);
const recoveryArtifactRead = (id: number) =>
@@ -3218,7 +3011,7 @@ try {
beforeRecovery.result.content[0].text,
/current continuation claim/,
);
- const recoveredThreadContext = await testServer.callTool(20172, {
+ const recoveredThreadContext = await testServer.callSuccessfulTool(20172, {
name: "get_codex_security_scan_context",
arguments: {
handoffClaimToken: fallbackClaimToken,
@@ -3226,21 +3019,20 @@ try {
},
_meta: { "openai/threadId": "fixture-replacement-recovery-thread" },
});
- assertNoError(recoveredThreadContext);
assert.equal(
- recoveredThreadContext.result.structuredContent.scan.handoffStatus,
+ recoveredThreadContext.structuredContent.scan.handoffStatus,
"delivered",
);
assert.equal(
- recoveredThreadContext.result.structuredContent.scan.continuationThreadId,
+ recoveredThreadContext.structuredContent.scan.continuationThreadId,
"fixture-recovery-thread",
);
assert.equal(
- recoveredThreadContext.result.structuredContent.scan.handoffClaimToken,
+ recoveredThreadContext.structuredContent.scan.handoffClaimToken,
undefined,
);
assert.equal(
- recoveredThreadContext.result.structuredContent.workspace.results
+ recoveredThreadContext.structuredContent.workspace.results
.handoffClaimToken,
undefined,
);
@@ -3250,13 +3042,12 @@ try {
afterRecovery.result.content[0].text,
/only available for Deep or diff scans/,
);
- const fallbackAppAcknowledgement = await testServer.callTool(2014, {
+ const fallbackAppAcknowledgement = await testServer.callSuccessfulTool(2014, {
name: "mark_codex_security_scan_handoff_delivered",
arguments: { claimToken: fallbackClaimToken, scanId: fallbackScanId },
});
- assertNoError(fallbackAppAcknowledgement);
assert.equal(
- fallbackAppAcknowledgement.result.structuredContent.workspace.results
+ fallbackAppAcknowledgement.structuredContent.workspace.results
.handoffStatus,
"delivered",
);
@@ -3284,43 +3075,40 @@ with sqlite3.connect(sys.argv[1]) as connection:
staleRecoveryContext.result.content[0].text,
/handoff delivery could not be recorded|owned by another continuation/i,
);
- const scanList = await testServer.callTool(2212, {
+ const scanList = await testServer.callSuccessfulTool(2212, {
name: "list_codex_security_scans",
arguments: {},
});
- assertNoError(scanList);
- const listedFallback = scanList.result.structuredContent.scans.find(
+ const listedFallback = scanList.structuredContent.scans.find(
(scan: { targetId: string; scanId: string }) =>
scan.scanId === fallbackScanId,
);
assert.equal(listedFallback.progress.status, "running");
assert.equal("artifacts" in listedFallback, false);
assert.equal("findings" in listedFallback, false);
- const globalFindings = await testServer.callTool(2213, {
+ const globalFindings = await testServer.callSuccessfulTool(2213, {
name: "list_codex_security_global_findings",
arguments: { limit: 1 },
});
- assertNoError(globalFindings);
- const indexedFinding = globalFindings.result.structuredContent.findings.find(
+ const indexedFinding = globalFindings.structuredContent.findings.find(
(finding: { occurrenceId: string }) =>
finding.occurrenceId === occurrenceId,
);
- assert.equal(globalFindings.result.structuredContent.limit, 1);
- assert.equal(globalFindings.result.structuredContent.nextOffset, 1);
+ assert.equal(globalFindings.structuredContent.limit, 1);
+ assert.equal(globalFindings.structuredContent.nextOffset, 1);
assert.equal(indexedFinding.scanId, scanId);
assert.equal(indexedFinding.status, "open");
assert.equal(indexedFinding.occurrenceCount, 1);
assert.match(indexedFinding.targetId, /^target_sha256_[0-9a-f]{64}$/);
- const globalFindingsNext = await testServer.callTool(2215, {
+ const globalFindingsNext = await testServer.callSuccessfulTool(2215, {
name: "list_codex_security_global_findings",
arguments: { limit: 20, offset: 1 },
});
- assertNoError(globalFindingsNext);
- assert.equal(globalFindingsNext.result.structuredContent.findings.length, 1);
- assert.equal(globalFindingsNext.result.structuredContent.limit, 20);
- assert.equal(globalFindingsNext.result.structuredContent.offset, 1);
- assert.equal(globalFindingsNext.result.structuredContent.nextOffset, null);
- const filteredGlobalFindings = await testServer.callTool(94002, {
+ assert.equal(globalFindingsNext.structuredContent.findings.length, 1);
+ assert.equal(globalFindingsNext.structuredContent.limit, 20);
+ assert.equal(globalFindingsNext.structuredContent.offset, 1);
+ assert.equal(globalFindingsNext.structuredContent.nextOffset, null);
+ const filteredGlobalFindings = await testServer.callSuccessfulTool(94002, {
name: "list_codex_security_global_findings",
arguments: {
limit: 1,
@@ -3330,38 +3118,32 @@ with sqlite3.connect(sys.argv[1]) as connection:
targetId: indexedFinding.targetId,
},
});
- assertNoError(filteredGlobalFindings);
assert.deepEqual(
- filteredGlobalFindings.result.structuredContent.findings.map(
+ filteredGlobalFindings.structuredContent.findings.map(
(finding: { occurrenceId: string }) => finding.occurrenceId,
),
[occurrenceId],
);
- assert.equal(
- filteredGlobalFindings.result.structuredContent.nextOffset,
- null,
- );
- const repositories = await testServer.callTool(2214, {
+ assert.equal(filteredGlobalFindings.structuredContent.nextOffset, null);
+ const repositories = await testServer.callSuccessfulTool(2214, {
name: "list_codex_security_repositories",
arguments: {},
});
- assertNoError(repositories);
- const indexedRepository =
- repositories.result.structuredContent.repositories.find(
- (repository: { targetId: string }) =>
- repository.targetId === indexedFinding.targetId,
- );
+ const indexedRepository = repositories.structuredContent.repositories.find(
+ (repository: { targetId: string }) =>
+ repository.targetId === indexedFinding.targetId,
+ );
assert.equal(indexedRepository.checkoutAvailable, true);
assert.equal(indexedRepository.latestScan.scanId, fallbackScanId);
assert.equal(indexedRepository.openFindingsCount, 2);
assert.equal(
indexedRepository.scanCount,
- scanList.result.structuredContent.scans.filter(
+ scanList.structuredContent.scans.filter(
(scan: { targetId: string; scanId: string }) =>
scan.targetId === indexedFinding.targetId,
).length,
);
- const filteredScans = await testServer.callTool(94003, {
+ const filteredScans = await testServer.callSuccessfulTool(94003, {
name: "list_codex_security_scans",
arguments: {
limit: 1,
@@ -3371,13 +3153,9 @@ with sqlite3.connect(sys.argv[1]) as connection:
targetId: indexedFinding.targetId,
},
});
- assertNoError(filteredScans);
- assert.equal(
- filteredScans.result.structuredContent.scans[0].scanId,
- fallbackScanId,
- );
- assert.equal(filteredScans.result.structuredContent.limit, 1);
- const filteredRepositories = await testServer.callTool(94004, {
+ assert.equal(filteredScans.structuredContent.scans[0].scanId, fallbackScanId);
+ assert.equal(filteredScans.structuredContent.limit, 1);
+ const filteredRepositories = await testServer.callSuccessfulTool(94004, {
name: "list_codex_security_repositories",
arguments: {
limit: 1,
@@ -3386,14 +3164,13 @@ with sqlite3.connect(sys.argv[1]) as connection:
targetId: indexedFinding.targetId,
},
});
- assertNoError(filteredRepositories);
assert.deepEqual(
- filteredRepositories.result.structuredContent.repositories.map(
+ filteredRepositories.structuredContent.repositories.map(
(repository: { targetId: string }) => repository.targetId,
),
[indexedFinding.targetId],
);
- const rotatedAttached = await testServer.callTool(2030, {
+ await testServer.callSuccessfulTool(2030, {
name: "attach_codex_security_scan_continuation_thread",
arguments: {
claimToken: rotatedFallbackClaimToken,
@@ -3401,14 +3178,12 @@ with sqlite3.connect(sys.argv[1]) as connection:
threadId: "fixture-rotated-recovery-thread",
},
});
- assertNoError(rotatedAttached);
- const observedRotatedScan = await testServer.callTool(2031, {
+ const observedRotatedScan = await testServer.callSuccessfulTool(2031, {
name: "get_codex_security_scan",
arguments: { scanId: fallbackScanId },
});
- assertNoError(observedRotatedScan);
assert.equal(
- observedRotatedScan.result.structuredContent.scan.continuationThreadId,
+ observedRotatedScan.structuredContent.scan.continuationThreadId,
"fixture-rotated-recovery-thread",
);
let rejectedRequestId = 2032;
@@ -3441,7 +3216,7 @@ with sqlite3.connect(sys.argv[1]) as connection:
);
}
}
- const rotatedProgress = await testServer.callTool(2038, {
+ await testServer.callSuccessfulTool(2038, {
name: "update_codex_security_scan_progress",
arguments: {
handoffClaimToken: rotatedFallbackClaimToken,
@@ -3449,9 +3224,8 @@ with sqlite3.connect(sys.argv[1]) as connection:
scanId: fallbackScanId,
},
});
- assertNoError(rotatedProgress);
const failureMessage = `--failure\n${"diagnostic ".repeat(500)}final cause`;
- const rotatedFailure = await testServer.callTool(2039, {
+ const rotatedFailure = await testServer.callSuccessfulTool(2039, {
name: "fail_codex_security_scan",
arguments: {
handoffClaimToken: rotatedFallbackClaimToken,
@@ -3459,16 +3233,12 @@ with sqlite3.connect(sys.argv[1]) as connection:
scanId: fallbackScanId,
},
});
- assertNoError(rotatedFailure);
- assertScanTarget(rotatedFailure.result._meta, fallbackScanId);
+ assertScanTarget(rotatedFailure._meta, fallbackScanId);
assert.equal(
- rotatedFailure.result.structuredContent.scan.failureMessage,
+ rotatedFailure.structuredContent.scan.failureMessage,
failureMessage,
);
- assert.equal(
- rotatedFailure.result.structuredContent.scan.progress.status,
- "failed",
- );
+ assert.equal(rotatedFailure.structuredContent.scan.progress.status, "failed");
const unavailableRecovery = await testServer.callTool(2040, {
name: "recover_codex_security_scan_results",
arguments: { scanId: fallbackScanId },
@@ -3479,22 +3249,20 @@ with sqlite3.connect(sys.argv[1]) as connection:
/No saved stopped-scan results were available to recover/,
);
- const silentRefresh = await testServer.callTool(11, {
+ await testServer.callSuccessfulTool(11, {
name: "open_codex_security_workspace",
arguments: { sessionId: workspace.id },
_meta: { "openai/threadId": "fixture-thread" },
});
- assertNoError(silentRefresh);
- const replacementWorkspaceResponse = await testServer.callTool(42, {
+ const replacementWorkspaceResponse = await testServer.callSuccessfulTool(42, {
name: "open_codex_security_workspace",
arguments: { targetPath: target, targetTitle: "Old target title" },
_meta: { "openai/threadId": "fixture-aux-thread" },
});
- assertNoError(replacementWorkspaceResponse);
const replacementWorkspace =
- replacementWorkspaceResponse.result.structuredContent.workspace;
- const replacementSaved = await testServer.callTool(43, {
+ replacementWorkspaceResponse.structuredContent.workspace;
+ const replacementSaved = await testServer.callSuccessfulTool(43, {
name: "submit_codex_security_setup",
arguments: {
sessionId: replacementWorkspace.id,
@@ -3503,13 +3271,12 @@ with sqlite3.connect(sys.argv[1]) as connection:
mode: "standard",
},
});
- assertNoError(replacementSaved);
assert.equal(
- replacementSaved.result.structuredContent.workspace.targetTitle,
+ replacementSaved.structuredContent.workspace.targetTitle,
path.basename(replacementTarget),
);
- const nativeSetupOpen = await testServer.callTool(9226, {
+ const nativeSetupOpen = await testServer.callSuccessfulTool(9226, {
name: "open_codex_security_workspace",
arguments: {
targetPath: target,
@@ -3518,29 +3285,23 @@ with sqlite3.connect(sys.argv[1]) as connection:
},
_meta: { "openai/threadId": "fixture-native-setup-thread" },
});
- assertNoError(nativeSetupOpen);
assert.match(
- nativeSetupOpen.result.structuredContent.workspace.id,
+ nativeSetupOpen.structuredContent.workspace.id,
/^[0-9a-f-]{36}$/,
);
- assert.equal(
- nativeSetupOpen.result.structuredContent.workspace.results,
- undefined,
- );
+ assert.equal(nativeSetupOpen.structuredContent.workspace.results, undefined);
- const invalidScanStarted = await testServer.callTool(9401, {
+ const invalidScanStarted = await testServer.callSuccessfulTool(9401, {
name: "start_codex_security_scan",
arguments: { sessionId: workspace.id },
});
- assertNoError(invalidScanStarted);
const invalidScanId =
- invalidScanStarted.result.structuredContent.workspace.results.scanId;
+ invalidScanStarted.structuredContent.workspace.results.scanId;
const invalidScanClaimToken = randomUUID();
- const invalidScanClaimed = await testServer.callTool(9402, {
+ await testServer.callSuccessfulTool(9402, {
name: "claim_codex_security_scan_handoff_delivery",
arguments: { claimToken: invalidScanClaimToken, scanId: invalidScanId },
});
- assertNoError(invalidScanClaimed);
const prematureCompletion = await testServer.callTool(9403, {
name: "complete_codex_security_scan",
arguments: {
@@ -3553,15 +3314,11 @@ with sqlite3.connect(sys.argv[1]) as connection:
prematureCompletion.result.content[0].text,
/scan-manifest\.json/,
);
- const resumableScan = await testServer.callTool(9404, {
+ const resumableScan = await testServer.callSuccessfulTool(9404, {
name: "get_codex_security_scan",
arguments: { scanId: invalidScanId },
});
- assertNoError(resumableScan);
- assert.equal(
- resumableScan.result.structuredContent.scan.progress.status,
- "running",
- );
+ assert.equal(resumableScan.structuredContent.scan.progress.status, "running");
assert.equal(
(await readFile(path.join(stateDir, "workbench.sqlite3"))).length > 0,
diff --git a/plugins/codex-security/mcp-app/tests/test_node_launcher.ts b/plugins/codex-security/mcp-app/tests/test_node_launcher.ts
index 5f395ce76..51fe18eaf 100644
--- a/plugins/codex-security/mcp-app/tests/test_node_launcher.ts
+++ b/plugins/codex-security/mcp-app/tests/test_node_launcher.ts
@@ -13,6 +13,7 @@ import { after, test } from "node:test";
import { nativeTarget } from "../../native/platform.mts";
import { createTemporaryDirectories } from "./support/temporary-directories.ts";
+const launcherTest = process.platform === "win32" ? test.skip : test;
const directories = createTemporaryDirectories(true);
after(() => directories.cleanup());
const sourcePluginRoot = path.resolve(import.meta.dirname, "../..");
@@ -24,6 +25,13 @@ function shellQuote(value: string): string {
return "'" + value.replaceAll("'", "'\\''") + "'";
}
+async function readLog(path: string) {
+ return (await readFile(path, "utf8"))
+ .trim()
+ .split("\n")
+ .map((line) => JSON.parse(line));
+}
+
async function fixture(
rejectManaged: boolean,
rejectOrdinary = false,
@@ -174,24 +182,17 @@ process.dlopen = function(module, filename, ...args) {
input,
});
},
- async loads() {
- return (await readFile(log, "utf8"))
- .trim()
- .split("\n")
- .map((line) => JSON.parse(line));
- },
- async launches() {
- return (await readFile(launchLog, "utf8"))
- .trim()
- .split("\n")
- .map((line) => JSON.parse(line));
+ loads: () => readLog(log),
+ async helperRuntimes() {
+ return (await readLog(launchLog))
+ .filter((entry) => entry.argv.includes("--helper"))
+ .map((entry) => entry.runtime);
},
};
}
-test(
+launcherTest(
"macOS helpers skip managed runtimes that reject the packaged addon",
- { skip: process.platform === "win32" },
async () => {
for (const command of ["synthetic-native-helper", "resolve-security-md"]) {
const setup = await fixture(
@@ -230,9 +231,8 @@ test(
},
);
-test(
+launcherTest(
"macOS helpers try later PATH runtimes after an incompatible first runtime",
- { skip: process.platform === "win32" },
async () => {
const setup = await fixture(true, true, true);
await setup.addPathRuntime();
@@ -243,18 +243,12 @@ test(
(await setup.loads()).slice(0, 3).map((entry) => entry.runtime),
["managed", "ordinary", "later"],
);
- assert.deepEqual(
- (await setup.launches())
- .filter((entry) => entry.argv.includes("--helper"))
- .map((entry) => entry.runtime),
- ["later"],
- );
+ assert.deepEqual(await setup.helperRuntimes(), ["later"]);
},
);
-test(
+launcherTest(
"compatible managed runtimes retain priority over PATH",
- { skip: process.platform === "win32" },
async () => {
const setup = await fixture(false);
const result = setup.run([
@@ -270,26 +264,21 @@ test(
},
);
-test(
- "explicit runtime selection remains authoritative",
- { skip: process.platform === "win32" },
- async () => {
- const setup = await fixture(true, false, true);
- const result = setup.run(["synthetic-native-helper"], setup.managed);
- assert.notEqual(result.status, 0);
- assert.match(result.stdout, /different Team IDs/);
- const loads = await setup.loads();
- assert.ok(loads.every((entry) => entry.runtime === "managed"));
- assert.ok(
- loads[0].argv.includes("--helper"),
- "Explicit runtimes launch directly.",
- );
- },
-);
+launcherTest("explicit runtime selection remains authoritative", async () => {
+ const setup = await fixture(true, false, true);
+ const result = setup.run(["synthetic-native-helper"], setup.managed);
+ assert.notEqual(result.status, 0);
+ assert.match(result.stdout, /different Team IDs/);
+ const loads = await setup.loads();
+ assert.ok(loads.every((entry) => entry.runtime === "managed"));
+ assert.ok(
+ loads[0].argv.includes("--helper"),
+ "Explicit runtimes launch directly.",
+ );
+});
-test(
+launcherTest(
"helper failures are reported without trying another runtime",
- { skip: process.platform === "win32" },
async () => {
const setup = await fixture(false);
const result = setup.run([
@@ -306,9 +295,8 @@ test(
},
);
-test(
+launcherTest(
"helpers without native dependencies still run when all runtimes reject the addon",
- { skip: process.platform === "win32" },
async () => {
for (const command of [
"validate-patch-risk-assessment",
@@ -329,11 +317,8 @@ test(
(await setup.loads()).map((entry) => entry.runtime),
["managed", "ordinary"],
);
- const helpers = (await setup.launches()).filter((entry) =>
- entry.argv.includes("--helper"),
- );
assert.deepEqual(
- helpers.map((entry) => entry.runtime),
+ await setup.helperRuntimes(),
["managed"],
"The original default must launch the command exactly once.",
);
@@ -341,9 +326,8 @@ test(
},
);
-test(
+launcherTest(
"native commands retain their error when no compatible runtime exists",
- { skip: process.platform === "win32" },
async () => {
const setup = await fixture(true, true, true);
const result = setup.run(["synthetic-native-helper"]);
@@ -356,20 +340,16 @@ test(
(await setup.loads()).map((entry) => entry.runtime),
["managed", "ordinary", "managed"],
);
- const helpers = (await setup.launches()).filter((entry) =>
- entry.argv.includes("--helper"),
- );
assert.deepEqual(
- helpers.map((entry) => entry.runtime),
+ await setup.helperRuntimes(),
["managed"],
"A failing command must not retry in another runtime.",
);
},
);
-test(
+launcherTest(
"database helpers retain the managed runtime when PATH Node lacks SQLite",
- { skip: process.platform === "win32" },
async () => {
const setup = await fixture(true, false, false, false);
const result = setup.run(
@@ -378,11 +358,6 @@ test(
JSON.stringify(setup.root),
);
assert.equal(result.status, 0, result.stderr);
- assert.deepEqual(
- (await setup.launches())
- .filter((entry) => entry.argv.includes("--helper"))
- .map((entry) => entry.runtime),
- ["managed"],
- );
+ assert.deepEqual(await setup.helperRuntimes(), ["managed"]);
},
);
diff --git a/plugins/codex-security/mcp-app/tests/test_plugin_bytecode.ts b/plugins/codex-security/mcp-app/tests/test_plugin_bytecode.ts
index 67bfeb06e..92d6bf13e 100644
--- a/plugins/codex-security/mcp-app/tests/test_plugin_bytecode.ts
+++ b/plugins/codex-security/mcp-app/tests/test_plugin_bytecode.ts
@@ -3,7 +3,6 @@ import { createHash } from "node:crypto";
import { cp, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
import { basename, join, relative, resolve } from "node:path";
import test from "node:test";
-import { assertNoError } from "./assertions.ts";
import { startRpcServer } from "./support/rpc-server.ts";
import { temporaryDirectory } from "./support/temporary-directories.ts";
@@ -59,19 +58,15 @@ test("repeated MCP launches leave the installed plugin unchanged", async (t) =>
},
});
try {
- assertNoError(await server.initialize("plugin-bytecode-test"));
- assertNoError(
- await server.callTool(2, {
- name: "inspect_codex_security_target",
- arguments: { targetPath: target },
- }),
- );
- assertNoError(
- await server.callTool(3, {
- name: "list_codex_security_scans",
- arguments: {},
- }),
- );
+ await server.initialize("plugin-bytecode-test");
+ await server.callSuccessfulTool(2, {
+ name: "inspect_codex_security_target",
+ arguments: { targetPath: target },
+ });
+ await server.callSuccessfulTool(3, {
+ name: "list_codex_security_scans",
+ arguments: {},
+ });
} finally {
await server.stop();
}
diff --git a/plugins/codex-security/mcp-app/tests/test_threat_model_installed.ts b/plugins/codex-security/mcp-app/tests/test_threat_model_installed.ts
index a11a7c7e8..935f17bc8 100644
--- a/plugins/codex-security/mcp-app/tests/test_threat_model_installed.ts
+++ b/plugins/codex-security/mcp-app/tests/test_threat_model_installed.ts
@@ -2,7 +2,6 @@ import assert from "node:assert/strict";
import { cp, mkdir, readFile, rm } from "node:fs/promises";
import { join, resolve } from "node:path";
import { test } from "node:test";
-import { assertNoError } from "./assertions.ts";
import { startRpcServer } from "./support/rpc-server.ts";
import { temporaryDirectory } from "./support/temporary-directories.ts";
@@ -42,7 +41,7 @@ test("installed worker MCP saves threat models without Python", async (t) => {
},
});
try {
- assertNoError(await server.initialize("threatmodel-installed"));
+ await server.initialize("threatmodel-installed");
const content = "# Saved model\r\n\r\n Preserve spacing.\r\n";
const threatModel = {
summary: "Legacy structured model.",
@@ -57,24 +56,21 @@ test("installed worker MCP saves threat models without Python", async (t) => {
findings: [],
reviewState: { surfaces: [], explicitExclusions: [], deferred: [] },
};
- const result = await server.callTool(2, {
+ const result = await server.callSuccessfulTool(2, {
name: "record_codex_security_scan_draft",
arguments: { ...draft, threatModel },
});
- assertNoError(result);
- assert.equal(result.result.structuredContent.warnings, undefined);
+ assert.equal(result.structuredContent.warnings, undefined);
const documentPath = join(artifactRoot, "threatmodel.md");
const document = await readFile(documentPath, "utf8");
assert.ok(document.startsWith(content));
assert.match(document, /Model origin: not recorded\n/);
assert.match(document, /Model scope: src\/\\\[api\\\]\n/);
assert.match(document, /provisional/);
- assertNoError(
- await server.callTool(3, {
- name: "record_codex_security_scan_draft",
- arguments: draft,
- }),
- );
+ await server.callSuccessfulTool(3, {
+ name: "record_codex_security_scan_draft",
+ arguments: draft,
+ });
assert.equal(await readFile(documentPath, "utf8"), document);
assert.deepEqual(
JSON.parse(await readFile(join(artifactRoot, "result.json"), "utf8"))
diff --git a/plugins/codex-security/mcp-app/tests/test_workbench_database.ts b/plugins/codex-security/mcp-app/tests/test_workbench_database.ts
index 05e6ffde3..ac108f1a4 100644
--- a/plugins/codex-security/mcp-app/tests/test_workbench_database.ts
+++ b/plugins/codex-security/mcp-app/tests/test_workbench_database.ts
@@ -49,6 +49,16 @@ function schema(database: DatabaseSync) {
.all();
}
+function storedValue(database: DatabaseSync, table: string, column: string) {
+ return database.prepare(`SELECT ${column} FROM ${table}`).get()?.[column];
+}
+
+function migrationHistory(database: DatabaseSync) {
+ return database
+ .prepare("SELECT * FROM schema_migrations ORDER BY version")
+ .all();
+}
+
function assertMigrationNames(database: DatabaseSync, ...versions: number[]) {
for (const version of versions)
assert.equal(
@@ -154,16 +164,9 @@ test("every released schema upgrades to the same current schema and remains idem
expected,
`upgrade from version ${version}`,
);
- const history = database
- .prepare("SELECT * FROM schema_migrations ORDER BY version")
- .all();
+ const history = migrationHistory(database);
applyMigrations(database);
- assert.deepEqual(
- database
- .prepare("SELECT * FROM schema_migrations ORDER BY version")
- .all(),
- history,
- );
+ assert.deepEqual(migrationHistory(database), history);
assert.deepEqual(database.prepare("PRAGMA foreign_key_check").all(), []);
}
});
@@ -215,28 +218,17 @@ for (const { missingVersions, legacyCheckpoint, mainReader } of [
const context = JSON.stringify("Original discovery context");
let originalDiscoveryMigration: Record<string, unknown> | undefined;
let originalCheckpointMigration: Record<string, unknown> | undefined;
+ // The preview with checkpoint migration 53 also lacked migration 52.
+ const firstMissing = legacyCheckpoint === 53 ? 52 : legacyCheckpoint;
const old = new DatabaseSync(databasePath);
try {
applyMigrations(
old,
migrations
.filter(
- (item) =>
- !missingVersions.includes(item.version) &&
- !(legacyCheckpoint && [54, 55, 56].includes(item.version)) &&
- !(
- [47, 48, 50, 52, 53].includes(legacyCheckpoint) &&
- [52, 53].includes(item.version)
- ) &&
- !(
- [47, 48, 50].includes(legacyCheckpoint) &&
- [50, 51].includes(item.version)
- ) &&
- !(
- [47, 48].includes(legacyCheckpoint) &&
- [48, 49].includes(item.version)
- ) &&
- !(legacyCheckpoint === 47 && item.version === 47),
+ ({ version }) =>
+ !missingVersions.includes(version) &&
+ !(firstMissing && version >= firstMissing && version <= 56),
)
.map((item) =>
legacyCheckpoint && item.version === 57
@@ -282,9 +274,7 @@ for (const { missingVersions, legacyCheckpoint, mainReader } of [
const upgraded = new DatabaseSync(databasePath);
try {
assert.equal(
- upgraded
- .prepare("SELECT retained_checkpoint_heads_json FROM scans")
- .get()?.retained_checkpoint_heads_json,
+ storedValue(upgraded, "scans", "retained_checkpoint_heads_json"),
!missingVersions.includes(57) ? heads : null,
);
upgraded
@@ -336,15 +326,15 @@ for (const { missingVersions, legacyCheckpoint, mainReader } of [
}
assert.deepEqual(reopened.prepare("PRAGMA foreign_key_check").all(), []);
assert.equal(
- reopened
- .prepare("SELECT discovery_user_context_json FROM deep_scan_runs")
- .get()?.discovery_user_context_json,
+ storedValue(reopened, "deep_scan_runs", "discovery_user_context_json"),
legacyCheckpoint !== 47 || mainReader ? context : null,
);
assert.equal(
- reopened
- .prepare("SELECT terminal_reviewed_surface_count FROM deep_scan_runs")
- .get()?.terminal_reviewed_surface_count,
+ storedValue(
+ reopened,
+ "deep_scan_runs",
+ "terminal_reviewed_surface_count",
+ ),
null,
);
assertMigrationNames(
@@ -496,10 +486,7 @@ test(
);
const database = new DatabaseSync(join(alias, "workbench.sqlite3"));
try {
- assert.equal(
- database.prepare("SELECT value FROM retained").get()?.value,
- "original",
- );
+ assert.equal(storedValue(database, "retained", "value"), "original");
assertMigrationNames(
database,
...migrations.map(({ version }) => version),
@@ -574,16 +561,9 @@ for (const previewVersion of [34, 40, 41, 42, 43, 44, 48]) {
null,
);
assert.deepEqual(upgraded.prepare("PRAGMA foreign_key_check").all(), []);
- const history = upgraded
- .prepare("SELECT * FROM schema_migrations ORDER BY version")
- .all();
+ const history = migrationHistory(upgraded);
await databaseInfo(directory);
- assert.deepEqual(
- upgraded
- .prepare("SELECT * FROM schema_migrations ORDER BY version")
- .all(),
- history,
- );
+ assert.deepEqual(migrationHistory(upgraded), history);
} finally {
upgraded.close();
}
@@ -608,15 +588,8 @@ test("database-info retains scan names from installed migration 42", async () =>
const upgraded = new DatabaseSync(databasePath);
try {
assertMigrationNames(upgraded, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51);
- assert.equal(
- upgraded.prepare("SELECT name FROM scans").get()?.name,
- "Original scan",
- );
- assert.equal(
- upgraded.prepare("SELECT source_scopes_json FROM scans").get()
- ?.source_scopes_json,
- null,
- );
+ assert.equal(storedValue(upgraded, "scans", "name"), "Original scan");
+ assert.equal(storedValue(upgraded, "scans", "source_scopes_json"), null);
assert.equal(
upgraded
.prepare("SELECT applied_at FROM schema_migrations WHERE version = 42")
@@ -634,9 +607,7 @@ test("database-info repairs recorded scan-name and source-scope columns", async
const old = new DatabaseSync(databasePath);
applyMigrations(old);
insertScan(old);
- const history = old
- .prepare("SELECT * FROM schema_migrations ORDER BY version")
- .all();
+ const history = migrationHistory(old);
old.exec(
"ALTER TABLE scans DROP COLUMN name; ALTER TABLE scans DROP COLUMN source_scopes_json",
);
@@ -654,12 +625,7 @@ test("database-info repairs recorded scan-name and source-scope columns", async
},
{ name: null, source_scopes_json: null, target_revision: "revision" },
);
- assert.deepEqual(
- repaired
- .prepare("SELECT * FROM schema_migrations ORDER BY version")
- .all(),
- history,
- );
+ assert.deepEqual(migrationHistory(repaired), history);
} finally {
repaired.close();
}
@@ -676,9 +642,7 @@ for (const version of [43, 50]) {
"UPDATE schema_migrations SET name = 'unknown source history' WHERE version = ?",
)
.run(version);
- const history = old
- .prepare("SELECT * FROM schema_migrations ORDER BY version")
- .all();
+ const history = migrationHistory(old);
const originalSchema = schema(old);
old.close();
await assert.rejects(
@@ -688,12 +652,7 @@ for (const version of [43, 50]) {
const unchanged = new DatabaseSync(databasePath);
try {
assert.deepEqual(schema(unchanged), originalSchema);
- assert.deepEqual(
- unchanged
- .prepare("SELECT * FROM schema_migrations ORDER BY version")
- .all(),
- history,
- );
+ assert.deepEqual(migrationHistory(unchanged), history);
} finally {
unchanged.close();
}
@@ -814,18 +773,13 @@ test("rejects unsupported history without partially changing its schema or rows"
"UPDATE schema_migrations SET name = 'scan execution profiles' WHERE version = 11",
);
const before = schema(database);
- const history = database
- .prepare("SELECT * FROM schema_migrations ORDER BY version")
- .all();
+ const history = migrationHistory(database);
assert.throws(
() => applyMigrations(database),
/unsupported execution-profile migration history/u,
);
assert.deepEqual(schema(database), before);
- assert.deepEqual(
- database.prepare("SELECT * FROM schema_migrations ORDER BY version").all(),
- history,
- );
+ assert.deepEqual(migrationHistory(database), history);
});
test("repairs pre-release numbering and shadowed migrations without repeating data cleanup", (t) => {
@@ -858,11 +812,7 @@ test("repairs pre-release numbering and shadowed migrations without repeating da
ALTER TABLE scan_progress DROP COLUMN preflight_issues_json;
ALTER TABLE scans DROP COLUMN recipe_json;`);
applyMigrations(database);
- assert.equal(
- database.prepare("SELECT handoff_claim_token FROM scans").get()
- ?.handoff_claim_token,
- null,
- );
+ assert.equal(storedValue(database, "scans", "handoff_claim_token"), null);
assert.equal(
database.prepare("SELECT COUNT(*) AS count FROM setup_preferences").get()
?.count,
@@ -872,8 +822,7 @@ test("repairs pre-release numbering and shadowed migrations without repeating da
database.exec("UPDATE scans SET handoff_claim_token = 'current'");
applyMigrations(database);
assert.equal(
- database.prepare("SELECT handoff_claim_token FROM scans").get()
- ?.handoff_claim_token,
+ storedValue(database, "scans", "handoff_claim_token"),
"current",
);
});
@@ -893,8 +842,7 @@ test("relocates released warning and progress histories while retaining their da
UPDATE schema_migrations SET version = 25 WHERE version = 26;`);
applyMigrations(database);
assert.equal(
- database.prepare("SELECT completion_warnings_json FROM scans").get()
- ?.completion_warnings_json,
+ storedValue(database, "scans", "completion_warnings_json"),
'["retained warning"]',
);
assertMigrationNames(database, 12, 13, 20, 21, 25, 26);
@@ -919,10 +867,7 @@ test("repairs recorded Deep Scan and target migrations and backfills stable iden
createHash("sha256")
.update("local-workspace\0/synthetic/repository")
.digest("hex");
- assert.equal(
- database.prepare("SELECT target_id FROM workspaces").get()?.target_id,
- targetId,
- );
+ assert.equal(storedValue(database, "workspaces", "target_id"), targetId);
const scan = database
.prepare("SELECT target_id, deep_scan_owner_thread_id FROM scans")
.get()!;
@@ -933,10 +878,7 @@ test("repairs recorded Deep Scan and target migrations and backfills stable iden
"UPDATE workspaces SET target_id = NULL; UPDATE scans SET target_id = NULL",
);
applyMigrations(database);
- assert.equal(
- database.prepare("SELECT target_id FROM scans").get()?.target_id,
- null,
- );
+ assert.equal(storedValue(database, "scans", "target_id"), null);
});
test("recorded additive migrations restore missing columns and configured error thresholds", (t) => {
@@ -976,47 +918,34 @@ test("recorded additive migrations restore missing columns and configured error
null,
);
assert.equal(
- database
- .prepare("SELECT terminal_reviewed_surface_count FROM deep_scan_runs")
- .get()?.terminal_reviewed_surface_count,
+ storedValue(database, "deep_scan_runs", "terminal_reviewed_surface_count"),
null,
);
assert.equal(
- database.prepare("SELECT deep_scan_config_json FROM workspaces").get()
- ?.deep_scan_config_json,
+ storedValue(database, "workspaces", "deep_scan_config_json"),
null,
);
assert.equal(
- database
- .prepare("SELECT pending_target_project_path FROM deep_scan_runs")
- .get()?.pending_target_project_path,
+ storedValue(database, "deep_scan_runs", "pending_target_project_path"),
null,
);
assert.equal(
- database
- .prepare("SELECT stop_after_consecutive_errors FROM deep_scan_runs")
- .get()?.stop_after_consecutive_errors,
+ storedValue(database, "deep_scan_runs", "stop_after_consecutive_errors"),
7,
);
assert.equal(
- database
- .prepare("SELECT discovery_user_context_json FROM deep_scan_runs")
- .get()?.discovery_user_context_json,
+ storedValue(database, "deep_scan_runs", "discovery_user_context_json"),
null,
);
database.exec(`UPDATE deep_scan_runs SET stop_after_consecutive_errors = 2,
discovery_user_context_json = '"Original discovery context"'`);
applyMigrations(database);
assert.equal(
- database
- .prepare("SELECT stop_after_consecutive_errors FROM deep_scan_runs")
- .get()?.stop_after_consecutive_errors,
+ storedValue(database, "deep_scan_runs", "stop_after_consecutive_errors"),
2,
);
assert.equal(
- database
- .prepare("SELECT discovery_user_context_json FROM deep_scan_runs")
- .get()?.discovery_user_context_json,
+ storedValue(database, "deep_scan_runs", "discovery_user_context_json"),
'"Original discovery context"',
);
});
diff --git a/plugins/codex-security/mcp-app/tests/test_workbench_state.ts b/plugins/codex-security/mcp-app/tests/test_workbench_state.ts
index 206483b88..ef700cbdc 100644
--- a/plugins/codex-security/mcp-app/tests/test_workbench_state.ts
+++ b/plugins/codex-security/mcp-app/tests/test_workbench_state.ts
@@ -64,7 +64,7 @@ async function openWorkspace(env: NodeJS.ProcessEnv) {
env,
});
try {
- assertNoError(await server.initialize("workbench-state-test"));
+ await server.initialize("workbench-state-test");
return await server.callTool(2, {
name: "open_codex_security_workspace",
arguments: { targetPath, scope: ".", mode: "standard" },