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(api): share prepared runtime fixtures (#405)

mldangelo-oaid48339ace1a1
diff --git a/sdk/typescript/tests-ts/api-post-scan.test.ts b/sdk/typescript/tests-ts/api-post-scan.test.ts
index c80d24653..c60563558 100644
--- a/sdk/typescript/tests-ts/api-post-scan.test.ts
+++ b/sdk/typescript/tests-ts/api-post-scan.test.ts
@@ -4,10 +4,10 @@ import { dirname, join } from "node:path";
import type { ThreadEvent } from "@openai/codex-sdk";
import { afterEach, describe, expect, test } from "bun:test";
import { CodexSecurity } from "../src/index.js";
-import { PLUGIN_ROOT } from "./plugin-root.js";
import {
completedEvents,
createApiTestFixtures,
+ preparedRuntime,
} from "./support/api-events.js";
const { cleanup, copyCompletedScan, temporaryDirectory } =
@@ -20,22 +20,6 @@ const TestClient = CodexSecurity as unknown as new (
dependencies: Record<string, unknown>,
) => CodexSecurity;
-function preparedRuntime(codexHome: string): Record<string, unknown> {
- return {
- codexHome,
- plugin: {
- pluginRoot: PLUGIN_ROOT,
- marketplaceRoot: PLUGIN_ROOT,
- installedRoot: PLUGIN_ROOT,
- marketplaceName: "codex-security-sdk",
- name: "codex-security",
- version: "0.1.0",
- },
- environment: {},
- credentialsAvailable: true,
- };
-}
-
function runWorkbench(_options: unknown, args: readonly string[]) {
if (args[0] === "register-cli-scan") {
return Promise.resolve({
diff --git a/sdk/typescript/tests-ts/api-surface.test.ts b/sdk/typescript/tests-ts/api-surface.test.ts
index c8710bbd4..96face64c 100644
--- a/sdk/typescript/tests-ts/api-surface.test.ts
+++ b/sdk/typescript/tests-ts/api-surface.test.ts
@@ -3,10 +3,10 @@ import { join } from "node:path";
import type { CodexOptions } from "@openai/codex-sdk";
import { afterEach, describe, expect, test } from "bun:test";
import { CodexSecurity } from "../src/index.js";
-import { PLUGIN_ROOT } from "./plugin-root.js";
import {
completedEvents,
createApiTestFixtures,
+ preparedRuntime,
} from "./support/api-events.js";
const fixtures = createApiTestFixtures();
@@ -20,22 +20,6 @@ afterEach(async () => {
await fixtures.cleanup();
});
-function preparedRuntime(codexHome: string): Record<string, unknown> {
- return {
- codexHome,
- plugin: {
- pluginRoot: PLUGIN_ROOT,
- marketplaceRoot: PLUGIN_ROOT,
- installedRoot: PLUGIN_ROOT,
- marketplaceName: "codex-security-sdk",
- name: "codex-security",
- version: "0.1.0",
- },
- environment: {},
- credentialsAvailable: true,
- };
-}
-
function mockWorkbench(args: readonly string[]) {
if (args[0] === "register-cli-scan") {
return {
diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.ts
index b65865d2c..c6feff274 100644
--- a/sdk/typescript/tests-ts/api.test.ts
+++ b/sdk/typescript/tests-ts/api.test.ts
@@ -52,6 +52,7 @@ import {
import { normalizeTarget } from "../src/targets.js";
import { SYNTHETIC_CREDENTIALS } from "./cli-fixtures.js";
import { INTEGRATION_TARGET, PLUGIN_ROOT } from "./plugin-root.js";
+import { preparedRuntime } from "./support/api-events.js";
import { runMockInSubprocess } from "./support/isolated-mock.js";
type ScanObserverName = Parameters<
@@ -268,22 +269,6 @@ async function* completedEvents(): AsyncGenerator<ThreadEvent> {
};
}
-function preparedRuntime(codexHome: string): Record<string, unknown> {
- return {
- codexHome,
- plugin: {
- pluginRoot: PLUGIN_ROOT,
- marketplaceRoot: PLUGIN_ROOT,
- installedRoot: PLUGIN_ROOT,
- marketplaceName: "codex-security-sdk",
- name: "codex-security",
- version: "0.1.0",
- },
- environment: {},
- credentialsAvailable: true,
- };
-}
-
describe("CodexSecurity orchestration", () => {
test("distinguishes local workbench and database errors from model transport failures", () => {
for (const message of [
diff --git a/sdk/typescript/tests-ts/support/api-events.ts b/sdk/typescript/tests-ts/support/api-events.ts
index c1de5c7d0..a73f8aa0e 100644
--- a/sdk/typescript/tests-ts/support/api-events.ts
+++ b/sdk/typescript/tests-ts/support/api-events.ts
@@ -6,6 +6,22 @@ import { runScanEvents } from "../../src/api.js";
import type { ScanOptions } from "../../src/index.js";
import { PLUGIN_ROOT } from "../plugin-root.js";
+export function preparedRuntime(codexHome: string): Record<string, unknown> {
+ return {
+ codexHome,
+ plugin: {
+ pluginRoot: PLUGIN_ROOT,
+ marketplaceRoot: PLUGIN_ROOT,
+ installedRoot: PLUGIN_ROOT,
+ marketplaceName: "codex-security-sdk",
+ name: "codex-security",
+ version: "0.1.0",
+ },
+ environment: {},
+ credentialsAvailable: true,
+ };
+}
+
export type ScanObserverName = Parameters<
NonNullable<ScanOptions["onObserverError"]>
>[0];