Files
reverse-engineering-anything/tests/fixtures/jebMcp.ts
T
morluto 60149282fc test: strengthen integration oracles and verification (#8295)
* test: strengthen integration oracles and verification

* test: bound lifecycle gates and strengthen workflow checks

* test: verify complete paged and extracted results

* test: preserve bytecode and cancellation evidence

* test: strengthen retained evidence and fixture cleanup

* test: require cross-projection bridge identities

* test: retain fixture owners through cleanup failures

* test: verify graph examples and project selectors

* test: tighten provider and lifecycle regressions

* test: consolidate hex coverage and bound cutter cleanup

* test: bound subprocess output waits and strengthen graph checks

* test: check mcp recovery and preserve cleanup owners

* test: verify structured mcp argument failures

* test: preserve artifact cleanup and gdb limit evidence

* test: preserve evidence identities and bound provider gates

* test: retain browser and comparison cleanup owners

* test: bound startup and strengthen fixture oracles

* test: bound lifecycle gates and verify recovered evidence

* test: verify public outcomes and lifecycle ownership

* test: assert precise evidence and release lifecycle gates

* test: verify selected facts and bound cleanup waits

* test: check retained evidence and decoded records

* test: verify final reports and retain cleanup ownership

* test: bound reviewed startup gates and retain cleanup

* test: verify PE errors and preserve MCP cleanup

* test: preserve MCP fixture cleanup ownership

* test: release provider gates before late startup
2026-11-01 00:15:28 +08:00

105 lines
3.6 KiB
TypeScript

import { createVerifierHttpServer } from "../../scripts/lib/verifier-http-server.mjs";
import { z } from "zod";
import type { JsonValue } from "../../src/domain/jsonValue.js";
import { JEB_ENGINE_TOOLS } from "../../src/jeb/JebMcpConnection.js";
const messageSchema = z.object({
id: z.union([z.string(), z.number()]).optional(),
method: z.string(),
params: z
.object({
name: z.string().optional(),
arguments: z.unknown().optional(),
})
.passthrough()
.optional(),
});
/** Real HTTP MCP transport; close drains admitted catalog/tool callbacks, preserving handled 500 replies. */
export const startJebMcpFixture = async (
respond: (tool: string) => JsonValue | Promise<JsonValue>,
catalogReply?: JsonValue | (() => JsonValue | Promise<JsonValue>),
) => {
const requests: { name: string; arguments: unknown }[] = [];
const { server, close } = createVerifierHttpServer(
async (request, response) => {
if (request.method !== "POST") {
request.resume();
response.writeHead(request.method === "DELETE" ? 200 : 405).end();
return;
}
try {
let body = "";
for await (const chunk of request) body += String(chunk);
const message = messageSchema.parse(JSON.parse(body));
if (message.id === undefined) {
response.writeHead(202).end();
return;
}
let result: unknown;
if (message.method === "initialize")
result = {
protocolVersion: "2025-11-25",
capabilities: { tools: {} },
serverInfo: { name: "jeb-response-fixture", version: "1" },
};
else if (message.method === "tools/list")
result = (typeof catalogReply === "function"
? await catalogReply()
: catalogReply) ?? {
tools: Object.values(JEB_ENGINE_TOOLS).map((name) => ({
name,
inputSchema: { type: "object", properties: {} },
})),
};
else if (
message.method === "tools/call" &&
message.params?.name !== undefined
) {
requests.push({
name: message.params.name,
arguments: message.params.arguments,
});
const payload = await respond(message.params.name);
result = {
structuredContent: payload,
content: [{ type: "text", text: JSON.stringify(payload) }],
};
} else throw new Error(`Unexpected fixture request: ${message.method}`);
response.writeHead(200, { "Content-Type": "application/json" });
response.end(
JSON.stringify({ jsonrpc: "2.0", id: message.id, result }),
);
} catch (cause: unknown) {
response.writeHead(500).end(String(cause));
}
},
);
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
const address = server.address();
if (address === null || typeof address === "string")
throw new Error("Expected TCP fixture listener");
return {
endpoint: `http://127.0.0.1:${address.port}/mcp`,
requests,
get calls() {
return requests.map(({ name }) => name);
},
close,
};
};
export const jebPrimaryResponses: Readonly<Record<string, JsonValue>> = {
get_client_information: {
success: true,
version: "5.48.0",
gui_client: false,
},
list_units: {
success: true,
units: [{ unit_path: "sample.dex", unit_type: "dex" }],
},
decompile_code_item: { success: true, text: "int value() { return 1; }" },
open_project: { success: true, name: "sample", input_files: [], units: [] },
};