Files
rea/tests/boundary/cli/wasmLateCancellationCli.test.ts
T
morlutoandTapraj-Pathak 279c590ef6 fix(cli): require cancellation through command finalization
Adapt the forwarding proposal in #4652 with a required signal before optional resource diagnostics. Migrate all callers and cover actual command registration during final close. Refs #4939.

Co-authored-by: Tapraj-Pathak <165466587+Tapraj-Pathak@users.noreply.github.com>
2026-10-18 09:48:11 +08:00

52 lines
1.5 KiB
TypeScript

import { EventEmitter } from "node:events";
import { expect, it } from "vitest";
import { WasmArtifactService } from "../../../src/application/wasm/WasmArtifactService.js";
import { withCommandCancellation } from "../../../src/cli/commandCancellation.js";
import { finishAnalysisCommand } from "../../../src/cli/finishAnalysisCommand.js";
import { ok } from "../../../src/domain/result.js";
import {
wasmArtifactExecution,
wasmArtifactFixture,
} from "../../fixtures/wasm/artifact.js";
it("delivers cancellation with completed WASM Evidence through the CLI boundary", async () => {
const value = wasmArtifactFixture();
const events = new EventEmitter();
const service = new WasmArtifactService({
close: () => Promise.resolve(),
inspect: async (_input, options) => {
await new Promise<void>((resolve) =>
options?.signal?.addEventListener("abort", () => resolve(), {
once: true,
}),
);
return ok(wasmArtifactExecution(value));
},
});
const command = withCommandCancellation(
(signal) =>
finishAnalysisCommand(
() => service.inspect({ path: value.artifact.path }, { signal }),
service,
"wabt-artifact",
"inspect_wasm_artifact",
signal,
),
{
on: events.on.bind(events),
off: events.off.bind(events),
},
);
events.emit("SIGINT");
await expect(command).resolves.toMatchObject({
code: "cancelled",
details: {
partial_observation: {
normalized_result: value,
confidence: "observed",
},
},
});
});