fix: snapshot payout terms at game start (what-you-saw-is-what-you-get)

Payouts were computed at completion from LIVE config, so an admin changing
multipliers mid-game would change the payout of an already-in-progress game.

- Migration 016 adds payout_escape_amount/payout_treasure_amount (BIGINT) and
  the corresponding multipliers to the games table.
- Both game-start paths stamp the resolved payout amounts (computed from the
  config in effect at entry) onto the game row.
- completeGame pays from the snapshot, falling back to live calculation only
  for legacy games that predate the snapshot columns.

Adds payoutSnapshot.test.js proving a mid-game config change cannot alter an
in-flight payout. Full suite: 15 suites / 131 tests.
This commit is contained in:
jwinterm
2026-05-31 09:55:45 -04:00
parent 24aed355c6
commit 473a4091d4
4 changed files with 159 additions and 7 deletions
+13
View File
@@ -0,0 +1,13 @@
-- Migration 016: Snapshot payout terms on the game at start
--
-- Payout amounts were computed at completion time from LIVE config, so an admin changing
-- multipliers mid-game would change the payout of an already-in-progress game ("what you
-- saw at entry" was not honoured). Snapshot the resolved payout amounts (and the
-- multipliers, for audit) onto the games row at start; completion reads the snapshot.
--
-- Amounts are atomic units (BIGINT, exact). Multipliers are stored for the audit trail.
ALTER TABLE games
ADD COLUMN IF NOT EXISTS payout_escape_amount BIGINT,
ADD COLUMN IF NOT EXISTS payout_treasure_amount BIGINT,
ADD COLUMN IF NOT EXISTS payout_escape_mult NUMERIC(8,3),
ADD COLUMN IF NOT EXISTS payout_treasure_mult NUMERIC(8,3);