fix(ghidra): harden location resolution and provider lifecycle
Preserve boundary diagnostics, resolve procedure names before bare hex addresses, and launch the inspected JVM directly on macOS for verifiable startup cancellation. Keep private socket paths within host limits and retain ownership when cleanup is incomplete. Exercise the fixes through real CLI/MCP Ghidra workflows and provider-boundary integration tests, replacing redundant unit coverage.
This commit is contained in:
@@ -1,6 +1,65 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { EnhancedTools } from "../../../src/application/EnhancedTools.js";
|
||||
import { connectGhidraMcp, sessionEvidence } from "./ghidraMcpHarness.js";
|
||||
import { functionDossierSchema } from "../../../src/domain/hopperValues.js";
|
||||
import { ghidraFunctionDossier } from "../../../src/domain/ghidraValues.fixture.js";
|
||||
import { jsonValueSchema } from "../../../src/domain/jsonValue.js";
|
||||
import { ok } from "../../../src/domain/result.js";
|
||||
|
||||
it("rejects contradictory annotation readback across the provider and MCP boundaries", async () => {
|
||||
const dossier = functionDossierSchema.parse(ghidraFunctionDossier());
|
||||
const annotations = {
|
||||
address: dossier.procedure.address,
|
||||
name: dossier.procedure.name,
|
||||
comment: null,
|
||||
inline_comment: "Finding",
|
||||
};
|
||||
const effects = {
|
||||
scope: "session-analysis-database",
|
||||
source_bytes_modified: false,
|
||||
persists_after_close: false,
|
||||
};
|
||||
const original = { annotations, dossier, effects };
|
||||
let output = jsonValueSchema.parse(original);
|
||||
const harness = await connectGhidraMcp("ghidra-malformed-annotation", () =>
|
||||
Promise.resolve(ok(output)),
|
||||
);
|
||||
try {
|
||||
const accepted = await harness.mcp.callTool({
|
||||
name: "annotate_native_function",
|
||||
arguments: {
|
||||
procedure: annotations.address,
|
||||
inline_comment: "Finding",
|
||||
},
|
||||
});
|
||||
expect(accepted.isError).not.toBe(true);
|
||||
expect(accepted.structuredContent).toMatchObject({
|
||||
result: { annotations },
|
||||
});
|
||||
for (const value of [
|
||||
{ ...original, annotations: { ...annotations, name: "different" } },
|
||||
{ ...original, annotations: { ...annotations, address: "0x9999" } },
|
||||
{ ...original, effects: { ...effects, source_bytes_modified: true } },
|
||||
{ ...original, effects: { ...effects, persists_after_close: true } },
|
||||
{ ...original, dossier: { ...dossier, native_value_flow: null } },
|
||||
]) {
|
||||
output = jsonValueSchema.parse(value);
|
||||
const reply = await harness.mcp.callTool({
|
||||
name: "annotate_native_function",
|
||||
arguments: {
|
||||
procedure: annotations.address,
|
||||
inline_comment: "Finding",
|
||||
},
|
||||
});
|
||||
expect(reply.isError).toBe(true);
|
||||
expect(reply.structuredContent).toMatchObject({
|
||||
error: { code: "unreadable_output" },
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
await harness.close();
|
||||
}
|
||||
});
|
||||
|
||||
describe("Ghidra MCP evidence parity", () => {
|
||||
it("preserves provider evidence, composed parity, and capability routing", async () => {
|
||||
|
||||
@@ -49,6 +49,9 @@ it("preserves queue failure diagnostics through the provider, CLI adapter and SD
|
||||
details: {
|
||||
diagnostics: {
|
||||
target_path: "/tmp/public-fixture",
|
||||
failure_kind: "protocol",
|
||||
failure_message:
|
||||
"Ghidra serial request execution rejected unexpectedly",
|
||||
failure_cause: {
|
||||
name: "TypeError",
|
||||
code: "EDECODE",
|
||||
|
||||
@@ -214,6 +214,9 @@ describe("Ghidra headless launcher", () => {
|
||||
process.platform === "win32" ? "C:\\Java\\jdk-21" : "/opt/jdk-21";
|
||||
const launcher = new GhidraHeadlessLauncher({
|
||||
analyzeHeadlessPath: fixturePath,
|
||||
// This fixture exercises the official script route. Native macOS JVM
|
||||
// launching is covered by the real Ghidra acceptance lane.
|
||||
platform: process.platform === "win32" ? "win32" : "linux",
|
||||
javaHome,
|
||||
bridgeScriptPath: "/package/bridge/ReaGhidraBridge.java",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user