mirror of
https://github.com/morluto/rea.git
synced 2026-11-30 18:39:24 +00:00
test(beam): reuse the CLI Evidence reader (#15171)
This commit is contained in:
1 parent
39fa51184d
commit
97322254dd
1 file changed
+18
-49
@@ -12,12 +12,20 @@ import {
|
||||
} 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";
|
||||
import { cliTest, type TestCli } from "../support/cli/cliFixture.js";
|
||||
|
||||
const completeBeamEvidenceSchema = toolContract(
|
||||
"inspect_erlang_beam",
|
||||
).outputSchema.safeExtend({ normalized_result: erlangBeamSchema });
|
||||
|
||||
const inspectBeam = async (cli: TestCli, path: string) => {
|
||||
const result = await cli.run({
|
||||
arguments: ["inspect-erlang-beam", path, "--json"],
|
||||
});
|
||||
expect(result.exitCode, result.stderr).toBe(0);
|
||||
return completeBeamEvidenceSchema.parse(result.json);
|
||||
};
|
||||
|
||||
const oneAtomBeam = (paddingByte: number): Buffer => {
|
||||
const bytes = Buffer.alloc(28);
|
||||
bytes.write("FOR1", 0, "latin1");
|
||||
@@ -166,13 +174,7 @@ cliTest(
|
||||
]) {
|
||||
const path = join(root, `${label}.beam`);
|
||||
await writeFile(path, bytes);
|
||||
const output = await cli.run({
|
||||
arguments: ["inspect-erlang-beam", path, "--json"],
|
||||
});
|
||||
expect(output.exitCode, output.stderr).toBe(0);
|
||||
const report = completeBeamEvidenceSchema.parse(
|
||||
output.json,
|
||||
).normalized_result;
|
||||
const { normalized_result: report } = await inspectBeam(cli, path);
|
||||
const reply = await call("inspect_erlang_beam", { path });
|
||||
expect(reply.isError, JSON.stringify(reply)).not.toBe(true);
|
||||
expect(
|
||||
@@ -221,13 +223,7 @@ cliTest(
|
||||
repeated.writeUInt32BE(repeated.length - 8, 4);
|
||||
const path = join(root, "repeated.beam");
|
||||
await writeFile(path, repeated);
|
||||
const result = await cli.run({
|
||||
arguments: ["inspect-erlang-beam", path, "--json"],
|
||||
});
|
||||
expect(result.exitCode, result.stderr).toBe(0);
|
||||
const report = completeBeamEvidenceSchema.parse(
|
||||
result.json,
|
||||
).normalized_result;
|
||||
const { normalized_result: report } = await inspectBeam(cli, path);
|
||||
expect(report.module).toBe("rea_beam_fixture");
|
||||
expect(report.exports).toContainEqual({
|
||||
function_index: 2,
|
||||
@@ -262,15 +258,8 @@ cliTest(
|
||||
await writeFile(controlPath, controlBytes);
|
||||
await writeFile(extendedPath, extendedBytes);
|
||||
|
||||
const inspect = async (path: string) => {
|
||||
const result = await cli.run({
|
||||
arguments: ["inspect-erlang-beam", path, "--json"],
|
||||
});
|
||||
expect(result.exitCode, result.stderr).toBe(0);
|
||||
return completeBeamEvidenceSchema.parse(result.json);
|
||||
};
|
||||
const control = await inspect(controlPath);
|
||||
const extended = await inspect(extendedPath);
|
||||
const control = await inspectBeam(cli, controlPath);
|
||||
const extended = await inspectBeam(cli, extendedPath);
|
||||
// Golden facts from beam_lib:chunks/2 on the compiler-produced OTP 29 file.
|
||||
expect(control.normalized_result.module).toBe("rea_beam_fixture");
|
||||
expect(control.normalized_result.atoms?.map((atom) => atom.name)).toEqual([
|
||||
@@ -344,15 +333,8 @@ cliTest(
|
||||
await writeFile(cleanPath, oneAtomBeam(0));
|
||||
await writeFile(paddedPath, oneAtomBeam(0x7f));
|
||||
|
||||
const inspect = async (path: string) => {
|
||||
const result = await cli.run({
|
||||
arguments: ["inspect-erlang-beam", path, "--json"],
|
||||
});
|
||||
expect(result.exitCode, result.stderr).toBe(0);
|
||||
return completeBeamEvidenceSchema.parse(result.json);
|
||||
};
|
||||
const clean = await inspect(cleanPath);
|
||||
const padded = await inspect(paddedPath);
|
||||
const clean = await inspectBeam(cli, cleanPath);
|
||||
const padded = await inspectBeam(cli, paddedPath);
|
||||
expect(padded.normalized_result.module).toBe("m");
|
||||
expect(padded.normalized_result.chunks).toEqual(
|
||||
clean.normalized_result.chunks,
|
||||
@@ -375,13 +357,7 @@ cliTest(
|
||||
// Move one byte of alignment padding into the AtU8 payload.
|
||||
bytes.writeUInt32BE(7, 16);
|
||||
await writeFile(path, bytes);
|
||||
const result = await cli.run({
|
||||
arguments: ["inspect-erlang-beam", path, "--json"],
|
||||
});
|
||||
expect(result.exitCode, result.stderr).toBe(0);
|
||||
const report = completeBeamEvidenceSchema.parse(
|
||||
result.json,
|
||||
).normalized_result;
|
||||
const { normalized_result: report } = await inspectBeam(cli, path);
|
||||
expect(report).toMatchObject({
|
||||
module: "m",
|
||||
chunks: [{ name: "AtU8", payload: { location: { bytes: 7 } } }],
|
||||
@@ -411,15 +387,8 @@ cliTest(
|
||||
await writeFile(controlPath, formBytes);
|
||||
await writeFile(trailingPath, Buffer.concat([formBytes, trailer]));
|
||||
|
||||
const inspect = async (path: string) => {
|
||||
const result = await cli.run({
|
||||
arguments: ["inspect-erlang-beam", path, "--json"],
|
||||
});
|
||||
expect(result.exitCode, result.stderr).toBe(0);
|
||||
return completeBeamEvidenceSchema.parse(result.json);
|
||||
};
|
||||
const control = await inspect(controlPath);
|
||||
const trailing = await inspect(trailingPath);
|
||||
const control = await inspectBeam(cli, controlPath);
|
||||
const trailing = await inspectBeam(cli, trailingPath);
|
||||
expect(trailing.normalized_result.form).toEqual(
|
||||
control.normalized_result.form,
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user