From 98c3fad24d95fd8cb1f87f0c8336a2776af09bb4 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Fri, 20 Nov 2026 07:41:43 -0500 Subject: [PATCH] test(erlang): consolidate Beam atom layout coverage (#12795) test(erlang): consolidate BEAM atom layout coverage --- src/erlang/BeamParser.test.ts | 23 ++++- .../acceptance/erlangBeamAtomLayouts.test.ts | 85 ------------------- 2 files changed, 19 insertions(+), 89 deletions(-) delete mode 100644 tests/acceptance/erlangBeamAtomLayouts.test.ts diff --git a/src/erlang/BeamParser.test.ts b/src/erlang/BeamParser.test.ts index 5a2b53a8dd..a37732acf0 100644 --- a/src/erlang/BeamParser.test.ts +++ b/src/erlang/BeamParser.test.ts @@ -295,12 +295,27 @@ it("rejects an AtU8 atom name that is not UTF-8", () => { ).toThrow(/BEAM atom name is not valid UTF-8/); }); -it("keeps a latin1 atom byte unchanged", () => { +it("uses a one-byte length and preserves Latin-1 bytes in legacy Atom", () => { const report = parse( - erlangBeamChunksFixture([["Atom", Buffer.from([0, 0, 0, 1, 1, 0xff])]]), + erlangBeamChunksFixture([ + ["Atom", Buffer.from([0, 0, 0, 1, 2, 0x61, 0xff])], + ]), ); - expect(report.atom_encoding).toBe("latin1"); - expect(report.module).toBe("ÿ"); + expect(report).toMatchObject({ + atom_encoding: "latin1", + module: "aÿ", + atoms: [{ index: 1, name: "aÿ" }], + coverage: { status: "complete" }, + }); +}); + +it.each([ + ["a negative count", [0xff, 0xff, 0xff, 0xff, 0x20, 0x61, 0x62]], + ["a compact length", [0, 0, 0, 1, 0x20, 0x61, 0x62]], +])("rejects %s in legacy Atom", (_name, payload) => { + expect(() => + parse(erlangBeamChunksFixture([["Atom", Buffer.from(payload)]])), + ).toThrow(expect.objectContaining({ reason: "format" })); }); it("rejects combined table rows before allocating them", () => { diff --git a/tests/acceptance/erlangBeamAtomLayouts.test.ts b/tests/acceptance/erlangBeamAtomLayouts.test.ts deleted file mode 100644 index ef686afbf5..0000000000 --- a/tests/acceptance/erlangBeamAtomLayouts.test.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { writeFile } from "node:fs/promises"; -import { join } from "node:path"; -import { expect } from "vitest"; - -import { erlangBeamChunksFixture } from "../../src/erlang/Beam.fixture.js"; -import { connectLocalToolsMcp } from "../fixtures/localToolsMcp.js"; -import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js"; -import { cliTest } from "../support/cli/cliFixture.js"; - -cliTest( - "uses the selected BEAM atom chunk's own count and length encoding", - async ({ cli }) => { - const root = await createTestTempDirectory("rea-beam-atom-layouts-"); - const { call } = await connectLocalToolsMcp(); - const compact = Buffer.from([0xff, 0xff, 0xff, 0xff, 0x20, 0x61, 0x62]); - const oldLayout = Buffer.from([0, 0, 0, 1, 2, 0x61, 0x62]); - const truncated = Buffer.from([0, 0, 0, 1, 0x20, 0x61, 0x62]); - for (const { name, chunk, bytes, valid, encoding } of [ - { name: "legacy-negative", chunk: "Atom", bytes: compact, valid: false }, - { - name: "legacy-truncated", - chunk: "Atom", - bytes: truncated, - valid: false, - }, - { - name: "legacy-valid", - chunk: "Atom", - bytes: oldLayout, - valid: true, - encoding: "latin1", - }, - { - name: "utf8-old", - chunk: "AtU8", - bytes: oldLayout, - valid: true, - encoding: "utf8", - }, - { - name: "utf8-compact", - chunk: "AtU8", - bytes: compact, - valid: true, - encoding: "utf8", - }, - ]) { - const path = join(root, `${name}.beam`); - await writeFile(path, erlangBeamChunksFixture([[chunk, bytes]])); - const output = await cli.run({ - arguments: ["inspect-erlang-beam", path, "--json"], - }); - const reply = await call("inspect_erlang_beam", { path }); - if (!valid) { - expect(output.exitCode, name).toBe(1); - expect(output.json, name).toMatchObject({ - code: "invalid_request", - details: { - issues: [expect.objectContaining({ reason: "invalid_format" })], - }, - }); - expect(reply.isError, name).toBe(true); - } else { - expect(output.exitCode, `${name}: ${output.stderr}`).toBe(0); - expect(output.json, name).toMatchObject({ - normalized_result: { - module: "ab", - atom_encoding: encoding, - atoms: [{ index: 1, name: "ab" }], - coverage: { status: "complete" }, - }, - }); - expect(reply.isError, name).not.toBe(true); - expect(reply.structuredContent).toMatchObject({ - normalized_result: { - module: "ab", - atom_encoding: encoding, - atoms: [{ index: 1, name: "ab" }], - coverage: { status: "complete" }, - }, - }); - } - } - }, -);