Files
rea/tests/boundary/go/goBinaryFinalization.test.ts
morluto 7bcefead69 test: strengthen and prune audited test coverage (#8573)
* test: strengthen and prune audited test coverage

* test: require delivered DeepSeek skill instructions

* test: keep schema fixture types private

* test: verify Gemini receives skill instructions

* test: bind Qwen skill evidence to its tool result

* test: report NativeAOT verifier checks precisely

* fix: verify Ghidra cleanup paths reliably

* fix: verify Command Code skill activation

* test: tighten cleanup and fixture checks

* test: verify packet capture evidence is recorded

* fix: report HTTP3 capture provenance accurately

* test: preserve resource coverage through MCP

* test: prune repeated assertions and retain cancellation identity

* fix: validate client verifier fixture paths

* test: skip Copilot verifier cases on Windows

* test: keep verifier setup target relative
2026-11-02 02:13:32 +08:00

81 lines
3.2 KiB
TypeScript

import { createHash } from "node:crypto";
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it, vi } from "vitest";
import { GoBinaryProvider } from "../../../src/go/GoBinaryProvider.js";
import { GoBinaryService } from "../../../src/application/go/GoBinaryService.js";
import { OwnedFileHandle } from "../../../src/filesystem/OwnedFileHandle.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
import { createGoBinaryFixture } from "../../fixtures/go/image.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it.each(["control", "close-failure", "close-cancel", "close-both"] as const)(
"retains completed Go acquisition through %s",
async (mode) => {
const root = await createTestTempDirectory("rea-go-finalization-");
const path = join(root, "selected.elf");
const bytes = createGoBinaryFixture().bytes;
await writeFile(path, bytes);
const controller = new AbortController();
const reason = { request: "cancel during Go close" };
const closeFailure = Object.assign(new Error("controlled Go close EIO"), {
code: "EIO",
});
const original = OwnedFileHandle.prototype.close;
let owner: OwnedFileHandle | undefined;
const close = vi
.spyOn(OwnedFileHandle.prototype, "close")
.mockImplementationOnce(async function (this: OwnedFileHandle) {
owner = this;
if (mode === "close-cancel" || mode === "close-both")
controller.abort(reason);
if (mode === "close-failure" || mode === "close-both")
throw closeFailure;
await original.call(this);
});
const service = new GoBinaryService(new GoBinaryProvider());
try {
const result = await service.inspect(
{ path },
{ signal: controller.signal },
);
if (mode === "control") {
if (!result.ok) throw result.error;
expect(result.value.normalized_result).toMatchObject({
build_info: { go_version: "go1.26.0" },
});
} else {
if (result.ok) throw new Error("Expected finalization failure");
const acquired = {
kind: "file-snapshot-hash",
path,
sha256: createHash("sha256").update(bytes).digest("hex"),
bytes: bytes.length,
};
expect(result.error.partialObservation).toEqual(acquired);
expect(
projectAnalysisError(result.error).details?.partial_observation,
).toEqual(acquired);
const failedClose = mode === "close-failure" || mode === "close-both";
expect(result.error.cleanupIncomplete).toBe(failedClose);
if (failedClose) expect(owner?.handle.fd).toBeGreaterThanOrEqual(0);
if (mode !== "close-failure") {
const primary = result.error.cleanupPrimary ?? result.error;
expect(primary).toMatchObject({
_tag: "AnalysisCancelledError",
cause: reason,
});
expect(primary.cause).toBe(reason);
}
close.mockRestore();
await service.close();
expect(result.error.cleanupIncomplete).toBe(false);
}
expect(owner?.handle.fd).toBe(-1);
} finally {
close.mockRestore();
await service.close();
}
},
);