// Golden vectors for the trader's pure decision surfaces — plan-actions and
// banks-to-open, exported off the :worker build. Expectations in
// test/vectors/bursa-plan.json are hand-computed from bursa's own fold, quote
// and trade rules (independent derivation — nothing here re-runs the
// implementation to produce its own oracle). Runs against the committed dist/
// — never src/.
//
// What each family proves:
// directory — the resident's own bank is published once and only when it is
// a real bank link; a BANK/1 or garbled-version row is refused
// out loud, because an unexplained absence reads as a bug.
// knocks — only from account state "none": "pending" is a knock already
// waiting on a banker and "closed" is a banker's answer.
// quotes — one ask and one bid per pair, anchored 1:1 with the spread as
// an EXACT rational, sized down to the inventory backing the leg
// the maker pays, and never posted when the quote leg floors to
// zero (no second lock ⇒ the take is inert).
// re-quote — price and advisory expiry decide; a changed target size does
// not, or the whole book would churn on every settlement.
// trades — bursa.lib.trade decides the phase and the act; this arm
// forwards the action VERBATIM and adds only the bank log it
// goes to. Every phase, both roles, and the lost-secret case.
// open — how many bank rooms to hold: fold order, foldable BANK/2 only,
// deduped against what is already up, capped at the relay budget.
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
const { bursaPlanActions, bursaBanksToOpen, bursaActKey, bursaDedupActs } =
await import(new URL("../stack-b/dist/worker.js", import.meta.url).href);
const vec = JSON.parse(
readFileSync(new URL("./vectors/bursa-plan.json", import.meta.url), "utf8"),
);
const plain = (v) => JSON.parse(JSON.stringify(v));
test("bursa plan-actions golden vectors", () => {
for (const c of vec.plan) {
assert.deepEqual(
plain(
bursaPlanActions(
c.market, c.banks, c.me, c.myBank, c.secrets, c.cfg, c.now,
),
),
c.ops,
c.name,
);
}
});
test("bursa banks-to-open golden vectors", () => {
for (const c of vec.open) {
assert.deepEqual(
plain(bursaBanksToOpen(c.snapshot, c.openTokens, c.cap)),
c.out,
c.name,
);
}
});
// The in-flight act memory's pure rule (bot.bursa/act-key + dedup-acts): the
// live-observed double-claim — a re-plan tick racing the append's fold echo —
// is dropped as "identical act already in flight", a key the fold moved past
// is forgotten (so a genuinely lost append may retry), and everything that is
// not an act passes through untouched, order preserved.
test("bursa act-key golden vectors", () => {
for (const c of vec.key) {
assert.equal(bursaActKey(c.m, c.action), c.key, c.name);
}
});
test("bursa dedup-acts golden vectors", () => {
for (const c of vec.dedup) {
assert.deepEqual(
plain(bursaDedupActs(c.ops, c.inflight)),
c.out,
c.name,
);
}
});