test(erlang): consolidate BEAM budget and truncation coverage (#12830)

test(erlang): consolidate BEAM limit and truncation checks
This commit is contained in:
morluto authored and GitHub committed 2026-11-20 08:30:16 -05:00
1 parent 68e6953897
commit 01895d33ef
4 files changed
+31 -48

No files matched your search

-14
View File
@@ -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" },
});
});
@@ -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: {
+1 -26
View File
@@ -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.`,
});
});
});
+19 -7
View File
@@ -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 {