Files
reverse-engineering-anything/tests/process-global/ghidraProjectReadCancellation.test.ts
T
19447516a4 feat(ghidra): reuse existing projects through verified copies (#7236)
Reuse selected Ghidra projects through verified private read-only copies, with shared CLI/MCP configuration, committed project identity, import-SHA verification and explicit historical/unknown analysis semantics. Preserve exact cancellation and platform capability boundaries.

Actual Ghidra 12.1.4/JDK21 Linux CLI/MCP investigations matched fresh import on 652-function ls and 14,338-function libcrypto inventories and pseudocode; authenticated complete Evidence, mismatch/staleness refusal, saved historical reports and shared /tmp projects verified. 958 focused tests passed with four platform skips; build/static/docs/format passed. Real macOS/Windows reuse remains unverified; Windows reuse is unavailable. See PR verification for measured whole-task costs and final CI attribution.

Co-authored-by: akushonkamen <akushonkamen@163.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-10-26 22:31:13 +08:00

58 lines
2.0 KiB
TypeScript

import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it, vi } from "vitest";
import { ArtifactFileCancelled } from "../../src/artifacts/ArtifactFileOperation.js";
import { ArtifactResourceScope } from "../../src/artifacts/ArtifactResourceScope.js";
import { AnalysisCancelledError } from "../../src/domain/analysisErrorCore.js";
import { resolveGhidraProject } from "../../src/ghidra/GhidraProjectSnapshot.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
const fault = vi.hoisted(() => ({ reason: undefined as unknown }));
vi.mock(
"../../src/artifacts/ArtifactFileOperation.js",
async (importOriginal) => {
const original =
await importOriginal<
typeof import("../../src/artifacts/ArtifactFileOperation.js")
>();
return {
...original,
withArtifactRegularFile: async () => {
throw new ArtifactFileCancelled({
reason: fault.reason,
outcome: { kind: "completed", value: undefined },
});
},
};
},
);
it.each([null, "cancel file read", { source: "caller" }])(
"preserves an owned file-read cancellation through project profile resolution: %j",
async (reason) => {
const root = await createTestTempDirectory("rea-ghidra-read-cancel-");
await mkdir(join(root, "selected.rep"));
await writeFile(join(root, "selected.gpr"), "marker");
const resources = new ArtifactResourceScope();
fault.reason = reason;
try {
let failure: unknown;
try {
await resolveGhidraProject(
{ path: join(root, "selected.gpr") },
{ path: join(root, "target") },
resources,
);
} catch (cause) {
failure = cause;
}
expect(failure).toBeInstanceOf(AnalysisCancelledError);
if (!(failure instanceof AnalysisCancelledError))
throw new Error("Expected cancellation");
expect(failure.cause).toBe(reason);
} finally {
await resources.close();
}
},
);