import { constants } from "node:buffer"; import { open } from "node:fs/promises"; import { join } from "node:path"; import { expect } from "vitest"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { cliTest } from "../../support/cli/cliFixture.js"; cliTest( "preserves the runtime string limit through CLI and Evidence file inputs", async ({ cli, processes }) => { const root = await createTestTempDirectory("rea-json-string-limit-"); const input = join(root, "oversized.json"); const file = await open(input, "wx"); try { // Sparse zero bytes are valid UTF-8. Decoded length exceeds the runtime // string limit before JSON syntax can be inspected; no fixture is retained. await file.truncate(constants.MAX_STRING_LENGTH + 1); } finally { await file.close(); } const limits = { input_path: input, input_bytes: constants.MAX_STRING_LENGTH + 1, max_string_code_units: constants.MAX_STRING_LENGTH, }; // Run readers sequentially in owned child processes, releasing each large // read buffer when its process exits instead of retaining it in Vitest. const result = await cli.run({ arguments: ["trace-application-feature", input, "--json"], }); expect(result.json).toMatchObject({ code: "resource_constraint", category: "resource_constraint", input_path: input, input_reason: "too-large", retryable: false, remediation: { action: expect.stringContaining("re-analyze") }, details: { operation: "trace-application-feature", resource: "memory", reported_limits: limits, }, }); expect(result.exitCode).toBe(1); expect(result.stderr).toBe(""); const evidence = await processes.run(process.execPath, [ "--input-type=module", "-e", `import { readJsonFile } from "./dist/application/JsonFiles.js"; import { projectAnalysisError } from "./dist/domain/analysisErrorProjection.js"; const result = await readJsonFile(process.argv[1]); console.log(JSON.stringify(result.ok ? result : projectAnalysisError(result.error)));`, input, ]); expect(JSON.parse(evidence.stdout)).toMatchObject({ code: "resource_constraint", details: { operation: "read_evidence_file", resource: "memory", reported_limits: limits, }, }); expect(evidence.stderr).toBe(""); expect(evidence.exitCode).toBe(0); }, );