From 74d19b99c5586656bf0e665c570ca096ae902d8c Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Tue, 18 Aug 2026 10:26:16 +0100 Subject: [PATCH 1/4] fix(progress): ignore failed preflight commands --- sdk/typescript/src/worker-progress.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/typescript/src/worker-progress.ts b/sdk/typescript/src/worker-progress.ts index 83fa1242a..2150d2950 100644 --- a/sdk/typescript/src/worker-progress.ts +++ b/sdk/typescript/src/worker-progress.ts @@ -108,6 +108,8 @@ function preflightStatus( item: Readonly>, ): ScanWorkerStatus | null { if ( + item["status"] === "failed" || + (typeof item["exit_code"] === "number" && item["exit_code"] !== 0) || typeof item["command"] !== "string" || !PREFLIGHT_COMMAND.test(item["command"]) || typeof item["aggregated_output"] !== "string" From 44841664a8b09b67794370483242f74416ad2853 Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Tue, 18 Aug 2026 10:26:29 +0100 Subject: [PATCH 2/4] test(progress): reject failed preflight capability output --- .../tests-ts/worker-preflight-failure.test.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 sdk/typescript/tests-ts/worker-preflight-failure.test.ts diff --git a/sdk/typescript/tests-ts/worker-preflight-failure.test.ts b/sdk/typescript/tests-ts/worker-preflight-failure.test.ts new file mode 100644 index 000000000..76417c9b2 --- /dev/null +++ b/sdk/typescript/tests-ts/worker-preflight-failure.test.ts @@ -0,0 +1,39 @@ +import { expect, test } from "bun:test"; +import { workerStatusFromEvent } from "../src/worker-progress.js"; + +const output = JSON.stringify({ + profile: "security_scan", + status: "ready", + results: [ + { capability: "delegated_workers", status: "pass", actual: true }, + { capability: "usable_worker_slots_6", status: "pass", actual: 8 }, + ], +}); + +function event(overrides: Record) { + return { + type: "item.completed", + item: { + id: "preflight-1", + type: "command_execution", + command: "python3 /plugin/scripts/config_preflight.py --profile security_scan", + aggregated_output: output, + status: "completed", + exit_code: 0, + ...overrides, + }, + }; +} + +test("ignores capability output from explicitly failed preflight commands", () => { + expect(workerStatusFromEvent(event({ status: "failed" }))).toBeNull(); + expect(workerStatusFromEvent(event({ exit_code: 2 }))).toBeNull(); +}); + +test("keeps successful preflight capability output", () => { + expect(workerStatusFromEvent(event({}))).toEqual({ + kind: "preflight", + delegation: "available", + configuredSlots: 8, + }); +}); From c9f2abcba352e0a6c14b66d113cea658bc2509c9 Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Tue, 18 Aug 2026 11:41:56 +0100 Subject: [PATCH 3/4] fix(progress): preserve valid blocked preflight status --- sdk/typescript/src/worker-progress.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sdk/typescript/src/worker-progress.ts b/sdk/typescript/src/worker-progress.ts index 2150d2950..e83c240f2 100644 --- a/sdk/typescript/src/worker-progress.ts +++ b/sdk/typescript/src/worker-progress.ts @@ -109,7 +109,6 @@ function preflightStatus( ): ScanWorkerStatus | null { if ( item["status"] === "failed" || - (typeof item["exit_code"] === "number" && item["exit_code"] !== 0) || typeof item["command"] !== "string" || !PREFLIGHT_COMMAND.test(item["command"]) || typeof item["aggregated_output"] !== "string" @@ -130,6 +129,23 @@ function preflightStatus( ) { return null; } + const exitCode = item["exit_code"]; + if (typeof exitCode === "number") { + const expectedExitCode = + payload["status"] === "blocked" + ? 1 + : payload["status"] === "incomplete" + ? 2 + : payload["status"] === "ready" + ? 0 + : null; + if ( + (expectedExitCode !== null && exitCode !== expectedExitCode) || + (expectedExitCode === null && exitCode !== 0) + ) { + return null; + } + } const results = payload["results"]; const delegated = results.filter( (result): result is Record => From c33e6d3f6ed700c08d328303308473ea8d87c5d0 Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Tue, 18 Aug 2026 11:42:10 +0100 Subject: [PATCH 4/4] test(progress): cover preflight exit semantics --- .../tests-ts/worker-preflight-failure.test.ts | 53 +++++++++++++------ 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/sdk/typescript/tests-ts/worker-preflight-failure.test.ts b/sdk/typescript/tests-ts/worker-preflight-failure.test.ts index 76417c9b2..6155132a8 100644 --- a/sdk/typescript/tests-ts/worker-preflight-failure.test.ts +++ b/sdk/typescript/tests-ts/worker-preflight-failure.test.ts @@ -1,23 +1,25 @@ import { expect, test } from "bun:test"; import { workerStatusFromEvent } from "../src/worker-progress.js"; -const output = JSON.stringify({ - profile: "security_scan", - status: "ready", - results: [ - { capability: "delegated_workers", status: "pass", actual: true }, - { capability: "usable_worker_slots_6", status: "pass", actual: 8 }, - ], -}); +function output(status: "ready" | "blocked" | "incomplete" = "ready") { + return JSON.stringify({ + profile: "security_scan", + status, + results: [ + { capability: "delegated_workers", status: "pass", actual: true }, + { capability: "usable_worker_slots_6", status: "pass", actual: 8 }, + ], + }); +} -function event(overrides: Record) { +function event(overrides: Record = {}) { return { type: "item.completed", item: { id: "preflight-1", type: "command_execution", command: "python3 /plugin/scripts/config_preflight.py --profile security_scan", - aggregated_output: output, + aggregated_output: output(), status: "completed", exit_code: 0, ...overrides, @@ -25,15 +27,32 @@ function event(overrides: Record) { }; } -test("ignores capability output from explicitly failed preflight commands", () => { +const capability = { + kind: "preflight", + delegation: "available", + configuredSlots: 8, +} as const; + +test("ignores capability output from failed or contradictory preflight commands", () => { expect(workerStatusFromEvent(event({ status: "failed" }))).toBeNull(); expect(workerStatusFromEvent(event({ exit_code: 2 }))).toBeNull(); + expect( + workerStatusFromEvent( + event({ aggregated_output: output("blocked"), exit_code: 2 }), + ), + ).toBeNull(); }); -test("keeps successful preflight capability output", () => { - expect(workerStatusFromEvent(event({}))).toEqual({ - kind: "preflight", - delegation: "available", - configuredSlots: 8, - }); +test("keeps capability output from valid ready, blocked, and incomplete preflights", () => { + expect(workerStatusFromEvent(event())).toEqual(capability); + expect( + workerStatusFromEvent( + event({ aggregated_output: output("blocked"), exit_code: 1 }), + ), + ).toEqual(capability); + expect( + workerStatusFromEvent( + event({ aggregated_output: output("incomplete"), exit_code: 2 }), + ), + ).toEqual(capability); });