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:
morluto
2026-10-09 02:38:07 +08:00
parent e2fc2493b6
commit 1f5be750bc
24 changed files with 962 additions and 297 deletions
-81
View File
@@ -1,81 +0,0 @@
import { describe, expect, it } from "vitest";
import { bindGhidraSessionFailure } from "./GhidraSessionError.js";
const diagnostics = {
target_path: "/tmp/public-fixture",
target_sha256: "a".repeat(64),
};
describe("Ghidra session failure diagnostics", () => {
it("retains the original Error while projecting its name, message and code", () => {
const cause = Object.assign(
new TypeError("Cannot decode /tmp/public-fixture at offset 17"),
{ code: "EDECODE" },
);
const failure = bindGhidraSessionFailure(() => diagnostics)(
"protocol",
"Request rejected",
cause,
);
expect(failure.cause).toBe(cause);
expect(failure.kind).toBe("protocol");
expect(failure.diagnostics).toEqual({
...diagnostics,
failure_cause: {
name: "TypeError",
message: cause.message,
code: "EDECODE",
},
});
expect(failure.diagnostics).not.toHaveProperty("stack");
});
it.each([
["decoder rejected", { type: "string", message: "decoder rejected" }],
[null, { type: "null", value: null }],
[false, { type: "boolean", value: false }],
[42, { type: "number", value: 42 }],
[{ opaque: true }, { type: "object" }],
])("handles a non-Error rejection (%j)", (cause, expected) => {
const failure = bindGhidraSessionFailure(() => diagnostics)(
"process",
"Shutdown rejected",
cause,
);
expect(failure.cause).toBe(cause);
expect(failure.diagnostics.failure_cause).toEqual(expected);
});
it("redacts only known authentication material in projected failure fields", () => {
const token = "actual-bridge-authentication";
const message = `Failure ${token}: http://localhost/secret?token=public-value /tmp/password-fixture`;
const cause = Object.assign(new Error(message), { code: `code-${token}` });
const failure = bindGhidraSessionFailure(
() => diagnostics,
(value) => value.replaceAll(token, "[REDACTED]"),
)("remote", message, cause, { remoteCode: `code-${token}` });
expect(failure.cause).toBe(cause);
expect(failure.message).toBe(message.replaceAll(token, "[REDACTED]"));
expect(failure.diagnostics).toMatchObject({
remote_code: "code-[REDACTED]",
remote_message: failure.message,
failure_cause: { message: failure.message, code: "code-[REDACTED]" },
});
expect(JSON.stringify(failure.diagnostics)).not.toContain(token);
expect(JSON.stringify(failure.diagnostics)).toContain(
"token=public-value /tmp/password-fixture",
);
});
it("leaves absent causes and existing timeout metadata unchanged", () => {
const failure = bindGhidraSessionFailure(() => diagnostics)(
"timeout",
"Deadline elapsed",
undefined,
{ timeoutMs: 5 },
);
expect(failure.timeoutMs).toBe(5);
expect(failure.diagnostics).toEqual(diagnostics);
});
});