From 35eaf6052714ab70859b52b7ff885febe51a3b2f Mon Sep 17 00:00:00 2001 From: Merge_Conflict - Pasi Date: Tue, 18 Aug 2026 12:26:54 +0000 Subject: [PATCH] fix(cli): emit ok:false envelope for failed history commands --- sdk/typescript/src/cli.ts | 6 +++--- sdk/typescript/tests-ts/cli.test.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.ts index 5f7c03fd8..2cc840dd9 100644 --- a/sdk/typescript/src/cli.ts +++ b/sdk/typescript/src/cli.ts @@ -1136,13 +1136,13 @@ export async function main( args: readonly string[], select: (value: JsonObject) => JsonObject | Promise = (value) => value, - ): Promise => { + ): Promise => { try { return await select(await dependencies.runWorkbench(args)); } catch (error) { errorOutput.write(`codex-security: ${errorMessage(error)}\n`); exitCode = 2; - return undefined; + throw error; } }; const latestScans = async ( @@ -1534,7 +1534,7 @@ export async function main( } catch (error) { errorOutput.write(`codex-security: ${errorMessage(error)}\n`); exitCode = 2; - return undefined; + throw error; } }, }) diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.ts index 8d891cefb..fb4bed695 100644 --- a/sdk/typescript/tests-ts/cli.test.ts +++ b/sdk/typescript/tests-ts/cli.test.ts @@ -1163,6 +1163,32 @@ describe("CLI", () => { ); }); + test("does not emit an ok: true envelope for a failed structured history command", async () => { + for (const argv of [ + ["scans", "show", "--json"], + ["scans", "list", "--json"], + ["scans", "compare", "before", "after", "--json"], + ["scans", "match", "before", "after", "--json"], + ]) { + const stdout = capture(); + const stderr = capture(); + const result = await main(argv, stdout.stream, stderr.stream, { + ...dependencies({ + onWorkbench: () => { + throw new Error( + "Scan ID prefixes must be at least eight characters.", + ); + }, + }), + }); + expect(result).toBe(2); + expect(stdout.text()).toBe(""); + expect(stderr.text()).toContain( + "Scan ID prefixes must be at least eight characters.", + ); + } + }); + test("shows finding history and optionally reveals linked findings", async () => { const findings: JsonObject[] = [ {