fix(contracts)!: require observed provider output metadata
Reject omitted segment bounds, procedure classification and body facts, unresolved-call observations, dossier facets, and Ghidra parameter flow metadata. Providers emit explicit nulls for unsupported facets. Verify those unknowns in the real Hopper workflow. BREAKING CHANGE: Provider analysis outputs must explicitly supply metadata previously repaired with defaults; unsupported nullable facets must be reported as null.
This commit is contained in:
@@ -35,6 +35,33 @@ const targetObservation = (value: unknown) =>
|
||||
),
|
||||
);
|
||||
|
||||
const functionDossier = {
|
||||
procedure: {
|
||||
address: "0x1",
|
||||
name: "entry",
|
||||
classification: null,
|
||||
body: {
|
||||
available: false,
|
||||
reason: "The provider did not report complete function body ranges.",
|
||||
},
|
||||
signature: null,
|
||||
locals: [],
|
||||
},
|
||||
pseudocode: "return 0;",
|
||||
assembly: [],
|
||||
comments: [],
|
||||
callers: [],
|
||||
callees: [],
|
||||
incoming_references: [],
|
||||
outgoing_references: [],
|
||||
referenced_strings: [],
|
||||
referenced_names: [],
|
||||
basic_blocks: [],
|
||||
native_api: null,
|
||||
native_value_flow: null,
|
||||
limitations: [],
|
||||
};
|
||||
|
||||
const fixturePort = (): AnalysisOperationPort => ({
|
||||
// oxlint-disable-next-line complexity -- this fixture exhaustively serves the registered MCP surface.
|
||||
execute: (name, arguments_) => {
|
||||
@@ -138,7 +165,16 @@ const fixturePort = (): AnalysisOperationPort => ({
|
||||
);
|
||||
case "list_segments":
|
||||
return Promise.resolve(
|
||||
ok([{ name: "__TEXT", start: "0x1000", end: "0x2000" }]),
|
||||
ok([
|
||||
{
|
||||
name: "__TEXT",
|
||||
start: "0x1000",
|
||||
end: "0x2000",
|
||||
readable: null,
|
||||
writable: null,
|
||||
executable: null,
|
||||
},
|
||||
]),
|
||||
);
|
||||
case "current_document":
|
||||
return Promise.resolve(ok("fixture"));
|
||||
@@ -151,26 +187,7 @@ const fixturePort = (): AnalysisOperationPort => ({
|
||||
case "search_procedures":
|
||||
return Promise.resolve(ok(inventory({})));
|
||||
case "analyze_function":
|
||||
return Promise.resolve(
|
||||
targetObservation({
|
||||
procedure: {
|
||||
address: "0x1",
|
||||
name: "entry",
|
||||
signature: null,
|
||||
locals: [],
|
||||
},
|
||||
pseudocode: "return 0;",
|
||||
assembly: [],
|
||||
comments: [],
|
||||
callers: [],
|
||||
callees: [],
|
||||
incoming_references: [],
|
||||
outgoing_references: [],
|
||||
referenced_strings: [],
|
||||
referenced_names: [],
|
||||
basic_blocks: [],
|
||||
}),
|
||||
);
|
||||
return Promise.resolve(targetObservation(functionDossier));
|
||||
default:
|
||||
return Promise.resolve(ok(null));
|
||||
}
|
||||
|
||||
@@ -46,8 +46,22 @@ describe("enhanced MCP tools", () => {
|
||||
case "list_segments":
|
||||
return Promise.resolve(
|
||||
ok([
|
||||
{ name: "__TEXT", start: "0x1000", end: "0x1800" },
|
||||
{ name: "__DATA", start: "0x1800", end: "0x2000" },
|
||||
{
|
||||
name: "__TEXT",
|
||||
start: "0x1000",
|
||||
end: "0x1800",
|
||||
readable: null,
|
||||
writable: null,
|
||||
executable: null,
|
||||
},
|
||||
{
|
||||
name: "__DATA",
|
||||
start: "0x1800",
|
||||
end: "0x2000",
|
||||
readable: null,
|
||||
writable: null,
|
||||
executable: null,
|
||||
},
|
||||
]),
|
||||
);
|
||||
case "current_document":
|
||||
@@ -113,6 +127,35 @@ describe("enhanced MCP tools", () => {
|
||||
JSON.stringify(parseMcpToolError(result)),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects a segment with omitted coordinates instead of reporting zero length", async () => {
|
||||
const client = await connect({
|
||||
execute: (name) =>
|
||||
Promise.resolve(
|
||||
name === "list_segments"
|
||||
? ok([
|
||||
{
|
||||
name: "__TEXT",
|
||||
end: "0x2000",
|
||||
readable: null,
|
||||
writable: null,
|
||||
executable: null,
|
||||
},
|
||||
])
|
||||
: ok(name === "current_document" ? "fixture" : []),
|
||||
),
|
||||
});
|
||||
const result = await client.callTool({
|
||||
name: "binary_overview",
|
||||
arguments: {},
|
||||
});
|
||||
|
||||
expect(result.isError).toBe(true);
|
||||
expect(result.content).toContainEqual({
|
||||
type: "text",
|
||||
text: JSON.stringify(parseMcpToolError(result)),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const overviewPort = (
|
||||
@@ -127,7 +170,16 @@ const overviewPort = (
|
||||
return Promise.resolve(ok([...documents]));
|
||||
case "list_segments":
|
||||
return Promise.resolve(
|
||||
ok([{ name: "text", start: "0x1000", end: "0x2000" }]),
|
||||
ok([
|
||||
{
|
||||
name: "text",
|
||||
start: "0x1000",
|
||||
end: "0x2000",
|
||||
readable: null,
|
||||
writable: null,
|
||||
executable: null,
|
||||
},
|
||||
]),
|
||||
);
|
||||
default:
|
||||
return Promise.resolve(ok([]));
|
||||
|
||||
@@ -31,6 +31,38 @@ describe("analyze_function MCP producer validation", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
"procedure.classification",
|
||||
"procedure.body",
|
||||
"native_api",
|
||||
"native_value_flow",
|
||||
"limitations",
|
||||
])("rejects a complete dossier missing %s", async (field) => {
|
||||
const dossier = functionDossierSchema.parse(ghidraFunctionDossier());
|
||||
const value = structuredClone(dossier) as unknown as Record<
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
if (field.startsWith("procedure.")) {
|
||||
const procedure = value.procedure as Record<string, unknown>;
|
||||
delete procedure[field.slice("procedure.".length)];
|
||||
} else delete value[field];
|
||||
|
||||
const client = await connect({
|
||||
execute: () => Promise.resolve(observed(value)),
|
||||
});
|
||||
const result = await client.callTool({
|
||||
name: "analyze_function",
|
||||
arguments: { procedure: "0x1" },
|
||||
});
|
||||
|
||||
expect(result.isError).toBe(true);
|
||||
expect(result.content).toContainEqual({
|
||||
type: "text",
|
||||
text: JSON.stringify(parseMcpToolError(result)),
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a malformed collection in an otherwise complete dossier", async () => {
|
||||
const dossier = functionDossierSchema.parse(ghidraFunctionDossier());
|
||||
const client = await connect({
|
||||
|
||||
@@ -129,7 +129,15 @@ const dossierWithCallees = (addresses: readonly string[]) => {
|
||||
parameters: base.parameters,
|
||||
result: jsonValueSchema.parse({
|
||||
...jsonObjectSchema.parse(base.normalized_result),
|
||||
callees: addresses.map((address) => ({ address, name: "next" })),
|
||||
callees: addresses.map((address) => ({
|
||||
address,
|
||||
name: "next",
|
||||
classification: null,
|
||||
body: {
|
||||
available: false,
|
||||
reason: "The fixture has no callee body-extent observation.",
|
||||
},
|
||||
})),
|
||||
}),
|
||||
rawResult: base.raw_result,
|
||||
confidence: base.confidence,
|
||||
|
||||
@@ -308,7 +308,16 @@ const makeProvider = (
|
||||
operation === "health"
|
||||
? null
|
||||
: operation === "list_segments"
|
||||
? [{ name: "__TEXT", start: "0x1000", end: "0x2000" }]
|
||||
? [
|
||||
{
|
||||
name: "__TEXT",
|
||||
start: "0x1000",
|
||||
end: "0x2000",
|
||||
readable: null,
|
||||
writable: null,
|
||||
executable: null,
|
||||
},
|
||||
]
|
||||
: operation === "list_documents"
|
||||
? ["fixture"]
|
||||
: operation === "list_procedures"
|
||||
|
||||
@@ -4,6 +4,7 @@ import { promisify } from "node:util";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
import { OFFICIAL_TOOL_CONTRACTS } from "../../../../src/contracts/officialToolContracts.js";
|
||||
import { functionDossierSchema } from "../../../../src/domain/hopperValues.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
const bridgePath = new URL(
|
||||
@@ -48,6 +49,7 @@ const probeResultSchema = z.strictObject({
|
||||
reason: z.string(),
|
||||
}),
|
||||
}),
|
||||
analyze_function: z.unknown(),
|
||||
procedure_references: z.strictObject({
|
||||
procedure: z.strictObject({
|
||||
address: z.literal("0x401000"),
|
||||
@@ -153,6 +155,19 @@ describe("Hopper API facade", () => {
|
||||
if (!parsed.success) throw new Error(`${name}: ${parsed.error.message}`);
|
||||
expect(parsed.success, name).toBe(true);
|
||||
}
|
||||
const dossier = functionDossierSchema.parse(result.analyze_function);
|
||||
expect(dossier).toMatchObject({
|
||||
procedure: {
|
||||
classification: null,
|
||||
body: {
|
||||
available: false,
|
||||
reason:
|
||||
"Hopper's public Python API does not expose complete function body ranges",
|
||||
},
|
||||
},
|
||||
native_api: null,
|
||||
native_value_flow: null,
|
||||
});
|
||||
expect(result.provider_faults.map((reply) => reply.error.message)).toEqual([
|
||||
"TypeError: Hopper bridge operation failed",
|
||||
"ValueError: Hopper bridge operation failed",
|
||||
|
||||
Reference in New Issue
Block a user