mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 05:51:06 +00:00
* perf(debugger): stop repeating command results as raw_result GDB console/startup, Rizin debug, Cutter and reverse-engineering command Evidence set rawResult to a copy of result, contrary to the raw_result contract. Every interactive debugger reply therefore carried its records and output twice. Omit rawResult where no distinct provider representation exists; tests assert the same facts on normalized_result. Closes #14145 * test(debugger): assert command results on normalized_result in remaining suites The composition, CLI delivery, acceptance and MCP suites still read command output through raw_result, and one fixture built a parent Evidence record that repeated its result as raw_result. They now assert the same fields on normalized_result and that raw_result is null.
86 lines
2.9 KiB
TypeScript
86 lines
2.9 KiB
TypeScript
import { chmod, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
|
|
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
|
import { expect, it } from "vitest";
|
|
|
|
import { createServer } from "../../../src/server/createServer.js";
|
|
import { createAnalysisExecution } from "../../../src/ports/AnalysisProvider.js";
|
|
import { ok } from "../../../src/domain/result.js";
|
|
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
const analysis = {
|
|
execute: async () =>
|
|
ok(
|
|
createAnalysisExecution({}, { id: "test", name: "Test", version: null }),
|
|
),
|
|
};
|
|
|
|
const writeRizin = async (directory: string, output: string): Promise<void> => {
|
|
const executable = join(directory, "rizin");
|
|
await writeFile(executable, `#!/bin/sh\nprintf '%s\\n' '${output}'\n`);
|
|
await chmod(executable, 0o755);
|
|
};
|
|
|
|
it("uses the server-selected environment unless a provider environment overrides it", async () => {
|
|
const directory = await createTestTempDirectory("rea-reverse-env-");
|
|
const selectedPath = join(directory, "selected");
|
|
const overridePath = join(directory, "override");
|
|
const artifactPath = join(directory, "sample.bin");
|
|
await Promise.all([mkdir(selectedPath), mkdir(overridePath)]);
|
|
await Promise.all([
|
|
writeRizin(selectedPath, "selected environment"),
|
|
writeRizin(overridePath, "provider override"),
|
|
writeFile(artifactPath, "fixture"),
|
|
]);
|
|
|
|
for (const scenario of [
|
|
{
|
|
environment: selectedPath,
|
|
expected: "selected environment",
|
|
},
|
|
{
|
|
environment: selectedPath,
|
|
provider: overridePath,
|
|
expected: "provider override",
|
|
},
|
|
]) {
|
|
const server = createServer(
|
|
{ kind: "fixed", analysis },
|
|
{
|
|
environment: { ...process.env, PATH: scenario.environment },
|
|
...(scenario.provider === undefined
|
|
? {}
|
|
: {
|
|
providerEnvironment: {
|
|
...process.env,
|
|
PATH: scenario.provider,
|
|
},
|
|
}),
|
|
},
|
|
);
|
|
const client = new Client(
|
|
{ name: "reverse-env-test", version: "1" },
|
|
{ jsonSchemaValidator: createMcpSchemaValidation() },
|
|
);
|
|
const [clientTransport, serverTransport] =
|
|
InMemoryTransport.createLinkedPair();
|
|
try {
|
|
await server.connect(serverTransport);
|
|
await client.connect(clientTransport);
|
|
const result = await client.callTool({
|
|
name: "execute_rizin_command",
|
|
arguments: { path: artifactPath, command: "iI" },
|
|
});
|
|
expect(result.isError).not.toBe(true);
|
|
expect(result.structuredContent).toMatchObject({
|
|
normalized_result: { stdout: `${scenario.expected}\n` },
|
|
});
|
|
} finally {
|
|
await Promise.all([client.close(), server.close()]);
|
|
}
|
|
}
|
|
});
|