mirror of
https://github.com/morluto/rea.git
synced 2026-10-30 11:25:39 +00:00
Reuse the pinned SDK's combined array-element and object-member admission before canonical validation, deferred runtime loading and tool execution. Share a configurable finite allowance across eager/deferred HTTP and stdio, and project refusals to bounded, actionable transport resource errors. Preserve canonical CLI/application contracts, caller-selected input values, ordinary validation semantics and complete Evidence access. Exercise actual transport boundaries, real artifact/TShark workflows, packaged installation, continued service and downstream identity/capacity regressions. Fixes #7882 BREAKING CHANGE: MCP tool arguments now default to 1,024 combined array elements and object members per call. Select a larger positive finite REA_MCP_MAX_INPUT_ELEMENTS allowance and restart for larger inline inputs, or use retained/file selectors where supported. Inputs are never truncated. Assisted-by: Reimu (gensokyo-skills:reimu-incident-triage) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
85 lines
2.8 KiB
TypeScript
85 lines
2.8 KiB
TypeScript
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.sharedCliRun ?? ((invocation) => cli.run(invocation));
|
|
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;
|
|
};
|