mirror of
https://github.com/morluto/rea.git
synced 2026-10-18 20:10:13 -05:00
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>
52 lines
1.5 KiB
TypeScript
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",
|
|
},
|
|
},
|
|
});
|
|
});
|