mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 05:07:49 +00:00
test(packages): reuse late cancellation evidence fixture (#15720)
This commit is contained in:
1 parent
1010b14e8e
commit
449fef2c03
4 files changed
+36
-77
No files matched your search
@@ -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,
|
||||
});
|
||||
});
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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])(
|
||||
|
||||
@@ -8,7 +8,7 @@ export const lateCancellationEvidence = async <
|
||||
Report extends { artifact: { path: string } },
|
||||
>(
|
||||
report: Report,
|
||||
request: string,
|
||||
request: string | Readonly<Record<string, unknown>>,
|
||||
createService: (inspect: () => Promise<Result<Report, never>>) => {
|
||||
inspect(
|
||||
input: { path: string },
|
||||
@@ -17,7 +17,7 @@ export const lateCancellationEvidence = async <
|
||||
},
|
||||
): Promise<Evidence> => {
|
||||
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));
|
||||
|
||||
Reference in new issue
Block a user