mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 11:13:21 +00:00
239 literal timeoutMs values on cli.run and processes.run only restated a guess at host speed. On hosted runners with four workers, cliOutput's 3-second value failed while the command still produced correct output. Deadlines that are the behavior under test, derived from an operation budget, or that bound a regression's wait remain. Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
122 lines
4.5 KiB
TypeScript
122 lines
4.5 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { readFile, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
|
|
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
|
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
|
|
import { fileLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
const mcp = fileLocalToolsMcp();
|
|
|
|
const large = "x".repeat(200_000);
|
|
for (const scenario of [
|
|
{ name: "quoted literal", expression: JSON.stringify(large), limited: true },
|
|
{ name: "cooked template", expression: `\`${large}\``, limited: true },
|
|
{
|
|
name: "limited member receiver",
|
|
expression: `(${JSON.stringify(large)}).field`,
|
|
limited: true,
|
|
},
|
|
{
|
|
name: "configuration-only default",
|
|
expression: `process.env.MODE ?? ${JSON.stringify(large)}`,
|
|
bare: true,
|
|
limited: true,
|
|
},
|
|
{
|
|
name: "equivalent addition",
|
|
expression: `${JSON.stringify(large.slice(0, 100_000))} + ${JSON.stringify(large.slice(100_000))}`,
|
|
limited: true,
|
|
},
|
|
{ name: "small exact control", expression: '"small"', limited: false },
|
|
]) {
|
|
cliTest(
|
|
`preserves normalized string-byte coverage for ${scenario.name}`,
|
|
async ({ cli }) => {
|
|
const root = await createTestTempDirectory("rea-literal-budget-");
|
|
const path = join(root, "main.js");
|
|
const source =
|
|
"bare" in scenario
|
|
? `${scenario.expression};\n`
|
|
: `export const payload = ${scenario.expression};\n`;
|
|
await writeFile(path, source);
|
|
const digest = createHash("sha256").update(source).digest("hex");
|
|
const cliResponse = await cli.run({
|
|
arguments: ["analyze-javascript-application", root, "--json"],
|
|
});
|
|
expect(cliResponse.exitCode).toBe(0);
|
|
const cliEvidence = toolContract(
|
|
"analyze_javascript_application",
|
|
).outputSchema.parse(cliResponse.json);
|
|
const response = await mcp.client.callTool({
|
|
name: "analyze_javascript_application",
|
|
arguments: { input_path: root },
|
|
});
|
|
expect(response.isError).not.toBe(true);
|
|
const evidence = toolContract(
|
|
"analyze_javascript_application",
|
|
).outputSchema.parse(response.structuredContent);
|
|
expect(evidence.evidence_id).toBe(cliEvidence.evidence_id);
|
|
|
|
for (const candidate of [cliEvidence, evidence]) {
|
|
const analysis = javascriptApplicationAnalysisResultSchema.parse(
|
|
candidate.normalized_result,
|
|
);
|
|
const stringLengths = analysis.semantic_graph.nodes.flatMap(
|
|
({ properties }) =>
|
|
typeof properties.value === "string"
|
|
? [properties.value.length]
|
|
: [],
|
|
);
|
|
expect(stringLengths).not.toContain(large.length);
|
|
if (scenario.limited) {
|
|
expect(analysis.graph.coverage.status).toBe("partial");
|
|
expect(analysis.graph.coverage.limits).toContainEqual(
|
|
expect.objectContaining({
|
|
name: "javascript_semantic_primitive_bytes",
|
|
unit: "bytes",
|
|
value: 1_048_576,
|
|
}),
|
|
);
|
|
expect(analysis.semantic_graph.unknowns).toContainEqual(
|
|
expect.objectContaining({
|
|
reason: "resource-limit",
|
|
detail: expect.stringMatching(
|
|
/primitive string-byte budget exceeded/i,
|
|
),
|
|
}),
|
|
);
|
|
} else {
|
|
expect(stringLengths).toContain(5);
|
|
expect(analysis.graph.coverage.limits).toEqual([]);
|
|
}
|
|
if ("bare" in scenario) {
|
|
const node = analysis.semantic_graph.nodes.find(
|
|
({ kind, properties }) =>
|
|
kind === "config-source" && properties.source_kind === "default",
|
|
);
|
|
expect(node?.properties).toMatchObject({
|
|
value: null,
|
|
value_resource_limit: "primitive-bytes",
|
|
});
|
|
expect(analysis.semantic_graph.unknowns).toContainEqual(
|
|
expect.objectContaining({
|
|
node_id: node?.node_id,
|
|
reason: "resource-limit",
|
|
}),
|
|
);
|
|
}
|
|
expect(
|
|
analysis.graph.nodes.find((node) => node.kind === "javascript-asset")
|
|
?.identity,
|
|
).toMatchObject({ sha256: digest });
|
|
}
|
|
expect(await readFile(path, "utf8")).toBe(source);
|
|
await mcp.client.ping();
|
|
},
|
|
);
|
|
}
|