// The derivation's highlight events (release 31, lane P3) against the test // kit's synthetic highlights (testing/frames/pokerReadings.mjs): hero pots, // all-ins with their outcome, level-ups from the log, players-left // milestones — each made by a named rule, its evidence on the event, and the // P2 guarantees kept (a flagged reading makes no event; one tournament). import { test } from "node:test"; import assert from "node:assert/strict"; import { syntheticPokerHighlights, SYNTH_MAIN } from "../../testing/frames/pokerReadings.mjs"; import { BIG_POT_BB, derivePoker, FINAL_TABLE, PLAYERS_LEFT_MILESTONES, type PokerReading } from "./poker"; import type { DerivedEvent } from "./types"; type R = PokerReading & { t: number }; const fx = syntheticPokerHighlights(); const d = derivePoker(fx.readings as R[], fx.spoken, { everySeconds: 10, hero: fx.hero }); const of = (k: string) => d.events.filter((e) => e.kind === k); const ts = (k: string) => of(k).map((e) => e.t); test("the named constants", () => { assert.equal(BIG_POT_BB, 25); assert.deepEqual([...PLAYERS_LEFT_MILESTONES], [100, 50, 27, 18]); assert.equal(FINAL_TABLE, 9); }); test("one tournament, named; the derivation's P2 events still there", () => { assert.equal(d.tournaments.length, 1); assert.equal(d.tournaments[0].name, SYNTH_MAIN); assert.deepEqual(ts("double-up"), [1010]); assert.deepEqual(ts("bust"), [2900]); assert.deepEqual(ts("eliminated"), [2910]); }); test("hero pots: big at 25 BB or more, the line read again as a near size is one pot, confirmed by the stack", () => { assert.deepEqual(ts("big-pot"), fx.expect["big-pot"]); assert.deepEqual(ts("pot"), fx.expect.pot); const big = of("big-pot")[0]; assert.equal(big.rule, "log-pot"); assert.deepEqual(big.evidence, { pot: 40000, line: "Dealer: SynthHero takes the pot 40,000.", bigBlind: 1200, potBB: 33.3, stackBefore: 50000, stackAfter: 80000 }); assert.equal(big.confidence, "confirmed"); assert.equal(big.detail, "takes the pot 40,000 (33 BB)"); // The small pot is measured against the log's 1,200, not the misread 16,000. assert.equal(of("pot")[0].evidence?.potBB, 2.5); }); test("all-ins: the hero's only, one per hand, with the outcome the next stack readings show", () => { assert.deepEqual(of("all-in").map((e) => [e.t, e.evidence?.outcome]), fx.expect["all-in"]); const [doubled, lost, busted] = of("all-in"); assert.deepEqual(doubled.evidence, { via: "log", role: "shove", text: "SynthHero raises 81,500 and is all-in", outcome: "doubled", stackBefore: 81500, stackAfter: 170000, afterT: 1010 }); assert.equal(doubled.detail, "all in with 81,500: doubles up (170,000)"); assert.equal(doubled.source, "log"); assert.equal(lost.evidence?.role, "call"); assert.equal(lost.evidence?.via, "action"); assert.equal(busted.evidence?.via, "action"); assert.equal(busted.detail, "all in with 120,000: busts"); for (const e of of("all-in")) assert.equal(e.confidence, "confirmed"); // The model's banner at 1,100 (another player's shove) is not the hero's. assert.ok(!ts("all-in").includes(1100)); }); test("an all-in with no stack read after it is unconfirmed, its outcome unknown", () => { const rs: R[] = [ { t: 0, phase: "table", hero: { stack: 5000 } }, { t: 10, phase: "table", hero: { stack: 5000 }, log: ["Villain bets 4,000, SynthHero calls and is all in"] }, { t: 20, phase: "other" }, ]; const x = derivePoker(rs, [], { everySeconds: 10, hero: "SynthHero" }); const e = x.events.find((ev) => ev.kind === "all-in")!; assert.equal(e.evidence?.role, "call"); assert.equal(e.evidence?.outcome, "unknown"); assert.equal(e.confidence, "unconfirmed"); // Another player's line is not the hero's. const other = derivePoker([{ t: 0, phase: "table", hero: { stack: 5000 }, log: ["Villain is all-in"] }], [], { everySeconds: 10, hero: "SynthHero" }); assert.deepEqual(other.events.filter((ev) => ev.kind === "all-in"), []); }); test("level-ups from the log: each new big blind once, the misread line undercut by a later one makes none", () => { assert.deepEqual(ts("level-up"), fx.expect["level-up"]); const [first, second, third, fourth] = of("level-up"); assert.equal(first.confidence, "unconfirmed"); assert.deepEqual(second.evidence, { smallBlind: 600, bigBlind: 1200, line: "Blinds are now 600/1,200", from: 1000, level: 2 }); assert.equal(second.detail, "blinds 600/1,200 (from 1,000), level 2"); assert.equal(third.evidence?.from, 1200); assert.equal(fourth.evidence?.line, "INFO Blinds are now 1,000/2,000"); for (const e of [second, third, fourth]) assert.equal(e.confidence, "confirmed"); // The 16,000 is a misread in the series too: set aside, the big blind held. assert.ok(d.misreads.some((m) => m.field === "bigBlind" && m.value === 16000 && m.t === 600)); assert.equal(d.misreads.filter((m) => m.field === "bigBlind" && m.value === 16000).length, 1); assert.ok(!d.tournaments[0].series.bigBlind.some(([, v]) => v === 16000), JSON.stringify(d.tournaments[0].series.bigBlind)); }); test("players-left milestones from the header, once each; a flagged reading crosses nothing", () => { assert.deepEqual(of("players-left").map((e) => [e.t, e.evidence?.milestone]), fx.expect["players-left"]); assert.deepEqual(ts("final-table"), fx.expect["final-table"]); const fifty = of("players-left").find((e) => e.evidence?.milestone === 50)!; assert.deepEqual(fifty.evidence, { milestone: 50, playersLeft: 45, before: 60, beforeT: 1000 }); assert.equal(fifty.rule, "players-left-milestone"); assert.equal(fifty.confidence, "confirmed"); assert.equal(of("final-table")[0].confidence, "confirmed"); assert.equal(d.flags.length, 1); }); test("milestones: never rising (a later reading over it moves the crossing), the lowest at one point, none from below", () => { const h = (t: number, left: number): R => ({ t, phase: "table", tournament: { playersLeft: left, position: 1 }, hero: { stack: 1000 } }); const ms = (rs: R[]) => derivePoker(rs, [], { everySeconds: 10 }).events.filter((e: DerivedEvent) => e.kind === "players-left" || e.kind === "final-table").map((e) => [e.t, e.kind, e.evidence?.milestone]); // 105 → 99 → 103 → 98: the crossing of 100 is at the 98. assert.deepEqual(ms([h(0, 105), h(10, 99), h(20, 103), h(30, 98), h(40, 97)]), [[30, "players-left", 100]]); // 52 → 26 crosses 50 and 27 at once: one event, the lower. assert.deepEqual(ms([h(0, 55), h(10, 52), h(20, 26), h(30, 25)]), [[20, "players-left", 27]]); // A field that starts under a milestone never crosses it. assert.deepEqual(ms([h(0, 40), h(10, 30)]), []); // The last point: unconfirmed (nothing holds it). const last = derivePoker([h(0, 30), h(10, 17)], [], { everySeconds: 10 }).events.find((e) => e.kind === "players-left")!; assert.equal(last.confidence, "unconfirmed"); });