mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 13:41:17 -05:00
test(go): share binary service fixture setup (#16091)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { GoBinaryService } from "./GoBinaryService.js";
|
||||
import type { GoBinaryPort } from "../../ports/go/GoBinaryPort.js";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisCancelledError,
|
||||
@@ -25,15 +26,14 @@ const report: GoBinary = {
|
||||
limitations: ["Build information unavailable."],
|
||||
};
|
||||
|
||||
const serviceFor = (inspect: GoBinaryPort["inspect"]) =>
|
||||
new GoBinaryService({ close: async () => {}, identity, inspect });
|
||||
|
||||
it("rejects invalid paths and extra caller arguments before invoking the reader", async () => {
|
||||
let calls = 0;
|
||||
const service = new GoBinaryService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: () => {
|
||||
calls += 1;
|
||||
return Promise.resolve(ok(report));
|
||||
},
|
||||
const service = serviceFor(() => {
|
||||
calls += 1;
|
||||
return Promise.resolve(ok(report));
|
||||
});
|
||||
for (const input of [
|
||||
{ path: "relative" },
|
||||
@@ -49,13 +49,9 @@ it("rejects invalid paths and extra caller arguments before invoking the reader"
|
||||
|
||||
it("requires a complete Evidence retention path before starting summary inspection", async () => {
|
||||
let calls = 0;
|
||||
const service = new GoBinaryService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: async () => {
|
||||
calls++;
|
||||
return ok(report);
|
||||
},
|
||||
const service = serviceFor(async () => {
|
||||
calls++;
|
||||
return ok(report);
|
||||
});
|
||||
const result = await service.inspect({
|
||||
path: report.artifact.path,
|
||||
@@ -68,11 +64,7 @@ it("requires a complete Evidence retention path before starting summary inspecti
|
||||
});
|
||||
|
||||
it("preserves unsupported subject architectures and does not duplicate metadata", async () => {
|
||||
const service = new GoBinaryService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: () => Promise.resolve(ok(report)),
|
||||
});
|
||||
const service = serviceFor(() => Promise.resolve(ok(report)));
|
||||
const result = await service.inspect({ path: report.artifact.path });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.subject).toMatchObject({
|
||||
@@ -113,11 +105,9 @@ it("preserves byte-valued build metadata and validates compiler source lengths",
|
||||
build_info: buildInfo,
|
||||
limitations: ["Some embedded strings contain non-UTF-8 bytes."],
|
||||
};
|
||||
const result = await new GoBinaryService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: () => Promise.resolve(ok(partial)),
|
||||
}).inspect({ path: report.artifact.path });
|
||||
const result = await serviceFor(() => Promise.resolve(ok(partial))).inspect({
|
||||
path: report.artifact.path,
|
||||
});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.normalized_result).toEqual(partial);
|
||||
|
||||
@@ -128,11 +118,9 @@ it("preserves byte-valued build metadata and validates compiler source lengths",
|
||||
version_location: { offset: 128, bytes: 2 },
|
||||
},
|
||||
};
|
||||
const invalid = await new GoBinaryService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: () => Promise.resolve(ok(mismatched)),
|
||||
}).inspect({ path: report.artifact.path });
|
||||
const invalid = await serviceFor(() =>
|
||||
Promise.resolve(ok(mismatched)),
|
||||
).inspect({ path: report.artifact.path });
|
||||
expect(invalid.ok).toBe(false);
|
||||
if (!invalid.ok) expect(invalid.error).toBeInstanceOf(AnalysisOutputError);
|
||||
});
|
||||
@@ -164,11 +152,9 @@ it("refuses reader identity changes and invalid original source ranges", async (
|
||||
{ ...report, artifact: { ...report.artifact, path: "/artifacts/other" } },
|
||||
outside,
|
||||
]) {
|
||||
const result = await new GoBinaryService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: () => Promise.resolve(ok(value)),
|
||||
}).inspect({ path: report.artifact.path });
|
||||
const result = await serviceFor(() => Promise.resolve(ok(value))).inspect({
|
||||
path: report.artifact.path,
|
||||
});
|
||||
expect(result.ok).toBe(false);
|
||||
if (!result.ok) expect(result.error).toBeInstanceOf(AnalysisOutputError);
|
||||
}
|
||||
@@ -178,14 +164,10 @@ it("honors cancellation before reading and after a completed observation", async
|
||||
const controller = new AbortController();
|
||||
const reason = { request: "late Go cancellation" };
|
||||
let calls = 0;
|
||||
const service = new GoBinaryService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: () => {
|
||||
calls += 1;
|
||||
controller.abort(reason);
|
||||
return Promise.resolve(ok(report));
|
||||
},
|
||||
const service = serviceFor(() => {
|
||||
calls += 1;
|
||||
controller.abort(reason);
|
||||
return Promise.resolve(ok(report));
|
||||
});
|
||||
const completed = await service.inspect(
|
||||
{ path: report.artifact.path },
|
||||
@@ -215,13 +197,9 @@ it("keeps malformed provider output ahead of a late cancellation", async () => {
|
||||
...report,
|
||||
artifact: { ...report.artifact, path: "/other" },
|
||||
};
|
||||
const result = await new GoBinaryService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: () => {
|
||||
controller.abort();
|
||||
return Promise.resolve(ok(malformed));
|
||||
},
|
||||
const result = await serviceFor(() => {
|
||||
controller.abort();
|
||||
return Promise.resolve(ok(malformed));
|
||||
}).inspect({ path: report.artifact.path }, { signal: controller.signal });
|
||||
expect(result.ok).toBe(false);
|
||||
if (!result.ok) expect(result.error).toBeInstanceOf(AnalysisOutputError);
|
||||
@@ -244,13 +222,9 @@ it.each([
|
||||
const controller = new AbortController();
|
||||
controller.abort(reason);
|
||||
let calls = 0;
|
||||
const service = new GoBinaryService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: async () => {
|
||||
calls += 1;
|
||||
throw new Error("cancelled admission must not invoke the reader");
|
||||
},
|
||||
const service = serviceFor(async () => {
|
||||
calls += 1;
|
||||
throw new Error("cancelled admission must not invoke the reader");
|
||||
});
|
||||
const result = await service.inspect(null, { signal: controller.signal });
|
||||
if (result.ok) throw new Error("expected cancelled admission");
|
||||
@@ -266,13 +240,9 @@ it.each([
|
||||
|
||||
it("validates string_literals input options and output invariants", async () => {
|
||||
let calls = 0;
|
||||
const service = new GoBinaryService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: () => {
|
||||
calls += 1;
|
||||
return Promise.resolve(ok(report));
|
||||
},
|
||||
const service = serviceFor(() => {
|
||||
calls += 1;
|
||||
return Promise.resolve(ok(report));
|
||||
});
|
||||
for (const invalidInput of [
|
||||
{ path: report.artifact.path, max_string_literals: 10 },
|
||||
@@ -347,12 +317,9 @@ it("validates string_literals input options and output invariants", async () =>
|
||||
],
|
||||
},
|
||||
]) {
|
||||
const out = await new GoBinaryService({
|
||||
close: async () => {},
|
||||
identity,
|
||||
inspect: () =>
|
||||
Promise.resolve(ok({ ...report, string_literals: malformedStrings })),
|
||||
}).inspect({
|
||||
const out = await serviceFor(() =>
|
||||
Promise.resolve(ok({ ...report, string_literals: malformedStrings })),
|
||||
).inspect({
|
||||
path: report.artifact.path,
|
||||
include_string_literals: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user