Deepen four modules: Point Ledger, GameStore, loader harness, gameClient#1
Merged
Conversation
Architecture review surfaced four shallow seams; this deepens all four. Point Ledger (packages/shared/src/pointLedger.ts): collapse three independent break/hold algorithms into one forward-pass module. calculateLineStats folds over it; delete web breakDetection.ts and the timestamp halftime heuristic; timeline, progression, lineup table, and StatsCalculator all read the ledger. Legacy behavior locked by a parity test against a verbatim copy of the old isBreakScore. GameStore (packages/bot/src/store/GameStore.ts): concentrate the DO<->D1 dual-write behind one seam. DO-first writes (ADR-0001), GameState converted to typed Durable Object RPC (ADR-0002, compat date bumped to 2025-10-01), router shrunk to a thin HTTP adapter. First tests for the sync logic via in-memory fakes. Fixes updateGame's fire-and-forget divergence and a broken cold-DO rehydration (chatId passed as gameId). Loader harness (packages/bot/scripts/lib/loader.ts): replace 22 copy-pasted tournament scripts with loadTournament(spec). Real IANA timezone conversion, one env-driven API URL, replace mode. Old scripts moved to scripts/archive/ unchanged; load-example-spec.ts is the template. gameClient (packages/web/src/api/gameClient.ts): make it the only web->API path. Four typed fetchers plus a poll() helper; one base URL, one error path. Game list standardized on limit=100. Also adds CONTEXT.md (domain glossary), the two ADRs, and the HTML architecture review that motivated the work. 241 tests passing (52 shared + 189 bot); verified end-to-end on wrangler dev. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts: # packages/web/src/stats.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Architecture review surfaced four shallow seams; this deepens all four. All 241 tests pass (52 shared + 189 bot) and the changes were verified end-to-end on
wrangler dev.What changed
packages/shared/src/pointLedger.ts) — collapses three independent break/hold algorithms into one forward-pass module.calculateLineStatsfolds over it; webbreakDetection.tsand the timestamp halftime heuristic are deleted; timeline, progression, lineup table, andStatsCalculatorall read the ledger. Legacy behavior locked by a parity test against a verbatim copy of the oldisBreakScore.packages/bot/src/store/GameStore.ts) — concentrates the DO↔D1 dual-write behind one seam. DO-first writes (ADR-0001),GameStateconverted to typed Durable Object RPC (ADR-0002,compatibility_date→ 2025-10-01), router shrunk to a thin HTTP adapter. First tests for the sync logic via in-memory fakes. FixesupdateGame's fire-and-forget divergence and a broken cold-DO rehydration (chatId passed as gameId).packages/bot/scripts/lib/loader.ts) — replaces 22 copy-pasted tournament scripts withloadTournament(spec). Real IANA timezone conversion, one env-driven API URL, replace mode. Old scripts moved toscripts/archive/unchanged;load-example-spec.tsis the template.packages/web/src/api/gameClient.ts) — now the only web→API path. Four typed fetchers plus apoll()helper; one base URL, one error path. Game list standardized onlimit=100.Also adds
CONTEXT.md(domain glossary), the two ADRs, and the HTML architecture review that motivated the work.Before deploy
The
compatibility_datebump (2024-01-01 → 2025-10-01) for the Durable Object RPC conversion is the one change local testing can't fully de-risk. ADR-0002 lists the post-deploy smoke checks; rollback is redeploying the old date.🤖 Generated with Claude Code