mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 14:05:49 +00:00
test(erlang): consolidate Beam atom layout coverage (#12795)
test(erlang): consolidate BEAM atom layout coverage
This commit is contained in:
1 parent
7735a4bca7
commit
98c3fad24d
2 files changed
+19
-89
No files matched your search
@@ -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", () => {
|
||||
|
||||
@@ -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" },
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user