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): run isolated scripts in parallel (#732)
mldangelo-oaib520ecf91682
diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.ymlindex 2db2c9f07..da46b8319 100644--- a/.github/workflows/node-ci.yml+++ b/.github/workflows/node-ci.yml@@ -238,6 +238,7 @@ jobs:path: |sdk/typescript/reports/junit-*.xmlsdk/typescript/coverage/lcov.info+ plugins/codex-security/mcp-app/reports/junit.xmlif-no-files-found: warnretention-days: 14diff --git a/plugins/codex-security/mcp-app/.gitignore b/plugins/codex-security/mcp-app/.gitignoreindex 1fcf9a5e6..345555f6f 100644--- a/plugins/codex-security/mcp-app/.gitignore+++ b/plugins/codex-security/mcp-app/.gitignore@@ -1,3 +1,4 @@.preview/dist/node_modules/+/reports/diff --git a/plugins/codex-security/mcp-app/TESTING.md b/plugins/codex-security/mcp-app/TESTING.mdnew file mode 100644index 000000000..4b1787d79--- /dev/null+++ b/plugins/codex-security/mcp-app/TESTING.md@@ -0,0 +1,13 @@+# MCP tests++From `sdk/typescript`, install both packages' dependencies and run `pnpm run test:mcp`. That command builds the bundled plugin before testing it. To rerun only the tests after a build, run `pnpm run test:mcp` from this directory.++Node's test runner discovers `tests/test_*.mjs` and runs at most two files at once, each in a separate process. Assertions within a file remain sequential. Keep shared helpers outside that filename pattern. A failing script fails the command. The reporter streams Node's TAP output and then tries to write Node's JUnit report to `reports/junit.xml`; an unavailable report path warns without changing the test result. CI uploads that file with the Node 22 reports.++For a serial comparison, run:++```sh+node --test --test-concurrency=1 "tests/test_*.mjs"+```++Use the existing injected clocks for retry policy tests. Keep real timers, subprocesses, SQLite files, and isolated temporary directories in the lifecycle, locking, permissions, and stdio tests. Do not share writable fixtures between test files or rebuild the bundled plugin while another test is reading it.diff --git a/plugins/codex-security/mcp-app/package.json b/plugins/codex-security/mcp-app/package.jsonindex f177f30e5..c8b6b11b1 100644--- a/plugins/codex-security/mcp-app/package.json+++ b/plugins/codex-security/mcp-app/package.json@@ -7,7 +7,7 @@"scripts": {"build": "tsc --noEmit","build:mcp": "node scripts/build_mcp_app.mjs --output .preview/mcp",- "test:mcp": "node tests/test_artifact_foundation.mjs && node tests/test_artifact_inventory.mjs && node tests/test_artifact_discovery.mjs && node tests/test_artifact_worker_threat_model.mjs && node tests/test_artifact_validation_phase.mjs && node tests/test_artifact_attack_path.mjs && node tests/test_artifact_deep_reducer.mjs && node tests/test_artifact_scan_draft.mjs && node tests/test_compact_artifact_server.mjs && node tests/test_scan_handoff.mjs && node tests/test_deep_scan_templates.mjs && node tests/test_deep_scan_parent_sandbox.mjs && node tests/test_deep_scan_permission_profile_preflight.mjs && node tests/test_deep_scan_artifact_validation.mjs && node tests/test_deep_scan_store.mjs && node tests/test_deep_scan_store_integration.mjs && node tests/test_deep_scan_executor.mjs && node tests/test_deep_scan_coordinator.mjs && node tests/test_deep_scan_stdio_lifecycle.mjs && node tests/test_workbench_state_fallback.mjs && node tests/test_python_command.mjs && node tests/test_mcp_app_smoke.mjs",+ "test:mcp": "node --test --test-concurrency=2 --test-reporter=./scripts/test_reporter.mjs \"tests/test_*.mjs\"","typecheck": "tsc --noEmit"},"dependencies": {diff --git a/plugins/codex-security/mcp-app/scripts/test_reporter.mjs b/plugins/codex-security/mcp-app/scripts/test_reporter.mjsnew file mode 100644index 000000000..8cd2c5ded--- /dev/null+++ b/plugins/codex-security/mcp-app/scripts/test_reporter.mjs@@ -0,0 +1,23 @@+import { mkdir, writeFile } from "node:fs/promises";+import { junit, tap } from "node:test/reporters";++export default async function* report(source) {+ const events = [];+ async function* record() {+ for await (const event of source) {+ events.push(event);+ yield event;+ }+ }++ yield* tap(record());++ try {+ await mkdir("reports", { recursive: true });+ await writeFile("reports/junit.xml", junit(events));+ } catch (error) {+ console.warn(+ `Could not write the optional MCP test report: ${error.message}`,+ );+ }+}diff --git a/plugins/codex-security/mcp-app/tests/test_reporter.mjs b/plugins/codex-security/mcp-app/tests/test_reporter.mjsnew file mode 100644index 000000000..c66a0ff7d--- /dev/null+++ b/plugins/codex-security/mcp-app/tests/test_reporter.mjs@@ -0,0 +1,85 @@+import assert from "node:assert/strict";+import { spawnSync } from "node:child_process";+import {+ copyFile,+ mkdir,+ mkdtemp,+ readFile,+ rm,+ writeFile,+} from "node:fs/promises";+import { tmpdir } from "node:os";+import { delimiter, dirname, join } from "node:path";++const packageJson = JSON.parse(+ await readFile(new URL("../package.json", import.meta.url), "utf8"),+);++for (const { blocked, fail } of [+ { blocked: undefined, fail: false },+ { blocked: "directory", fail: false },+ { blocked: "file", fail: false },+ { blocked: undefined, fail: true },+ { blocked: "directory", fail: true },+]) {+ const root = await mkdtemp(join(tmpdir(), "codex-security-mcp-report-"));+ try {+ await writeFile(+ join(root, "package.json"),+ JSON.stringify({+ scripts: { "test:mcp": packageJson.scripts["test:mcp"] },+ }),+ );+ await mkdir(join(root, "scripts"));+ await copyFile(+ new URL("../scripts/test_reporter.mjs", import.meta.url),+ join(root, "scripts", "test_reporter.mjs"),+ );+ await mkdir(join(root, "tests"));+ if (blocked === "directory") {+ await writeFile(join(root, "reports"), "synthetic blocker");+ } else if (blocked === "file") {+ await mkdir(join(root, "reports", "junit.xml"), { recursive: true });+ }+ const probe = join(root, "tests", "test_probe.mjs");+ await writeFile(+ probe,+ fail ? 'throw new Error("synthetic test failure");\n' : "",+ );+ const child = spawnSync(process.execPath, ["--run", "test:mcp"], {+ cwd: root,+ env: {+ ...process.env,+ NODE_TEST_CONTEXT: undefined,+ PATH: `${dirname(process.execPath)}${delimiter}${process.env.PATH ?? ""}`,+ },+ encoding: "utf8",+ timeout: 30_000,+ });+ assert.equal(child.error, undefined);+ assert.equal(child.status, fail ? 1 : 0, child.stderr);+ assert.match(child.stdout, fail ? /not ok 1/ : /ok 1/);+ if (blocked) {+ assert.match(+ child.stderr,+ /Could not write the optional MCP test report/,+ );+ if (blocked === "directory") {+ assert.equal(+ await readFile(join(root, "reports"), "utf8"),+ "synthetic blocker",+ );+ }+ } else {+ const xml = await readFile(join(root, "reports", "junit.xml"), "utf8");+ assert.match(xml, /<testcase /);+ assert.equal(xml.includes("<failure "), fail);+ assert.doesNotMatch(+ child.stderr,+ /Could not write the optional MCP test report/,+ );+ }+ } finally {+ await rm(root, { recursive: true, force: true });+ }+}