// Golden-vector tests: wire frames must serialize byte-identically to the TS
// implementation's (fixtures generated while the TS was canon).
import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import * as lib from "../test-dist/testlib.js";
const vectors = JSON.parse(readFileSync(new URL("./vectors/frames.json", import.meta.url), "utf8"));
const byName = Object.fromEntries(vectors.map((v) => [v.name, v]));
const built = {
hi: () => lib.mkHi("zed", 3),
"ro-idle": () => lib.mkRo("12D3KooWA", [["12D3KooWA", "zed", 0, 2], ["12D3KooWB", "rex", 1, 0]], false),
"ro-live": () => lib.mkRo("12D3KooWA", [["12D3KooWA", "zed", 0, 2]], true),
in: () => lib.mkIn(3),
st: () => lib.mkSt(2, 76, ["12D3KooWA", "12D3KooWB"], [[114, 48, 3], [14, 48, 1]]),
tk: () => lib.mkTk(17, [[0, 10, 20, 1], [1, 30, 40, 0]]),
ov: () => lib.mkOv("12D3KooWA", [["12D3KooWA", 3], ["12D3KooWB", 1]]),
"ov-draw": () => lib.mkOv(null, [["12D3KooWA", 0]]),
ma: () => lib.mkMa("12D3KooWA", [["12D3KooWA", 5]]),
lo: () => lib.mkLo(),
sn: () => lib.mkSn(1, 80, 42, ["12D3KooWA"], [[5, 6, 1, 0]], [0, 773, 1, 1, 0, 11514]),
};
for (const [name, make] of Object.entries(built)) {
test(`frame ${name} serializes byte-identically to TS`, () => {
assert.equal(JSON.stringify(make()), byName[name].json);
});
}
test("isGameFrame accepts frames, rejects junk", () => {
for (const v of vectors) assert.equal(lib.isGameFrame(v.frame), true);
for (const junk of [null, undefined, 42, "hi", [], {}, { t: 7 }]) {
assert.equal(Boolean(lib.isGameFrame(junk)), false, `junk: ${JSON.stringify(junk)}`);
}
});