Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

perf(tests): reuse CLI compilation for exported binding checks

Ysopwnable55cef2566a5c
diff --git a/tests/acceptance/applications/exportedFunctionBindingsCli.test.ts b/tests/acceptance/applications/exportedFunctionBindingsCli.test.ts
index c9ee1aeb1..97c470a4f 100644
--- a/tests/acceptance/applications/exportedFunctionBindingsCli.test.ts
+++ b/tests/acceptance/applications/exportedFunctionBindingsCli.test.ts
@@ -7,12 +7,19 @@ import { promisify } from "node:util";
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
-import { afterAll, describe, expect, it } from "vitest";
+import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { z } from "zod";
+import { closeVerifierResources } from "../../../scripts/lib/verifier-cleanup.mjs";
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
import { javaScriptExportShapeComparisonResultSchema } from "../../../src/domain/javascript/javascriptExportShapeComparisonSchemas.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
+import { cliCompileCacheEnvironment } from "../../support/cli/cliFixture.js";
+import {
+ createTestWorkspace,
+ removeTestWorkspace,
+ type TestWorkspace,
+} from "../../support/workspace/workspaceFixture.js";
const execute = promisify(execFile);
const requireFixture = createRequire(import.meta.url);
@@ -22,6 +29,12 @@ const comparisonEnvelope = z.object({
const applicationEnvelope = z.object({
normalized_result: javascriptApplicationAnalysisResultSchema,
});
+let cliCacheWorkspace: TestWorkspace | undefined;
+
+beforeAll(async () => {
+ cliCacheWorkspace = await createTestWorkspace("rea-export-bindings-cache-");
+});
+
// Source semantics use the real stdio workflow throughout the matrix. The
// missing-export and count-change cases also check compiled CLI adapter parity.
let mcpConnection:
@@ -33,17 +46,25 @@ let mcpConnection:
| undefined;
afterAll(async () => {
- if (mcpConnection === undefined) return;
- try {
- await mcpConnection.ready;
- } catch {
- // Keep the failed connection owned until both resources are closed below.
- }
- try {
- await mcpConnection.client.close();
- } finally {
- await mcpConnection.transport.close();
+ if (mcpConnection !== undefined) {
+ try {
+ await mcpConnection.ready;
+ } catch {
+ // Keep the failed connection owned until both resources are closed below.
+ }
}
+ await closeVerifierResources([
+ async () => {
+ await mcpConnection?.client.close();
+ },
+ async () => {
+ await mcpConnection?.transport.close();
+ },
+ async () => {
+ if (cliCacheWorkspace !== undefined)
+ await removeTestWorkspace(cliCacheWorkspace.root);
+ },
+ ]);
});
describe("exported function binding resolution through stdio MCP and CLI", () => {
@@ -1192,12 +1213,17 @@ const expectCountChange = (
};
const runCli = async (args: readonly string[]): Promise<unknown> => {
+ if (cliCacheWorkspace === undefined)
+ throw new Error("CLI compile-cache workspace was not initialized");
const { stdout } = await execute(
process.execPath,
[resolve("scripts/rea.mjs"), ...args],
{
maxBuffer: 16 * 1024 * 1024,
- env: { ...process.env, REA_LOG_LEVEL: "silent" },
+ env: cliCompileCacheEnvironment(
+ { ...process.env, REA_LOG_LEVEL: "silent" },
+ cliCacheWorkspace.path("node-compile"),
+ ),
},
);
return JSON.parse(stdout);
diff --git a/tests/support/cli/cliFixture.ts b/tests/support/cli/cliFixture.ts
index 012944a9a..e41f6ea95 100644
--- a/tests/support/cli/cliFixture.ts
+++ b/tests/support/cli/cliFixture.ts
@@ -40,6 +40,17 @@ const parseJson = (stdout: string): unknown | undefined => {
}
};
+/** Reuse CLI compilation without overriding caller-selected cache or coverage. */
+export const cliCompileCacheEnvironment = (
+ environment: NodeJS.ProcessEnv | undefined,
+ compileCache?: string,
+): NodeJS.ProcessEnv => ({
+ ...(compileCache === undefined || environment?.NODE_V8_COVERAGE !== undefined
+ ? {}
+ : { NODE_COMPILE_CACHE: compileCache }),
+ ...environment,
+});
+
/** Create a compiled CLI driver backed by the supplied process registry. */
export const createTestCli = (
processes: TestProcesses,
@@ -68,11 +79,7 @@ export const createTestCli = (
TMP: tmpdir(),
}
: {}),
- ...(compileCache === undefined ||
- environment?.NODE_V8_COVERAGE !== undefined
- ? {}
- : { NODE_COMPILE_CACHE: compileCache }),
- ...environment,
+ ...cliCompileCacheEnvironment(environment, compileCache),
},
...(input === undefined ? {} : { input }),
...(timeoutMs === undefined ? {} : { timeoutMs }),