fix(analysis): resolve procedure identities and preserve literal queries

This commit is contained in:
morluto
2026-10-09 02:42:39 +08:00
parent f2e22e13a6
commit d830cb79b3
9 changed files with 117 additions and 116 deletions
@@ -40,7 +40,6 @@ const fixturePort = (): AnalysisOperationPort => ({
execute: (name, arguments_) => {
switch (name) {
case "inspect_native_dispatch_metadata":
case "procedure_address":
return Promise.resolve(
err(
new AnalysisCapabilityUnavailableError(
@@ -50,6 +49,24 @@ const fixturePort = (): AnalysisOperationPort => ({
),
),
);
case "procedure_address": {
const procedure = inventory(PROCEDURES).find(
(item) =>
item.address === arguments_.procedure ||
item.value === arguments_.procedure,
);
return Promise.resolve(
procedure === undefined
? err(
new AnalysisCapabilityUnavailableError(
"fixture",
name,
"No matching procedure in this symbol-only fixture",
),
)
: ok(procedure.address),
);
}
case "list_procedures":
return Promise.resolve(ok(inventory(PROCEDURES)));
case "list_names":
@@ -19,9 +19,11 @@ describe("enhanced MCP tools", () => {
it("returns typed graph failures and stable unresolved-name results", async () => {
const tools = new EnhancedTools({
execute: (name) =>
name === "procedure_callees"
? Promise.resolve(err(new AnalysisOutputError(name, "failed")))
: Promise.resolve(ok(inventory({}))),
name === "procedure_address"
? Promise.resolve(ok("0x1"))
: name === "procedure_callees"
? Promise.resolve(err(new AnalysisOutputError(name, "failed")))
: Promise.resolve(ok(inventory({}))),
});
const graph = await tools.execute("get_call_graph", {
@@ -58,40 +60,6 @@ describe("enhanced MCP tools", () => {
});
});
it("traverses the complete reachable call graph and stops at cycles", async () => {
const tools = new EnhancedTools({
execute: (name, arguments_) => {
if (name !== "procedure_callees") return Promise.resolve(ok([]));
const address = String(arguments_.procedure);
const next = Number.parseInt(address.slice(2), 16) + 1;
return Promise.resolve(
ok(next <= 8 ? [`0x${next.toString(16)}`] : ["0x2"]),
);
},
});
const result = await tools.execute("get_call_graph", {
address: "0x1",
direction: "forward",
});
expect(result).toEqual({
ok: true,
value: Object.fromEntries(
Array.from({ length: 8 }, (_, index) => [
String(index),
[
{
address: `0x${index + 1}`,
calls: [index === 7 ? "0x2" : `0x${index + 2}`],
status: "ok",
},
],
]),
),
});
});
it("uses every procedure in one complete inventory", async () => {
const client = await connect({
execute: () => {
@@ -11,41 +11,6 @@ import { observed as ok } from "../../fixtures/analysisExecution.js";
afterEach(closeEnhancedToolResources);
describe("enhanced MCP tools", () => {
it("returns Evidence IDs and a complete call path", async () => {
const client = await connect({
execute: async (_name, arguments_) => {
const procedure = arguments_.procedure;
return ok(
procedure === "0x1"
? ["0x2", "0x3"]
: procedure === "0x2"
? ["0x1"]
: [],
);
},
});
const result = await client.callTool({
name: "trace_call_path",
arguments: {
start: "0x1",
goal: "0x3",
},
});
expect(result.isError).not.toBe(true);
expect(result.structuredContent).toMatchObject({
evidence_id: expect.stringMatching(/^ev_[a-f0-9]{64}$/u),
result: {
goal_status: "reached",
nodes: expect.arrayContaining([
expect.objectContaining({ address: "0x1" }),
expect.objectContaining({ address: "0x3" }),
]),
truncated: false,
},
});
});
it("returns every batch item in caller order with its own result", async () => {
const addresses = Array.from(
{ length: 37 },