test(wasm): reuse inspect provider fixtures (#16052)

This commit is contained in:
Vincent Koc
2026-12-03 01:05:32 +08:00
committed by GitHub
parent 867dd60c2d
commit 6f7068642e
@@ -11,6 +11,11 @@ import {
} from "../../../tests/fixtures/wasm/artifact.js";
import { ok } from "../../domain/result.js";
import { createAnalysisProfile } from "../../domain/analysisProfile.js";
import type { WasmArtifactPort } from "../../ports/wasm/WasmArtifactPort.js";
const serviceWithInspect = (inspect: WasmArtifactPort["inspect"]) =>
new WasmArtifactService({ close: () => Promise.resolve(), inspect });
it.each([
{ path: "relative" },
{ path: "/module", glue_paths: ["relative"] },
@@ -33,11 +38,8 @@ it.each([
})),
),
])("rejects invalid selection before effects: %j", async (input) => {
const service = new WasmArtifactService({
close: () => Promise.resolve(),
inspect: () => {
throw new Error("Must not execute");
},
const service = serviceWithInspect(() => {
throw new Error("Must not execute");
});
expect(await service.inspect(input)).toMatchObject({
ok: false,
@@ -46,11 +48,8 @@ it.each([
});
it("reports the path count that admits every oversized selection field", async () => {
const service = new WasmArtifactService({
close: () => Promise.resolve(),
inspect: () => {
throw new Error("Must not execute");
},
const service = serviceWithInspect(() => {
throw new Error("Must not execute");
});
expect(
await service.inspect({
@@ -71,12 +70,9 @@ it("reports the path count that admits every oversized selection field", async (
it("preserves the selected command budget in provider input and Evidence", async () => {
const value = wasmArtifactFixture();
value.tool_profile.timeout_ms = 42_000;
const service = new WasmArtifactService({
close: () => Promise.resolve(),
inspect: async (input) => {
expect(input).toMatchObject({ command_timeout_ms: 42_000 });
return ok(wasmArtifactExecution(value));
},
const service = serviceWithInspect(async (input) => {
expect(input).toMatchObject({ command_timeout_ms: 42_000 });
return ok(wasmArtifactExecution(value));
});
const result = await service.inspect({
path: value.artifact.path,
@@ -91,10 +87,9 @@ it.each([{ command_timeout_ms: 42_000 }, { max_output_bytes: 1024 }])(
"rejects a provider report that silently changes the selected budget: %j",
async (selection) => {
const value = wasmArtifactFixture();
const service = new WasmArtifactService({
close: () => Promise.resolve(),
inspect: async () => ok(wasmArtifactExecution(value)),
});
const service = serviceWithInspect(async () =>
ok(wasmArtifactExecution(value)),
);
expect(
await service.inspect({
path: value.artifact.path,
@@ -111,24 +106,22 @@ it.each(["path", "subject-path", "digest", "wat", "candidates", "glue"])(
if (problem === "wat") value.wat.sha256 = "b".repeat(64);
if (problem === "candidates") value.candidates = [];
const execution = wasmArtifactExecution(value);
const service = new WasmArtifactService({
close: () => Promise.resolve(),
inspect: () =>
Promise.resolve(
ok({
...execution,
subject: {
path:
problem === "subject-path"
? "/different"
: "/artifacts/module.wasm",
format: "file",
sha256:
problem === "digest" ? "b".repeat(64) : value.artifact.sha256,
},
}),
),
});
const service = serviceWithInspect(() =>
Promise.resolve(
ok({
...execution,
subject: {
path:
problem === "subject-path"
? "/different"
: "/artifacts/module.wasm",
format: "file",
sha256:
problem === "digest" ? "b".repeat(64) : value.artifact.sha256,
},
}),
),
);
expect(
await service.inspect({
path: "/artifacts/module.wasm",
@@ -140,12 +133,9 @@ it.each(["path", "subject-path", "digest", "wat", "candidates", "glue"])(
it("cancels before provider work and delivers observed Evidence on success", async () => {
const value = wasmArtifactFixture();
let calls = 0;
const service = new WasmArtifactService({
close: () => Promise.resolve(),
inspect: () => {
calls++;
return Promise.resolve(ok(wasmArtifactExecution(value)));
},
const service = serviceWithInspect(() => {
calls++;
return Promise.resolve(ok(wasmArtifactExecution(value)));
});
const controller = new AbortController();
const reason = Object.freeze({ requested: "wasm-stop" });
@@ -183,17 +173,14 @@ it.each([false, true])(
limited_directions: ["callers", "callees"] as ["callers", "callees"],
} as const;
const controller = new AbortController();
const service = new WasmArtifactService({
close: () => Promise.resolve(),
inspect: async () => {
if (cancel) controller.abort();
return ok({
...execution,
rawResult: { stdout: "retained command output" },
analysisProfile: profile,
relationshipCoverage: coverage,
});
},
const service = serviceWithInspect(async () => {
if (cancel) controller.abort();
return ok({
...execution,
rawResult: { stdout: "retained command output" },
analysisProfile: profile,
relationshipCoverage: coverage,
});
});
const result = await service.inspect(
@@ -220,12 +207,9 @@ it("preserves malformed-output failure when cancellation arrives with it", async
const value = wasmArtifactFixture();
const controller = new AbortController();
const malformed = { ...wasmArtifactExecution(value), result: {} };
const service = new WasmArtifactService({
close: () => Promise.resolve(),
inspect: async () => {
controller.abort();
return ok(malformed);
},
const service = serviceWithInspect(async () => {
controller.abort();
return ok(malformed);
});
expect(
@@ -243,12 +227,9 @@ it("gives cancellation precedence over malformed raw input", async () => {
const controller = new AbortController();
controller.abort();
let calls = 0;
const service = new WasmArtifactService({
close: () => Promise.resolve(),
inspect: () => {
calls++;
return Promise.resolve(ok(wasmArtifactExecution()));
},
const service = serviceWithInspect(() => {
calls++;
return Promise.resolve(ok(wasmArtifactExecution()));
});
const malformed = { path: "relative.wasm" };
expect(
@@ -307,10 +288,9 @@ it("uses runtime defaults only for omitted budgets, preserving explicit input an
it("replays imported rebound WASM Evidence in views and comparisons", async () => {
const report = wasmArtifactFixture();
const service = new WasmArtifactService({
close: () => Promise.resolve(),
inspect: async () => ok(wasmArtifactExecution(report)),
});
const service = serviceWithInspect(async () =>
ok(wasmArtifactExecution(report)),
);
const completed = await service.inspect({ path: report.artifact.path });
if (!completed.ok) throw completed.error;
const rebound = rebindEvidenceToTargetPath(completed.value, {