OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
test(mcp): reuse scan fixture configuration (#1486)
mldangelo-oai8419ed5050e6
diff --git a/plugins/codex-security/mcp-app/tests/test_artifact_scan_draft.ts b/plugins/codex-security/mcp-app/tests/test_artifact_scan_draft.tsindex e4d091e35..242058145 100644--- a/plugins/codex-security/mcp-app/tests/test_artifact_scan_draft.ts+++ b/plugins/codex-security/mcp-app/tests/test_artifact_scan_draft.ts@@ -141,6 +141,20 @@ try {findings: [finding],coverage,};+ const partialWorkerInput = (+ deferred: Record<string, unknown>,+ surfaces: Record<string, unknown>[] = [],+ ) => ({+ ...workerInput,+ complete: false,+ findings: [],+ coverage: {+ ...coverage,+ completeness: "partial",+ surfaces,+ deferred: [deferred],+ },+ });const workerResultPath = path.join(workerRoot, "result.json");const checkpointContext = await createWorkerContext("checkpoint-worker");@@ -228,14 +242,14 @@ try {rejectedIncompleteContext,workerInput,);- await recordCodexSecurityWorkerScanDraft(rejectedIncompleteContext, {- ...workerInput,- complete: false,- findings: [],- coverage: {- ...coverage,- completeness: "partial",- surfaces: [+ await recordCodexSecurityWorkerScanDraft(+ rejectedIncompleteContext,+ partialWorkerInput(+ {+ candidateId: "late-incomplete-review",+ reason: "This arrived after the worker completed.",+ },+ [{candidateId: finding.provenance.candidateId,label: "Archive extraction",@@ -243,14 +257,8 @@ try {notes: "The incomplete writer rejected this candidate.",},],- deferred: [- {- candidateId: "late-incomplete-review",- reason: "This arrived after the worker completed.",- },- ],- },- });+ ),+ );const acceptedHead = await readJson(rejectedIncompleteRoot,"checkpoint-head.json",@@ -283,22 +291,13 @@ try {deferredDoesNotRejectContext,workerInput,);- await recordCodexSecurityWorkerScanDraft(deferredDoesNotRejectContext, {- ...workerInput,- complete: false,- findings: [],- coverage: {- ...coverage,- completeness: "partial",- surfaces: [],- deferred: [- {- candidateId: finding.provenance.candidateId,- reason: "A stale worker row still says validation is pending.",- },- ],- },- });+ await recordCodexSecurityWorkerScanDraft(+ deferredDoesNotRejectContext,+ partialWorkerInput({+ candidateId: finding.provenance.candidateId,+ reason: "A stale worker row still says validation is pending.",+ }),+ );const deferredDoesNotReject = await readJson(deferredDoesNotRejectRoot,"result.json",@@ -434,22 +433,16 @@ try {},],};- await recordCodexSecurityWorkerScanDraft(renamedProgressContext, {- ...workerInput,- complete: false,- findings: [],- coverage: {- ...coverage,- completeness: "partial",- surfaces: staleSurfaces,- deferred: [- {- candidateId: finding.provenance.candidateId,- reason: "Archive path traversal validation is pending.",- },- ],- },- });+ await recordCodexSecurityWorkerScanDraft(+ renamedProgressContext,+ partialWorkerInput(+ {+ candidateId: finding.provenance.candidateId,+ reason: "Archive path traversal validation is pending.",+ },+ staleSurfaces,+ ),+ );await recordCodexSecurityWorkerScanDraft(renamedProgressContext, {...workerInput,complete: false,@@ -504,19 +497,13 @@ try {complete: false,findings: [anchoredFinding],});- await recordCodexSecurityWorkerScanDraft(anchorContext, {- ...workerInput,- complete: false,- findings: [],- coverage: {- ...coverage,- completeness: "partial",- surfaces: [],- deferred: [- { id: anchor, reason: "An unrelated review item remains pending." },- ],- },- });+ await recordCodexSecurityWorkerScanDraft(+ anchorContext,+ partialWorkerInput({+ id: anchor,+ reason: "An unrelated review item remains pending.",+ }),+ );const anchorResult = await readJson(anchorRoot, "result.json");assert.equal(anchorResult.findings.length, 1);assert.deepEqual(anchorResult.findings[0].identity, { anchor });@@ -885,23 +872,11 @@ try {summary: "An unvalidated archive extraction candidate.",evidence: "Original nested-worker source trace.",};- const pending = {- ...workerInput,- complete: false,- findings: [],- coverage: {- ...coverage,- completeness: "partial",- surfaces: [],- deferred: [- {- candidateId: finding.provenance.candidateId,- reason: "Pending parent validation",- candidate,- },- ],- },- };+ const pending = partialWorkerInput({+ candidateId: finding.provenance.candidateId,+ reason: "Pending parent validation",+ candidate,+ });await recordCodexSecurityWorkerScanDraft(pendingContext, pending);await recordCodexSecurityWorkerScanDraft(pendingContext, workerInput);const resolved = await readJson(pendingRoot, "result.json");@@ -926,19 +901,12 @@ try {"undefined-candidate-worker",);const undefinedCandidateRoot = undefinedCandidateContext.root;- await recordCodexSecurityWorkerScanDraft(undefinedCandidateContext, {- ...workerInput,- complete: false,- findings: [],- coverage: {- ...coverage,- completeness: "partial",- surfaces: [],- deferred: [- { reason: "An unrelated anonymous review item remains pending." },- ],- },- });+ await recordCodexSecurityWorkerScanDraft(+ undefinedCandidateContext,+ partialWorkerInput({+ reason: "An unrelated anonymous review item remains pending.",+ }),+ );const literalUndefinedFinding = structuredClone(finding);literalUndefinedFinding.provenance.candidateId = "undefined";literalUndefinedFinding.extensions.candidateId = "undefined";@@ -1728,17 +1696,10 @@ try {candidateId: finding.provenance.candidateId,reason: "The later attempt demoted this candidate for more review.",};- await recordCodexSecurityWorkerScanDraft(archivedResolution, {- ...workerInput,- complete: false,- findings: [],- coverage: {- ...coverage,- completeness: "partial",- surfaces: [],- deferred: [demotedCandidate],- },- });+ await recordCodexSecurityWorkerScanDraft(+ archivedResolution,+ partialWorkerInput(demotedCandidate),+ );await archiveFirstWorkerAttempt(archivedResolution.root);await recordCodexSecurityWorkerScanDraft(archivedResolution, {...withoutScanContext(workerInput),@@ -1766,17 +1727,10 @@ try {"checkpoints",findingCheckpointName,);- await recordCodexSecurityWorkerScanDraft(repeatedCheckpoint, {- ...workerInput,- complete: false,- findings: [],- coverage: {- ...coverage,- completeness: "partial",- surfaces: [],- deferred: [demotedCandidate],- },- });+ await recordCodexSecurityWorkerScanDraft(+ repeatedCheckpoint,+ partialWorkerInput(demotedCandidate),+ );const demotionCheckpointName = (await readdir(path.join(repeatedCheckpoint.root, "checkpoints"))).find((name) => name !== findingCheckpointName);@@ -1933,23 +1887,14 @@ try {const partialDeferredFinding = {summary: "Partial evidence captured before validation.",};- await recordCodexSecurityWorkerScanDraft(partialDeferredContext, {- ...workerInput,- complete: false,- findings: [],- coverage: {- ...coverage,- completeness: "partial",- surfaces: [],- deferred: [- {- candidateId: finding.provenance.candidateId,- reason: "Validation is pending.",- finding: partialDeferredFinding,- },- ],- },- });+ await recordCodexSecurityWorkerScanDraft(+ partialDeferredContext,+ partialWorkerInput({+ candidateId: finding.provenance.candidateId,+ reason: "Validation is pending.",+ finding: partialDeferredFinding,+ }),+ );await recordCodexSecurityWorkerScanDraft(partialDeferredContext, workerInput);const resolvedPartialDeferred = await readJson(partialDeferredRoot,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.tsindex 056f97216..d4bb261f6 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@@ -2,6 +2,7 @@ import { readJson, writeJson } from "./support/json.ts";import type { CoordinatorOptions } from "../src/deep-scan/coordinator.js";import type { ScanDraftInput } from "../src/artifact-scan-draft.js";import type {+ DeepScanConfig,DeepScanRunState,PersistedDeepScanWorker,DeepScanLogEvent,@@ -46,6 +47,10 @@ import {type StoreInput,} from "./deep_scan_coordinator_fixture.ts";+function twoRunConfig(config: Partial<DeepScanConfig> = {}) {+ return { ...config, stopAfterNoNew: 2, maxDiscoveryRuns: 2 };+}+async function testCappedQueueAndSerialDedup() {const { fixture, store } = await coordinatorFixture({workers: 3,@@ -309,11 +314,9 @@ async function testWorkerScopedCandidateSourceAggregation() {}async function testConsumedSourceIsNotRereadAfterReducerWritesResult() {- const { fixture, store } = await coordinatorFixture({- workers: 2,- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const { fixture, store } = await coordinatorFixture(+ twoRunConfig({ workers: 2 }),+ );const executor = new FakeExecutor({discoveryCandidateId: "candidate-1",canonicalCandidateId: "candidate-1",@@ -333,11 +336,9 @@ async function testConsumedSourceIsNotRereadAfterReducerWritesResult() {}async function testConsumedSourceWithToolDiagnosticIsNotRereadAfterReducerWritesResult() {- const { fixture, store } = await coordinatorFixture({- workers: 2,- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const { fixture, store } = await coordinatorFixture(+ twoRunConfig({ workers: 2 }),+ );const executor = new FakeExecutor({corruptAcceptedSource: true,dedupDiagnostics: [@@ -357,12 +358,9 @@ async function testConsumedSourceWithToolDiagnosticIsNotRereadAfterReducerWrites}async function testRetryKeepsLogicalWorker() {- const { fixture, store } = await coordinatorFixture({- workers: 2,- subagents: 1,- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const { fixture, store } = await coordinatorFixture(+ twoRunConfig({ workers: 2, subagents: 1 }),+ );const executor = new FakeExecutor({failFirstDiscoveryAttempt: true,});@@ -706,12 +704,9 @@ async function testSingletonHardCapReduction() {}async function testExhaustedRetryFailsScan() {- const { fixture, store } = await coordinatorFixture({- workers: 2,- subagents: 1,- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const { fixture, store } = await coordinatorFixture(+ twoRunConfig({ workers: 2, subagents: 1 }),+ );const executor = new FakeExecutor({discoveryFailureMessage: "transient worker failure",});@@ -1101,12 +1096,9 @@ async function testLongWorkerErrorIsBoundedOnlyAtPersistenceBoundary() {}async function testDiscoveryPhasePersistenceFailureStopsDispatch() {- const { fixture, store } = await coordinatorFixture({- workers: 2,- subagents: 1,- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const { fixture, store } = await coordinatorFixture(+ twoRunConfig({ workers: 2, subagents: 1 }),+ );store.failProgressAt = 1;const executor = new FakeExecutor();const terminal = await runCoordinator(fixture, store, executor);@@ -1204,12 +1196,9 @@ async function testMissingDiscoveryResultResumesExistingThread(}async function testInvalidArtifactsRetry() {- const { fixture, store } = await coordinatorFixture({- workers: 2,- subagents: 1,- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const { fixture, store } = await coordinatorFixture(+ twoRunConfig({ workers: 2, subagents: 1 }),+ );const executor = new FakeExecutor({malformedDiscoveryAttempts: 1,});@@ -1283,12 +1272,9 @@ async function testInvalidArtifactsRetry() {async function testInvalidReducerResultRetriesFromSnapshot(missingCandidateLedger = false,) {- const { fixture, store } = await coordinatorFixture({- workers: 2,- subagents: 1,- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const { fixture, store } = await coordinatorFixture(+ twoRunConfig({ workers: 2, subagents: 1 }),+ );const executor = new FakeExecutor({...(missingCandidateLedger? {@@ -1781,11 +1767,9 @@ async function testAmbiguousReducerCommitPreservesPublishedCandidates() {}async function testReducerTraceabilityRetryNamesExactMissingSource() {- const { fixture, store } = await coordinatorFixture({- workers: 2,- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const { fixture, store } = await coordinatorFixture(+ twoRunConfig({ workers: 2 }),+ );const executor = new FakeExecutor({discoveryCandidateId: "candidate-1",canonicalCandidateId: "candidate-1",@@ -2125,10 +2109,7 @@ async function testTerminalReadFailureIsNotRecordedAsPublicationFailure() {}async function testCoordinatorHeartbeatsStopAfterOwnershipChanges() {- const fixture = await fixtureRun({- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const fixture = await fixtureRun(twoRunConfig());const run = {...fixture.run,coordinatorGeneration: 2,@@ -2189,10 +2170,7 @@ async function testCoordinatorHeartbeatsStopAfterOwnershipChanges() {}async function testCoordinatorHeartbeatsContinueDuringBlockedOwnershipRead() {- const fixture = await fixtureRun({- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const fixture = await fixtureRun(twoRunConfig());const run = { ...fixture.run, coordinatorGeneration: 2 };const store = new FakeStore(run);const ownershipRead = Promise.withResolvers<void>();@@ -2332,10 +2310,7 @@ async function testRemoteObserverRetriesTransientPersistenceFailures() {}async function testStaleMutationObservesReplacement() {- const fixture = await fixtureRun({- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const fixture = await fixtureRun(twoRunConfig());const run = { ...fixture.run, coordinatorGeneration: 2 };const store = new FakeStore(run);store.updateProgress = async () => {@@ -2379,12 +2354,7 @@ async function testStaleMutationObservesReplacement() {}async function testJoinAndOrphanRules() {- const fixture = await fixtureRun({- workers: 2,- subagents: 1,- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const fixture = await fixtureRun(twoRunConfig({ workers: 2, subagents: 1 }));const existingCoordinator = { marker: "existing" };const defaults = {executor: {},@@ -2559,10 +2529,7 @@ async function testJoinAndOrphanRules() {async function testPausedDiscoverySurvivesCoordinatorRestart(removeHistoricalPrompts = true,) {- const fixture = await fixtureRun({- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const fixture = await fixtureRun(twoRunConfig());const handoffClaimToken = randomUUID();const store = new FakeStore({...fixture.run,@@ -3358,11 +3325,9 @@ async function testSaturationOmitsWorkerAcceptedDuringCancellation() {}async function testSuccessfulDeepCoverageIgnoresWorkerAndReducerReviewStatus() {- const { fixture, store } = await coordinatorFixture({- workers: 2,- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const { fixture, store } = await coordinatorFixture(+ twoRunConfig({ workers: 2 }),+ );const executor = new FakeExecutor();const run = executor.run.bind(executor);const reviewed = { label: "Reviewed query", disposition: "no_issue_found" };@@ -3519,10 +3484,7 @@ async function testPublicationUsesAcceptedReducerSnapshot() {async function testResumeDoesNotRequireHistoricalWorkerPrompt(status: "failed" | "canceled",) {- const fixture = await fixtureRun({- stopAfterNoNew: 2,- maxDiscoveryRuns: 2,- });+ const fixture = await fixtureRun(twoRunConfig());const promptPath = path.join(fixture.run.scanDir, "missing-prompt.md");const store = new FakeStore({...fixture.run,