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(sdk): use a smaller plugin for credential tests (#2057)

Michael D'Angelo7a6fa3f79c38
diff --git a/sdk/typescript/tests-ts/api-credentials.test.ts b/sdk/typescript/tests-ts/api-credentials.test.ts
index af46fc3ce..a80bbec7b 100644
--- a/sdk/typescript/tests-ts/api-credentials.test.ts
+++ b/sdk/typescript/tests-ts/api-credentials.test.ts
@@ -10,7 +10,11 @@ import { parse as parseToml } from "smol-toml";
import { initialCredentialsAvailable } from "../src/api.js";
import { AuthenticationRequiredError } from "../src/errors.js";
import { setCodexSecurityCredentialLogout } from "../src/runtime.js";
-import { copyCompletedScan, PLUGIN_ROOT } from "./plugin-root.js";
+import {
+ copyCompletedScan,
+ copyCredentialTestPlugin,
+ PLUGIN_ROOT,
+} from "./plugin-root.js";
import { TestClient } from "./support/api-client.js";
import {
codexFactory,
@@ -113,7 +117,12 @@ describe("CodexSecurity orchestration", () => {
const originalOverrides = structuredClone(overrides);
let captured: (CodexOptions & { nativeProfile?: string }) | undefined;
const client = new TestClient(
- { pluginPath: PLUGIN_ROOT, codexOverrides: overrides },
+ {
+ pluginPath: profile
+ ? PLUGIN_ROOT
+ : await copyCredentialTestPlugin(root),
+ codexOverrides: overrides,
+ },
{
environment: {
CODEX_HOME: relative(process.cwd(), home),
@@ -589,7 +598,7 @@ describe("CodexSecurity orchestration", () => {
const runs: Array<{ home: string; apiKey?: string }> = [];
const client = new TestClient(
{
- pluginPath: PLUGIN_ROOT,
+ pluginPath: await copyCredentialTestPlugin(root),
codexOverrides: {
model_provider: "synthetic.account",
model_providers: {
diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.ts
index 538956df8..c6b1df056 100644
--- a/sdk/typescript/tests-ts/api.test.ts
+++ b/sdk/typescript/tests-ts/api.test.ts
@@ -69,7 +69,11 @@ import {
matchScanFindingsInternal,
} from "../src/scan-comparison.js";
import { normalizeTarget } from "../src/targets.js";
-import { copyCompletedScan, PLUGIN_ROOT } from "./plugin-root.js";
+import {
+ copyCompletedScan,
+ copyCredentialTestPlugin,
+ PLUGIN_ROOT,
+} from "./plugin-root.js";
import {
mockScanRegistration,
mockWorkbench,
@@ -6166,9 +6170,10 @@ if __name__ == "__main__":
process.platform === "win32" ? "junction" : "dir",
);
}
+ const sessions = new Map<string, string>();
const client = new TestClient(
{
- pluginPath: PLUGIN_ROOT,
+ pluginPath: await copyCredentialTestPlugin(root),
codexOverrides: {
model,
...(provider === undefined
@@ -6221,9 +6226,12 @@ if __name__ == "__main__":
? "synthetic-transient-key"
: undefined,
);
- await writeUsageSession(codexHome, "persistent-thread", {
- input_tokens: 1,
- });
+ const path = await writeUsageSession(
+ codexHome,
+ `persistent-thread-${sessions.size + 1}`,
+ { input_tokens: 1 },
+ );
+ sessions.set(path, await readFile(path, "utf8"));
throw new Error("persistent session recorded");
},
}),
@@ -6242,18 +6250,10 @@ if __name__ == "__main__":
await client.close();
}
- expect(
- existsSync(
- join(
- codexHome,
- "sessions",
- "2026",
- "07",
- "26",
- "rollout-persistent-thread.jsonl",
- ),
- ),
- ).toBe(true);
+ expect(sessions.size).toBe(2);
+ for (const [path, contents] of sessions) {
+ expect(await readFile(path, "utf8")).toBe(contents);
+ }
expect(existsSync(join(codexHome, "auth.json"))).toBe(false);
const persistentConfigText = await readFile(
join(codexHome, "config.toml"),
diff --git a/sdk/typescript/tests-ts/plugin-root.ts b/sdk/typescript/tests-ts/plugin-root.ts
index e92f12d4d..d2f9c8892 100644
--- a/sdk/typescript/tests-ts/plugin-root.ts
+++ b/sdk/typescript/tests-ts/plugin-root.ts
@@ -1,5 +1,12 @@
import { existsSync } from "node:fs";
-import { chmod, cp, readdir, readFile, writeFile } from "node:fs/promises";
+import {
+ chmod,
+ cp,
+ mkdir,
+ readdir,
+ readFile,
+ writeFile,
+} from "node:fs/promises";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { brotliDecompressSync } from "node:zlib";
@@ -11,6 +18,30 @@ const hasMonorepoSdk = existsSync(
export const PLUGIN_ROOT = fileURLToPath(bundledPlugin);
+// Credential tests run worker configuration and plugin refresh up to the Codex
+// client boundary, so copy the MCP descriptor and both platform launchers.
+export async function copyCredentialTestPlugin(root: string): Promise<string> {
+ const plugin = join(root, "plugin");
+ const manifest = ".codex-plugin/plugin.json";
+ const { name, version, skills, mcpServers, codexSecurity } = JSON.parse(
+ await readFile(new URL(manifest, bundledPlugin), "utf8"),
+ );
+ await mkdir(join(plugin, ".codex-plugin"), { recursive: true });
+ await writeFile(
+ join(plugin, manifest),
+ JSON.stringify({ name, version, skills, mcpServers, codexSecurity }),
+ );
+ for (const file of [
+ ".mcp.json",
+ "scripts/launch_codex_security_mcp",
+ "scripts/launch_codex_security_mcp.cmd",
+ "skills/security-scan/SKILL.md",
+ ]) {
+ await cp(new URL(file, bundledPlugin), join(plugin, file));
+ }
+ return plugin;
+}
+
export const INTEGRATION_TARGET = hasMonorepoSdk
? "project/codex-security-sdk/src"
: "sdk/typescript/src";