Files
reverse-engineering-anything/tests/boundary/mcp/reverseEngineeringProviderEnvironmentMcp.test.ts
T
385e5d228f test: own temporary directories through createTestTempDirectory in remaining tests/ (#12727)
* test: own temporary directories through createTestTempDirectory in remaining tests/

Give per-test directories in the remaining tests/ suites to
createTestTempDirectory so onTestFinished removes them through
removeTestWorkspace. Keep suite-scoped roots and child-process directories
whose removal is the assertion.

* test: drop empty cleanup callbacks and keep the capture skip reason visible

Remove the no-op withVerifierCleanup steps left after directory removal
moved to createTestTempDirectory. Put the native capture skip explanation
in the Linux sample test name, because it.skipIf only tests truthiness.

Co-authored-by: morluto <morluto@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: morluto <morluto@users.noreply.github.com>
2026-11-19 23:22:53 -05:00

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({
raw_result: { stdout: `${scenario.expected}\n` },
});
} finally {
await Promise.all([client.close(), server.close()]);
}
}
});