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>
75 lines
2.4 KiB
TypeScript
75 lines
2.4 KiB
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import { finishAnalysisCommand } from "../../../src/cli/finishAnalysisCommand.js";
|
|
import { AnalysisOutputError } from "../../../src/domain/analysisErrorCore.js";
|
|
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
|
import { ProviderCleanupError } from "../../../src/domain/providerCleanupError.js";
|
|
import { err, ok } from "../../../src/domain/result.js";
|
|
import { scriptCaptureEvidenceFixture } from "../../fixtures/webScriptCapture.js";
|
|
|
|
it("preserves producer-owned cleanup failure when service close does not resolve it", async () => {
|
|
const evidence = scriptCaptureEvidenceFixture();
|
|
const failure = new ProviderCleanupError(
|
|
"fixture-provider",
|
|
["producer-owned-resource"],
|
|
{ reason: "producer cleanup was not confirmed" },
|
|
{ operation: "inspect_web_page", partialObservation: evidence },
|
|
);
|
|
const expected = projectAnalysisError(failure);
|
|
const result = await finishAnalysisCommand(
|
|
async () => err(failure),
|
|
{ close: async () => {} },
|
|
"fixture-provider",
|
|
"inspect_web_page",
|
|
new AbortController().signal,
|
|
);
|
|
|
|
expect(result).toEqual(expected);
|
|
expect(failure.cleanupIncomplete).toBe(true);
|
|
});
|
|
|
|
it("returns completed partial Evidence when cancellation arrives during close", async () => {
|
|
const evidence = scriptCaptureEvidenceFixture();
|
|
const controller = new AbortController();
|
|
const result = await finishAnalysisCommand(
|
|
async () => ok(evidence),
|
|
{
|
|
close: async () => {
|
|
controller.abort(new Error("cancelled during close"));
|
|
},
|
|
},
|
|
"fixture-provider",
|
|
"capture_browser_scenario",
|
|
controller.signal,
|
|
);
|
|
|
|
expect(result).toMatchObject({
|
|
code: "cancelled",
|
|
details: { partial_observation: { evidence_id: evidence.evidence_id } },
|
|
});
|
|
});
|
|
|
|
it("preserves the primary operation error when cancellation arrives during close", async () => {
|
|
const controller = new AbortController();
|
|
const result = await finishAnalysisCommand(
|
|
async () =>
|
|
err(new AnalysisOutputError("inspect_web_page", "primary failure")),
|
|
{
|
|
close: async () => {
|
|
controller.abort();
|
|
},
|
|
},
|
|
"fixture-provider",
|
|
"inspect_web_page",
|
|
controller.signal,
|
|
);
|
|
|
|
expect(result).toMatchObject({
|
|
code: "unreadable_output",
|
|
details: {
|
|
reason: "primary failure",
|
|
operation: "inspect_web_page",
|
|
},
|
|
});
|
|
});
|