// Golden-vector tests: the CLJS dist must reproduce the TS implementation's
// outputs byte-for-byte / value-for-value. Vectors were extracted from the
// TS sources while they were still canon (test/vectors/*.json).
// Runs against the committed dist/ — never src/.
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync, writeFileSync, mkdtempSync, rmSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
const bot = await import("../stack-a/dist/main.js");
const vec = (name) => JSON.parse(readFileSync(new URL(`./vectors/${name}`, import.meta.url), "utf8"));
test("room keys", () => {
for (const c of vec("room-key.json")) {
assert.equal(bot.roomKey(c.app, c.secret), c.key);
}
});
test("app of host", () => {
for (const c of vec("app-of-host.json")) {
assert.equal(bot.appOfHost(c.host) ?? null, c.app);
}
});
test("config merge", () => {
const dir = mkdtempSync(join(tmpdir(), "botcfg-"));
try {
for (const c of vec("config-merge.json")) {
const p = join(dir, `${c.name}.json`);
writeFileSync(p, JSON.stringify(c.raw));
assert.deepEqual(JSON.parse(JSON.stringify(bot.loadConfig(p))), c.merged, c.name);
}
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
test("reaper decision table", () => {
for (const c of vec("reaper.json")) {
assert.equal(
bot.shouldReap(c.provenance, c.matchEnded, c.idleMs),
c.drop,
`${c.provenance} matchEnded=${c.matchEnded} idle=${c.idleMs}`,
);
}
});
test("worker respawn backoff", () => {
for (const c of vec("backoff.json")) {
assert.equal(bot.backoffDelay(c.restarts), c.delayMs);
}
});
test("seance state encoding", () => {
for (const c of vec("seance-encode.json")) {
assert.equal(bot.encodeSeanceState(c.view), c.key);
}
});
test("seance qs + action mapping", () => {
const v = vec("seance-qs.json");
for (const c of v.cases) {
const model = c.key === "nullmodel" ? null : v.model;
const key = c.key === "nullmodel" ? "k1" : c.key;
assert.deepEqual([...bot.seanceQs(model, key)], c.qs);
}
for (const c of v.actions) {
assert.equal(bot.seanceAction(c.a) ?? null, c.out);
}
});
test("neon-grid features", () => {
for (const c of vec("neon-features.json")) {
const out = bot.neonFeatures(c.view);
assert.deepEqual([...out.dirs], c.out.dirs);
assert.deepEqual(out.feats.map((f) => [...f]), c.out.feats);
}
});
test("valley-blocks features + fallback", () => {
for (const c of vec("vb-features.json")) {
assert.deepEqual(bot.vbFeatures(c.candidates).map((f) => [...f]), c.feats);
assert.equal(bot.vbFallback(c.candidates), c.fallback);
}
});