Files
scrabble-game/docs/TESTING.md
T
Ilia Denisov 751e74b14f
Tests · Go / test (push) Successful in 6s
Tests · Integration / integration (push) Successful in 8s
Tests · Go / test (pull_request) Successful in 5s
Tests · Integration / integration (pull_request) Successful in 8s
Stage 3: game domain (lifecycle, journal+cache, hint, word-check, GCG, stats)
internal/game drives the engine over a single match and owns everything the
engine does not: event-sourced persistence (a games row + an append-only decoded
move journal, with the live engine.Game kept warm in a cache and rebuilt by
replay on a miss), the play/pass/exchange/resign transitions with
validate-at-submit scoring, an unlimited score/legality preview, the hint
(per-game allowance + profile wallet), the word-check tool with complaint
capture, per-player game state, history and GCG export (Poslfit dialect), and a
background turn-timeout sweeper that auto-resigns overdue turns honouring each
player's daily away window. Like Stages 1-2 it is a service/store layer with no
HTTP; the gateway surface lands in Stage 6.

Engine: additive decoded domain API (Direction, SubmitPlay/SubmitExchange/
EvaluatePlay/HintView/Hand, MoveRecord.{Dir,MainRow,MainCol}, Registry.Lookup,
ParseVariant) so internal/game never imports scrabble-solver; and a Resign fix
so the resigner keeps their score yet never wins (the other player wins a
two-player game). Timeout reuses Resign.

Persistence: migration 00002 adds games, game_players, game_moves, complaints,
account_stats and extends accounts with away_start/away_end/hint_balance; go-jet
regenerated. account gained SpendHint. Config adds BACKEND_DICT_DIR (required),
BACKEND_DICT_VERSION, BACKEND_GAME_TIMEOUT_SWEEP_INTERVAL, BACKEND_GAME_CACHE_TTL;
main loads the registry at boot (hard dependency) and starts the sweeper.

Tests: engine resign + decoded-API tests; game unit tests (GCG, away-window
boundaries, hint budget, cache, keyed mutex, payload); inttest integration
(lifecycle, replay equivalence, timeout sweep with away grace, resign stats,
hint policy, word-check/complaint, per-game-lock). Docs (PLAN, ARCHITECTURE,
FUNCTIONAL +_ru, TESTING, README) updated.
2026-06-02 17:33:49 +02:00

3.0 KiB

Scrabble Game — Testing

How the project is tested and the gate every stage must pass. Read before adding tests or touching CI.

Layers

  • Go unit tests — table-driven where it helps; testing + standard library. Every functional change ships with regression coverage. Run: go test -count=1 ./backend/... (the module list grows with the workspace).
  • Integration (Stage 1+) — Postgres-backed tests behind the integration build tag spin a throwaway postgres:17-alpine via testcontainers-go. They live in backend/internal/inttest and run with go test -tags=integration -count=1 -p=1 ./backend/... (needs Docker), guarded by a separate CI workflow (integration.yaml; Ryuk disabled, serial). Slow.
  • UI (introduced with the UI in Stage 7) — Vitest (unit) + Playwright (e2e), mirroring the chosen plain-Svelte + Vite toolchain.
  • Engine (Stage 2+) — correctness of scoring and move generation is owned by scrabble-solver's own GCG-backed tests. backend/internal/engine adds, on top of the embedded solver: per-variant smoke tests (load all three committed DAWGs and validate a known word, including Эрудит), bag draw/return determinism and exchange accounting, the Game end-conditions (empty bag with an empty rack, and six scoreless turns) with end-game rack scoring, and dictionary-independent history replay (ReplayBoard reproduces a full greedy game's final board from decoded records alone), and the resignation win/loss rule (the resigner keeps their score yet loses). The engine tests read the DAWGs from BACKEND_DICT_DIR (or the sibling scrabble-solver checkout) and fail loudly when it is absent.
  • Game domain (Stage 3+)backend/internal/game adds pure unit tests (the GCG writer, the away-window / effective-deadline boundaries, the hint budget, the live-game cache and per-game lock, payload round-trips) plus Postgres-backed integration tests in inttest (full lifecycle to a natural end, journal-replay equivalence, the turn-timeout sweep with away-window grace, resign win/loss and statistics, the hint allowance-then-wallet policy, word-check and complaint capture, and per-game-lock serialisation). The robot balance/margin regression tests arrive with Stage 5.

Principles

  • A green run must not depend on cached state: use -count=1 in CI.
  • Tests that need infrastructure fail loudly (t.Fatal) when it is unavailable rather than silently skipping coverage.
  • No network or real platform calls in unit tests; validate platform credentials behind an interface seam and test with fixtures.

Per-stage CI gate

Every completed stage is exercised on gitea.iliadenisov.ru before it is marked done in ../PLAN.md:

  1. Commit the stage on its feature/* branch.
  2. Push to origin.
  3. Watch the run to completion — never hand-roll a poll loop: python3 ~/.claude/bin/gitea-ci-watch.py (launch in the background).
  4. Only after every workflow that fired is green may the stage be marked done.