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: share scan fixtures and stabilize recovery ordering (#1467)

mldangelo-oai7f0d909e6df8
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 4826db998..38181c09a 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
@@ -988,6 +988,18 @@ for (const layout of ["standard", "diff", "worker"] as const) {
: ["coverage.json", "scan-manifest.json"]) {
test(`${layout}: recover explicit work after ${destination} publication fails`, async (t) => {
const f = await fixture(t, layout);
+ const originalRename = fsPromises.rename;
+ let publicationTime = 0;
+ // Keep successive publications distinct on coarse filesystem clocks.
+ t.mock.method(
+ fsPromises,
+ "rename",
+ async (...args: Parameters<typeof originalRename>) => {
+ await originalRename(...args);
+ publicationTime += 1;
+ await utimes(args[1], publicationTime, publicationTime);
+ },
+ );
const pending = { id: "review", ...generic };
const closing = f.draft({ resolvedDeferred: [close(pending.id)] }, true);
const fail = (input: ScanDraftInput) =>
diff --git a/sdk/typescript/tests-ts/deep-scan-workbench.test.ts b/sdk/typescript/tests-ts/deep-scan-workbench.test.ts
index b05aebea8..25da3b41e 100644
--- a/sdk/typescript/tests-ts/deep-scan-workbench.test.ts
+++ b/sdk/typescript/tests-ts/deep-scan-workbench.test.ts
@@ -1,5 +1,6 @@
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
+import type { CoverageDocument } from "../src/models.js";
import { afterEach, describe, expect, test } from "bun:test";
import { workbenchCommand as workbench } from "./support/workbench-command.js";
import { loadBundledRuntime, PLUGIN_ROOT } from "./plugin-root.js";
@@ -599,48 +600,19 @@ describe("deep scan workbench ownership", () => {
0,
);
if (existingDeferred) {
- await Promise.all([
- writeFile(
- join(scanDir, "scan-manifest.json"),
- JSON.stringify({
- scan: {
- target: {
- kind: "directory_snapshot",
- targetId,
- displayName: "repository",
- },
- scope: { limitations: [], validationMode: "incomplete" },
- },
- }),
- ),
- writeFile(
- join(scanDir, "findings.json"),
- JSON.stringify({ findings: [] }),
- ),
- writeFile(
- join(scanDir, "coverage.json"),
- JSON.stringify({
- completeness: "partial",
- inventoryStrategy,
- surfaces: [],
- explicitExclusions: [],
- deferred: [
- {
- id: "candidate-001",
- candidateId: "candidate-001",
- reason:
- "Existing candidate validation dependency was unavailable.",
- paths: ["src/source.py"],
- },
- {
- id: "candidate-deferred",
- candidateId: "candidate-deferred",
- reason: "Existing runtime policy could not be inspected.",
- paths: ["src/source.py"],
- },
- ],
- }),
- ),
+ await writePartialScanArtifacts(scanDir, targetId, inventoryStrategy, [
+ {
+ id: "candidate-001",
+ candidateId: "candidate-001",
+ reason: "Existing candidate validation dependency was unavailable.",
+ paths: ["src/source.py"],
+ },
+ {
+ id: "candidate-deferred",
+ candidateId: "candidate-deferred",
+ reason: "Existing runtime policy could not be inspected.",
+ paths: ["src/source.py"],
+ },
]);
}
const warning =
@@ -1205,34 +1177,8 @@ describe("deep scan workbench ownership", () => {
const reason =
"The configured discovery time limit elapsed before any source review completed.";
- await Promise.all([
- writeFile(
- join(scanDir, "scan-manifest.json"),
- JSON.stringify({
- scan: {
- target: {
- kind: "directory_snapshot",
- targetId,
- displayName: "repository",
- },
- scope: { limitations: [], validationMode: "incomplete" },
- },
- }),
- ),
- writeFile(
- join(scanDir, "findings.json"),
- JSON.stringify({ findings: [] }),
- ),
- writeFile(
- join(scanDir, "coverage.json"),
- JSON.stringify({
- completeness: "partial",
- inventoryStrategy: "repository",
- surfaces: [],
- explicitExclusions: [],
- deferred: [{ id: "source-review", reason }],
- }),
- ),
+ await writePartialScanArtifacts(scanDir, targetId, "repository", [
+ { id: "source-review", reason },
]);
const completed = command(["complete-scan", "--scan-id", scanId])[
"scan"
@@ -1548,6 +1494,40 @@ describe("deep scan workbench ownership", () => {
});
});
+function writePartialScanArtifacts(
+ scanDir: string,
+ targetId: string,
+ inventoryStrategy: CoverageDocument["inventoryStrategy"],
+ deferred: CoverageDocument["deferred"],
+) {
+ return Promise.all([
+ writeFile(
+ join(scanDir, "scan-manifest.json"),
+ JSON.stringify({
+ scan: {
+ target: {
+ kind: "directory_snapshot",
+ targetId,
+ displayName: "repository",
+ },
+ scope: { limitations: [], validationMode: "incomplete" },
+ },
+ }),
+ ),
+ writeFile(join(scanDir, "findings.json"), JSON.stringify({ findings: [] })),
+ writeFile(
+ join(scanDir, "coverage.json"),
+ JSON.stringify({
+ completeness: "partial",
+ inventoryStrategy,
+ surfaces: [],
+ explicitExclusions: [],
+ deferred,
+ }),
+ ),
+ ]);
+}
+
function workbenchCommand(
python: string | null,
stateDir: string,