test: add critical provider workflow coverage
This commit is contained in:
@@ -43,10 +43,58 @@ __attribute__((noinline, used)) int rea_ghidra_inventory_switch(
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((noinline, used)) int rea_ghidra_inventory_dense_switch(
|
||||
unsigned int selector, int value) {
|
||||
switch (selector) {
|
||||
case 0: return rea_ghidra_inventory_leaf(value + 0);
|
||||
case 1: return rea_ghidra_inventory_leaf(value + 1);
|
||||
case 2: return rea_ghidra_inventory_leaf(value + 2);
|
||||
case 3: return rea_ghidra_inventory_leaf(value + 3);
|
||||
case 4: return rea_ghidra_inventory_leaf(value + 4);
|
||||
case 5: return rea_ghidra_inventory_leaf(value + 5);
|
||||
case 6: return rea_ghidra_inventory_leaf(value + 6);
|
||||
case 7: return rea_ghidra_inventory_leaf(value + 7);
|
||||
case 8: return rea_ghidra_inventory_leaf(value + 8);
|
||||
case 9: return rea_ghidra_inventory_leaf(value + 9);
|
||||
case 10: return rea_ghidra_inventory_leaf(value + 10);
|
||||
case 11: return rea_ghidra_inventory_leaf(value + 11);
|
||||
case 12: return rea_ghidra_inventory_leaf(value + 12);
|
||||
case 13: return rea_ghidra_inventory_leaf(value + 13);
|
||||
case 14: return rea_ghidra_inventory_leaf(value + 14);
|
||||
case 15: return rea_ghidra_inventory_leaf(value + 15);
|
||||
case 16: return rea_ghidra_inventory_leaf(value + 16);
|
||||
case 17: return rea_ghidra_inventory_leaf(value + 17);
|
||||
case 18: return rea_ghidra_inventory_leaf(value + 18);
|
||||
case 19: return rea_ghidra_inventory_leaf(value + 19);
|
||||
case 20: return rea_ghidra_inventory_leaf(value + 20);
|
||||
case 21: return rea_ghidra_inventory_leaf(value + 21);
|
||||
case 22: return rea_ghidra_inventory_leaf(value + 22);
|
||||
case 23: return rea_ghidra_inventory_leaf(value + 23);
|
||||
case 24: return rea_ghidra_inventory_leaf(value + 24);
|
||||
case 25: return rea_ghidra_inventory_leaf(value + 25);
|
||||
case 26: return rea_ghidra_inventory_leaf(value + 26);
|
||||
case 27: return rea_ghidra_inventory_leaf(value + 27);
|
||||
case 28: return rea_ghidra_inventory_leaf(value + 28);
|
||||
case 29: return rea_ghidra_inventory_leaf(value + 29);
|
||||
case 30: return rea_ghidra_inventory_leaf(value + 30);
|
||||
case 31: return rea_ghidra_inventory_leaf(value + 31);
|
||||
case 32: return rea_ghidra_inventory_leaf(value + 32);
|
||||
case 33: return rea_ghidra_inventory_leaf(value + 33);
|
||||
case 34: return rea_ghidra_inventory_leaf(value + 34);
|
||||
case 35: return rea_ghidra_inventory_leaf(value + 35);
|
||||
case 36: return rea_ghidra_inventory_leaf(value + 36);
|
||||
case 37: return rea_ghidra_inventory_leaf(value + 37);
|
||||
case 38: return rea_ghidra_inventory_leaf(value + 38);
|
||||
case 39: return rea_ghidra_inventory_leaf(value + 39);
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((noinline, used)) int rea_ghidra_inventory_entry(void) {
|
||||
puts("REA_GHIDRA_INVENTORY_ENTRY");
|
||||
return rea_ghidra_inventory_branch(35) +
|
||||
rea_ghidra_inventory_indirect(rea_ghidra_inventory_leaf, 0);
|
||||
rea_ghidra_inventory_indirect(rea_ghidra_inventory_leaf, 0) +
|
||||
rea_ghidra_inventory_dense_switch(100, 0) + 1;
|
||||
}
|
||||
|
||||
int main(void) { return rea_ghidra_inventory_entry() == 49 ? 0 : 1; }
|
||||
|
||||
Vendored
+7
-4
@@ -48,7 +48,7 @@ export const ghidraBounded = (items: readonly JsonValue[]) => ({
|
||||
next_offset: null,
|
||||
});
|
||||
|
||||
export const ghidraNativeApiBoundary = () => ({
|
||||
export const ghidraNativeApiBoundary = (mappingsTruncated = false) => ({
|
||||
available: true as const,
|
||||
provenance: "ghidra-high-function",
|
||||
signature_source: "analysis",
|
||||
@@ -115,7 +115,7 @@ export const ghidraNativeApiBoundary = () => ({
|
||||
],
|
||||
},
|
||||
],
|
||||
mappings_truncated: false,
|
||||
mappings_truncated: mappingsTruncated,
|
||||
limitations: [],
|
||||
},
|
||||
],
|
||||
@@ -136,7 +136,10 @@ export const ghidraNativeApiBoundary = () => ({
|
||||
],
|
||||
});
|
||||
|
||||
export const ghidraFunctionDossier = (includeAssembly = true): JsonValue => {
|
||||
export const ghidraFunctionDossier = (
|
||||
includeAssembly = true,
|
||||
mappingsTruncated = false,
|
||||
): JsonValue => {
|
||||
const pseudocode = "int fixture_main(void) { return 42; }";
|
||||
return {
|
||||
procedure: {
|
||||
@@ -171,7 +174,7 @@ export const ghidraFunctionDossier = (includeAssembly = true): JsonValue => {
|
||||
{ start: "0x401000", end: "0x401006", successors: [] },
|
||||
]),
|
||||
instruction_scan: { scanned: 2, truncated: false },
|
||||
native_api: ghidraNativeApiBoundary(),
|
||||
native_api: ghidraNativeApiBoundary(mappingsTruncated),
|
||||
limitations: [
|
||||
"Unresolved computed or indirect flows without target addresses are not represented as reference edges.",
|
||||
"Thunk and external classifications are Ghidra FunctionManager observations; they do not resolve targetless calls.",
|
||||
|
||||
+144
-42
@@ -29,46 +29,9 @@ const INSTALL = "/opt/ghidra_12.1.2_PUBLIC";
|
||||
|
||||
describe("Ghidra MCP and shared CLI composition", () => {
|
||||
it("preserves provider evidence, composed parity, and capability routing", async () => {
|
||||
const calls: GhidraOperation[] = [];
|
||||
const factory: GhidraProviderClientFactory = (options) => ({
|
||||
start: () =>
|
||||
Promise.resolve(
|
||||
ok(sessionInfo(options.profileDigest, options.targetSha256)),
|
||||
),
|
||||
callTool: (operation, input) => {
|
||||
calls.push(operation);
|
||||
return Promise.resolve(ok(resultFor(operation, input)));
|
||||
},
|
||||
close: () => Promise.resolve(),
|
||||
});
|
||||
const config = parseConfig({ GHIDRA_INSTALL_DIR: INSTALL });
|
||||
if (!config.ok) throw config.error;
|
||||
const provider = new GhidraProvider(
|
||||
config.value,
|
||||
silentLogger,
|
||||
installationHost(),
|
||||
factory,
|
||||
);
|
||||
const session = new BinarySession(
|
||||
SessionProviderRouter.selectable(
|
||||
new AnalysisProviderRegistry([provider]),
|
||||
[],
|
||||
),
|
||||
);
|
||||
const server = createServer(session, session, { logger: silentLogger });
|
||||
const mcp = new Client({ name: "ghidra-parity", version: "1.0.0" });
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
|
||||
const harness = await connectGhidraMcp("ghidra-parity");
|
||||
const { calls, mcp, session } = harness;
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await mcp.connect(clientTransport);
|
||||
const opened = await mcp.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: process.execPath },
|
||||
});
|
||||
expect(opened.isError).not.toBe(true);
|
||||
|
||||
const listed = sessionEvidence(
|
||||
session,
|
||||
(
|
||||
@@ -269,12 +232,147 @@ describe("Ghidra MCP and shared CLI composition", () => {
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
await Promise.allSettled([mcp.close(), server.close()]);
|
||||
await session.close();
|
||||
await harness.close();
|
||||
}
|
||||
}, 10_000);
|
||||
|
||||
it("records approved native API truncation once and links its evidence", async () => {
|
||||
const harness = await connectGhidraMcp("ghidra-native-api");
|
||||
const { mcp, session } = harness;
|
||||
try {
|
||||
const unapprovedInspection = sessionEvidence(
|
||||
session,
|
||||
(
|
||||
await mcp.callTool({
|
||||
name: "inspect_native_api",
|
||||
arguments: { procedure: "fixture_truncated" },
|
||||
})
|
||||
).structuredContent,
|
||||
);
|
||||
expect(unapprovedInspection.normalized_result).toMatchObject({
|
||||
boundary: {
|
||||
available: true,
|
||||
jump_tables: [{ mappings_truncated: true }],
|
||||
},
|
||||
residual_unknowns: [
|
||||
expect.stringContaining("additional data sources or targets"),
|
||||
],
|
||||
});
|
||||
expect(
|
||||
(
|
||||
await mcp.callTool({
|
||||
name: "list_unknowns",
|
||||
arguments: {},
|
||||
})
|
||||
).structuredContent,
|
||||
).toMatchObject({ result: [] });
|
||||
|
||||
const approvedInspection = sessionEvidence(
|
||||
session,
|
||||
(
|
||||
await mcp.callTool({
|
||||
name: "inspect_native_api",
|
||||
arguments: {
|
||||
procedure: "fixture_truncated",
|
||||
unknown_registry_approved: true,
|
||||
},
|
||||
})
|
||||
).structuredContent,
|
||||
);
|
||||
await mcp.callTool({
|
||||
name: "inspect_native_api",
|
||||
arguments: {
|
||||
procedure: "fixture_truncated",
|
||||
unknown_registry_approved: true,
|
||||
},
|
||||
});
|
||||
expect(
|
||||
(
|
||||
await mcp.callTool({
|
||||
name: "list_unknowns",
|
||||
arguments: {},
|
||||
})
|
||||
).structuredContent,
|
||||
).toMatchObject({
|
||||
result: [
|
||||
{
|
||||
status: "open",
|
||||
domain: "native-api",
|
||||
question: expect.stringContaining(
|
||||
"additional data sources or targets",
|
||||
),
|
||||
supporting_evidence_ids: [approvedInspection.evidence_id],
|
||||
recommended_probes: [
|
||||
{
|
||||
operation: "inspect_native_api",
|
||||
rationale: expect.stringContaining("ABI probe"),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
} finally {
|
||||
await harness.close();
|
||||
}
|
||||
}, 10_000);
|
||||
});
|
||||
|
||||
const connectGhidraMcp = async (name: string) => {
|
||||
const calls: GhidraOperation[] = [];
|
||||
const factory: GhidraProviderClientFactory = (options) => ({
|
||||
start: () =>
|
||||
Promise.resolve(
|
||||
ok(sessionInfo(options.profileDigest, options.targetSha256)),
|
||||
),
|
||||
callTool: (operation, input) => {
|
||||
calls.push(operation);
|
||||
return Promise.resolve(ok(resultFor(operation, input)));
|
||||
},
|
||||
close: () => Promise.resolve(),
|
||||
});
|
||||
const config = parseConfig({ GHIDRA_INSTALL_DIR: INSTALL });
|
||||
if (!config.ok) throw config.error;
|
||||
const provider = new GhidraProvider(
|
||||
config.value,
|
||||
silentLogger,
|
||||
installationHost(),
|
||||
factory,
|
||||
);
|
||||
const session = new BinarySession(
|
||||
SessionProviderRouter.selectable(
|
||||
new AnalysisProviderRegistry([provider]),
|
||||
[],
|
||||
),
|
||||
);
|
||||
const server = createServer(session, session, { logger: silentLogger });
|
||||
const mcp = new Client({ name, version: "1.0.0" });
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
const close = async () => {
|
||||
await Promise.allSettled([mcp.close(), server.close()]);
|
||||
await session.close();
|
||||
};
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await mcp.connect(clientTransport);
|
||||
const opened = await mcp.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: process.execPath },
|
||||
});
|
||||
if (opened.isError === true)
|
||||
throw new Error("The Ghidra MCP harness could not open its target");
|
||||
} catch (cause: unknown) {
|
||||
await close();
|
||||
throw cause;
|
||||
}
|
||||
return {
|
||||
calls,
|
||||
mcp,
|
||||
session,
|
||||
close,
|
||||
};
|
||||
};
|
||||
|
||||
const sessionEvidence = (session: BinarySession, value: unknown) => {
|
||||
if (
|
||||
typeof value !== "object" ||
|
||||
@@ -453,7 +551,11 @@ const resultBuilders = new Map<GhidraOperation, GhidraResultBuilder>([
|
||||
["xrefs", () => ["0x401001"]],
|
||||
[
|
||||
"analyze_function",
|
||||
(input, _limit) => ghidraFunctionDossier(input.include_assembly === true),
|
||||
(input, _limit) =>
|
||||
ghidraFunctionDossier(
|
||||
input.include_assembly === true,
|
||||
input.procedure === "fixture_truncated",
|
||||
),
|
||||
],
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user