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

fix: support stdin in workbench commands (#500)

faizan-oai4fbc859d84a9
diff --git a/sdk/typescript/src/runtime.ts b/sdk/typescript/src/runtime.ts
index 758949782..1a18cfbcb 100644
--- a/sdk/typescript/src/runtime.ts
+++ b/sdk/typescript/src/runtime.ts
@@ -1360,33 +1360,39 @@ export async function preparePersistentOutputRoot(
export async function runWorkbench(
options: WorkbenchCommandOptions,
args: readonly string[],
+ input?: string,
): Promise<JsonObject> {
let stdout: string;
try {
- ({ stdout } = await execFile(
- options.python,
+ const environment = Object.fromEntries(
+ Object.entries(options.environment).filter(
+ ([name]) =>
+ name.toUpperCase() !== "OPENAI_API_KEY" &&
+ name.toUpperCase() !== "CODEX_API_KEY" &&
+ name.toUpperCase() !== "OPENROUTER_API_KEY" &&
+ name.toUpperCase() !== "FIREWORKS_API_KEY",
+ ),
+ );
+ const result = await runCodexCommand(
+ { command: options.python },
[
"-I",
"-B",
join(options.pluginRoot, "scripts", "workbench_db.py"),
...args,
],
- {
- env: Object.fromEntries(
- Object.entries(options.environment).filter(
- ([name]) =>
- name.toUpperCase() !== "OPENAI_API_KEY" &&
- name.toUpperCase() !== "CODEX_API_KEY" &&
- name.toUpperCase() !== "OPENROUTER_API_KEY" &&
- name.toUpperCase() !== "FIREWORKS_API_KEY",
- ),
- ),
- encoding: "utf8",
- maxBuffer: Infinity,
- windowsHide: true,
- signal: options.signal,
- },
- ));
+ environment,
+ input,
+ options.signal,
+ );
+ if (!result.success) {
+ throw new Error(
+ result.stderr.trim() ||
+ result.stdout.trim() ||
+ `Workbench exited with status ${result.exitCode}.`,
+ );
+ }
+ stdout = result.stdout;
} catch (error) {
if (options.signal?.aborted) throw error;
const detail = processErrorDetail(error);
diff --git a/sdk/typescript/tests-ts/runtime.test.ts b/sdk/typescript/tests-ts/runtime.test.ts
index 423039d73..34a120b29 100644
--- a/sdk/typescript/tests-ts/runtime.test.ts
+++ b/sdk/typescript/tests-ts/runtime.test.ts
@@ -3893,7 +3893,8 @@ describe("runtime directories and plugin Python boundary", () => {
"assert os.environ.get('CODEX_API_KEY') is None",
"assert os.environ.get('OPENROUTER_API_KEY') is None",
"assert os.environ.get('FIREWORKS_API_KEY') is None",
- "print(json.dumps({'ok': True, 'details': 'x' * (5 * 1024 * 1024)}))",
+ "payload = sys.stdin.read()",
+ "print(json.dumps({'ok': True, 'inputLength': len(payload), 'details': 'x' * (5 * 1024 * 1024)}))",
].join("\n"),
);
const python = Bun.which("python3") ?? Bun.which("python");
@@ -3911,8 +3912,10 @@ describe("runtime directories and plugin Python boundary", () => {
},
},
["test-command"],
+ "x".repeat(64 * 1024),
);
expect(result["ok"]).toBe(true);
+ expect(result["inputLength"]).toBe(64 * 1024);
expect(result["details"]).toHaveLength(5 * 1024 * 1024);
});