From 55cef2566a5cf7bad3ed4f2dfefecbeee386beea Mon Sep 17 00:00:00 2001 From: Ysopwnable <161784452+N0zoM1z0@users.noreply.github.com> Date: Thu, 15 Oct 2026 19:00:04 +0800 Subject: [PATCH] perf(tests): reuse CLI compilation for exported binding checks Reuse the existing CLI compilation policy in the exported binding acceptance matrix. Own and clean a fresh cache per file while preserving caller cache and coverage choices, all 92 cases, and every live CLI/MCP request and oracle. Fixes #4079 Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com> --- .../exportedFunctionBindingsCli.test.ts | 50 ++++++++++++++----- tests/support/cli/cliFixture.ts | 17 +++++-- 2 files changed, 50 insertions(+), 17 deletions(-) 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 => { + 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 }),