feat: evolve REA analysis platform

This commit is contained in:
morluto
2026-07-12 19:32:13 +08:00
parent 1f235cb52f
commit 4f18e26ee5
47 changed files with 1841 additions and 334 deletions
+37 -27
View File
@@ -2,11 +2,11 @@ import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
import type { CallToolResult } from "@modelcontextprotocol/server";
import { afterEach, describe, expect, it } from "vitest";
import {
BinarySession,
type BinaryClient,
} from "../../src/application/BinarySession.js";
import type { HopperToolPort } from "../../src/application/HopperToolPort.js";
import { BinarySession } from "../../src/application/BinarySession.js";
import type {
AnalysisClient,
AnalysisOperationPort,
} from "../../src/application/AnalysisProvider.js";
import { HopperRemoteError } from "../../src/domain/errors.js";
import { err, ok } from "../../src/domain/result.js";
import { createServer } from "../../src/server/createServer.js";
@@ -19,8 +19,8 @@ afterEach(async () => {
);
});
const connect = async (hopper: HopperToolPort) => {
const server = createServer(hopper);
const connect = async (analysis: AnalysisOperationPort) => {
const server = createServer(analysis);
const client = new Client({
name: "integration-test",
version: "1.0.0",
@@ -51,7 +51,7 @@ const structured = (result: CallToolResult): Record<string, unknown> => {
describe("full MCP integration with multi-tool sequences", () => {
it("executes a realistic workflow: list methods, decompile selected, get xrefs", async () => {
const client = await connect({
callTool: (name, args) => {
execute: (name, args) => {
switch (name) {
case "list_procedures":
return Promise.resolve(
@@ -85,19 +85,26 @@ describe("full MCP integration with multi-tool sequences", () => {
});
expect(listResult.isError).not.toBe(true);
expect(structured(listResult)).toMatchObject({
items: [
{ address: "0x1000", value: "main" },
{ address: "0x2000", value: "helper" },
],
total: 2,
has_more: false,
artifact: null,
operation: "list_procedures",
provider: { id: "hopper", version: null },
result: {
items: [
{ address: "0x1000", value: "main" },
{ address: "0x2000", value: "helper" },
],
total: 2,
has_more: false,
},
});
const decompileResult = await client.callTool({
name: "procedure_pseudo_code",
arguments: { procedure: "0x1000" },
});
expect(structured(decompileResult)).toEqual({
expect(structured(decompileResult)).toMatchObject({
operation: "procedure_pseudo_code",
parameters: { document: null, procedure: "0x1000" },
result: "pseudo for 0x1000",
});
@@ -105,19 +112,22 @@ describe("full MCP integration with multi-tool sequences", () => {
name: "xrefs",
arguments: {},
});
expect(structured(xrefResult)).toEqual({ result: ["0x1000"] });
expect(structured(xrefResult)).toMatchObject({
operation: "xrefs",
result: ["0x1000"],
});
});
it("preserves the complete 43-tool inventory with a session", async () => {
it("preserves the complete 46-tool inventory with a session", async () => {
const session = new BinarySession(
(_path) =>
({
callTool: () => Promise.resolve(ok(null)),
execute: () => Promise.resolve(ok(null)),
close: () => Promise.resolve(),
}) satisfies BinaryClient,
}) satisfies AnalysisClient,
);
const server = createServer(
{ callTool: () => Promise.resolve(ok(null)) },
{ execute: () => Promise.resolve(ok(null)) },
session,
);
const client = new Client({
@@ -131,7 +141,7 @@ describe("full MCP integration with multi-tool sequences", () => {
await client.connect(clientTransport);
const listed = await client.listTools();
expect(listed.tools).toHaveLength(43);
expect(listed.tools).toHaveLength(46);
const names = listed.tools.map((t) => t.name);
expect(names).toContain("open_binary");
expect(names).toContain("close_binary");
@@ -140,12 +150,12 @@ describe("full MCP integration with multi-tool sequences", () => {
expect(names).toContain("batch_decompile");
});
it("preserves the 40-tool inventory without a session", async () => {
it("preserves the 43-tool inventory without a session", async () => {
const client = await connect({
callTool: () => Promise.resolve(ok(null)),
execute: () => Promise.resolve(ok(null)),
});
const listed = await client.listTools();
expect(listed.tools).toHaveLength(40);
expect(listed.tools).toHaveLength(43);
const names = listed.tools.map((t) => t.name);
expect(names).toContain("binary_overview");
expect(names).toContain("batch_decompile");
@@ -154,7 +164,7 @@ describe("full MCP integration with multi-tool sequences", () => {
it("propagates remote Hopper errors with structured content", async () => {
const client = await connect({
callTool: () =>
execute: () =>
Promise.resolve(err(new HopperRemoteError(-32000, "bridge timeout"))),
});
@@ -170,7 +180,7 @@ describe("full MCP integration with multi-tool sequences", () => {
it("handles concurrent tool calls without corruption", async () => {
const invocations: string[] = [];
const client = await connect({
callTool: (name) => {
execute: (name) => {
invocations.push(name);
return Promise.resolve(
ok(
@@ -183,7 +193,7 @@ describe("full MCP integration with multi-tool sequences", () => {
next_offset: null,
has_more: false,
}
: { handled: name },
: [],
),
);
},