Skip to content

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

test(deep-scan): make worker lifecycle fixtures deterministic on Windows (#2375)

Michael D'Angelo1cc9df5e09b3
diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml
index fcc640ed4..ddb1e4fba 100644
--- a/.github/workflows/node-ci.yml
+++ b/.github/workflows/node-ci.yml
@@ -544,6 +544,14 @@ jobs:
TMPDIR: ${{ steps.windows-temp.outputs.path }}
CODEX_SECURITY_ALLOW_MACHINE_POLICY_TEST: "false"
run: node --experimental-strip-types sdk/typescript/scripts/run-ci-tests.mts ${{ matrix.shard }}/14 --seed=${{ github.run_number }}
+ - name: Test Deep Scan worker cleanup and discovery deadlines on Windows
+ if: matrix.shard == 2
+ working-directory: plugins/codex-security/mcp-app
+ env: *windows-shard-env
+ run: >-
+ node --experimental-strip-types --test --test-reporter=tap
+ --test-name-pattern="^(testAbortKillsPreflightChild|testDiscoveryDeadlineReducesSingleBufferedFinding)$"
+ tests/test_deep_scan_permission_profile_preflight.ts tests/test_deep_scan_coordinator.ts
- name: Test MCP helper paths on Windows
if: matrix.shard == 1
working-directory: plugins/codex-security/mcp-app
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 84a83180d..3ac8307a8 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
@@ -152,6 +152,7 @@ export function workerRuntimeEnvironment(root: string, virtualenv?: string) {
: path.join(virtualenv, "bin"),
path.dirname(process.execPath),
].join(path.delimiter),
+ CODEX_MCP_NODE_PATH: process.execPath,
HOME: path.join(root, "home"),
PYTHON:
virtualenv === undefined
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 607ceac8c..f648e4e18 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
@@ -20,7 +20,7 @@ import type {
CodexWorkerRequest,
CodexWorkerResult,
} from "../src/deep-scan/types.js";
-import { after, mock, test } from "node:test";
+import { after, mock, test, type TestContext } from "node:test";
import assert from "node:assert/strict";
import { randomUUID } from "node:crypto";
import {
@@ -2468,28 +2468,36 @@ async function testComparisonStopCondition(mode: "quota" | "deadline") {
if (mode === "quota") assert.match(terminal.error ?? "", /Quota exceeded/);
}
-async function testDiscoveryDeadlineReducesSingleBufferedFinding() {
+async function testDiscoveryDeadlineReducesSingleBufferedFinding(
+ t: TestContext,
+) {
const { fixture, store } = await coordinatorFixture({
stopAfterNoNew: 99,
maxDiscoveryRuns: 8,
});
- const executor = new FakeExecutor({
- blockDiscoveryAfterCalls: 1,
- discoveryCandidateId: "candidate-1",
- });
- const coordinator = createCoordinator(fixture, store, executor, {
- discoveryTimeoutMs: 500,
- });
+ const first = new FakeExecutor({ discoveryCandidateId: "candidate-1" });
+ const blocked = new FakeExecutor({ blockDiscoveryAfterCalls: 0 });
+ let dispatched = 0;
+ t.mock.timers.enable({ apis: ["setTimeout"] });
+ const coordinator = createCoordinator(
+ fixture,
+ store,
+ {
+ run(request) {
+ return (++dispatched === 1 ? first : blocked).run(request);
+ },
+ },
+ { discoveryTimeoutMs: 500 },
+ );
+ t.after(() => coordinator.cancel("fixture cleanup"));
coordinator.start();
-
- await eventually(
- () =>
- executor.discoveryCalls === 2 &&
- executor.runningDiscovery === 1 &&
- [...store.workers.values()].some(
- (worker) =>
- worker.kind === "discovery" && worker.status === "succeeded",
- ),
+ await blocked.discoveryStarted.promise;
+ assert.equal(dispatched, 2);
+ assert.equal(blocked.runningDiscovery, 1);
+ assert.ok(
+ [...store.workers.values()].some(
+ (worker) => worker.kind === "discovery" && worker.status === "succeeded",
+ ),
);
assert.equal(
store.iterations.length,
@@ -2497,6 +2505,8 @@ async function testDiscoveryDeadlineReducesSingleBufferedFinding() {
"the completed scan is checkpointed before the next scan starts",
);
+ t.mock.timers.tick(500);
+ t.mock.timers.reset();
const terminal = await coordinator.wait(undefined, 5_000);
assert.equal(terminal?.status, "succeeded", terminal?.error);
assert.equal(terminal?.terminalReason, "capped");
@@ -2506,7 +2516,7 @@ async function testDiscoveryDeadlineReducesSingleBufferedFinding() {
true,
);
assert.equal(store.failureMessages.length, 0);
- assert.equal(executor.runningDiscovery, 0);
+ assert.equal(blocked.runningDiscovery, 0);
const manifest = await readJson(terminal.manifestPath);
assert.equal(store.iterations[0].workerIds.length, 1);
@@ -2905,7 +2915,7 @@ test(testRetryKeepsLogicalWorker);
test(testSandboxDiagnosticSurvivesArtifactRetries);
test(testSuccessfulDeepCoverageRetainsIndependentWorkerReviewStatus);
registerCases(testComparisonStopCondition, [["quota"], ["deadline"]]);
-test(testDiscoveryDeadlineReducesSingleBufferedFinding);
+test({ timeout: 30_000 }, testDiscoveryDeadlineReducesSingleBufferedFinding);
test(testDiscoveryAcceptedAtDeadlineIsReduced);
test(testDiscoveryDeadlineWithoutAcceptedWorkersReturnsPartialEvidence);
test(testDiscoveryDeadlineBeforeWorkerDispatchReturnsPartialEvidence);
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 68c69ffc2..8ecea436e 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
@@ -1138,7 +1138,13 @@ async function withFakeCodex(
}
childProcess.spawn = originalSpawn;
syncBuiltinESMExports();
- await rm(root, { recursive: true, force: true });
+ // On Windows a terminated fixture descendant may briefly retain its working directory.
+ await rm(root, {
+ recursive: true,
+ force: true,
+ maxRetries: 5,
+ retryDelay: 50,
+ });
}
}