From 01895d33efd70d3291e91e89907db058e90b135e Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Fri, 20 Nov 2026 08:30:16 -0500 Subject: [PATCH] test(erlang): consolidate BEAM budget and truncation coverage (#12830) test(erlang): consolidate BEAM limit and truncation checks --- tests/acceptance/erlangBeamCli.test.ts | 14 ---------- .../stableArtifactParserFailureCli.test.ts | 12 ++++++++- tests/boundary/filesystem/erlangBeam.test.ts | 27 +------------------ tests/boundary/mcp/erlangBeamMcp.test.ts | 26 +++++++++++++----- 4 files changed, 31 insertions(+), 48 deletions(-) diff --git a/tests/acceptance/erlangBeamCli.test.ts b/tests/acceptance/erlangBeamCli.test.ts index ef9add7ff3..a92643032b 100644 --- a/tests/acceptance/erlangBeamCli.test.ts +++ b/tests/acceptance/erlangBeamCli.test.ts @@ -521,17 +521,3 @@ cliTest("rejects an empty BEAM path before reading", async ({ cli }) => { expect(result.exitCode, result.stderr).not.toBe(0); expect(result.stdout).not.toContain("sha256"); }); - -cliTest("reports a truncated BEAM as invalid input", async ({ cli }) => { - const root = await createTestTempDirectory("rea-beam-cli-bad-"); - const path = join(root, "broken.beam"); - await writeFile(path, Buffer.from("FOR1")); - const result = await cli.run({ - arguments: ["inspect-erlang-beam", path, "--json"], - }); - expect(result.exitCode).toBe(1); - expect(result.json).toMatchObject({ - code: "invalid_request", - details: { operation: "inspect_erlang_beam" }, - }); -}); diff --git a/tests/acceptance/stableArtifactParserFailureCli.test.ts b/tests/acceptance/stableArtifactParserFailureCli.test.ts index 741a8893d0..edd9fa8b8b 100644 --- a/tests/acceptance/stableArtifactParserFailureCli.test.ts +++ b/tests/acceptance/stableArtifactParserFailureCli.test.ts @@ -26,10 +26,20 @@ for (const command of [ async ({ cli }) => { const root = await createTestTempDirectory("rea-format-refusal-"); const path = join(root, "foreign.bin"); - const bytes = Buffer.alloc(64, 0x7f); + const isBeam = command === "inspect-erlang-beam"; + const bytes = isBeam ? Buffer.from("FOR1") : Buffer.alloc(64, 0x7f); await writeFile(path, bytes); const result = await cli.run({ arguments: [command, path, "--json"] }); expect(result.exitCode, result.stderr).toBe(1); + if (isBeam) { + expect(result.json).toMatchObject({ + code: "invalid_request", + details: { + operation: "inspect_erlang_beam", + issues: [{ path: ["path"], reason: "invalid_format" }], + }, + }); + } expect(result.json).toMatchObject({ details: { partial_observation: { diff --git a/tests/boundary/filesystem/erlangBeam.test.ts b/tests/boundary/filesystem/erlangBeam.test.ts index 302a4de09b..5578328b84 100644 --- a/tests/boundary/filesystem/erlangBeam.test.ts +++ b/tests/boundary/filesystem/erlangBeam.test.ts @@ -2,11 +2,7 @@ import { symlink, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; import { createBeamService } from "../../../src/composition/erlang.js"; -import { MAX_INSPECT_ERLANG_BEAM_TABLE_ROWS } from "../../../src/domain/erlang/beam.js"; -import { - erlangBeamRowsFixture, - erlangBeamFixture, -} from "../../../src/erlang/Beam.fixture.js"; +import { erlangBeamFixture } from "../../../src/erlang/Beam.fixture.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; describe("Erlang BEAM stable filesystem boundary", () => { @@ -59,25 +55,4 @@ describe("Erlang BEAM stable filesystem boundary", () => { expect(cancelled.error._tag).toBe("AnalysisCancelledError"); expect(cancelled.error.cause).toBe(reason); }); - - it("stops combined table rows at the shared budget", async () => { - const root = await createTestTempDirectory("rea-beam-rows-"); - const path = join(root, "rows.beam"); - const below = Math.floor(MAX_INSPECT_ERLANG_BEAM_TABLE_ROWS / 2); - await writeFile( - path, - erlangBeamRowsFixture([ - ["ExpT", below], - ["ImpT", below], - ["FunT", MAX_INSPECT_ERLANG_BEAM_TABLE_ROWS - below * 2 + 1], - ]), - ); - const result = await createBeamService().inspect({ path }); - if (result.ok) throw new Error("Expected row budget failure"); - expect(result.error).toMatchObject({ - _tag: "AnalysisResourceConstraintError", - resource: "capacity", - remediationAction: `The file exceeds the ${String(MAX_INSPECT_ERLANG_BEAM_TABLE_ROWS)}-row ceiling this operation accepts; select a smaller artifact.`, - }); - }); }); diff --git a/tests/boundary/mcp/erlangBeamMcp.test.ts b/tests/boundary/mcp/erlangBeamMcp.test.ts index 0e1f1a05cc..cd186ffa33 100644 --- a/tests/boundary/mcp/erlangBeamMcp.test.ts +++ b/tests/boundary/mcp/erlangBeamMcp.test.ts @@ -92,6 +92,9 @@ mcpTest( async ({ mcp }) => { const { client, session } = await connect(mcp); const root = await createTestTempDirectory("rea-beam-capacity-"); + const rowLimit = MAX_INSPECT_ERLANG_BEAM_TABLE_ROWS; + const halfRowLimit = Math.floor(rowLimit / 2); + const rowRemediation = `The file exceeds the ${String(rowLimit)}-row ceiling this operation accepts; select a smaller artifact.`; try { for (const [label, bytes, settings, budget, remediation] of [ [ @@ -109,13 +112,22 @@ mcpTest( "Raise max_chunks above 1", ], [ - "rows", + "single-table-rows", + erlangBeamRowsFixture([["ExpT", rowLimit + 1]]), + {}, + { max_table_rows: rowLimit }, + rowRemediation, + ], + [ + "combined-table-rows", erlangBeamRowsFixture([ - ["ExpT", MAX_INSPECT_ERLANG_BEAM_TABLE_ROWS + 1], + ["ExpT", halfRowLimit], + ["ImpT", halfRowLimit], + ["FunT", rowLimit - halfRowLimit * 2 + 1], ]), {}, - { max_table_rows: MAX_INSPECT_ERLANG_BEAM_TABLE_ROWS }, - `${String(MAX_INSPECT_ERLANG_BEAM_TABLE_ROWS)}-row ceiling`, + { max_table_rows: rowLimit }, + rowRemediation, ], ] as const) { const path = join(root, `${label}.beam`); @@ -124,13 +136,13 @@ mcpTest( name: "inspect_erlang_beam", arguments: { path, ...settings }, }); - expect(response.isError).toBe(true); + expect(response.isError, label).toBe(true); const error = parseMcpToolError(response).error; - expect(error).toMatchObject({ + expect(error, label).toMatchObject({ code: "resource_constraint", retryable: false, remediation: { action: expect.stringContaining(remediation) }, - details: { reported_limits: budget }, + details: { resource: "capacity", reported_limits: budget }, }); } } finally {