Files
reverse-engineering-anything/tests/support/cli/javascriptApplication.ts
T
morluto 88fd8a9df0 test: drop detail requests the budget seed made redundant (#14615)
PR #14252 added explicit complete-detail requests across tests before the
vitest REA_AGENT_RESULT_BUDGET_BYTES seed and the complete-Evidence harness
existed. Restore the pre-#14252 form where the seed or the harness already
delivers complete Evidence.

Keep the requests that are load-bearing: delivery, summary and budget tests,
tools whose omitted detail is summary, and callers that neither the seed nor
the harness reaches (unwrapped SDK clients on servers with an explicit
environment, and in-process CLIs). Those were found by running the touched
files with the shipped budget lowered to its 4 KiB minimum.
2026-11-25 21:08:12 +00:00

112 lines
3.4 KiB
TypeScript

import { createHash } from "node:crypto";
import { execFile } from "node:child_process";
import { promisify } from "node:util";
import { expect } from "vitest";
import { z } from "zod";
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
import { INLINE_EVIDENCE_MCP_ENVIRONMENT } from "../../../scripts/lib/mcp-verification-environment.mjs";
import type { SharedMcpCall, TestCli } from "./cliFixture.js";
const execute = promisify(execFile);
export const runNodeJsonControl = async (
root: string,
filename: string,
): Promise<unknown> => {
const { stdout } = await execute(process.execPath, [filename], {
cwd: root,
timeout: 5_000,
});
return JSON.parse(stdout) as unknown;
};
/**
* Use an explicit caller when the test owns the server. Otherwise reuse the
* file-scoped session from `cliTest`, and start a fresh server only for
* drivers created outside that fixture.
*/
export const resolveJavaScriptApplicationMcpCall = async (
cli: TestCli,
mcpCall: SharedMcpCall | undefined,
): Promise<SharedMcpCall> => {
if (mcpCall !== undefined) return mcpCall;
if (cli.sharedMcpCall !== undefined) return cli.sharedMcpCall();
return (await connectLocalToolsMcp(INLINE_EVIDENCE_MCP_ENVIRONMENT)).call;
};
/**
* Analyze a directory. A supplied MCP caller reuses its test-owned connection.
* CLI uses the driver's file-scoped process when present, and a fresh process
* otherwise.
*/
export const analyzeJavaScriptDirectory = async (
surface: "CLI" | "stdio MCP",
cli: TestCli,
root: string,
{
sourcePaths = [],
mcpCall,
}: {
readonly sourcePaths?: readonly string[];
readonly mcpCall?: SharedMcpCall | undefined;
} = {},
) => {
let document: unknown;
if (surface === "CLI") {
const run = cli.run.bind(cli);
const response = await run({
arguments: [
"analyze-javascript-application",
root,
...sourcePaths.flatMap((path) => ["--source-path", path]),
"--format",
"json",
],
environment: { REA_LOG_LEVEL: "silent" },
});
expect(response.exitCode, response.stderr).toBe(0);
document = response.json;
} else {
const call = await resolveJavaScriptApplicationMcpCall(cli, mcpCall);
const response = await call("analyze_javascript_application", {
input_path: root,
format: "directory",
...(sourcePaths.length === 0 ? {} : { source_paths: sourcePaths }),
});
expect(response.isError, JSON.stringify(response)).not.toBe(true);
document = response.structuredContent;
}
return z
.object({ normalized_result: javascriptApplicationAnalysisResultSchema })
.parse(document).normalized_result;
};
export const sourceEvidence = (
sourcePath: string,
source: string,
limitation?: string,
): unknown =>
expect.objectContaining({
artifact: expect.objectContaining({
available: true,
sha256: createHash("sha256").update(source).digest("hex"),
}),
location: expect.objectContaining({
available: true,
value: expect.objectContaining({
kind: "source-range",
source: sourcePath,
}),
}),
...(limitation === undefined
? {}
: {
limitations: expect.arrayContaining([
expect.stringContaining(limitation),
]),
}),
});