diff --git a/src/application/nuget/NugetNupkgService.test.ts b/src/application/nuget/NugetNupkgService.test.ts index f1828fc52b2..8d68e7892b8 100644 --- a/src/application/nuget/NugetNupkgService.test.ts +++ b/src/application/nuget/NugetNupkgService.test.ts @@ -1,11 +1,9 @@ +import { lateCancellationEvidence } from "../../../tests/support/lateCancellationEvidence.js"; import { expect, it } from "vitest"; import { NugetNupkgService } from "./NugetNupkgService.js"; import type { NugetNupkg } from "../../domain/nuget/nupkg.js"; import { ok } from "../../domain/result.js"; -import { - AnalysisCancelledError, - AnalysisInputError, -} from "../../domain/analysisErrorCore.js"; +import { AnalysisInputError } from "../../domain/analysisErrorCore.js"; const identity = { id: "fixture-nuget-nupkg", @@ -88,28 +86,15 @@ it("rejects a relative path and extra arguments before reading", async () => { }); it("retains completed Evidence and caller selections on late cancellation", async () => { - const controller = new AbortController(); - const reason = { source: "caller-request", operation: "cancel" }; - const service = new NugetNupkgService({ - close: async () => {}, - identity, - inspect: () => { - controller.abort(reason); - return Promise.resolve(ok(report)); - }, - }); - const result = await service.inspect( - { path: report.artifact.path }, - { signal: controller.signal }, + const evidence = await lateCancellationEvidence( + report, + { source: "caller-request", operation: "cancel" }, + (inspect) => + new NugetNupkgService({ close: async () => {}, identity, inspect }), ); - expect(result.ok).toBe(false); - if (!result.ok) { - expect(result.error).toBeInstanceOf(AnalysisCancelledError); - expect(result.error.cause).toBe(reason); - expect(result.error.partialObservation).toMatchObject({ - operation: "inspect_nuget_nupkg", - parameters: { path: report.artifact.path }, - normalized_result: report, - }); - } + expect(evidence).toMatchObject({ + operation: "inspect_nuget_nupkg", + parameters: { path: report.artifact.path }, + normalized_result: report, + }); }); diff --git a/src/application/oci/OciImageLayoutService.test.ts b/src/application/oci/OciImageLayoutService.test.ts index 4163af2784b..23b36d10887 100644 --- a/src/application/oci/OciImageLayoutService.test.ts +++ b/src/application/oci/OciImageLayoutService.test.ts @@ -1,3 +1,4 @@ +import { lateCancellationEvidence } from "../../../tests/support/lateCancellationEvidence.js"; import { expect, it } from "vitest"; import { OciImageLayoutService } from "./OciImageLayoutService.js"; @@ -8,7 +9,6 @@ import { import { createOciImageLayoutEvidence } from "../../domain/oci/imageLayoutEvidence.js"; import { err, ok } from "../../domain/result.js"; import { - AnalysisCancelledError, AnalysisInputError, AnalysisOutputError, } from "../../domain/analysisErrorCore.js"; @@ -85,30 +85,17 @@ it("rejects a relative path and extra arguments before reading", async () => { }); it("retains completed Evidence and caller selections on late cancellation", async () => { - const controller = new AbortController(); - const reason = { source: "caller-request", operation: "cancel" }; - const service = new OciImageLayoutService({ - close: async () => {}, - identity, - inspect: () => { - controller.abort(reason); - return Promise.resolve(ok(report)); - }, - }); - const result = await service.inspect( - { path: report.artifact.path }, - { signal: controller.signal }, + const evidence = await lateCancellationEvidence( + report, + { source: "caller-request", operation: "cancel" }, + (inspect) => + new OciImageLayoutService({ close: async () => {}, identity, inspect }), ); - expect(result.ok).toBe(false); - if (!result.ok) { - expect(result.error).toBeInstanceOf(AnalysisCancelledError); - expect(result.error.cause).toBe(reason); - expect(result.error.partialObservation).toMatchObject({ - operation: "inspect_oci_image_layout", - parameters: { path: report.artifact.path }, - normalized_result: report, - }); - } + expect(evidence).toMatchObject({ + operation: "inspect_oci_image_layout", + parameters: { path: report.artifact.path }, + normalized_result: report, + }); }); it("keeps caller selections in Evidence recovered from a cleanup failure", async () => { diff --git a/src/application/vsix/VsixPackageService.test.ts b/src/application/vsix/VsixPackageService.test.ts index 1b2a10560b7..5a3c2c13904 100644 --- a/src/application/vsix/VsixPackageService.test.ts +++ b/src/application/vsix/VsixPackageService.test.ts @@ -1,9 +1,9 @@ +import { lateCancellationEvidence } from "../../../tests/support/lateCancellationEvidence.js"; import { expect, it } from "vitest"; import { VsixPackageService } from "./VsixPackageService.js"; import type { VsixPackage } from "../../domain/vsix/vsixPackage.js"; import { ok } from "../../domain/result.js"; import { - AnalysisCancelledError, AnalysisInputError, AnalysisOutputError, } from "../../domain/analysisErrorCore.js"; @@ -141,30 +141,17 @@ it("rejects a relative path and extra arguments before reading", async () => { }); it("retains completed Evidence and caller selections on late cancellation", async () => { - const controller = new AbortController(); - const reason = { source: "caller-request", operation: "cancel" }; - const service = new VsixPackageService({ - close: async () => {}, - identity, - inspect: () => { - controller.abort(reason); - return Promise.resolve(ok(report)); - }, - }); - const result = await service.inspect( - { path: report.artifact.path }, - { signal: controller.signal }, + const evidence = await lateCancellationEvidence( + report, + { source: "caller-request", operation: "cancel" }, + (inspect) => + new VsixPackageService({ close: async () => {}, identity, inspect }), ); - expect(result.ok).toBe(false); - if (!result.ok) { - expect(result.error).toBeInstanceOf(AnalysisCancelledError); - expect(result.error.cause).toBe(reason); - expect(result.error.partialObservation).toMatchObject({ - operation: "inspect_vsix_package", - parameters: { path: report.artifact.path }, - normalized_result: report, - }); - } + expect(evidence).toMatchObject({ + operation: "inspect_vsix_package", + parameters: { path: report.artifact.path }, + normalized_result: report, + }); }); it.each([undefined, 67108864, 128])( diff --git a/tests/support/lateCancellationEvidence.ts b/tests/support/lateCancellationEvidence.ts index 0f23a896596..d60b16f0a42 100644 --- a/tests/support/lateCancellationEvidence.ts +++ b/tests/support/lateCancellationEvidence.ts @@ -8,7 +8,7 @@ export const lateCancellationEvidence = async < Report extends { artifact: { path: string } }, >( report: Report, - request: string, + request: string | Readonly>, createService: (inspect: () => Promise>) => { inspect( input: { path: string }, @@ -17,7 +17,7 @@ export const lateCancellationEvidence = async < }, ): Promise => { const controller = new AbortController(); - const reason = { request }; + const reason = typeof request === "string" ? { request } : request; const service = createService(() => { controller.abort(reason); return Promise.resolve(ok(report));