OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix(cli): unify structured scan failure responses (#1080)
mldangelo-oaid8ccbb4f52b3
diff --git a/sdk/typescript/docs/cli.md b/sdk/typescript/docs/cli.mdindex fe94d7d54..acfbe3d89 100644--- a/sdk/typescript/docs/cli.md+++ b/sdk/typescript/docs/cli.md@@ -286,14 +286,22 @@ SARIF, when produced, is saved at `<scan-dir>/exports/results.sarif`.Scans are report-only by default. `--fail-on-severity high` exits with `1` forhigh or critical findings. Incomplete scans exit with `2`, returning available-results and a coverage warning. Runtime failures with JSON or JSONL output produce:+results and a coverage warning. `scan`, `scans rerun`, and `scans resume`+execution failures with `--json`, JSON, or JSONL output produce:```json{ "status": "failed", "code": "SCAN_FAILED", "message": "..." }```With `--full-output`, the error appears under `error` in an `ok: false` envelope.-Diagnostics stay on stderr. `scan --schema --format json` describes the output.+Saved-scan setup failures use the same output shape with+`SCAN_REPLAY_UNAVAILABLE` for `scans rerun` (including when no completed scan is+available) or `SCAN_RESUME_UNAVAILABLE` for `scans resume`. Rerunning an imported+scan uses `SCAN_IMPORT_FAILED` if the import fails. Other output formats retain+stderr-only failures, including when `--full-output` is selected.++Diagnostics stay on stderr. Each command's `--schema --format json` describes+its successful output and failure codes.See [Exports and CI](#exports-and-ci) for exit codes and CI examples.### Project filesdiff --git a/sdk/typescript/src/cli.ts b/sdk/typescript/src/cli.tsindex 1c7a5a141..f6f718d03 100644--- a/sdk/typescript/src/cli.ts+++ b/sdk/typescript/src/cli.ts@@ -1028,16 +1028,18 @@ interface ScanOutcome {error?: string;}-const scanOutputSchema = z- .union([- z.record(z.string(), z.unknown()),- z.object({- status: z.literal("failed"),- code: z.literal("SCAN_FAILED"),- message: z.string(),- }),- ])- .optional();+function scanOutputSchema(...codes: [string, ...string[]]) {+ return z+ .union([+ z.record(z.string(), z.unknown()),+ z.object({+ status: z.literal("failed"),+ code: z.literal(codes),+ message: z.string(),+ }),+ ])+ .optional();+}type ExportArguments = ArtifactExportArguments;@@ -1829,6 +1831,35 @@ export async function main(let renderedPatch: string | undefined;let patchStructuredError = false;let scanStructuredError = false;+ let filteredScanFailure:+ { format: string; data: Record<string, unknown> } | undefined;+ let renderedScanFailure: string | undefined;+ const finishScan = (+ outcome: ScanOutcome,+ format: string,+ incurError: (error: {+ code: string;+ message: string;+ exitCode: number;+ }) => never,+ code = "SCAN_FAILED",+ ): Record<string, unknown> | undefined => {+ exitCode = outcome.exitCode;+ if (outcome.error === undefined) return outcome.data;+ if (format === "json" || format === "jsonl") {+ const message = errorMessage(outcome.error);+ if (!argv.includes("--full-output")) {+ const data = { status: "failed", code, message };+ if (argv.some((argument) => /^--filter-output(?:=|$)/u.test(argument)))+ filteredScanFailure = { format, data };+ return data;+ }+ // Incur would wrap returned data in an ok: true envelope.+ scanStructuredError = true;+ return incurError({ code, message, exitCode });+ }+ return incurError({ code, message: outcome.error, exitCode });+ };const runImport = (options: ImportScanOptions) =>runScanImport(options, errorOutput, dependencies);const history = async (@@ -2215,8 +2246,8 @@ export async function main(.default(false).describe("Print additional scan diagnostics to stderr."),}),- output: z.record(z.string(), z.unknown()).optional(),- async run({ args, error: incurError, options }) {+ output: scanOutputSchema("SCAN_FAILED", "SCAN_RESUME_UNAVAILABLE"),+ async run({ args, error: incurError, format, options }) {let scanArguments: ScanArguments;try {const saved = await dependencies.runWorkbench([@@ -2256,23 +2287,15 @@ export async function main(} catch (error) {const message = errorMessage(error);errorOutput.write(`codex-security: ${message}\n`);- exitCode = 2;- return incurError({- code: "SCAN_RESUME_UNAVAILABLE",- message,- exitCode,- });+ return finishScan(+ { exitCode: 2, error: message },+ format,+ incurError,+ "SCAN_RESUME_UNAVAILABLE",+ );}const outcome = await runScan(scanArguments, errorOutput, dependencies);- exitCode = outcome.exitCode;- if (outcome.error !== undefined) {- return incurError({- code: "SCAN_FAILED",- message: outcome.error,- exitCode,- });- }- return outcome.data;+ return finishScan(outcome, format, incurError);},}).command("rerun", {@@ -2303,7 +2326,11 @@ export async function main(.default(false).describe("Print additional scan diagnostics to stderr."),}),- output: z.record(z.string(), z.unknown()).optional(),+ output: scanOutputSchema(+ "SCAN_FAILED",+ "SCAN_REPLAY_UNAVAILABLE",+ "SCAN_IMPORT_FAILED",+ ),async run({ args, error: incurError, format, options }) {if (format === "md") {errorOutput.write(@@ -2312,7 +2339,19 @@ export async function main(exitCode = 2;return;}- const scanId = args.scanId ?? (await latestScans())?.[0]?.scanId;+ let scanId: string | undefined;+ try {+ scanId = args.scanId ?? (await latestScans())?.[0]?.scanId;+ } catch (error) {+ const message = errorMessage(error);+ if (exitCode === 0) errorOutput.write(`codex-security: ${message}\n`);+ return finishScan(+ { exitCode: 2, error: message },+ format,+ incurError,+ "SCAN_REPLAY_UNAVAILABLE",+ );+ }if (scanId === undefined) return;let scanArguments: ScanArguments;try {@@ -2342,10 +2381,10 @@ export async function main(}const imported = recipe["import"];const sourcePath = imported["sourcePath"];- const format = imported["format"];+ const importFormat = imported["format"];if (!isNonEmptyString(sourcePath) ||- (format !== "csv" && format !== "json")+ (importFormat !== "csv" && importFormat !== "json")) {throw new CodexSecurityError("The saved scan recipe contains invalid import settings.",@@ -2353,18 +2392,15 @@ export async function main(}const outcome = await runImport({sourcePath,- format,+ format: importFormat,parentScanId,});- exitCode = outcome.exitCode;- if (outcome.error !== undefined) {- return incurError({- code: "SCAN_IMPORT_FAILED",- message: outcome.error,- exitCode,- });- }- return outcome.data;+ return finishScan(+ outcome,+ format,+ incurError,+ "SCAN_IMPORT_FAILED",+ );}scanArguments = await prepareScanArgumentsFromRecipe(recipe,@@ -2392,12 +2428,12 @@ export async function main(} catch (error) {const message = errorMessage(error);errorOutput.write(`codex-security: ${message}\n`);- exitCode = 2;- return incurError({- code: "SCAN_REPLAY_UNAVAILABLE",- message,- exitCode,- });+ return finishScan(+ { exitCode: 2, error: message },+ format,+ incurError,+ "SCAN_REPLAY_UNAVAILABLE",+ );}const outcome = await runScan(scanArguments,@@ -2405,15 +2441,7 @@ export async function main(dependencies,format !== "json" && format !== "jsonl",);- exitCode = outcome.exitCode;- if (outcome.error !== undefined) {- return incurError({- code: "SCAN_FAILED",- message: outcome.error,- exitCode,- });- }- return outcome.data;+ return finishScan(outcome, format, incurError);},}).command("match", {@@ -3554,7 +3582,7 @@ export async function main(message: "--mock cannot be combined with --dry-run or --patch.",},),- output: scanOutputSchema,+ output: scanOutputSchema("SCAN_FAILED"),async run({ args, error: incurError, format, options }) {if (format === "md") {errorOutput.write(@@ -3634,30 +3662,16 @@ export async function main(errorOutput.write(`${message}\n`);outcome = { exitCode: 2, error: message };}- exitCode = outcome.exitCode;- if (outcome.error !== undefined) {- if (format === "json" || format === "jsonl") {- const message = errorMessage(outcome.error);- if (!argv.includes("--full-output"))- return { status: "failed", code: "SCAN_FAILED", message };- // Incur would wrap returned data in an ok: true envelope.- scanStructuredError = true;- return incurError({ code: "SCAN_FAILED", message, exitCode });- }- return incurError({- code: "SCAN_FAILED",- message: outcome.error,- exitCode,- });- }if (+ outcome.error === undefined &&!options.dryRun &&format === "toon" &&!argv.some((argument) => OUTPUT_OPTION.test(argument))) {+ exitCode = outcome.exitCode;return;}- return outcome.data;+ return finishScan(outcome, format, incurError);},}).command("install-hook", {@@ -5803,6 +5817,34 @@ export async function main(} finally {updateController.abort();}+ if (filteredScanFailure !== undefined) {+ // Success-field filters do not apply to diagnostics. Reuse Incur's format+ // and token controls without running the saved scan a second time.+ const failureOutput = captureOutput();+ const failureArguments = ["render", "--format", filteredScanFailure.format];+ for (let index = 0; index < argv.length; index += 1) {+ const argument = argv[index]!;+ if (!/^--token-(?:count|limit|offset)(?:=|$)/u.test(argument)) continue;+ const separator = argument.indexOf("=");+ if (separator !== -1)+ failureArguments.push(+ argument.slice(0, separator),+ argument.slice(separator + 1),+ );+ else {+ failureArguments.push(argument);+ if (argument !== "--token-count") failureArguments.push(argv[++index]!);+ }+ }+ const failure = filteredScanFailure.data;+ await Cli.create("codex-security-scan-error")+ .command("render", { run: () => failure })+ .serve(failureArguments, {+ stdout: failureOutput.stream.write,+ exit: () => undefined,+ });+ renderedScanFailure = failureOutput.text();+ }const frameworkOutput = frameworkCapture.text();if (notice !== undefined) errorOutput.write(formatUpdateNotice(notice));if (frameworkExit !== undefined) {@@ -5816,7 +5858,11 @@ export async function main(return 2;}}- if (frameworkOutput.length === 0 && streamedLogs === undefined)+ if (+ frameworkOutput.length === 0 &&+ streamedLogs === undefined &&+ renderedScanFailure === undefined+ )return exitCode;try {// Incur can add a stale-skills CTA after the logs handler returns.@@ -5830,6 +5876,7 @@ export async function main(await writeCliOutput(output,logOutput ??+ renderedScanFailure ??renderedPolicy ??renderedPatch ??renderedPublication ??diff --git a/sdk/typescript/tests-ts/cli-scan-failures.test.ts b/sdk/typescript/tests-ts/cli-scan-failures.test.tsnew file mode 100644index 000000000..90def59cf--- /dev/null+++ b/sdk/typescript/tests-ts/cli-scan-failures.test.ts@@ -0,0 +1,438 @@+import { describe, expect, test } from "bun:test";+import { main } from "../src/cli.js";+import { CodexSecurityError } from "../src/index.js";+import {+ FakeSignals,+ capture,+ dependencies,+ fakePreflight,+ fakeResult,+} from "./cli-fixtures.js";++const commands = [+ ["scan", ["scan", "."]],+ ["rerun", ["scans", "rerun", "saved-scan"]],+ ["resume", ["scans", "resume", "saved-scan"]],+] as const;++function scanDependencies() {+ return dependencies({+ onWorkbench: () => ({+ scanId: "saved-scan",+ scanDir: "/tmp/saved-scan",+ recipe: {+ repository: "/original/repository",+ target: { kind: "repository", paths: [] },+ mode: "standard",+ config: {},+ },+ }),+ });+}++function failingScan(message: string, onRun?: () => void) {+ const deps = scanDependencies();+ deps.createSecurity = () => ({+ run: async () => {+ onRun?.();+ throw new CodexSecurityError(message);+ },+ preflight: async () => fakePreflight(),+ close: async () => {},+ });+ return deps;+}++function expectFailure(+ text: string,+ fullOutput: boolean,+ code: string,+ message: string,+) {+ const result = JSON.parse(text);+ if (fullOutput) {+ expect(result).toMatchObject({ ok: false, error: { code, message } });+ expect(result).not.toHaveProperty("data");+ } else {+ expect(result).toEqual({ status: "failed", code, message });+ }+}++for (const formatArgs of [+ ["--json"],+ ["--format", "json"],+ ["--format", "jsonl"],+]) {+ for (const fullOutput of [false, true]) {+ describe(`scan failures with ${formatArgs.join(" ")}${fullOutput ? " --full-output" : ""}`, () => {+ const flags = [...formatArgs, ...(fullOutput ? ["--full-output"] : [])];++ test.each(commands)(+ "formats %s execution failures consistently",+ async (_name, command) => {+ const stdout = capture();+ const stderr = capture();+ const message = "The scan could not save its results.";+ expect(+ await main(+ [...command, ...flags],+ stdout.stream,+ stderr.stream,+ failingScan(message),+ ),+ ).toBe(2);+ expectFailure(stdout.text(), fullOutput, "SCAN_FAILED", message);+ expect(stderr.text()).toContain(`${message}\n`);+ },+ );++ test.each([+ ["rerun", "SCAN_REPLAY_UNAVAILABLE"],+ ["resume", "SCAN_RESUME_UNAVAILABLE"],+ ])("preserves %s preparation failure codes", async (command, code) => {+ const stdout = capture();+ const stderr = capture();+ const message = "This scan does not have a saved launch recipe.";+ const deps = scanDependencies();+ deps.runWorkbench = async () => ({+ scanId: "saved-scan",+ scanDir: "/tmp/saved-scan",+ });+ expect(+ await main(+ ["scans", command, "saved-scan", ...flags],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(2);+ expectFailure(stdout.text(), fullOutput, code, message);+ expect(stderr.text()).toBe(`codex-security: ${message}\n`);+ });++ test("reports unavailable latest scans with the replay failure code", async () => {+ const stdout = capture();+ const stderr = capture();+ const deps = scanDependencies();+ deps.runWorkbench = async () => ({ scans: [] });+ expect(+ await main(+ ["scans", "rerun", ...flags],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(2);+ const message = "No completed scans found for the current repository.";+ expectFailure(+ stdout.text(),+ fullOutput,+ "SCAN_REPLAY_UNAVAILABLE",+ message,+ );+ expect(stderr.text()).toBe(`codex-security: ${message}\n`);+ });++ test.each(["csv", "json"])(+ "formats rerun failures independently of the %s import format",+ async (format) => {+ const stdout = capture();+ const stderr = capture();+ const message = "The saved import source is unavailable.";+ const deps = scanDependencies();+ deps.runWorkbench = async () => ({+ recipe: {+ import: { sourcePath: `/tmp/findings.${format}`, format },+ },+ });+ deps.importScan = async () => {+ throw new CodexSecurityError(message);+ };+ expect(+ await main(+ ["scans", "rerun", "saved-scan", ...flags],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(2);+ expectFailure(+ stdout.text(),+ fullOutput,+ "SCAN_IMPORT_FAILED",+ message,+ );+ expect(stderr.text()).toBe(`codex-security: ${message}\n`);+ },+ );++ test.each(commands)(+ "preserves diagnostic text for %s failures",+ async (_name, command) => {+ const stdout = capture();+ const stderr = capture();+ const message =+ "network failure ECONNRESET Bearer SYNTHETIC_TOKEN_123";+ expect(+ await main(+ [...command, ...flags],+ stdout.stream,+ stderr.stream,+ failingScan(message),+ ),+ ).toBe(2);+ expectFailure(stdout.text(), fullOutput, "SCAN_FAILED", message);+ expect(stderr.text()).toContain(message);+ },+ );+ });+ }+}++test.each(commands)(+ "preserves successful %s JSON output",+ async (_name, command) => {+ const stdout = capture();+ expect(+ await main(+ [...command, "--json"],+ stdout.stream,+ capture().stream,+ scanDependencies(),+ ),+ ).toBe(0);+ expect(JSON.parse(stdout.text())).toEqual(fakeResult().toJSON());+ },+);++test.each(commands)(+ "keeps non-JSON %s failures on stderr",+ async (_name, command) => {+ for (const flags of [[], ["--full-output"], ["--format", "yaml"]]) {+ const stdout = capture();+ const stderr = capture();+ const message = "The scan could not save its results.";+ expect(+ await main(+ [...command, ...flags],+ stdout.stream,+ stderr.stream,+ failingScan(message),+ ),+ ).toBe(2);+ expect(stdout.text()).toBe("");+ expect(stderr.text()).toContain(`${message}\n`);+ }+ },+);++test.each(commands)(+ "retains %s cancellation exit codes",+ async (_name, command) => {+ for (const [signal, exitCode, message] of [+ ["SIGINT", 130, "Scan canceled by Ctrl-C."],+ ["SIGTERM", 143, "Scan terminated by SIGTERM."],+ ] as const) {+ for (const fullOutput of [false, true]) {+ const stdout = capture();+ const signals = new FakeSignals();+ const deps = dependencies({+ signals,+ onRun: () => signals.emit(signal),+ });+ deps.runWorkbench = scanDependencies().runWorkbench;+ expect(+ await main(+ [...command, "--json", ...(fullOutput ? ["--full-output"] : [])],+ stdout.stream,+ capture().stream,+ deps,+ ),+ ).toBe(exitCode);+ expectFailure(stdout.text(), fullOutput, "SCAN_FAILED", message);+ }+ }+ },+);++test("retains diagnostics when the latest-scan working directory is unavailable", async () => {+ for (const flags of [[], ["--json"], ["--json", "--full-output"]]) {+ const stdout = capture();+ const stderr = capture();+ const deps = scanDependencies();+ const message = "The working directory is unavailable.";+ deps.currentDirectory = () => {+ throw new Error(message);+ };+ expect(+ await main(+ ["scans", "rerun", ...flags],+ stdout.stream,+ stderr.stream,+ deps,+ ),+ ).toBe(2);+ expect(stderr.text()).toBe(`codex-security: ${message}\n`);+ if (flags.length === 0) expect(stdout.text()).toBe("");+ else+ expectFailure(+ stdout.text(),+ flags.includes("--full-output"),+ "SCAN_REPLAY_UNAVAILABLE",+ message,+ );+ }+});++test.each([+ [["scan"], ["SCAN_FAILED"]],+ [+ ["scans", "rerun"],+ ["SCAN_FAILED", "SCAN_REPLAY_UNAVAILABLE", "SCAN_IMPORT_FAILED"],+ ],+ [+ ["scans", "resume"],+ ["SCAN_FAILED", "SCAN_RESUME_UNAVAILABLE"],+ ],+])(+ "documents failure codes in the %j output schema",+ async (command, codes) => {+ const stdout = capture();+ expect(+ await main(+ [...command, "--schema", "--json"],+ stdout.stream,+ capture().stream,+ dependencies(),+ ),+ ).toBe(0);+ const schema = JSON.parse(stdout.text());+ const failure = schema.output.anyOf.find(+ (variant: { properties?: { status?: { const?: string } } }) =>+ variant.properties?.status?.const === "failed",+ );+ expect(failure.required).toEqual(["status", "code", "message"]);+ expect(+ failure.properties.code.enum ?? [failure.properties.code.const],+ ).toEqual(codes);+ },+);++test.each(commands.slice(1))(+ "preserves diagnostics and token controls for filtered %s failures",+ async (_name, command) => {+ const message =+ "Synthetic saved scan failure with its complete diagnostic.";+ for (const formatArgs of [["--json"], ["--format", "jsonl"]]) {+ for (const tokens of [+ [],+ ["--token-count"],+ ["--token-limit", "4"],+ ["--token-offset=4", "--token-limit=4"],+ ]) {+ const reference = capture();+ expect(+ await main(+ [...command, ...formatArgs, ...tokens],+ reference.stream,+ capture().stream,+ failingScan(message),+ ),+ ).toBe(2);+ for (const filter of [+ ["--filter-output", "manifest,findings"],+ ["--filter-output=manifest,findings"],+ ["--filter-output", "findings"],+ ["--filter-output=manifest"],+ ]) {+ const stdout = capture();+ const stderr = capture();+ let runs = 0;+ expect(+ await main(+ [...command, ...formatArgs, ...filter, ...tokens],+ stdout.stream,+ stderr.stream,+ failingScan(message, () => runs++),+ ),+ ).toBe(2);+ expect(runs).toBe(1);+ expect(stdout.text()).toBe(reference.text());+ expect(stderr.text()).toContain(message);+ }+ }+ }+ },+);++test.each(["rerun", "resume"])(+ "preserves filtered %s preparation failures",+ async (command) => {+ const stdout = capture();+ const deps = scanDependencies();+ deps.runWorkbench = async () => ({+ scanId: "saved-scan",+ scanDir: "/tmp/saved-scan",+ });+ expect(+ await main(+ [+ "scans",+ command,+ "saved-scan",+ "--json",+ "--filter-output",+ "manifest,findings",+ ],+ stdout.stream,+ capture().stream,+ deps,+ ),+ ).toBe(2);+ expectFailure(+ stdout.text(),+ false,+ command === "rerun"+ ? "SCAN_REPLAY_UNAVAILABLE"+ : "SCAN_RESUME_UNAVAILABLE",+ "This scan does not have a saved launch recipe.",+ );+ },+);++test.each(commands.slice(1))(+ "preserves success filtering and full error envelopes for %s",+ async (_name, command) => {+ const success = capture();+ expect(+ await main(+ [...command, "--json", "--filter-output", "manifest,findings"],+ success.stream,+ capture().stream,+ scanDependencies(),+ ),+ ).toBe(0);+ const original = fakeResult().toJSON();+ expect(JSON.parse(success.text())).toEqual({+ manifest: original["manifest"],+ findings: original["findings"],+ });+ const failure = capture();+ const message = "Synthetic full envelope failure.";+ expect(+ await main(+ [+ ...command,+ "--json",+ "--full-output",+ "--filter-output",+ "manifest,findings",+ ],+ failure.stream,+ capture().stream,+ failingScan(message),+ ),+ ).toBe(2);+ expectFailure(failure.text(), true, "SCAN_FAILED", message);+ },+);diff --git a/sdk/typescript/tests-ts/finding-workflow-integration.test.ts b/sdk/typescript/tests-ts/finding-workflow-integration.test.tsindex 34a9649cd..82eaf50c5 100644--- a/sdk/typescript/tests-ts/finding-workflow-integration.test.ts+++ b/sdk/typescript/tests-ts/finding-workflow-integration.test.ts@@ -483,7 +483,7 @@ test.each(["screen", "pair"])(const { scanDir, environment, document, history } = await fixture();const findings = [document.findings[0]!,- ...[1, 2, 3].map((index) => ({+ ...[1, 2].map((index) => ({...structuredClone(document.findings[0]!),findingId: `csf_${"f".repeat(23)}${index}`,title: `Synthetic original ${index}`,@@ -528,7 +528,7 @@ test.each(["screen", "pair"])(),}: originals.some(- (finding) => finding.findingId === findings[3]!.findingId,+ (finding) => finding.findingId === findings[2]!.findingId,)? distinct: merged(originals),@@ -560,13 +560,13 @@ test.each(["screen", "pair"])(fetch,});expect(result.duplicateGroups).toEqual([- findings.slice(0, 3).map((finding) => finding.findingId),+ findings.slice(0, 2).map((finding) => finding.findingId),]);expect(calls.filter((stage) => stage === "screen")).toHaveLength(interruptAt === "screen" ? 2 : 1,);expect(calls.filter((stage) => stage === "pair")).toHaveLength(- interruptAt === "pair" ? 4 : 3,+ interruptAt === "pair" ? 3 : 2,);const count = calls.length;expect(@@ -584,7 +584,7 @@ test.each(["screen", "pair"])(test.each(["screening", "pair-review"] as const)("drains concurrent %s checkpoints after failure and resumes with different concurrency",async (failedStage) => {- const { environment, document, history } = await fixtureWithFindings(4);+ const { environment, document, history } = await fixtureWithFindings(3);const options = {workflowId: `concurrent-${failedStage}`,findingsUrl: "http://synthetic.test",@@ -687,7 +687,7 @@ test.each(["screening", "pair-review"] as const)(expect(groupWrites).toHaveBeenCalledTimes(1);expect(attempts.get(interruptedKeys[0]!)).toBe(2);expect(attempts.get(interruptedKeys[1]!)).toBe(1);- expect(attempts.size).toBe(10);+ expect(attempts.size).toBe(6);for (const [key, count] of attempts)expect(count).toBe(key === interruptedKeys[0] ? 2 : 1);expect(