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(dedupe): do not report a successful envelope for a failed dedupe (#1071)

Merge_Conflict - Pasi26e07e4fedf4
diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts
index 46fc3a242..2e6cfc165 100644
--- a/sdk/typescript/src/cli.ts
+++ b/sdk/typescript/src/cli.ts
@@ -4190,7 +4190,7 @@ export async function main(
}\n`,
);
exitCode = interruptedExitCode(controller.signal) ?? 2;
- return undefined;
+ throw error;
} finally {
removeSignals();
}
diff --git a/sdk/typescript/tests-ts/cli-dedupe.test.ts b/sdk/typescript/tests-ts/cli-dedupe.test.ts
index ade687cb9..544bc495d 100644
--- a/sdk/typescript/tests-ts/cli-dedupe.test.ts
+++ b/sdk/typescript/tests-ts/cli-dedupe.test.ts
@@ -322,27 +322,88 @@ test("dedupe defaults to local storage without a findings URL", async () => {
).toBe(0);
});
-test("dedupe forwards cancellation and removes signal handlers", async () => {
- for (const [signal, expectedCode] of [
- ["SIGINT", 130],
- ["SIGTERM", 143],
- ] as const) {
- const signals = new FakeSignals();
- const deps = dependencies();
- deps.addSignalListener = (name, listener) => signals.add(name, listener);
- deps.removeSignalListener = (name, listener) =>
- signals.remove(name, listener);
- deps.deduplicateScan = async (_scanId, options) => {
- signals.emit(signal);
- options.signal!.throwIfAborted();
- throw new Error("Cancellation must throw");
- };
- const { stdout, stderr, runCli } = createCliTest(main);
-
- expect(await runCli(args, deps)).toBe(expectedCode);
+test.each([
+ ["local", [], "requires --scan or --workflow-id"],
+ [
+ "service",
+ ["--findings-url", "http://127.0.0.1:3000"],
+ "requires --scan or --workflow-id",
+ ],
+])(
+ "dedupe does not emit an ok: true envelope when a scan is missing: %s",
+ async (_label, flags, expected) => {
+ const { stdout, stderr } = createCliTest(main);
+ expect(
+ await main(
+ ["dedupe", ...flags, "--json", "--full-output"],
+ stdout.stream,
+ stderr.stream,
+ dependencies(),
+ ),
+ ).toBe(2);
expect(stdout.text()).toBe("");
- expect(stderr.text()).toContain("Deduplication canceled");
- expect(signals.listeners.get("SIGINT")?.size).toBe(0);
- expect(signals.listeners.get("SIGTERM")?.size).toBe(0);
- }
+ expect(stderr.text()).toContain(expected);
+ },
+);
+
+test("dedupe does not emit an ok: true envelope for a failed structured dedupe run", async () => {
+ const deps = dependencies();
+ deps.deduplicateScan = async () => {
+ throw new Error("Finding has not been indexed");
+ };
+ const { stdout, stderr } = createCliTest(main);
+ expect(
+ await main([...args, "--full-output"], stdout.stream, stderr.stream, deps),
+ ).toBe(2);
+ expect(stdout.text()).toBe("");
+ expect(stderr.text()).toContain("Finding has not been indexed");
});
+
+test.each([
+ ["JSON", ["--json"]],
+ ["JSON full output", ["--json", "--full-output"]],
+ ["JSONL full output", ["--format", "jsonl", "--full-output"]],
+])(
+ "dedupe forwards cancellation and removes signal handlers: %s",
+ async (_label, outputFlags) => {
+ for (const [signal, expectedCode] of [
+ ["SIGINT", 130],
+ ["SIGTERM", 143],
+ ] as const) {
+ for (const [findingsFlags, expectedDiagnostic] of [
+ [
+ [],
+ "Deduplication canceled. Completed local preparation is saved for retry.",
+ ],
+ [
+ ["--findings-url", "http://127.0.0.1:3000"],
+ "Deduplication canceled. Findings are unchanged.",
+ ],
+ ] as const) {
+ const signals = new FakeSignals();
+ const deps = dependencies();
+ deps.addSignalListener = (name, listener) =>
+ signals.add(name, listener);
+ deps.removeSignalListener = (name, listener) =>
+ signals.remove(name, listener);
+ deps.deduplicateScan = async (_scanId, options) => {
+ signals.emit(signal);
+ options.signal!.throwIfAborted();
+ throw new Error("Cancellation must throw");
+ };
+ const { stdout, stderr, runCli } = createCliTest(main);
+
+ expect(
+ await runCli(
+ ["dedupe", "--scan", "latest", ...findingsFlags, ...outputFlags],
+ deps,
+ ),
+ ).toBe(expectedCode);
+ expect(stdout.text()).toBe("");
+ expect(stderr.text()).toBe(`codex-security: ${expectedDiagnostic}\n`);
+ expect(signals.listeners.get("SIGINT")?.size).toBe(0);
+ expect(signals.listeners.get("SIGTERM")?.size).toBe(0);
+ }
+ }
+ },
+);