Files
scrabble-game/docs/TESTING.md
T
Ilia Denisov bfa8797f8c
Tests · Go / test (push) Successful in 6s
Tests · Integration / integration (push) Successful in 9s
Tests · Go / test (pull_request) Successful in 6s
Tests · Integration / integration (pull_request) Successful in 9s
Stage 4: lobby & social (matchmaking, friends, blocks, chat+nudge, invitations, profile, email, multi-player drop-out)
Engine: multi-player drop-out-and-continue with a per-game tile disposition (remove default / return), resigned seats skipped and excluded from the win, leaver rack never revealed; 2-player behaviour unchanged.

New domains (service/store, no HTTP yet): internal/social (friend request/accept graph, per-user blocks, per-game chat with nudge as a message kind, content filter via mvdan.cc/xurls/v2 + leet/separator normaliser + phone heuristic) and internal/lobby (in-memory variant-keyed matchmaking pool, friend-game invitations invite->accept with lazy 7-day expiry). account gains profile editing and the email confirm-code flow (Mailer seam: SMTP or log mailer).

Migration 00003_social.sql + regenerated jet. main wires the new services into the server (accessors for the Stage 6 handlers); robot substitution stays in Stage 5, REST/stream/push in Stage 6/8. Docs (PLAN, ARCHITECTURE, FUNCTIONAL+ru, TESTING, README) updated.
2026-06-02 19:29:30 +02:00

4.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. Stage 4 adds the engine's multi-player drop-out cases (continue after one resign, last-survivor win, the tile-disposition bag effect) and a domain integration test for a 3-player timeout that continues.
  • Social & lobby (Stage 4+)backend/internal/social unit-tests the chat content filter (links/emails/phones plus obfuscated forms) and backend/internal/lobby unit-tests the in-memory matchmaker (FIFO pairing, cancel, per-variant pools) with a fake game creator. Postgres-backed inttest covers the friend request/accept lifecycle with the block/toggle guards, the per-user block (and its severing of friendships), chat post/list with the IP, content and block-visibility rules, the nudge turn/rate-limit rules, the invitation flow (all-accept starts the game, decline cancels, lazy expiry, inviter-only cancel), and the email confirm-code flow (request/confirm, taken email, expiry and attempt-cap) with a fixture mailer.

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.