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
ci: smoke test published npm installs across supported platforms (#1129)
mldangelo-oai1b90b6732f4e
diff --git a/.github/workflows/published-install-smoke.yml b/.github/workflows/published-install-smoke.ymlnew file mode 100644index 000000000..37f2ed0ad--- /dev/null+++ b/.github/workflows/published-install-smoke.yml@@ -0,0 +1,48 @@+name: published-install-smoke++on:+ pull_request:+ paths:+ - .github/workflows/published-install-smoke.yml+ - sdk/typescript/scripts/smoke-published-package.mjs+ - sdk/typescript/scripts/package-smoke-npm.mjs+ - sdk/typescript/scripts/package-smoke-timeouts.mjs+ - sdk/typescript/tests-ts/published-install-smoke.test.ts+ schedule:+ - cron: "43 9 * * *"+ workflow_dispatch:++permissions:+ contents: read++concurrency:+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}++jobs:+ install:+ name: published latest / ${{ matrix.os }} / node-${{ matrix.node }}+ runs-on: ${{ matrix.os }}+ timeout-minutes: 15+ strategy:+ fail-fast: false+ matrix:+ os: [ubuntu-latest]+ node: ["22", "24", "26"]+ include:+ - os: macos-latest+ node: "24"+ - os: windows-latest+ node: "24"+ steps:+ - name: Checkout smoke checks+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ persist-credentials: false+ - name: Set up Node.js+ uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0+ with:+ node-version: ${{ matrix.node }}+ package-manager-cache: false+ - name: Install and start the published package+ run: node sdk/typescript/scripts/smoke-published-package.mjsdiff --git a/RELEASING.md b/RELEASING.mdindex 199b12e38..b52513ea9 100644--- a/RELEASING.md+++ b/RELEASING.md@@ -248,6 +248,20 @@ Check the published state before announcing the release:- Every merged pull request is included or has an intentional`skip-release-notes` label.+The `published-install-smoke` workflow checks npm's current `latest` daily,+on pull requests changing its smoke checks, and on manual dispatch. It installs+into a temporary consumer, checks the npm CLI shim and public SDK, starts the+bundled Codex executable with `--version`,+and initializes the bundled MCP server. Linux covers supported Node majors+22, 24, and 26; macOS and Windows cover Node 24. These checks use temporary+configuration directories and do not run scans or call model APIs.++The smoke test uses the installed version, so it can run while `main` contains+unreleased changes. A failure reports the installed version or failing startup+command in the Actions log; inspect that job before treating it as a release+regression. To reproduce locally, run+`node sdk/typescript/scripts/smoke-published-package.mjs` from the repository.+## Recover or repair a releaseDo not retarget a release tag or publish a second package under the samediff --git a/sdk/typescript/scripts/package-smoke-npm.mjs b/sdk/typescript/scripts/package-smoke-npm.mjsnew file mode 100644index 000000000..130834d8c--- /dev/null+++ b/sdk/typescript/scripts/package-smoke-npm.mjs@@ -0,0 +1,35 @@+import { stat } from "node:fs/promises";+import { basename, dirname, resolve } from "node:path";++export async function resolveNpm() {+ const nodeDirectory = dirname(process.execPath);+ const candidates = [+ process.env.npm_execpath,+ resolve(nodeDirectory, "../lib/node_modules/npm/bin/npm-cli.js"),+ resolve(nodeDirectory, "node_modules/npm/bin/npm-cli.js"),+ resolve(nodeDirectory, "../node_modules/npm/bin/npm-cli.js"),+ ];++ for (const candidate of new Set(candidates)) {+ if (+ typeof candidate !== "string" ||+ basename(candidate).toLowerCase() !== "npm-cli.js"+ ) {+ continue;+ }++ try {+ if ((await stat(candidate)).isFile()) {+ return { command: process.execPath, args: [candidate] };+ }+ } catch (error) {+ if (error.code !== "ENOENT" && error.code !== "ENOTDIR") throw error;+ }+ }++ if (process.platform === "win32") {+ throw new Error("The Node.js installation does not include the npm CLI.");+ }++ return { command: "npm", args: [] };+}diff --git a/sdk/typescript/scripts/smoke-package.mjs b/sdk/typescript/scripts/smoke-package.mjsindex ca0157f44..22026d83a 100644--- a/sdk/typescript/scripts/smoke-package.mjs+++ b/sdk/typescript/scripts/smoke-package.mjs@@ -13,17 +13,10 @@ import {writeFile,} from "node:fs/promises";import { tmpdir } from "node:os";-import {- basename,- dirname,- isAbsolute,- join,- relative,- resolve,- sep,-} from "node:path";+import { isAbsolute, join, relative, resolve, sep } from "node:path";import { fileURLToPath, pathToFileURL } from "node:url";import { packageSmokeTimeouts } from "./package-smoke-timeouts.mjs";+import { resolveNpm } from "./package-smoke-npm.mjs";const {commandTimeoutMs: PACKAGE_SMOKE_TIMEOUT_MS,@@ -118,39 +111,6 @@ function run(return result.stdout ?? "";}-async function resolveNpm() {- const nodeDirectory = dirname(process.execPath);- const candidates = [- process.env.npm_execpath,- resolve(nodeDirectory, "../lib/node_modules/npm/bin/npm-cli.js"),- resolve(nodeDirectory, "node_modules/npm/bin/npm-cli.js"),- resolve(nodeDirectory, "../node_modules/npm/bin/npm-cli.js"),- ];-- for (const candidate of new Set(candidates)) {- if (- typeof candidate !== "string" ||- basename(candidate).toLowerCase() !== "npm-cli.js"- ) {- continue;- }-- try {- if ((await stat(candidate)).isFile()) {- return { command: process.execPath, args: [candidate] };- }- } catch (error) {- if (error.code !== "ENOENT" && error.code !== "ENOTDIR") throw error;- }- }-- if (process.platform === "win32") {- throw new Error("The Node.js installation does not include the npm CLI.");- }-- return { command: "npm", args: [] };-}-async function pluginFiles(directory) {const files = [];const directories = [directory];diff --git a/sdk/typescript/scripts/smoke-published-package.mjs b/sdk/typescript/scripts/smoke-published-package.mjsnew file mode 100644index 000000000..4213b51d7--- /dev/null+++ b/sdk/typescript/scripts/smoke-published-package.mjs@@ -0,0 +1,170 @@+import assert from "node:assert/strict";+import { execFileSync } from "node:child_process";+import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { fileURLToPath } from "node:url";+import { resolveNpm } from "./package-smoke-npm.mjs";+import { packageSmokeTimeouts } from "./package-smoke-timeouts.mjs";++const packageName = "@openai/codex-security";+const { commandTimeoutMs, installTimeoutMs } = packageSmokeTimeouts();++function run(command, args, options) {+ return execFileSync(command, args, {+ encoding: "utf8",+ stdio: "pipe",+ timeout: commandTimeoutMs,+ killSignal: "SIGKILL",+ windowsHide: true,+ ...options,+ });+}++export async function verifyInstalledPackage(consumer, environment) {+ const installedRoot = join(+ consumer,+ "node_modules",+ ...packageName.split("/"),+ );+ const manifest = JSON.parse(+ await readFile(join(installedRoot, "package.json"), "utf8"),+ );+ assert.equal(manifest.name, packageName);+ console.log(+ `Checking ${packageName}@${manifest.version} on ${process.platform}/${process.arch}, Node ${process.version}.`,+ );+ const options = { cwd: consumer, env: environment };+ const shim = join(+ consumer,+ "node_modules",+ ".bin",+ process.platform === "win32" ? "codex-security.cmd" : "codex-security",+ );+ function cli(argument) {+ return process.platform === "win32"+ ? run(+ environment.ComSpec ?? "cmd.exe",+ ["/d", "/s", "/c", `""${shim}" ${argument}"`],+ { ...options, windowsVerbatimArguments: true },+ )+ : run(shim, [argument], options);+ }+ assert.equal(cli("--version").trim(), manifest.version);+ assert.match(cli("--help"), /Usage: codex-security\b/u);++ // Resolve the public entrypoint from the consumer, without importing checkout code.+ const codex = JSON.parse(+ run(+ process.execPath,+ [+ "--input-type=module",+ "--eval",+ `+ import assert from "node:assert/strict";+ import { CodexSecurity, resolveCodexCommand } from "${packageName}";+ const client = new CodexSecurity();+ assert.equal(typeof client.run, "function");+ await client.close();+ console.log(JSON.stringify(resolveCodexCommand({})));+ `,+ ],+ options,+ ),+ );+ assert.match(run(codex.command, ["--version"], options), /^codex-cli\s+\d/u);++ const pluginRoot = join(installedRoot, "_bundled_plugin");+ const configuration = JSON.parse(+ await readFile(join(pluginRoot, ".mcp.json"), "utf8"),+ );+ const server = configuration.mcpServers["codex-security"];+ const launcher = join(pluginRoot, server.command);+ const initialized = run(+ process.platform === "win32"+ ? (environment.ComSpec ?? "cmd.exe")+ : launcher,+ process.platform === "win32"+ ? ["/d", "/s", "/c", "call", `${launcher}.cmd`, ...server.args]+ : server.args,+ {+ ...options,+ cwd: pluginRoot,+ input: `${JSON.stringify({+ jsonrpc: "2.0",+ id: 1,+ method: "initialize",+ params: {+ protocolVersion: "2025-11-25",+ capabilities: {},+ clientInfo: { name: "published-install-smoke", version: "1.0.0" },+ },+ })}\n`,+ },+ );+ const response = JSON.parse(initialized.trim());+ assert.equal(response.id, 1);+ assert.equal(response.result.serverInfo.name, "codex-security");+ console.log(+ `Validated published ${packageName}@${manifest.version}: npm CLI shim, public SDK, bundled Codex, and plugin initialization.`,+ );+}++async function smokePublishedPackage() {+ const consumer = await mkdtemp(join(tmpdir(), "codex-security-published-"));+ try {+ await writeFile(+ join(consumer, "package.json"),+ JSON.stringify({+ name: "published-install-smoke",+ private: true,+ type: "module",+ }),+ );+ const npm = await resolveNpm();+ run(+ npm.command,+ [+ ...npm.args,+ "install",+ "--include=optional",+ "--package-lock=false",+ "--no-audit",+ "--no-fund",+ "--registry=https://registry.npmjs.org",+ `${packageName}@latest`,+ ],+ {+ cwd: consumer,+ timeout: installTimeoutMs,+ stdio: "inherit",+ },+ );++ const smokeHome = join(consumer, "home");+ await mkdir(smokeHome);+ await verifyInstalledPackage(consumer, {+ ...process.env,+ HOME: smokeHome,+ USERPROFILE: smokeHome,+ XDG_CONFIG_HOME: join(smokeHome, ".config"),+ XDG_CACHE_HOME: join(smokeHome, ".cache"),+ APPDATA: join(smokeHome, "AppData", "Roaming"),+ LOCALAPPDATA: join(smokeHome, "AppData", "Local"),+ CODEX_HOME: join(smokeHome, ".codex"),+ CODEX_SECURITY_STATE_DIR: join(smokeHome, ".codex-security"),+ CODEX_MCP_NODE_PATH: process.execPath,+ });+ } finally {+ await rm(consumer, {+ recursive: true,+ force: true,+ maxRetries: 10,+ retryDelay: 100,+ });+ }+}++if (process.argv[1] === fileURLToPath(import.meta.url)) {+ await smokePublishedPackage();+}diff --git a/sdk/typescript/tests-ts/published-install-smoke.test.ts b/sdk/typescript/tests-ts/published-install-smoke.test.tsnew file mode 100644index 000000000..e0696a0e1--- /dev/null+++ b/sdk/typescript/tests-ts/published-install-smoke.test.ts@@ -0,0 +1,74 @@+import { afterEach, expect, test } from "bun:test";+import { chmod, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";+import { tmpdir } from "node:os";+import { join } from "node:path";++const { verifyInstalledPackage } = (await import(+ new URL("../scripts/smoke-published-package.mjs", import.meta.url).href+)) as {+ verifyInstalledPackage: (+ consumer: string,+ environment: NodeJS.ProcessEnv,+ ) => Promise<void>;+};+const directories: string[] = [];+afterEach(async () => {+ await Promise.all(+ directories+ .splice(0)+ .map((directory) => rm(directory, { recursive: true, force: true })),+ );+});++async function installedFixture(cliVersion: string) {+ const consumer = await mkdtemp(join(tmpdir(), "published smoke "));+ directories.push(consumer);+ const installedRoot = join(+ consumer,+ "node_modules",+ "@openai",+ "codex-security",+ );+ const bin = join(consumer, "node_modules", ".bin");+ await mkdir(installedRoot, { recursive: true });+ await mkdir(bin);+ await writeFile(+ join(installedRoot, "package.json"),+ JSON.stringify({+ name: "@openai/codex-security",+ version: "99.1.2",+ }),+ );+ const shim = join(+ bin,+ process.platform === "win32" ? "codex-security.cmd" : "codex-security",+ );+ await writeFile(+ shim,+ process.platform === "win32"+ ? `@echo off\r\nif "%~1"=="--version" (echo ${cliVersion}) else (echo Usage: codex-security)\r\n`+ : `#!/bin/sh\nif [ "$1" = "--version" ]; then printf '%s\\n' '${cliVersion}'; else printf '%s\\n' 'Usage: codex-security'; fi\n`,+ );+ await chmod(shim, 0o755);+ return { consumer, shim };+}++test("fails when the installed CLI reports a different package version", async () => {+ const { consumer } = await installedFixture("99.1.1");+ await expect(verifyInstalledPackage(consumer, process.env)).rejects.toThrow(+ "99.1.2",+ );+});++test("fails when the installed CLI cannot start", async () => {+ const { consumer, shim } = await installedFixture("99.1.2");+ await writeFile(+ shim,+ process.platform === "win32"+ ? "@echo off\r\necho synthetic CLI startup failure 1>&2\r\nexit /b 7\r\n"+ : "#!/bin/sh\nprintf '%s\\n' 'synthetic CLI startup failure' >&2\nexit 7\n",+ );+ await expect(verifyInstalledPackage(consumer, process.env)).rejects.toThrow(+ "synthetic CLI startup failure",+ );+});