Compare commits
2 Commits
08c2c5f660
..
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 24017bcb7f | |||
| 2c4f4b10dc |
@@ -31,7 +31,7 @@ on:
|
|||||||
# unit/integration jobs inherit it. The deploy job overrides it per contour with
|
# unit/integration jobs inherit it. The deploy job overrides it per contour with
|
||||||
# vars.TEST_DICT_VERSION (the seed for a fresh volume), see deploy/README.md.
|
# vars.TEST_DICT_VERSION (the seed for a fresh volume), see deploy/README.md.
|
||||||
env:
|
env:
|
||||||
DICT_VERSION: v1.3.0
|
DICT_VERSION: v1.2.1
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# changes detects which areas a PR/push touched, so the test jobs can skip when
|
# changes detects which areas a PR/push touched, so the test jobs can skip when
|
||||||
|
|||||||
@@ -1,97 +1,96 @@
|
|||||||
# scrabble-game — project guide
|
# scrabble-game — project guide
|
||||||
|
|
||||||
Multiplatform Scrabble game, **in production** at `https://erudit-game.ru`. Read this
|
Multiplatform Scrabble game. Read this first every session. The owner drives the
|
||||||
first every session. The repository — not conversation memory — is the source of
|
project **one stage per session** (tariff constraint), so the repository — not
|
||||||
continuity; keep it that way.
|
conversation memory — is the source of continuity. Keep it that way.
|
||||||
|
|
||||||
## Sources of truth (read before changing behaviour)
|
## Sources of truth (read before changing behaviour)
|
||||||
|
|
||||||
- [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) — architecture, transport, security,
|
- [`PLAN.md`](PLAN.md) — staged plan + **stage tracker** + per-stage *open
|
||||||
the decision record. Always describes the current state.
|
details to interview*.
|
||||||
- [`docs/FUNCTIONAL.md`](docs/FUNCTIONAL.md) (+ [`_ru`](docs/FUNCTIONAL_ru.md) mirror)
|
- [`PRERELEASE.md`](PRERELEASE.md) — pre-release hardening tracker (phases R1–R7
|
||||||
— per-domain user stories. English authoritative.
|
before Stage 18); same per-phase *interview + bake-back* discipline as `PLAN.md`.
|
||||||
- [`docs/TESTING.md`](docs/TESTING.md) — test layers + the CI gate.
|
- [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) — architecture, transport,
|
||||||
|
security, the decision record. Always describes current state.
|
||||||
|
- [`docs/FUNCTIONAL.md`](docs/FUNCTIONAL.md) (+ [`_ru`](docs/FUNCTIONAL_ru.md)
|
||||||
|
mirror) — per-domain user stories. English authoritative.
|
||||||
|
- [`docs/TESTING.md`](docs/TESTING.md) — test layers + the per-stage CI gate.
|
||||||
- [`docs/UI_DESIGN.md`](docs/UI_DESIGN.md) — the `ui` visual/interaction design system.
|
- [`docs/UI_DESIGN.md`](docs/UI_DESIGN.md) — the `ui` visual/interaction design system.
|
||||||
- [`deploy/README.md`](deploy/README.md) — the deploy contour + the production
|
|
||||||
rollout / rollback runbook.
|
|
||||||
|
|
||||||
## How we work
|
## Mandatory per-stage workflow
|
||||||
|
|
||||||
- Inspect the relevant code path and the docs above before changing behaviour.
|
**Start of a stage**
|
||||||
- **Interview the owner on every fork** — do not silently pick borderline decisions;
|
1. Read `PLAN.md` (the stage's scope + *open details*) and the relevant `docs/`.
|
||||||
offer options with brief pros/cons.
|
2. Analyse what the stage actually requires against the current code.
|
||||||
- Smallest correct diff. Prefer compact code; reuse before adding; do not add deps,
|
3. **Interview the owner** on every open detail and any fork not already fixed
|
||||||
seams or knobs until they are needed.
|
in the plan — do not silently pick borderline decisions. Offer options with
|
||||||
- **Update or add tests for every functional change**, at the layers
|
brief pros/cons.
|
||||||
`docs/TESTING.md` calls out.
|
4. Only then implement, strictly within the stage's scope.
|
||||||
- **Bake docs in the same PR**: update `docs/ARCHITECTURE.md`, `docs/FUNCTIONAL.md`
|
|
||||||
(+`_ru`), the affected service `README` and Go Doc comments alongside the change.
|
**End of a stage**
|
||||||
- Document added packages, types, funcs, consts and vars with Go Doc comments.
|
1. Bake every new agreement back into `PLAN.md`, `docs/ARCHITECTURE.md`,
|
||||||
|
`docs/FUNCTIONAL.md` (+ `_ru`), the affected service `README`, and Go Doc
|
||||||
|
comments — in the **same** PR. Correct earlier stages' docs/code if a new
|
||||||
|
decision changes them.
|
||||||
|
2. Update the stage tracker; add a line under *Refinements logged during
|
||||||
|
implementation* for any plan deviation.
|
||||||
|
3. Get CI green, then mark the stage done.
|
||||||
|
|
||||||
|
(The `stage-implementation` skill encodes this same loop and can be invoked.)
|
||||||
|
|
||||||
## Conventions
|
## Conventions
|
||||||
|
|
||||||
- All code, comments, identifiers, commits, docs, filenames in **English**.
|
- All code, comments, identifiers, commits, docs, filenames in **English**.
|
||||||
- Chat with the owner follows the user-level `~/.claude/CLAUDE.md` (Russian, the
|
- Chat with the owner follows the user-level `~/.claude/CLAUDE.md` (Russian,
|
||||||
agreed persona and translation rules).
|
the agreed persona and translation rules).
|
||||||
- Mirror every point edit of `docs/FUNCTIONAL.md` into `docs/FUNCTIONAL_ru.md` in the
|
- Mirror every point edit of `docs/FUNCTIONAL.md` into `docs/FUNCTIONAL_ru.md`
|
||||||
same patch (translate only the touched paragraphs).
|
in the same patch (translate only the touched paragraphs).
|
||||||
|
- Prefer compact code; do not add deps, seams or knobs until a stage needs them.
|
||||||
|
Reuse before adding. Document added packages/types/funcs with Go Doc comments.
|
||||||
|
- Update or add tests for every functional change.
|
||||||
|
|
||||||
## Branching, CI & production
|
## Branching & CI
|
||||||
|
|
||||||
- **Two long-lived branches**: **`development`** is the integration branch; **`master`**
|
- **Two long-lived branches** (Stage 16 onward): **`development`** is the
|
||||||
is the production trunk. Cut `feature/*` from `development` and PR back into it;
|
integration branch; **`master`** is the production trunk. Cut `feature/*`
|
||||||
promote `development → master` via PR when ready to release. Both branches require
|
branches **from `development`** and PR them back into it. (Stages 0–15 used
|
||||||
one approval + the `CI / gate` check.
|
`master` as the trunk with `feature/* → master`; the genesis Stage 0 commit is
|
||||||
- A commit to a `feature/*` branch triggers nothing. The single workflow
|
on `master` by necessity.)
|
||||||
`.gitea/workflows/ci.yaml` runs the full suite (`unit` + `integration` + `ui`) on a
|
- A commit to a `feature/*` branch triggers **nothing**. The single workflow
|
||||||
PR into `development` or `master`, and the gated **`deploy`** job auto-rolls the
|
`.gitea/workflows/ci.yaml` runs the full suite (`unit` + `integration` + `ui`)
|
||||||
**test contour** on a PR into — or a push to — `development`
|
on a PR into `development` or `master`, and the gated **`deploy`** job auto-rolls
|
||||||
(`docker compose up -d --build` on the runner host + landing/SPA/backend probes). A
|
the **test contour** on a PR into — or a push to — `development`
|
||||||
PR into `master` is test-only.
|
(`docker compose up -d --build` on the runner host + a `GET /` probe). A PR into
|
||||||
- **Production is live on two hosts** (main + the Telegram bot host) and deploys
|
`master` is test-only.
|
||||||
**only manually** (`workflow_dispatch`), never automatically:
|
- Merge `development → master` only when CI is green; the **prod** deploy is then a
|
||||||
- **`.gitea/workflows/prod-deploy.yaml`** (`confirm=deploy`, from `master`) builds +
|
**manual** workflow (Stage 18), never automatic. Secrets/variables are prefixed
|
||||||
pushes the images to the registry, then SSH-deploys both hosts — rolling per
|
`TEST_` / `PROD_` per contour (Gitea 1.26 has no deployment environments).
|
||||||
service in dependency order, health-gated, **auto-rollback to the previous tag**;
|
- After any push, watch the run to green before declaring a stage done — use the
|
||||||
a schema migration adds a maintenance window + a consistent `pg_dump`. Four visible
|
ready-made watcher, never an inline poll loop:
|
||||||
jobs: build → deploy-main → deploy-bot → verify.
|
`python3 ~/.claude/bin/gitea-ci-watch.py` (background). It reads `$GITEA_URL`
|
||||||
- **`.gitea/workflows/prod-rollback.yaml`** (`confirm=rollback`) re-deploys a prior
|
/ `$GITEA_TOKEN`; `gitea.iliadenisov.ru` is allow-listed in
|
||||||
release (blank `target_version` = the previous deployed version) — image-only,
|
`.claude/settings.json`. Remote: `origin git@gitea.iliadenisov.ru:developer/scrabble-game.git`.
|
||||||
rolling, health-gated.
|
|
||||||
- **Releases are git tags `vX.Y.Z` on `master`**; the deploy stamps `git describe
|
|
||||||
--tags` into the image tag, every binary (`pkg/version` via `-ldflags` → the
|
|
||||||
`service.version` telemetry attribute) and the SPA About screen. Tag the release
|
|
||||||
before deploying.
|
|
||||||
- Hosts are provisioned idempotently by **`deploy/ansible/`**. Per-contour
|
|
||||||
secrets/variables use the `TEST_` / `PROD_` prefix (Gitea 1.26 has no deployment
|
|
||||||
environments). Migrations must be **expand-contract** (backward-compatible) so
|
|
||||||
image rollback stays DB-safe. Full runbook + variable list in `deploy/README.md`.
|
|
||||||
- After any push, merge or deploy, **watch the run to green** before declaring done —
|
|
||||||
use the ready-made watcher (run it in the background), never an inline poll loop:
|
|
||||||
`python3 ~/.claude/bin/gitea-ci-watch.py`. It reads `$GITEA_URL` / `$GITEA_TOKEN`;
|
|
||||||
`gitea.iliadenisov.ru` is allow-listed in `.claude/settings.json`. Remote:
|
|
||||||
`origin git@gitea.iliadenisov.ru:developer/scrabble-game.git`.
|
|
||||||
|
|
||||||
## Stack
|
## Stack
|
||||||
|
|
||||||
Go 1.26.3, `go.work` monorepo, module paths `scrabble/<name>`. Backend uses `gin` +
|
Go 1.26.3, `go.work` monorepo, module paths `scrabble/<name>`. Dependencies are
|
||||||
`zap` + `pgx`/`go-jet`/`goose`/OTel. Client↔gateway is Connect-RPC + FlatBuffers
|
added **when first used** (incremental): backend uses `gin` + `zap` +
|
||||||
(h2c); gateway↔backend is REST/JSON + `X-User-ID` plus a gRPC server-stream for live
|
`pgx`/`go-jet`/`goose`/OTel (added in Stage 1). Client↔gateway is Connect-RPC +
|
||||||
events. UI is pure HTML5/CSS on plain Svelte + Vite, packaged to native with
|
FlatBuffers (h2c); gateway↔backend is REST/JSON + `X-User-ID` plus a gRPC
|
||||||
Capacitor. No Redis.
|
server-stream for live events. UI is pure HTML5/CSS on plain Svelte + Vite,
|
||||||
|
packaged to native with Capacitor. Likely no Redis.
|
||||||
|
|
||||||
## Reused engine: `../scrabble-solver` (module `scrabble-solver`, Go 1.26.3)
|
## Reused engine: `../scrabble-solver` (module `scrabble-solver`, Go 1.26.3)
|
||||||
|
|
||||||
Embedded **in-process as a library** (`replace scrabble-solver => ../scrabble-solver`
|
Embedded **in-process as a library** — there is no per-game container. Public
|
||||||
in `go.work`; CI checks out the sibling from
|
API to reuse (do not reimplement):
|
||||||
`https://gitea.iliadenisov.ru/.../scrabble-solver.git`). There is no per-game
|
|
||||||
container. Public API to reuse (do not reimplement):
|
|
||||||
|
|
||||||
- `scrabble.NewSolver(rs, finder)` → `GenerateMoves(b, r, mode)` (ranked, highest
|
- `scrabble.NewSolver(rs, finder)` → `GenerateMoves(b, r, mode)` (ranked,
|
||||||
score first), `ValidatePlay(b, dir, tiles)`, `ScorePlay(...)`; `scrabble.Apply(b, m)`;
|
highest score first), `ValidatePlay(b, dir, tiles)`, `ScorePlay(...)`;
|
||||||
types `Move/Word/Placement/Direction/Mode`
|
`scrabble.Apply(b, m)`; types `Move/Word/Placement/Direction/Mode`
|
||||||
(`scrabble-solver/scrabble/{solver,move,apply}.go`).
|
(`scrabble-solver/scrabble/{solver,move,apply}.go`).
|
||||||
- `rules.English() / RussianScrabble() / Erudit()` (`scrabble-solver/rules/rules.go`).
|
- `rules.English() / RussianScrabble() / Erudit()`
|
||||||
|
(`scrabble-solver/rules/rules.go`).
|
||||||
- `board.New / Parse / Clone / Transpose`; `rack.New / Add / Remove / Clone`;
|
- `board.New / Parse / Clone / Transpose`; `rack.New / Add / Remove / Clone`;
|
||||||
`selfplay.NewBag / Draw / Len` (bag pattern).
|
`selfplay.NewBag / Draw / Len` (bag pattern).
|
||||||
- Load committed dictionaries with `dawg.Load(path)` from
|
- Load committed dictionaries with `dawg.Load(path)` from
|
||||||
@@ -100,17 +99,20 @@ container. Public API to reuse (do not reimplement):
|
|||||||
|
|
||||||
Constraints:
|
Constraints:
|
||||||
- Words/tiles are **alphabet-index bytes**, meaningful only with the matching
|
- Words/tiles are **alphabet-index bytes**, meaningful only with the matching
|
||||||
`rules.Ruleset` (`Alphabet.Decode`); the blank flag is carried separately. **Decode
|
`rules.Ruleset` (`Alphabet.Decode`); blank flag carried separately. **Decode
|
||||||
to real characters before persisting history** (history must be
|
to real characters before persisting history** (history must be
|
||||||
dictionary-independent — see `docs/ARCHITECTURE.md` §9.1).
|
dictionary-independent — see `docs/ARCHITECTURE.md` §9.1).
|
||||||
- The solver's `internal/*` is NOT importable from this sibling module.
|
- The solver's `internal/*` is NOT importable from this sibling module.
|
||||||
- **GCG is test-only** in the solver (no public writer) — we ship our own.
|
- **GCG is test-only** in the solver (no public writer) — we ship our own.
|
||||||
- The solver uses published `github.com/iliadenisov/{alphabet,dafsa}` (no local replace).
|
- Wiring: add `replace scrabble-solver => ../scrabble-solver` to `go.work` in
|
||||||
|
**Stage 2** (when `internal/engine` first imports it), and make CI check out
|
||||||
|
the solver sibling (`https://gitea.iliadenisov.ru/.../scrabble-solver.git`).
|
||||||
|
It uses published `github.com/iliadenisov/{alphabet,dafsa}` (no local replace).
|
||||||
|
|
||||||
## Repository layout
|
## Repository layout
|
||||||
|
|
||||||
```
|
```
|
||||||
go.work # the go.work monorepo
|
go.work # use the existing modules; grows per stage
|
||||||
backend/ # module scrabble/backend
|
backend/ # module scrabble/backend
|
||||||
cmd/backend/ # main: telemetry -> db+migrate -> cache -> server
|
cmd/backend/ # main: telemetry -> db+migrate -> cache -> server
|
||||||
cmd/jetgen/ # dev tool: regenerate go-jet code (throwaway container)
|
cmd/jetgen/ # dev tool: regenerate go-jet code (throwaway container)
|
||||||
@@ -121,14 +123,12 @@ backend/ # module scrabble/backend
|
|||||||
internal/session/ # opaque tokens, sessions store, cache, service
|
internal/session/ # opaque tokens, sessions store, cache, service
|
||||||
internal/server/ # gin engine, /api/v1 groups, X-User-ID, probes
|
internal/server/ # gin engine, /api/v1 groups, X-User-ID, probes
|
||||||
internal/inttest/ # //go:build integration Postgres-backed tests
|
internal/inttest/ # //go:build integration Postgres-backed tests
|
||||||
gateway/ # module scrabble/gateway: Connect-RPC edge, embeds the SPA
|
docs/ .gitea/workflows/ PLAN.md CLAUDE.md README.md
|
||||||
ui/ # Svelte + Vite SPA + landing (Node project, not in go.work)
|
gateway/ ui/ pkg/ # added by their stages
|
||||||
pkg/ # shared: telemetry, version, wire/FlatBuffers, proto, mtls
|
platform/telegram/ # Telegram side-service, two binaries (Stage 9; split in phase TX): cmd/validator (HMAC, no VPN) + cmd/bot (Bot API; dials gateway over reverse mTLS bot-link)
|
||||||
platform/telegram/ # Telegram side-service: cmd/validator (HMAC, no VPN) + cmd/bot (Bot API; dials gateway over reverse mTLS bot-link)
|
loadtest/ # module scrabble/loadtest: the pre-release stress harness (R2)
|
||||||
loadtest/ # module scrabble/loadtest: the load/stress harness
|
backend/Dockerfile gateway/Dockerfile platform/telegram/Dockerfile loadtest/Dockerfile # multi-stage distroless (Stage 16; loadtest R2); gateway/Dockerfile has the `landing` target (R3), platform/telegram/Dockerfile has `validator`+`bot` targets (TX)
|
||||||
docs/ .gitea/workflows/ CLAUDE.md README.md
|
deploy/ # docker-compose (per-service limits, R7) + caddy + landing + otelcol (OTLP + docker_stats per-container metrics) + prometheus/tempo/grafana + postgres_exporter
|
||||||
backend/Dockerfile gateway/Dockerfile platform/telegram/Dockerfile loadtest/Dockerfile # multi-stage distroless; gateway/Dockerfile has the `landing` target, platform/telegram/Dockerfile has `validator`+`bot` targets
|
|
||||||
deploy/ # docker-compose (+ prod overlay + bot host) + ansible provisioning + caddy + landing + otelcol (OTLP + docker_stats) + prometheus/tempo/grafana + node_exporter + postgres_exporter; prod-deploy.sh
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Build & test
|
## Build & test
|
||||||
@@ -138,19 +138,20 @@ go build ./backend/... # per module ('./...' from the root won't span t
|
|||||||
go vet ./backend/...
|
go vet ./backend/...
|
||||||
gofmt -l . # must print nothing
|
gofmt -l . # must print nothing
|
||||||
go test -count=1 ./backend/...
|
go test -count=1 ./backend/...
|
||||||
go build ./platform/telegram/... && go test ./platform/telegram/... # Telegram validator + bot
|
go build ./platform/telegram/... && go test ./platform/telegram/... # Telegram validator + bot (Stage 9; split in TX)
|
||||||
go run ./backend/cmd/backend # /healthz, /readyz on :8080
|
go run ./backend/cmd/backend # /healthz, /readyz on :8080
|
||||||
|
|
||||||
cd ui && pnpm install && pnpm check && pnpm test:unit && pnpm build # the UI
|
cd ui && pnpm install && pnpm check && pnpm test:unit && pnpm build # the UI (Stage 7+)
|
||||||
pnpm start # UI mock mode: lobby -> game, no backend
|
pnpm start # UI mock mode: lobby -> game, no backend
|
||||||
|
|
||||||
docker build --build-arg DICT_VERSION=v1.3.0 -f backend/Dockerfile -t scrabble-backend . # DICT_VERSION required (no default); gateway embeds the SPA
|
docker build -f backend/Dockerfile -t scrabble-backend . # images (Stage 16); gateway embeds the SPA
|
||||||
docker build -f gateway/Dockerfile --target gateway -t scrabble-gateway .
|
docker build -f gateway/Dockerfile --target gateway -t scrabble-gateway .
|
||||||
docker build -f gateway/Dockerfile --target landing -t scrabble-landing . # static landing
|
docker build -f gateway/Dockerfile --target landing -t scrabble-landing . # static landing (R3)
|
||||||
docker compose -f deploy/docker-compose.yml config # validate the full contour
|
docker compose -f deploy/docker-compose.yml config # validate the full contour
|
||||||
```
|
```
|
||||||
|
|
||||||
The `ui` module is a Node project (pnpm), **not** in `go.work`; it is the `ui` job of
|
The `ui` module is a Node project (pnpm), **not** in `go.work`; it is the `ui` job
|
||||||
the single `.gitea/workflows/ci.yaml`. Committed edge codegen under `ui/src/gen/`
|
of the single `.gitea/workflows/ci.yaml` (Stage 16 folded the former go-unit /
|
||||||
|
integration / ui-test workflows into it). Committed edge codegen under `ui/src/gen/`
|
||||||
(regenerate with `pnpm codegen`); pnpm build-script approval lives in
|
(regenerate with `pnpm codegen`); pnpm build-script approval lives in
|
||||||
`ui/pnpm-workspace.yaml` (`allowBuilds: esbuild: true`).
|
`ui/pnpm-workspace.yaml` (`allowBuilds: esbuild: true`).
|
||||||
|
|||||||
+632
@@ -0,0 +1,632 @@
|
|||||||
|
# Pre-release plan — hardening before Stage 18
|
||||||
|
|
||||||
|
Living tracker for the pre-release hardening pass that runs **before Stage 18** (the
|
||||||
|
prod cutover). Same discipline as [`PLAN.md`](PLAN.md): one phase per session,
|
||||||
|
**interview the owner on the open details** at the start of each phase, bake every
|
||||||
|
decision back into `PLAN.md` / `docs/` / the affected `README`s / Go Doc comments in
|
||||||
|
the **same** PR, get CI green, then mark the phase done. Phases run as
|
||||||
|
`feature/* → development` PRs (the Stage 16 branch model); the owner approves+merges.
|
||||||
|
|
||||||
|
**Why now:** the system is feature-complete through Stage 17 and the test contour is
|
||||||
|
green, but there is **no prod data yet** — schema, wire labels and the dictionary
|
||||||
|
layout can still change for free. These phases spend that one-time freedom and harden
|
||||||
|
the edge before prod. Each phase maps back to the owner's raw pre-release TODO list
|
||||||
|
(numbers in the tracker).
|
||||||
|
|
||||||
|
## Phase tracker
|
||||||
|
|
||||||
|
| # | Phase | Raw TODOs | Status |
|
||||||
|
|---|-------|-----------|--------|
|
||||||
|
| R1 | Schema & naming reset | 1 + 10 | **done** |
|
||||||
|
| R2 | Stress harness + contour observability + early run | 9a | **done** |
|
||||||
|
| R3 | Edge hardening | 2 + 8 + 3 | **done** |
|
||||||
|
| R4 | Push enrichment + kill the last poll | 4 + 5 | **done** |
|
||||||
|
| R5 | Bundle slimming | 6 | **done** |
|
||||||
|
| R6 | Refactor + docs reconciliation + de-staging | 7 | **done** |
|
||||||
|
| R7 | Final stress run + tuning | 9b | **done** |
|
||||||
|
| UI | Tab-bar navigation redesign (drop the hamburger) | owner ad-hoc | **done** |
|
||||||
|
| MW | "Multiple words per turn" rule for Russian games (engine v1.1.0) | owner ad-hoc | **done** |
|
||||||
|
| MW2 | Single-word rule connectivity fix: the word must run along its own line through an existing tile (perpendicular-only contact no longer connects); single-tile direction picks the best legal word (engine v1.1.1) | owner ad-hoc | **done** |
|
||||||
|
| MW3 | Graceful replay degradation: a game whose journalled move became illegal under MW2 is closed as a draw (`end_reason='aborted'`) on open instead of erroring, with an impersonal organizer note in the history + GCG (migration `00002`) | owner ad-hoc | **done** |
|
||||||
|
| OW | Open auto-match: enter the game at once and wait inside it (robot after 90–180 s) | owner ad-hoc | **done** |
|
||||||
|
| DA | Dictionary admin: online release-archive upload → word-diff preview → install/activate; versioned dict volume; active version persisted in DB; resident label = release tag | owner ad-hoc | **done** |
|
||||||
|
| AB | Manual account block (admin suspension): permanent/temporary with an editable en+ru reason picklist; a block forfeits the player's active games + cancels their open ones; a backend gate refuses a blocked account with **403 `account_blocked`**; the UI shows a terminal blocked screen and stops all push/poll; manual unblock; temporary blocks self-expire (migration `00003`) | owner ad-hoc | **done** |
|
||||||
|
| AI | Honest AI opponent in quick game: an explicit 🤖 AI / 👤 random selector (AI default); the robot is seated and moves at once; 7-day inactivity loss (the per-turn timeout reused); chat/nudge disabled, no statistics; the opponent is shown as 🤖 everywhere | owner ad-hoc | **done** |
|
||||||
|
| AD | Advertising banner ("ad network"): server-driven weighted campaigns (percent weight + validity window; the perpetual default fills the remainder up to 100%), bilingual messages shown by bot (`service_language`); eligibility = free account + empty hint wallet + no `no_banner` role (guests included); the resolved feed rides `profile.get` with a `notify` `banner` re-poll on eligibility change; `/_gm/banners` admin + global display timings; client smooth-weighted-round-robin rotation + fade-out/gap/fade-in UX. A single `app.load` bootstrap aggregator was considered and **deferred** (see ARCHITECTURE §10). | owner ad-hoc | **done** (PR1 backend+admin, PR2 UI rotation) |
|
||||||
|
| GL | Simultaneous quick-game cap (10): grey "New Game" + a lobby notice at the cap; backend gate on quick enqueue + invitation creation (409 `game_limit_reached`), accepting invitations exempt; `at_game_limit` rides `games.list` | owner ad-hoc | **done** |
|
||||||
|
| CR | In-game chat read receipts: per-message `unread_seats` bitmask (migration `00008`); a per-viewer unread **dot** in the lobby + game header (a nudge counts and clears when its recipient moves); reading = opening the move history (the 💬 fade-blinks twice) or the chat, acked (`chat.read`) only when unread; `chat_read_duration` + `chat_unread_messages` metrics + tracing + the **Scrabble — Messages** Grafana dashboard (follow-up PR); a message to a disguised robot opponent is born read; admin unread-only filter / read column / per-seat read card | owner ad-hoc | **done** |
|
||||||
|
| BX | Asymmetric per-user block + in-game controls: a block now silently suppresses everything **from** the blocked user (chat, nudge, friend requests, invitations are kept but never delivered/surfaced, born-read) while they notice nothing, **without** deleting the friendship (unblock restores it); auto-match excludes a block-related pair (either direction); in-game opponent card gains a ✖️ **block** control (mirroring 🤝, red "Block?" confirm, mutual-hide, struck name + hidden chat composer when blocked); optimistic apply + `user_blocked`/`user_unblocked` event confirm + rollback; admin user card gains **blocks / blocked-by / friends** cross-linked lists. Blocking a disguised-robot opponent is recorded per-game in a separate **`robot_blocks`** table (migration `00011`), keyed on game+seat with the seen name — never the shared robot account — so the matchmaker keeps giving robots; it shows in the blocked list and re-marks the in-game card | owner ad-hoc | **done** |
|
||||||
|
| FM | First-move tile draw (official rules): each seated player draws a tile, the one closest to "A" leads (a blank beats every letter), ties re-drawing until a single leader; **honest per-draw `crypto/rand` entropy**, not the bag seed, so the **record** (`game_setup_draws`, migration `00013`) — not a seed — is the only account of the outcome, kept for future **tournaments** (designed as a discrete per-tile "player N draws" step). Friend/AI draws at create; **auto-match draws at *open*** against a synthetic `uuid.Nil` opponent whose draw rows are back-filled on join, so the opener's seat is fixed up front and the existing open-game pre-move is preserved (no reseating, no play-gating). Admin `/_gm/games/:id` gains the recorded draw list + a simple **step-by-step board replay** (`ReplayTimeline`). | owner ad-hoc | **done** |
|
||||||
|
| SB | Single Telegram bot + per-user variant preferences: the two per-language bots collapse into **one** (drop `accounts.service_language`, `supported_languages`, the `*_EN`/`*_RU` env vars and game-language push routing — the single bot renders in the recipient's `preferred_language`); New Game variant gating moves to a profile **`variant_preferences`** set (default Erudit only, Erudit-first, server-enforced on the caller's auto-match/vs-AI/invitation-create paths, an invited friend may accept any variant); env vars collapse to unsuffixed `TELEGRAM_BOT_TOKEN`/`TELEGRAM_GAME_CHANNEL_ID`/`VITE_TELEGRAM_LINK`/`VITE_TELEGRAM_GAME_CHANNEL_NAME` and `GATEWAY_DEFAULT_SUPPORTED_LANGUAGES` is removed; wire drops `service_language`/`supported_languages` (Session, ValidateInitDataResponse) + the push `language` routing field and adds `variant_preferences` to Profile/UpdateProfile. | owner ad-hoc | **done** |
|
||||||
|
| DV | Dictionary version hygiene: CI + image/compose seed track the current release (`v1.2.1`); a **seed-drift guard** records the flat dir's seed in an authoritative `.seed_version` marker so a bumped build seed on a live volume is ignored (it can't relabel live bytes — which would mis-serve the dictionary + void games pinned to the prior label); `DICT_VERSION` is the fresh-volume seed only, a live contour migrates through the admin console | owner ad-hoc | **done** |
|
||||||
|
| TX | Telegram egress off the main host: split the connector into a home **validator** (Mini App / Login-Widget HMAC, no VPN, no Bot API — so game login no longer depends on Telegram being reachable) and a remote **bot** (Bot API long-poll + `sendMessage`) that holds **no inbound port** and dials the gateway over a reverse **mTLS bot-link** (`pkg/proto/botlink/v1`); the gateway funnels out-of-app push (fire-and-forget, at-most-once) and the backend admin broadcasts (a relay that awaits the bot's ack) down the link. The bot is Telegram-rate-limited; **one bot now**, with seams (a bot registry + `owns_updates` + command ids) for N later; **no webhook** (rejected: one URL per token, adds inbound + a static address). The **unified test contour** runs the split (the bot keeps its VPN sidecar and dials the gateway by its internal name; certs from `deploy/gen-certs.sh`). The **prod** wiring — the bot on a separate host (no VPN), the gateway bot-link port published, `PROD_` certs, an SSH deploy of both hosts together — is **built in Stage 18** (the two-host registry rollout; first cutover pending the `erudit-game.ru` DNS). | owner ad-hoc | **done** (code + test contour; prod wiring built — Stage 18) |
|
||||||
|
| AG | Anti-abuse IP ban + honeypot/honeytoken (prod-only): a fail2ban-style in-memory `ratelimit.Banlist` keyed by client IP, fed by sustained rate-limiter rejections (the IP-keyed public/email/admin classes — the user class stays the soft-flag's concern), a **honeypot** decoy path (the contour caddy tags `/.env`, `/.git`, `/wp-*`, … with `X-Scrabble-Honeypot` and routes them to the gateway), and a **honeytoken** (`GATEWAY_HONEYTOKEN`, a planted bearer). The `abuseGuard` edge middleware refuses a banned IP with **429** before any work — closing the R3 gap that the static SPA/landing was outside the token bucket. Off by default — it keys by the real client IP the shared-NAT test contour does not expose (detection still logs there); enabled in prod via `GATEWAY_ABUSE_BAN_ENABLED`. Operators see + lift bans on the console **Throttled** page; the gateway syncs its active set to the backend (`/api/v1/internal/bans/sync`, `internal/banview`) every 30 s and applies operator unbans. | owner ad-hoc | **done** (code + test contour; ban on in prod via Stage 18 — machinery built, cutover pending DNS) |
|
||||||
|
| CM | Channel-chat moderation + promo bot: a second standalone bot in the bot container answers `/start` with a localized message + a **URL** button into the **main** bot's Mini App (`?startapp`; a `web_app` button would sign initData with the promo token, which the main validator rejects). The **main** bot gates write access in a channel's linked discussion chat. The chat **allows sending by default** and the bot only restricts (Telegram intersects the chat default with the per-user permission, so a per-user grant cannot exceed a deny-by-default group): it **mutes** a member who is not registered or is admin-suspended or holding a new **`chat_muted`** role, and **un-mutes** an eligible one it had muted, for a member currently in the chat (a `getChatMember` guard, since bots cannot list members). Eligibility = `registered AND NOT suspended AND NOT chat_muted` (the game suspension dominates), resolved once in the backend and reached two ways: the bot's `ResolveChatEligibility` on a `chat_member` event over the existing mTLS bot-link, and a backend `chat_access_changed` event → gateway → `ChatGate` command (emitted on block/unblock, a `chat_muted` change, a first registration, or a temporary-block expiry via a sweeper; idempotent). No schema change — `chat_muted` reuses `account_roles`. | owner ad-hoc | **done** |
|
||||||
|
| → | Stage 18 — prod contour deploy | — | see [`PLAN.md`](PLAN.md) |
|
||||||
|
|
||||||
|
## Key findings (these reshaped the raw list — read before starting a phase)
|
||||||
|
|
||||||
|
- **R1 (TODO 1 + 10) is one cheap moment, now.** Squashing the 12 goose migrations is
|
||||||
|
safe precisely because there is no prod data and the contour DB is wiped. Folding the
|
||||||
|
new variant labels (`scrabble_ru`/`scrabble_en`/`erudit_ru`) into that single baseline
|
||||||
|
makes the rename need **no data migration and no back-compat mapping**. Today's labels
|
||||||
|
(`english`/`russian_scrabble`/`erudit`) are persisted in `games.variant`,
|
||||||
|
`game_invitations.variant`, in `pkg/fbs` and the UI — ~100 files, but a mechanical sweep
|
||||||
|
on a clean DB.
|
||||||
|
- **R4 (TODO 4 + 5): the app is already push-first.** Game state refreshes on
|
||||||
|
`your_turn`/`opponent_moved`, the lobby on `notify`, chat on `chat_message`. The **only**
|
||||||
|
genuine periodic server poll is `lobby.poll` (matchmaking, 2.5 s,
|
||||||
|
`ui/src/screens/NewGame.svelte`). What remains is killing that one poll **and** enriching
|
||||||
|
push events to carry payloads so the UI stops re-fetching after each signal.
|
||||||
|
- **R3 (TODO 2): identity forgery is already mitigated.** Identity is always derived from
|
||||||
|
the session (`Authorization: Bearer` → `X-User-ID`); the client cannot inject identity,
|
||||||
|
the backend re-validates resource ownership, Telegram initData is HMAC-checked. The real
|
||||||
|
gaps are a missing **request-body size limit** (cheap DoS) and **invisible rate-limit
|
||||||
|
rejections** (no log/metric/admin view — that is TODO 8). Static landing serving is **not**
|
||||||
|
covered by the gateway token bucket (it only guards `Execute`).
|
||||||
|
- **R6 (TODO 7) scale:** ~431 `Stage N` references across ~104 files (incl. the file name
|
||||||
|
`backend/internal/inttest/stage6_test.go`). Code is the source of truth; `docs/` describe
|
||||||
|
current state; `PLAN.md` keeps the decision history.
|
||||||
|
|
||||||
|
## Locked decisions (owner interview)
|
||||||
|
|
||||||
|
- **Stress test (TODO 9):** **early + final** runs. Driver = **edge protocol** (Connect/FB
|
||||||
|
through the gateway, moves generated by the solver) **plus a separate gateway-hammer**
|
||||||
|
saturation test. Pacing = **realistic (under limits) + saturation (ramp to the knee)**.
|
||||||
|
Resource metrics = **add cAdvisor + postgres_exporter to the contour** (today only
|
||||||
|
Go-runtime metrics exist). The harness stays in the repo for repeats.
|
||||||
|
- **Push (TODO 4 + 5):** **both** — kill `lobby.poll` (use the existing `match_found`, keep
|
||||||
|
poll as the ws-down fallback) **and** enrich push events with payloads.
|
||||||
|
- **Refactor (TODO 7):** **hygiene + structural changes by a reviewed list** —
|
||||||
|
behaviour-preserving, test-gated, contentious items surfaced to the owner before applying.
|
||||||
|
- **Landing (TODO 3):** **separate static container** behind the project caddy
|
||||||
|
(`/` → landing, `/app/` + `/telegram/` → gateway); drop `landing.html` from the gateway
|
||||||
|
`go:embed`.
|
||||||
|
- **Rate-abuse (TODO 8):** metric + Grafana + admin view **plus a conservative auto-flag** —
|
||||||
|
a *soft, reversible* "suspected high-rate" marker for operator review, tunable threshold,
|
||||||
|
**no auto-ban**.
|
||||||
|
- **Anti-abuse IP ban (AG, owner ad-hoc):** a honeypot was considered and rejected as a *DDoS*
|
||||||
|
defence — it detects/deceives but does not shed volumetric load, cannot cover the real
|
||||||
|
endpoints, and a tarpit backfires under flood; volumetric L3/L4 is an upstream/CDN concern,
|
||||||
|
out of scope. The effective layer is a **temporary IP ban** (fail2ban-style) that the honeypot
|
||||||
|
and honeytoken merely *feed*. This does **not** reverse the TODO-8 "no auto-ban": that decision
|
||||||
|
governs the **account** soft-flag (still never a gate); the IP ban is a separate, IP-keyed,
|
||||||
|
**prod-only** layer with an **operator unban** in the console. Decisions: banlist lives in the
|
||||||
|
existing `ratelimit` package (smallest surface); the decoy path list is a **single source of
|
||||||
|
truth in the caddy** (it tags requests with a header — the gateway keeps no second list);
|
||||||
|
bans are in-memory + single-instance (like `ratewatch`), auto-expiring, **plus** an admin
|
||||||
|
console view + manual unban over a bidirectional 30 s sync (operator control = owner's choice).
|
||||||
|
An active-bans Grafana **gauge** was trimmed (the console view + the `gateway_abuse_banned_total`
|
||||||
|
counter cover it) to keep the diff focused.
|
||||||
|
- **Open auto-match (owner ad-hoc):** a quick game **enters a real game at once and waits inside
|
||||||
|
it** (status `open`, the opponent seat empty); a second human searching the same variant+rule
|
||||||
|
joins it, or a robot fills it after a **90 s + random 0–90 s** wait, pushing the in-app
|
||||||
|
**opponent_joined** event. While open, the starter may move on their turn but resign, chat and
|
||||||
|
nudge are disabled, and the lobby + opponent card read "searching for opponent". Matchmaking is
|
||||||
|
now **DB-backed open games** — the in-memory pool, `lobby.poll` and `lobby.cancel` are gone. The
|
||||||
|
schema is edited in the baseline (no prod data); `game_players.account_id` is nullable for the
|
||||||
|
empty seat.
|
||||||
|
- **Telegram egress off-host (TX, owner ad-hoc):** the driver is **removing VPN/Telegram
|
||||||
|
traffic from the main host** (OPSEC / one fewer analysis vector), not only notification
|
||||||
|
resilience. Login is local HMAC, so it stays up regardless of the bot — confirmed in the
|
||||||
|
code and made structural by the split. **Unified topology in code** (validator + bot, the
|
||||||
|
bot dialing the gateway) in **both** contours, differing only in deployment; the test bot
|
||||||
|
keeps its VPN sidecar. Transport = a **reverse gRPC bidi stream, mTLS, bot-dials-gateway**
|
||||||
|
(no inbound/static IP on the bot), reusing the push-stream pattern; **webhook rejected**
|
||||||
|
(one URL per token, adds inbound + a static address). Delivery **at-most-once** (a dropped
|
||||||
|
nudge beats a duplicate). **One bot now**, seams (registry + `owns_updates` + command ids)
|
||||||
|
for N later. **Cert rotation** by a scheduled CI job from a long-lived CA. **Prod deploy by
|
||||||
|
SSH** (pull excluded), the bot rolled **together** with the main app (the bot-link protocol
|
||||||
|
kept back-compatible by one version as the non-atomic-two-host-deploy safety net). The bot
|
||||||
|
is monitored **from the gateway** (connection + ack metrics). The bot-host token-at-rest is
|
||||||
|
**accepted**.
|
||||||
|
|
||||||
|
## Phases
|
||||||
|
|
||||||
|
Each phase: read this tracker + the relevant `docs/`, **interview the owner on the open
|
||||||
|
details below**, implement within scope, then update the tracker + docs/code and get CI
|
||||||
|
green before marking it done.
|
||||||
|
|
||||||
|
### R1 — Schema & naming reset *(TODO 1 + 10)* — first
|
||||||
|
Squash `backend/internal/postgres/migrations/00001..00012` into one `00001_baseline.sql`
|
||||||
|
(method: `pg_dump --schema-only` from a fully-migrated DB → wrap as the goose baseline →
|
||||||
|
prove a fresh migrate yields a schema identical to the 12-migration chain via the
|
||||||
|
integration suite → delete the old files; keep goose). Bake the new variant labels into the
|
||||||
|
baseline. Propagate `scrabble_ru`/`scrabble_en`/`erudit_ru` through the backend
|
||||||
|
(`engine.Variant`/`ParseVariant`, `registry.dictFiles`, the CHECK values), the wire
|
||||||
|
(`pkg/fbs` `variant:string`, regenerate FB) and the UI (`lib/model.ts` union, `variants.ts`,
|
||||||
|
fixtures, premium/alphabet keys, tests); i18n display keys stay display-only. Tidy
|
||||||
|
`../scrabble-dictionary` to a single source→dawg build point and align the dawg artifact
|
||||||
|
names to the new labels (crosses into `../scrabble-solver`'s committed fixtures — keep them
|
||||||
|
byte-identical). After merge, **wipe the contour DB** (drop the volume) so it re-provisions
|
||||||
|
on the next deploy.
|
||||||
|
- Critical files: `backend/internal/postgres/migrations/`,
|
||||||
|
`backend/internal/engine/{engine,registry}.go`, `pkg/fbs/scrabble.fbs`,
|
||||||
|
`ui/src/lib/{model,variants}.ts`, `../scrabble-dictionary/{Makefile,cmd/builddict,…}`.
|
||||||
|
- Open details to interview: the exact dawg filename scheme; whether the dict-repo tidy is
|
||||||
|
one PR or split; how to script the contour DB wipe in the deploy.
|
||||||
|
|
||||||
|
### R2 — Stress harness + contour observability + early run *(TODO 9, part 1)*
|
||||||
|
Build the reusable load harness as a new `loadtest` module in `go.work` (reuses `pkg/fbs`,
|
||||||
|
`connect-go`, and `scrabble-solver` for legal-move generation): a seeder that inserts
|
||||||
|
**1000 guest + 10000 durable** accounts with pre-created sessions (token hashes) directly in
|
||||||
|
the DB and hands the plaintext tokens to the client; a driver that runs N virtual users,
|
||||||
|
each in 3–5 concurrent 2–4-player games, exercising submit-play / pass / exchange / nudge /
|
||||||
|
chat / check-word / draft-move / profile-save through the **edge protocol**, in
|
||||||
|
**realistic** (under rate limits) and **saturation** (ramp) modes; plus a separate
|
||||||
|
**gateway-hammer** that deliberately exceeds limits to verify the limiter holds and measure
|
||||||
|
its cost. Add **cAdvisor + postgres_exporter** to `deploy/docker-compose.yml` and a Grafana
|
||||||
|
resource dashboard. Run the **early pass** against the freshly-wiped contour; produce a
|
||||||
|
**trip report** (logic/concurrency bugs + a resource baseline) that feeds R3 and R6.
|
||||||
|
- Critical files: new `loadtest/`, `deploy/docker-compose.yml`, `deploy/observability/*`,
|
||||||
|
`docs/TESTING.md`.
|
||||||
|
- Open details: the scale ramp steps; the move-selection policy (a mid-ranked solver move
|
||||||
|
for realistic game progress); run duration; the pass/fail bar.
|
||||||
|
|
||||||
|
### R3 — Edge hardening *(TODO 2 + 8 + 3)*
|
||||||
|
Add a **request-body size cap** at the gateway h2c mux / `Execute` (e.g. ~1 MB). Add
|
||||||
|
**rate-limit observability**: a `gateway_rate_limited_total{class}` counter + a structured
|
||||||
|
log per rejection; an **aggregate** Grafana panel (request rate + rejection rate — spikes
|
||||||
|
visible without per-user label cardinality, honouring the Stage 12/17 discipline); an
|
||||||
|
**admin-console view** of recently throttled users/IPs (in-memory ring buffer, single-
|
||||||
|
instance, reset-on-restart, like the `active_users` gauge). Add the **conservative
|
||||||
|
auto-flag**: when a user is *sustained*-throttled past a tunable threshold, set a soft,
|
||||||
|
reversible `account.flagged_high_rate_at` marker (baked into the R1 baseline) surfaced in the
|
||||||
|
admin user list/detail — **no auto-ban**; the operator clears it. Split the **landing** into
|
||||||
|
its own static container (`deploy/` + a Caddyfile route `/` → landing) and drop
|
||||||
|
`landing.html` from the gateway `go:embed`.
|
||||||
|
- Critical files: `gateway/internal/connectsrv/server.go`, `gateway/internal/ratelimit/`,
|
||||||
|
`gateway/internal/connectsrv/metrics.go`, `backend/internal/adminconsole/`,
|
||||||
|
`deploy/caddy/Caddyfile`, `deploy/docker-compose.yml`, `gateway/internal/webui/`.
|
||||||
|
- Open details: the auto-flag threshold/window + whether the marker is persisted vs
|
||||||
|
in-memory; the landing image base (caddy vs nginx).
|
||||||
|
|
||||||
|
### R4 — Push enrichment + kill the last poll *(TODO 4 + 5)*
|
||||||
|
Replace `lobby.poll` with the existing `match_found` push (keep the poll as a ws-down
|
||||||
|
fallback). Enrich `your_turn`/`opponent_moved`/`notify` to carry the state payload so the UI
|
||||||
|
renders from the event without a follow-up `game.state` (removes the lobby↔game nav latency
|
||||||
|
the owner noticed). Wire-contract change: `pkg/fbs` event payloads → backend `notify` emit →
|
||||||
|
UI stream consumers (`ui/src/lib/app.svelte.ts`), with the per-game cache as the landing
|
||||||
|
spot; regenerate FB.
|
||||||
|
- Critical files: `pkg/fbs/scrabble.fbs`, `backend/internal/notify/events.go`,
|
||||||
|
`ui/src/lib/{app.svelte,transport}.ts`, `ui/src/screens/NewGame.svelte`.
|
||||||
|
- Open details: which events carry full vs delta payloads; the fallback-poll cadence when the
|
||||||
|
stream is down.
|
||||||
|
|
||||||
|
### R5 — Bundle slimming *(TODO 6)* — done
|
||||||
|
Analysed the bundle against the 100 KB-gzip budget; **no code slimming was warranted**, and the
|
||||||
|
budget metric was retargeted to measure the app correctly. The build already minifies +
|
||||||
|
tree-shakes; the dominant cost is the Connect/FlatBuffers transport runtime + generated bindings
|
||||||
|
+ the Svelte runtime (≈⅔ of `main`'s source is third-party/generated) — irreducible within scope.
|
||||||
|
**Lazy-loading was rejected**: `bundle-size.mjs` sums every emitted chunk, so code-splitting yields
|
||||||
|
no total-size win and adds request latency (+N gateway fetches on first navigation to a split
|
||||||
|
screen). i18n lazy-load was skipped (the catalogs are a sliver of a Svelte-runtime-dominated shared
|
||||||
|
chunk, and `en` must stay bundled as the `MessageKey` type source + fallback). Instead,
|
||||||
|
`bundle-size.mjs` now measures **per HTML entry**, with three independent gates on the natural chunk
|
||||||
|
boundaries — **app entry ≤ 100 KB, the Svelte+i18n shared chunk ≤ 30 KB, the landing's own chunk
|
||||||
|
≤ 5 KB** — since the app's real payload is its entry chunk plus the shared chunk (≈97 KB), while the
|
||||||
|
landing (≈24 KB) is reported separately and kept minimal. Same CLI + exit-code contract, so the CI
|
||||||
|
step is unchanged.
|
||||||
|
- Critical files: `ui/scripts/bundle-size.mjs`; no app code changed.
|
||||||
|
|
||||||
|
### R6 — Refactor + docs reconciliation + de-staging *(TODO 7)* — done
|
||||||
|
Behaviour-preserving only. Three separable, separately-committed passes: (a) mechanical
|
||||||
|
**de-staging** — remove `Stage N`/`TODO-N` references from code, comments and service
|
||||||
|
READMEs (rename `stage6_test.go`); (b) **docs↔code reconciliation** — reconcile
|
||||||
|
`docs/ARCHITECTURE.md` / `docs/FUNCTIONAL.md`(+`_ru`) against the code-as-truth, fixing drift
|
||||||
|
and Go Doc comments; (c) **structural changes by a reviewed list** — surface a list of
|
||||||
|
proposed optimizations / test-suite consolidations to the owner, apply only the approved,
|
||||||
|
behaviour-preserving, test-gated ones. The full suite + the final stress run (R7) are the
|
||||||
|
regression gate. Incorporates the early-run (R2) bug fixes not already shipped.
|
||||||
|
- Open details: the structural-changes list itself (owner-approved before applying); the test
|
||||||
|
consolidation targets.
|
||||||
|
|
||||||
|
### R7 — Final stress run + tuning *(TODO 9, part 2)* — done
|
||||||
|
Re-run the R2 harness against the final, refactored system on a clean contour; analyse
|
||||||
|
resource consumption across **all** components (gateway, backend, Postgres, the
|
||||||
|
metrics/observability stack, docker log volume) and agree the tuning (pool sizes, rate
|
||||||
|
limits, cache TTLs, container limits, GOMAXPROCS, log levels). Apply the agreed tuning; record
|
||||||
|
the methodology + results in the repo.
|
||||||
|
|
||||||
|
→ **Stage 18** (prod contour) then proceeds per [`PLAN.md`](PLAN.md).
|
||||||
|
|
||||||
|
## Sequencing rationale
|
||||||
|
|
||||||
|
`R1` first (cheapest now; everything builds on the final schema/naming and the stress test
|
||||||
|
must run against it). `R2` builds the harness and runs the **early** pass to surface bugs and
|
||||||
|
a resource baseline that feed `R3` and `R6`. `R3`/`R4`/`R5` harden and improve the system.
|
||||||
|
`R6` (de-stage + reconcile + structural) runs near the end so it sweeps settled code once and
|
||||||
|
benefits from all accumulated bug knowledge. `R7` validates the final system and tunes it.
|
||||||
|
Then Stage 18.
|
||||||
|
|
||||||
|
## Regression-safety discipline (cross-cutting)
|
||||||
|
|
||||||
|
- Every phase is a `feature/* → development` PR; CI (`unit` + `integration` + `ui` behind the
|
||||||
|
`CI / gate` check) must be green before the owner merges; watch the post-merge contour
|
||||||
|
deploy with `gitea-ci-watch.py`.
|
||||||
|
- `R6` structural changes are behaviour-preserving, test-gated, and split from the mechanical
|
||||||
|
sweeps; contentious items are owner-approved first.
|
||||||
|
- The two stress runs (`R2` early, `R7` final) are the system-level regression gate.
|
||||||
|
|
||||||
|
## Verification (per phase)
|
||||||
|
|
||||||
|
- `go build ./<module>/...`, `go vet`, `gofmt -l .` clean, `go test -count=1 ./<module>/...`;
|
||||||
|
UI: `pnpm check && pnpm test:unit && pnpm build`; the integration suite
|
||||||
|
(`-tags integration`) for DB/schema changes; `docker compose config` for deploy changes;
|
||||||
|
green CI on the PR + a healthy contour deploy.
|
||||||
|
- `R1`: prove the squashed baseline yields a schema identical to the 12-migration chain
|
||||||
|
(integration suite on a fresh DB) **before** deleting the old files.
|
||||||
|
- `R2`/`R7`: the harness runs end-to-end against the contour; the trip report lists concrete
|
||||||
|
defects + a resource profile from the Grafana cAdvisor/postgres_exporter panels.
|
||||||
|
|
||||||
|
## Refinements logged during implementation
|
||||||
|
|
||||||
|
- **R1** (interview + implementation):
|
||||||
|
- **Variant labels** `english`/`russian_scrabble`/`erudit` → **`scrabble_en`/`scrabble_ru`/`erudit_ru`**
|
||||||
|
across the backend (`engine.Variant.String`/`ParseVariant`; the `games`/`game_invitations` `variant`
|
||||||
|
CHECK in the baseline; GCG `#lexicon` and the `variant` metric attribute both flow from `String`),
|
||||||
|
the wire (`pkg/fbs` `variant` is a `string` field — values change with **no FlatBuffers regen**) and
|
||||||
|
the UI (`model.ts` union, `variants.ts` records, `codec`/`premiums`/mocks/tests, the admin
|
||||||
|
`dictionary.gohtml`). **Kept:** the Go enum identifiers (`VariantEnglish`…, internal) and the i18n
|
||||||
|
display keys (`new.english`/`new.russian`/`new.erudit`, display-only). `complaints.variant` stays
|
||||||
|
free-text (no CHECK, as before).
|
||||||
|
- **dawg filenames kept descriptive** (`en_sowpods`/`ru_scrabble`/`ru_erudit`) — only the registry's
|
||||||
|
`Variant` key carries the rename, so `registry.go`, the published `scrabble-solver` fixtures and the
|
||||||
|
dictionary release artifact are untouched (decouples the three repos).
|
||||||
|
- **Migrations squashed** 12 → one hand-written `00001_baseline.sql`. Verified by a
|
||||||
|
`pg_dump --schema-only` diff (the chain vs the baseline are **identical** but for the two intended
|
||||||
|
variant-CHECK values) plus the green integration suite. **No data migration** (no production data).
|
||||||
|
- **Done (cross-repo + contour):** the **`scrabble-dictionary` tidy** merged (PR #2) and was re-cut as
|
||||||
|
the **byte-identical `v1.0.1`** release for clean provenance (the backend stays on `v1.0.0` — same
|
||||||
|
bytes, no rewire; the backend pulls a version-pinned release artifact, not master). Post-merge the
|
||||||
|
contour `backend` schema was wiped (`DROP SCHEMA backend CASCADE` + restart, not a volume drop) and
|
||||||
|
re-migrated to the baseline — verified the new variant CHECK (`scrabble_en/scrabble_ru/erudit_ru`),
|
||||||
|
`games`=0 and a clean boot.
|
||||||
|
|
||||||
|
- **R2** (interview + implementation):
|
||||||
|
- **Locked decisions:** game assembly via **invitations** (real path, no robots; not direct game-row
|
||||||
|
inserts); **moderate** ramp **50 → 200 → 500** at 10 min/step; **diagnostic** pass bar (no SLO gate);
|
||||||
|
run as a **one-shot container on `scrabble-internal`** in this PR.
|
||||||
|
- **Harness** = new `scrabble/loadtest` module (`use ./loadtest` + a `replace scrabble/gateway` for the
|
||||||
|
dot-free edge-proto import). It seeds 1000 guest + 10000 durable accounts + sessions **directly in
|
||||||
|
Postgres** (token hash mirrors `backend/internal/session`), drives players over the **edge protocol**,
|
||||||
|
generates **mid-ranked legal moves locally** with the embedded `scrabble-solver` by replaying
|
||||||
|
`game.history` (the edge carries no board — mirrors `engine.ReplayBoard` via the public API), and a
|
||||||
|
**gateway-hammer**. Compact CLI (`run` / `cleanup`), distroless Dockerfile (DAWGs baked), Go unit tests.
|
||||||
|
- **Adding the module broke the other images' builds** — backend/gateway/telegram Dockerfiles reduce the
|
||||||
|
workspace but still referenced `./loadtest` (not in their context); each now also
|
||||||
|
`-dropuse=./loadtest` (backend/telegram additionally `-dropreplace` the gateway replace). Caught by the
|
||||||
|
first deploy run; verified by building all four images.
|
||||||
|
- **Harness payload fixes found by the smoke pass:** the draft DTO's `rack_order` is a string (was sent
|
||||||
|
as `[]` → `bad_request`); the display-name validator forbids digits/colons, so the cleanup marker
|
||||||
|
became a letters-only `Zzloadtest` so `profile.update` resends the seeded name. `chat_not_your_turn` /
|
||||||
|
`nudge_own_turn` are **by-design** turn gates, correctly exercised.
|
||||||
|
- **Observability:** added **cAdvisor + postgres_exporter** + the **Scrabble — Resources** dashboard +
|
||||||
|
two Prometheus jobs. **Finding:** cAdvisor yields only the root cgroup on the contour host (separate
|
||||||
|
XFS `/var/lib/docker` breaks its layer-ID resolution — the existing galaxy deploy has the same limit),
|
||||||
|
so per-container CPU/RSS for the early pass was captured via `docker stats`. **R7:** adopt the otelcol
|
||||||
|
`docker_stats` receiver (already the contrib image) for per-container metrics in Grafana.
|
||||||
|
- **Early run (2026-06-09):** ramped clean to 500 players, no crash/deadlock, cleanup removed all 11000
|
||||||
|
accounts. 1.2 M edge calls, 48 870 plays, 2 798 games finished; the per-user limiter held under the
|
||||||
|
hammer (99.97 % rejected, p99 2 ms). **Top finding:** ~14 % `transport_error` on `game.state` at 500
|
||||||
|
players, under CPU saturation (backend/gateway/Postgres each ~1 core) and amplified by the harness's
|
||||||
|
single shared `http2.Transport`; the harness itself peaked at 86 % of a core on the same host, so the
|
||||||
|
figures are pessimistic. Full trip report in [`../loadtest/REPORT.md`](../loadtest/REPORT.md);
|
||||||
|
it feeds R3 (h2c `MaxConcurrentStreams`/timeouts, body-size cap), R6 and R7 (per-player transports,
|
||||||
|
separate hardware, pool/limit sizing).
|
||||||
|
- **CI:** `./loadtest/...` added to the path filter + vet/build/test; `go.work.sum` carries the new deps.
|
||||||
|
|
||||||
|
- **R3** (interview + implementation):
|
||||||
|
- **Locked decisions:** the flag column lands by **editing the R1 baseline** (+ a contour schema
|
||||||
|
wipe after merge — no migration chain accrues before prod); auto-flag defaults **1000 rejected /
|
||||||
|
10 min** (`BACKEND_HIGHRATE_FLAG_THRESHOLD`/`_WINDOW`, rolling window, set-once, operator clears,
|
||||||
|
no auto-ban); landing image = **caddy:2-alpine**; throttle data flows **gateway → backend** (a
|
||||||
|
30 s per-key summary POST to the new `/api/v1/internal/ratelimit/report`, the existing trusted
|
||||||
|
direction) with the episode window + flag rule in the backend (`internal/ratewatch`); rejection
|
||||||
|
logging = **Warn summary per key per window + Debug per rejection** — a deliberate deviation from
|
||||||
|
the phase's "structured log per rejection" (the R2 hammer would have logged ~522k lines in
|
||||||
|
minutes); all three R2-report tails included (explicit h2c sizing, the session-resolve failure
|
||||||
|
cause at Warn, reviving the admin limiter).
|
||||||
|
- **Body cap:** `GATEWAY_MAX_BODY_BYTES` (default 1 MiB) as both the Connect per-message read limit
|
||||||
|
and an `http.MaxBytesReader` wrap of the public mux; an oversized Execute is `resource_exhausted`.
|
||||||
|
- **Dead config found:** `AdminPerMinute`/`AdminBurst` were never wired — the gateway `/_gm` mount is
|
||||||
|
now 429-guarded per IP ahead of its Basic-Auth. The caddy-fronted contour path stays unlimited
|
||||||
|
(stock caddy has no limiter) — an accepted gap, recorded in `docs/ARCHITECTURE.md` §12.
|
||||||
|
- **Landing split:** a `landing` target in `gateway/Dockerfile` (the UI build stage is shared;
|
||||||
|
identical compose build args keep it one cached build); the gateway drops `landing.html` from the
|
||||||
|
embed and 308-redirects `/` → `/app/`; the contour caddy routes `/app/`, `/telegram/` and the
|
||||||
|
Connect path to the gateway and the catch-all to the landing container; the CI deploy probe now
|
||||||
|
checks both `/` (landing) and `/app/` (gateway).
|
||||||
|
- **Observability:** `gateway_rate_limited_total{class}` (user/public/email/admin, aggregate-only)
|
||||||
|
+ a rate-vs-rejections panel on the Edge/UX dashboard; the admin console gains the **Throttled**
|
||||||
|
page (the in-memory episode window, reset-on-restart like `active_users`, plus the flagged-account
|
||||||
|
queue) and the flag badge / clear action on the user list / card.
|
||||||
|
- The jet regen also restored the previously missing `game_drafts`/`game_hidden` generated models
|
||||||
|
(their tables were added after the last jetgen run; no behaviour change).
|
||||||
|
|
||||||
|
- **R4** (interview + implementation):
|
||||||
|
- **Locked decisions:** **delta-first**, not full snapshots — an event carries only the new move and
|
||||||
|
the UI applies it to its per-game cache, keyed on `move_count` (idempotent + gap-safe: a gap or the
|
||||||
|
actor's own move falls back to a `game.state` + `game.history` refetch). `match_found` /
|
||||||
|
`game_started` carry the recipient's **initial `StateView`** (instant lobby→game); the fallback
|
||||||
|
refetch stays the existing two calls (no merged endpoint); the matchmaking poll runs **only while
|
||||||
|
the stream is down** (2.5 s); **all** UI-state-changing events carry their payload (incl. lobby `notify`).
|
||||||
|
- **Enriched events** (`pkg/fbs` trailing fields — backward-compatible, no FB regen of *values*, only
|
||||||
|
the schema): `opponent_moved` (+`move`/`game`/`bag_len`), `your_turn` (+`move_count`), `match_found`
|
||||||
|
(+`state`), `game_over` (+`game`), `notify` (+`account`/`invitation`/`state`). The pre-R4
|
||||||
|
`opponent_moved` scalars (`seat`/`action`/`score`/`total`) stay for wire back-compat, now redundant
|
||||||
|
with `move`/`game` — slated for the R6 de-stage.
|
||||||
|
- **Encoding placement:** the `notify` package keeps ownership of the FlatBuffers encoding (a new
|
||||||
|
`encode.go` mirrors the gateway transcode but reads wire-agnostic `notify.*` input structs +
|
||||||
|
`engine.MoveRecord`); the game/lobby/social services map their domain types to those structs, so the
|
||||||
|
wire schema stays out of the domain. **Flagged for R6:** this partly duplicates the gateway encoders
|
||||||
|
(different source types) — a candidate consolidation.
|
||||||
|
- **Actor self-fetch killed too** (beyond literal "push"): the `submit_play`/`pass`/`exchange`/`resign`
|
||||||
|
**response** (`MoveResult`) now returns the actor's refilled rack + bag size, so the mover renders the
|
||||||
|
next turn from the response — `Game.svelte`'s `commit`/`pass`/`exchange`/`resign` drop their `await load()`.
|
||||||
|
- **`match_found` enrichment** needs a per-seat initial state: `lobby.GameCreator` gained `InitialState`,
|
||||||
|
and `game.Service.InitialState` builds the `notify.PlayerState` (rack re-encoded to wire indices, the
|
||||||
|
variant alphabet embedded for a first-seen variant).
|
||||||
|
- **UI:** a pure `lib/gamedelta.ts` reducer (`applyMoveDelta` / `applyGameOver` / `seedInitialState`,
|
||||||
|
unit-tested) advances the cache; `app.svelte` seeds it on `match_found` / `game_started`; `Game.svelte`
|
||||||
|
applies the delta (falling back to `load()` while composing, on a gap, or on its own move's new rack);
|
||||||
|
`NewGame.svelte` polls only when `app.streamAlive` is false and guards its teardown so a push-delivered
|
||||||
|
match is not cancelled.
|
||||||
|
- **notify (friends/invitations) scope:** the backend carries the full account / invitation payload on the
|
||||||
|
wire (per "all events → push"); the UI seeds the game cache from `game_started` but keeps its lightweight
|
||||||
|
**authoritative** badge refresh (`refreshNotifications`, on the rare `notify` event + on foreground) rather
|
||||||
|
than adding client-side friend/invitation caches — the per-move hot path is fully de-fetched, which was the
|
||||||
|
goal. Deeper lobby-cache consumption is an easy follow-up.
|
||||||
|
- **No schema change** (no migration); the contour needs no DB wipe. Tests: `notify` FB round-trips +
|
||||||
|
`emitMove` delta + the `gamedelta` reducer; the e2e mock now emits the enriched delta.
|
||||||
|
|
||||||
|
- **R5** (interview + implementation):
|
||||||
|
- **No code slimming — by analysis.** A gzip measure + sourcemap attribution of the real `dist` showed
|
||||||
|
the app bundle is already minified + tree-shaken and dominated by the Connect/FlatBuffers transport
|
||||||
|
runtime + generated FB/PB bindings (≈⅔ of `main`'s source) and the Svelte runtime — all
|
||||||
|
third-party/generated, irreducible within R5's scope. App-authored code carries no hand-trimmable fat.
|
||||||
|
- **Lazy-load rejected** (screens *and* i18n): `bundle-size.mjs` sums every emitted chunk, so
|
||||||
|
code-splitting moves bytes between chunks for **zero total-size win** while adding request latency (+N
|
||||||
|
gateway fetches on first navigation to a split screen). i18n lazy-load additionally buys ≤3 KB (en-only
|
||||||
|
users) at the cost of an async `t()`, and `en` must stay bundled (it is the `MessageKey` type source +
|
||||||
|
fallback). **Chunk-collapsing rejected** too — keeping the near-static Svelte runtime in its own
|
||||||
|
cacheable chunk is the recommended practice (an app deploy then re-busts only `main`, not the runtime),
|
||||||
|
and HTTP/2 makes the extra preload request negligible.
|
||||||
|
- **Metric retargeted to the app.** The two-entry build (`index.html` app + `landing.html`) makes Rollup
|
||||||
|
hoist the code shared by both (Svelte runtime + i18n + `aboutContent`) into one preloaded chunk, so the
|
||||||
|
app actually loads its entry chunk **+ the shared chunk** (≈74 + ≈23 = **≈97 KB**), never `landing.js`
|
||||||
|
(≈1.6 KB). The old script summed all three chunks (98.8 KB), over-counting the app by `landing.js`.
|
||||||
|
`bundle-size.mjs` now parses each built HTML for the JS it eagerly loads and gates three parts
|
||||||
|
independently — **app entry ≤ 100 KB, shared (Svelte+i18n) ≤ 30 KB, landing-own ≤ 5 KB** — reporting the
|
||||||
|
app total (≈97) and landing total (≈24.5). Same CLI + exit-code contract, so the CI step is unchanged.
|
||||||
|
- **No app/source/build change** (`App.svelte`, `lib/i18n/`, `vite.config.ts` untouched); no schema
|
||||||
|
change, no contour wipe. The stale "~82 KB" figure was corrected in `bundle-size.mjs` and `ui/README.md`.
|
||||||
|
|
||||||
|
- **R6** (interview + implementation):
|
||||||
|
- **Locked decisions:** apply **both** wire/code structural changes (**B** + **A**) and **only C1+C2** of
|
||||||
|
the test consolidation (not C3/C5); strip the `*(Stage N)*` tags from **all current-state docs**
|
||||||
|
(ARCHITECTURE / FUNCTIONAL+`_ru` / TESTING / UI_DESIGN), keeping PLAN.md / PRERELEASE.md / CLAUDE.md as
|
||||||
|
history; **split `stage6_test.go`** by domain. The `h2cMaxConcurrentStreams` sizing stays an **R7**
|
||||||
|
concern (tuning, not behaviour-preserving); the R2 early run forced no code fix, so nothing was carried in.
|
||||||
|
- **(a) De-staging:** removed the `Stage N` / `TODO-N` / `(RN)` references across code, comments, service
|
||||||
|
READMEs and the current-state docs, rewording narratives to present tense (no technical content lost).
|
||||||
|
Renamed the only stage-named identifiers (`registerStage8`→`registerSocialOps`,
|
||||||
|
`registerStage11`→`registerLinkOps`) and split `stage6_test.go` (`TestEmailLoginFlow`→`email_test.go`;
|
||||||
|
`TestGuestAutoMatchLeavesNoStats`+`provisionGuest`→`account_test.go`). De-staged the `.fbs`/`.proto`
|
||||||
|
comments and regenerated: only the `.proto`-derived Go docstrings (`*_grpc.pb.go`, `push.pb.go`) changed —
|
||||||
|
flatc strips schema comments, so the FB Go/TS bindings were untouched.
|
||||||
|
- **(b) Reconciliation:** the docs were accurate (each R-phase baked its own); the one drift was a stale
|
||||||
|
"guest-reaping deferred (TODO-3)" note in `ARCHITECTURE.md` §3 — guest reaping is implemented, so the
|
||||||
|
note was replaced with the current behaviour (FUNCTIONAL/TESTING already described it).
|
||||||
|
- **(c) B — dead `opponent_moved` scalars:** removed `seat/action/score/total` from `OpponentMovedEvent`
|
||||||
|
(`pkg/fbs/scrabble.fbs` + the `notify` emit + the round-trip test); regenerated FB Go + TS. No reader
|
||||||
|
used them (the UI codec/mock take `move`/`game`/`bag_len`; the gateway forwards the payload verbatim).
|
||||||
|
A pre-release wire-slot renumber — free with no prod data, no DB change.
|
||||||
|
- **(c) A — shared FB builders:** new `scrabble/pkg/wire` holds the single definition of the nested wire
|
||||||
|
tables (GameView / MoveRecord / StateView / AccountRef / Invitation) shared by the backend `notify`
|
||||||
|
encoder and the gateway `transcode`; both map their own source types to neutral `wire.*` structs and
|
||||||
|
delegate. **Honest tradeoff:** the verbose `Start/Add/End` + reverse-prepend boilerplate is now written
|
||||||
|
once, but the field *set* is still mapped per side, and the new package makes the change net **+~145 LOC**
|
||||||
|
— a single-source / anti-drift win for the fiddly mechanics rather than a line-count cut. Behaviour-
|
||||||
|
preserving: the two sides' field sets were verified identical and the round-trip tests pass unchanged.
|
||||||
|
- **(c) C1+C2 — inttest fixtures:** moved the cross-file service/game fixtures (`newGameService` was used by
|
||||||
|
10 files) into `backend/internal/inttest/helpers.go`; single-file helpers stay local. Pure relocation.
|
||||||
|
- **No schema change → no contour DB wipe.** Regression gate: the full unit + integration + UI suites plus
|
||||||
|
the R7 stress run.
|
||||||
|
|
||||||
|
- **R7** (interview + implementation):
|
||||||
|
- **Locked decisions:** run the harness **same-host** (one-shot container on `scrabble-internal`, capped
|
||||||
|
`--cpus=3` so the contour keeps spare cores); **apply container limits + `GOMAXPROCS` now** (not just a
|
||||||
|
prod recommendation); **replace cAdvisor with the otelcol `docker_stats` receiver** (it resolved only the
|
||||||
|
root cgroup on this host); keep rate-limit / h2c knobs **compiled-in** (change values only if the data
|
||||||
|
demands — it did not).
|
||||||
|
- **Harness refinements (pre-run):** each virtual player builds its **own `edge.Client`** (its own h2c
|
||||||
|
connection for its Subscribe stream + Execute calls) instead of all players sharing one `http2.Transport` —
|
||||||
|
the R2 `transport_error` artifact; and `playTurn` now reports a **finished** game so the player drops it
|
||||||
|
from rotation. Effect, measured: `game.state` `transport_error` 14 % (R2) → **2.49 %**; `game_finished` on
|
||||||
|
chat ≈ 3 900 → **35**.
|
||||||
|
- **Observability:** added the `docker_stats` receiver to `otelcol` (`api_version: "1.44"` — the daemon's
|
||||||
|
minimum is 1.40; the receiver defaults to 1.25 and crash-looped until pinned), mounted the docker socket
|
||||||
|
read-only with `group_add` (the contrib image runs as UID 10001), dropped the cAdvisor service + its
|
||||||
|
Prometheus job, and retargeted the **Scrabble — Resources** dashboard to the docker_stats metric names
|
||||||
|
(`container_cpu_utilization`/100 == cores). Cross-checked against `docker stats` within sampling error.
|
||||||
|
- **Profile (final run, 500 players, limits in force):** the **gateway is the binding constraint** — with
|
||||||
|
one connection per player it bursts into its 2-core cap (the residual 2.49 % `transport_error`); backend
|
||||||
|
~0.85 core and postgres ~1.4 cores had headroom; **tempo reached its 1 GiB cap**; the backend pool sat at
|
||||||
|
its `MaxOpenConns=25` cap (28 backends); docker logs were unbounded (~14 MiB / 30 min on the backend at
|
||||||
|
info). Full write-up in [`../loadtest/REPORT.md`](../loadtest/REPORT.md). *(Superseded in part: a
|
||||||
|
later pass modelling the `game.evaluate` hot path traced the gateway's CPU appetite to
|
||||||
|
**gateway→backend connection churn** — the default 2-idle-connection HTTP transport — not proxying
|
||||||
|
work. Pooling the connections cut peak gateway CPU ~7× (~1.75 → ~0.26 cores at 500 players) and
|
||||||
|
removed the ephemeral-port-exhaustion cliff behind the residual `transport_error`, so the gateway is
|
||||||
|
no longer the binding constraint — postgres is. The 3-core gateway cap below is now generous headroom.)*
|
||||||
|
- **Round-2 tuning (owner-agreed, all in `deploy/docker-compose.yml`, no code change):** gateway **2 → 3
|
||||||
|
cores + `GOMAXPROCS=3`**; tempo memory **1 → 2 GiB**; backend `MAX_OPEN_CONNS` **25 → 40**; a json-file
|
||||||
|
**log-rotation** default (10m × 3) applied contour-wide via a YAML anchor (level stays info).
|
||||||
|
backend/postgres kept at 2 cores / 512 MiB (headroom is cheap on the shared host).
|
||||||
|
- **Validation:** the same gradual ramp on the tuned contour cut `game.state` `transport_error` to **0.72 %**
|
||||||
|
(gateway ~2 cores, now under the 3-core cap, no throttle; tempo ~1.27 GiB, under 2 GiB). A separate
|
||||||
|
**burst** run (a single 100 → 500 jump) pegged the gateway at 3 cores (≈296 % sustained, 9.27 % error),
|
||||||
|
confirming it is **connection-CPU-bound** — a true arrival spike is a **horizontal-scaling** lever, not
|
||||||
|
more cores per node (recorded in the prod-sizing recommendation).
|
||||||
|
- **No schema change → no contour DB wipe.** Bake-back: `loadtest/REPORT.md`, `loadtest/README.md`,
|
||||||
|
`docs/TESTING.md`, the telemetry/observability section of `docs/ARCHITECTURE.md`, the repo-layout line in `CLAUDE.md`.
|
||||||
|
|
||||||
|
- **UI — Tab-bar navigation redesign** (owner ad-hoc, not on the raw TODO list): drop the hamburger
|
||||||
|
`Menu.svelte` everywhere (it fought the Telegram-fullscreen layout, where it had to be re-centred).
|
||||||
|
- **Locked decisions (interview):** the in-Settings sub-nav is a **bottom TabBar with the active tab
|
||||||
|
highlighted** (icon-only); **Export GCG** moves to the left slot of the move-history header (free in a
|
||||||
|
finished game, where 🏁 *leave* does not apply); the lobby **⚙️ badge counts incoming friend requests
|
||||||
|
only** (invitations keep their own lobby section); unread chat is badged on **the score bar and the 💬**.
|
||||||
|
- **What shipped:** a ⚙️ **Settings hub** (`screens/SettingsHub.svelte`) over the existing
|
||||||
|
Settings/Profile/Friends/About bodies and an in-game **comms hub** (`game/CommsHub.svelte`) over
|
||||||
|
chat + dictionary, both with in-place tabs and a fixed back target; the game's menu items relocate into
|
||||||
|
the open move history (🏁 leave / 📤 export + 💬 comms header) and the player cards (🤝 add-friend); a
|
||||||
|
shared **TapConfirm** (`components/TapConfirm.svelte`, `lib/tapconfirm.ts`) — tap → fading ✅ → tap —
|
||||||
|
replaces the Skip/Hint press-and-hold popovers and drives the add-friend confirm. Fixed the move-history
|
||||||
|
"jump" bug (the slid board is now inert and the stage can't scroll, so a swipe up genuinely closes it).
|
||||||
|
`Menu.svelte` + `HoldConfirm.svelte` removed.
|
||||||
|
- **No schema/wire change → no contour DB wipe.** Bake-back: `docs/UI_DESIGN.md`, `docs/FUNCTIONAL.md`
|
||||||
|
(+`_ru`). Regression gate: UI `check` + unit (`tapconfirm`) + build + bundle budget + e2e (Chromium &
|
||||||
|
WebKit), all green.
|
||||||
|
|
||||||
|
- **UI — Merge Exchange/Pass; drop the dead Tournaments tab** (owner ad-hoc, not on the raw TODO
|
||||||
|
list): the lobby's 🏆 *Tournaments* tab was an inert `lobby.soon` toast — removed (the lobby is back
|
||||||
|
to three tabs, matching `docs/FUNCTIONAL.md`). In-game the separate 🥺 *Skip* (pass) tab folds into
|
||||||
|
the 🔄 tab, now **Exchange/Pass**, whose dialog passes when no tile is selected and exchanges when
|
||||||
|
tiles are.
|
||||||
|
- **Decision — a pass is NOT an exchange of zero (verified against the rules + GCG):** the merge is
|
||||||
|
**UI-only**. Pass and exchange stay distinct game actions end-to-end — wire (`GameActionRequest` vs
|
||||||
|
`ExchangeRequest`), engine (`ActionPass` vs `ActionExchange`), and the GCG Poslfit dialect (a pass is
|
||||||
|
a bare `-`, an exchange is `-TILES`). The engine forbids a zero-tile exchange (`ErrNothingToExchange`)
|
||||||
|
and allows an exchange only with a full rack left in the bag (`ErrNotEnoughTilesToExchange`), while a
|
||||||
|
pass is always legal — collapsing them would lose a real distinction. The dialog dispatches the
|
||||||
|
existing `gateway.pass` / `gateway.exchange`.
|
||||||
|
- **What shipped:** `Lobby.svelte` (tab removed); `Game.svelte` (one 🔄 Exchange/Pass tab no longer
|
||||||
|
gated on an empty bag; the dialog disables tile selection while the bag is below a full rack
|
||||||
|
(`bagLen >= RACK_SIZE`), its confirm button reading **Pass without exchanging** / **Exchange N**);
|
||||||
|
i18n (`game.draw` → Exchange/Pass, new `game.passNoExchange`, dropped `game.skip` /
|
||||||
|
`lobby.tournaments` / `lobby.soon`). No backend/wire/history/GCG change.
|
||||||
|
- **No schema/wire change → no contour DB wipe.** Bake-back: `docs/UI_DESIGN.md`, `docs/FUNCTIONAL.md`
|
||||||
|
(+`_ru`). Regression gate: UI `check` + unit + build + bundle budget + e2e (Chromium & WebKit).
|
||||||
|
|
||||||
|
- **AI — Honest AI opponent in quick game** (owner ad-hoc, not on the raw TODO list): a second quick-game
|
||||||
|
opponent the player *knowingly* chooses, distinct from the disguised robot of the random/open path
|
||||||
|
(which is kept as-is). New Game's quick-game mode replaces the "auto-match" subtitle with a two-button
|
||||||
|
selector **🤖 AI / 👤 Random player** (the `.seg`/`.opt` segmented style, AI the default); for AI the
|
||||||
|
move-clock line reads "Loss after 7 days of inactivity" and the "searching" hint is hidden.
|
||||||
|
- **Locked decisions (interview):** AI move is **event-driven** (the robot replies the instant the
|
||||||
|
player's move commits; the 30 s driver is the fallback); AI games **do not touch `account_stats`**
|
||||||
|
(practice, like guests); the **Stage 5 strength logic is reused unchanged** (`playToWin` 40 % from the
|
||||||
|
seed + margin band); **no per-move timeout — a 7-day inactivity loss** instead; the 7-day line lives on
|
||||||
|
the New Game screen (the in-game screen has no move-clock line); chat + nudge **disabled**, word-check
|
||||||
|
kept, add-friend never drawn, opponent shown as **🤖** everywhere.
|
||||||
|
- **The 7-day rule reuses the existing per-turn timeout:** an AI game is created with
|
||||||
|
`turn_timeout_secs = AIInactivityTimeout` (7 days) and the existing timeout sweeper resigns the overdue
|
||||||
|
seat — since the robot moves at once, only the human is ever on the clock, so the per-turn timeout *is*
|
||||||
|
the abandon rule (no new column, no new sweeper).
|
||||||
|
- **One game flag drives everything:** `games.vs_ai` (edited into the R1 baseline — pre-release, so a
|
||||||
|
contour DB wipe after merge). It is set **only** on AI-started games, so a robot-filled random game keeps
|
||||||
|
`vs_ai=false` and the disguised opponent is never revealed; the UI derives 🤖 / the gates **from the flag,
|
||||||
|
never from the opponent account**. New backend path `Matchmaker.StartVsAI` (picks a pooled robot via the
|
||||||
|
existing `Pick`, creates an **active** seated game via `game.Service.Create`, random seat order) — the AI
|
||||||
|
request never enters the open pool, so the open-game reaper never touches it. The robot driver gains a
|
||||||
|
`vs_ai` branch (no sleep, no proactive nudge, zero delay) and a focused `DriveGame`/`TriggerMove` fast
|
||||||
|
path wired from the game service's after-create/after-commit hook (`SetAITrigger`, a func value so the
|
||||||
|
game package never imports the robot package). Chat/nudge gated by a new `social` `VsAI` check
|
||||||
|
(`ErrGameVsAI` → 409 `ai_game`); statistics skipped in `commit` when `vs_ai`.
|
||||||
|
- **Wire:** `EnqueueRequest` += `vs_ai`, `GameView` += `vs_ai` (trailing FB fields, regenerated Go + TS),
|
||||||
|
threaded through the backend DTO, the gateway transcode and the `pkg/wire` + `notify` builders.
|
||||||
|
- **Tests:** `lobby` unit (StartVsAI seats a robot + flags the game; empty pool leaves no game); backend
|
||||||
|
integration (`ai_game_test.go`: active+seated+vs_ai+7-day clock, robot moves immediately, stats skipped,
|
||||||
|
7-day timeout resigns the human, chat/nudge rejected); UI codec round-trip (`vs_ai` on enqueue + game
|
||||||
|
view); e2e (an AI game shows 🤖, no "searching", chat disabled, the dictionary still works) + the
|
||||||
|
existing quick-match e2e updated to pick **Random player** (the default is now AI).
|
||||||
|
- **Schema/wire change → a contour DB wipe** after merge (`DROP SCHEMA backend CASCADE` + restart, the
|
||||||
|
R1/R3 pattern). Bake-back: `docs/ARCHITECTURE.md`, `docs/FUNCTIONAL.md` (+`_ru`), `docs/UI_DESIGN.md`,
|
||||||
|
`backend/README.md`, Go Doc comments.
|
||||||
|
- **Post-review refinements (owner, same PR):** (1) the **GCG export labels the robot seat "AI"** rather
|
||||||
|
than its human-like pool name (`ExportGCG` overrides the name via `accounts.IsRobot`; the in-app 🤖 is
|
||||||
|
unchanged); (2) honest-AI games **emit no `your_turn`** — the robot replies instantly, so the signal
|
||||||
|
would arrive with the move and be pointless; `opponent_moved` still advances the UI; (3) the **admin
|
||||||
|
console surfaces the AI flag** — a **🤖 column** in `/games` and an "AI game" line on the game card
|
||||||
|
(`GameRow`/`GameDetailView` gain `VsAI`); (4) `games_started_total` / `games_abandoned_total` gain a
|
||||||
|
**`vs_ai`** attribute and the Grafana *Game domain* dashboard splits started/abandoned into **human**
|
||||||
|
and **AI** panels.
|
||||||
|
- **Follow-up (separate PR — strategy deviation):** the robot now plays **≈20%** of opening/midgame moves
|
||||||
|
*against* its per-game `playToWin` intent (toward the opposite margin band — a winning robot eases off, a
|
||||||
|
losing one surges ahead), tapering linearly to **0 over the last 14 bag tiles** and **0 once the bag is
|
||||||
|
empty**, so the endgame follows the chosen strategy strictly while earlier outcomes can swing the human's
|
||||||
|
way. Deterministic from the seed (`mix(seed,"deviate",moveCount)`), applied to **both** robot paths via
|
||||||
|
the shared `selectMove`; the per-game intent (and the admin card) is unchanged. Tests: `robot` unit
|
||||||
|
(taper bounds + monotonicity, never-in-endgame, determinism, ~20% distribution). Bake-back:
|
||||||
|
`docs/ARCHITECTURE.md` §7, `docs/FUNCTIONAL.md` (+`_ru`), `backend/README.md`, `PLAN.md` Stage 5.
|
||||||
|
|
||||||
|
- **GL — Simultaneous quick-game cap** (owner ad-hoc, not on the raw TODO list): a player may hold at
|
||||||
|
most **10** active quick games; at the cap the lobby greys **New Game** and shows a plain notice
|
||||||
|
"Вы достигли лимита одновременных партий", both clearing automatically when an active game finishes.
|
||||||
|
- **Locked decisions (interview):** what counts = active **+** open (searching) quick games, **including
|
||||||
|
AI** (`vs_ai`); friend games (invitation-linked) **never** count. The backend gate refuses **all** new-game
|
||||||
|
creation at the cap — `lobby/enqueue` **and** `invitations` — with **409 `game_limit_reached`**; **accepting**
|
||||||
|
an invitation is never gated, so friend games are capped "from the other end". Delivery = a boolean
|
||||||
|
**`at_game_limit`** on the existing `games.list` (no per-event payload: a turn change does not move the count,
|
||||||
|
and the lobby already re-fetches `games.list` on entry + every game event); the first uncached lobby frame
|
||||||
|
defaults the button **enabled** (the backend gate is the authority).
|
||||||
|
- **What shipped:** `game.MaxActiveQuickGames` + `Store/Service.CountActiveQuickGames` (active/open seats, no
|
||||||
|
`game_invitations` row; hidden games still count → a dedicated count, not a filter over the lobby list);
|
||||||
|
`Server.atGameLimit`/`ensureUnderGameLimit` gating `handleEnqueue` + `handleCreateInvitation`;
|
||||||
|
`gameListDTO.at_game_limit`; the FB `GameList` trailing `at_game_limit` (regenerated Go + TS) threaded through
|
||||||
|
the gateway transcode + UI codec; `lib/model` + `lobbycache` snapshot + `Lobby.svelte` (disabled tab + a muted
|
||||||
|
`.limit` notice); i18n `lobby.limitReached` (en authoritative + ru).
|
||||||
|
- **Caveat (logged):** the gate is a pre-check, not transaction-atomic — concurrent creates from one account could
|
||||||
|
momentarily exceed by 1–2 (harmless soft cap; the UI disables the button regardless). Strict atomicity was judged
|
||||||
|
a disproportionate diff across the two create paths.
|
||||||
|
- **No schema change → no contour DB wipe** (only a trailing FB field, no migration). Tests: backend integration
|
||||||
|
(`game_limit_test.go`: count rule + HTTP gate 409 + accept bypass), server unit (error mapping), gateway
|
||||||
|
transcode round-trip, UI codec + lobbycache unit, e2e (`gamelimit.spec.ts`). Bake-back: `docs/FUNCTIONAL.md`
|
||||||
|
(+`_ru`), `docs/ARCHITECTURE.md` §8, `docs/UI_DESIGN.md`, `backend/README.md`.
|
||||||
|
|
||||||
|
- **CM — Channel-chat moderation + promo bot** (owner ad-hoc, not on the raw TODO list):
|
||||||
|
- **Locked decisions (interview):** the promo bot is a **goroutine in `cmd/bot`** (its own token, no
|
||||||
|
bot-link); the moderated chat's default-no-send is configured by a **human** in the group settings (the
|
||||||
|
bot only grants, never `setChatPermissions`); a non-eligible joiner is **left muted silently**; a
|
||||||
|
temporary-suspension expiry is handled by a **backend sweeper** that emits the re-evaluate event; and a new
|
||||||
|
**`chat_muted` role** is a chat-only mute with the **game suspension dominating**
|
||||||
|
(`eligible = registered AND NOT suspended AND NOT chat_muted`).
|
||||||
|
- **Bot API reality (verified against the docs):** a cross-bot Mini App launch must be a **URL button** to the
|
||||||
|
main bot's `t.me/<bot>?startapp` link — a `web_app` button signs initData with the *sending* bot's token,
|
||||||
|
which the main validator rejects — so the promo button reuses the UI's `VITE_TELEGRAM_LINK`. `chat_member`
|
||||||
|
updates arrive **only** when the bot is a chat **admin** with the "Ban users" right (the client label for the
|
||||||
|
Bot API `can_restrict_members`) and `chat_member` is in `allowed_updates`; bots cannot list members but can
|
||||||
|
`getChatMember` a single user, which is the membership guard on the block/unblock path.
|
||||||
|
- **Wire:** `pkg/proto/botlink/v1` gains a `ChatGateCommand` in the `Command` oneof and a unary
|
||||||
|
`ResolveChatEligibility`; the backend gains `notify.KindChatAccessChanged` (no payload, infra-only — never an
|
||||||
|
out-of-app message) and an internal `POST /api/v1/internal/chat-access` resolver; the gateway resolves the
|
||||||
|
join (by external_id) and the event (by user_id) through it and pushes the chat-gate command fire-and-forget
|
||||||
|
(at-most-once, recovered by the next moderation action or a re-join).
|
||||||
|
- **No schema change → no contour DB wipe:** `chat_muted` is a new `account.KnownRoles` entry (the
|
||||||
|
`account_roles` table is data-driven). The suspension-expiry sweeper is a new `account.SuspensionSweeper`
|
||||||
|
(a 1-minute window, idempotent) started in `cmd/backend`, alongside the guest reaper.
|
||||||
|
- **Deploy:** new `TEST_`/`PROD_` `TELEGRAM_PROMO_BOT_TOKEN` (secret), `TELEGRAM_BOT_USERNAME` and
|
||||||
|
`TELEGRAM_CHAT_ID` (variables); the promo link reuses the existing `*_VITE_TELEGRAM_LINK` variable as
|
||||||
|
`TELEGRAM_BOT_LINK`. The bot must be promoted to admin in the real discussion group, and the group default
|
||||||
|
set to no-send, as part of the Stage 18 prod cutover (the test contour exercises the code path).
|
||||||
|
- **Bake-back:** `docs/ARCHITECTURE.md`, `docs/FUNCTIONAL.md` (+`_ru`), `platform/telegram/README.md`,
|
||||||
|
`backend/README.md`, Go Doc comments. Tests: backend resolver truth table + publish on block/unblock/role +
|
||||||
|
the sweeper window (unit + integration); gateway hub `ResolveChatEligibility` + the chat-gate command; bot
|
||||||
|
`chat_member` grant + `ApplyChatGate` getChatMember-guard; promo `/start` localization + URL button; config
|
||||||
|
parsing.
|
||||||
|
- **Post-contour-test fixes (same PR):** a live test drove three corrections. (1) **Strategy
|
||||||
|
inversion (the key one)** — the original "group default no-send, bot grants the eligible" cannot
|
||||||
|
work: Telegram intersects the chat default with each user's permission, so a per-user grant never
|
||||||
|
exceeds a deny-by-default group (the bot set `can_send=true` yet the user still could not write).
|
||||||
|
The group now **allows sending by default** and the bot only **restricts** — it mutes an ineligible
|
||||||
|
member (unregistered / admin-suspended / `chat_muted`) and un-mutes an eligible one it had muted,
|
||||||
|
acting only when the current state differs (idempotent; the bot's own change is skipped by matching
|
||||||
|
the actor id to the bot). A present member in a default-allow group can appear as `restricted` with
|
||||||
|
`is_member`, so the gate reads both. (2) **Join-before-register** — a user who joins before
|
||||||
|
registering is covered by no `chat_member` event, so `ProvisionTelegram` now reports first contact
|
||||||
|
and the Telegram auth handler emits `chat_access_changed` on it. (3) **Observability** — a startup
|
||||||
|
self-check logs whether the bot is an admin-with-restrict in the chat (it caught a misconfigured
|
||||||
|
`TELEGRAM_CHAT_ID` set to a channel id, not the discussion-group id); the per-event trace is at
|
||||||
|
Debug, the actual mute/unmute and warnings at Info.
|
||||||
@@ -22,8 +22,9 @@ supports English Scrabble, Russian Scrabble and Эрудит.
|
|||||||
security, cross-service contracts.
|
security, cross-service contracts.
|
||||||
- [`docs/FUNCTIONAL.md`](docs/FUNCTIONAL.md) (+ [`_ru`](docs/FUNCTIONAL_ru.md)) —
|
- [`docs/FUNCTIONAL.md`](docs/FUNCTIONAL.md) (+ [`_ru`](docs/FUNCTIONAL_ru.md)) —
|
||||||
per-domain user stories.
|
per-domain user stories.
|
||||||
- [`docs/TESTING.md`](docs/TESTING.md) — test layers and the CI gate.
|
- [`docs/TESTING.md`](docs/TESTING.md) — test layers and the per-stage CI gate.
|
||||||
- [`CLAUDE.md`](CLAUDE.md) — project guide and development workflow.
|
- [`PLAN.md`](PLAN.md) — the staged implementation plan and stage tracker.
|
||||||
|
- [`CLAUDE.md`](CLAUDE.md) — project guide and the mandatory per-stage workflow.
|
||||||
|
|
||||||
## Build & test
|
## Build & test
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ observability stack (OTel Collector → Prometheus + Tempo → Grafana) + a fron
|
|||||||
services build from multi-stage distroless `*/Dockerfile`.
|
services build from multi-stage distroless `*/Dockerfile`.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker build --build-arg DICT_VERSION=v1.3.0 -f backend/Dockerfile -t scrabble-backend . # DICT_VERSION required; pulls that DAWG release artifact
|
docker build -f backend/Dockerfile -t scrabble-backend . # pulls the DAWG release artifact
|
||||||
docker build -f gateway/Dockerfile -t scrabble-gateway . # node stage builds + embeds the UI
|
docker build -f gateway/Dockerfile -t scrabble-gateway . # node stage builds + embeds the UI
|
||||||
docker compose -f deploy/docker-compose.yml config # validate (needs the TEST_/PROD_ env)
|
docker compose -f deploy/docker-compose.yml config # validate (needs the TEST_/PROD_ env)
|
||||||
```
|
```
|
||||||
|
|||||||
+4
-6
@@ -7,14 +7,12 @@
|
|||||||
# (GOPRIVATE), so the build stage needs git and network.
|
# (GOPRIVATE), so the build stage needs git and network.
|
||||||
#
|
#
|
||||||
# Build from the repository root so go.work, go.work.sum, pkg/ and backend/ are all
|
# Build from the repository root so go.work, go.work.sum, pkg/ and backend/ are all
|
||||||
# in the Docker context. DICT_VERSION has no default — the caller supplies the
|
# in the Docker context:
|
||||||
# scrabble-dictionary release tag (compose/CI pass it; see deploy/README.md
|
# docker build -f backend/Dockerfile -t scrabble-backend .
|
||||||
# "Bumping the dictionary version"):
|
|
||||||
# docker build --build-arg DICT_VERSION=v1.3.0 -f backend/Dockerfile -t scrabble-backend .
|
|
||||||
|
|
||||||
# --- dictionary artifact -----------------------------------------------------
|
# --- dictionary artifact -----------------------------------------------------
|
||||||
FROM alpine:3.20 AS dawg
|
FROM alpine:3.20 AS dawg
|
||||||
ARG DICT_VERSION
|
ARG DICT_VERSION=v1.2.1
|
||||||
RUN apk add --no-cache curl tar
|
RUN apk add --no-cache curl tar
|
||||||
RUN mkdir -p /dawg \
|
RUN mkdir -p /dawg \
|
||||||
&& curl -fsSL -o /tmp/dawg.tar.gz \
|
&& curl -fsSL -o /tmp/dawg.tar.gz \
|
||||||
@@ -44,7 +42,7 @@ FROM gcr.io/distroless/static-debian12:nonroot
|
|||||||
# Re-declare the build arg in this stage so it labels the seed dictionary. One
|
# Re-declare the build arg in this stage so it labels the seed dictionary. One
|
||||||
# DICT_VERSION drives both the artifact the dawg stage downloads and the version
|
# DICT_VERSION drives both the artifact the dawg stage downloads and the version
|
||||||
# label the binary pins, so the resident version equals the release tag.
|
# label the binary pins, so the resident version equals the release tag.
|
||||||
ARG DICT_VERSION
|
ARG DICT_VERSION=v1.2.1
|
||||||
COPY --from=build /out/backend /usr/local/bin/backend
|
COPY --from=build /out/backend /usr/local/bin/backend
|
||||||
# Own the seed dictionary as the nonroot runtime user (UID 65532): a named volume
|
# Own the seed dictionary as the nonroot runtime user (UID 65532): a named volume
|
||||||
# mounted at /opt/dawg inherits this ownership on first use, so the admin console
|
# mounted at /opt/dawg inherits this ownership on first use, so the admin console
|
||||||
|
|||||||
+1
-1
@@ -228,7 +228,7 @@ internal/banview/ # gateway active-ban mirror: the console's Active IP bans p
|
|||||||
```sh
|
```sh
|
||||||
docker run -d --name scrabble-pg -e POSTGRES_PASSWORD=dev -p 5432:5432 postgres:17-alpine
|
docker run -d --name scrabble-pg -e POSTGRES_PASSWORD=dev -p 5432:5432 postgres:17-alpine
|
||||||
# DAWGs: extract the dictionary release artifact (or point at a local scrabble-solver/dawg):
|
# DAWGs: extract the dictionary release artifact (or point at a local scrabble-solver/dawg):
|
||||||
mkdir -p /tmp/dawg && curl -fsSL https://gitea.iliadenisov.ru/developer/scrabble-dictionary/releases/download/v1.3.0/scrabble-dawg-v1.3.0.tar.gz | tar xz -C /tmp/dawg
|
mkdir -p /tmp/dawg && curl -fsSL https://gitea.iliadenisov.ru/developer/scrabble-dictionary/releases/download/v1.2.1/scrabble-dawg-v1.2.1.tar.gz | tar xz -C /tmp/dawg
|
||||||
BACKEND_POSTGRES_DSN='postgres://postgres:dev@localhost:5432/postgres?search_path=backend&sslmode=disable' \
|
BACKEND_POSTGRES_DSN='postgres://postgres:dev@localhost:5432/postgres?search_path=backend&sslmode=disable' \
|
||||||
BACKEND_DICT_DIR=/tmp/dawg \
|
BACKEND_DICT_DIR=/tmp/dawg \
|
||||||
GOPRIVATE='gitea.iliadenisov.ru/*' \
|
GOPRIVATE='gitea.iliadenisov.ru/*' \
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
// loads the dictionaries into the engine registry, warms the session cache,
|
// loads the dictionaries into the engine registry, warms the session cache,
|
||||||
// constructs the game domain and starts its turn-timeout sweeper, constructs the
|
// constructs the game domain and starts its turn-timeout sweeper, constructs the
|
||||||
// lobby and social domains, then serves the HTTP listener with the infrastructure
|
// lobby and social domains, then serves the HTTP listener with the infrastructure
|
||||||
// probes and the /api/v1 route group, behind which the domains expose their HTTP
|
// probes and the /api/v1 route-group skeleton. Domain HTTP endpoints are added
|
||||||
// endpoints to the gateway.
|
// with the gateway in a later stage described in PLAN.md.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -207,11 +207,10 @@ type provisionSeed struct {
|
|||||||
|
|
||||||
// telegramSeed derives the create-time seed from Telegram launch fields: a
|
// telegramSeed derives the create-time seed from Telegram launch fields: a
|
||||||
// supported preferred language from languageCode (an ISO-639 code, possibly
|
// supported preferred language from languageCode (an ISO-639 code, possibly
|
||||||
// region-tagged like "ru-RU"), and a display name. The name precedence is the real
|
// region-tagged like "ru-RU"), and a display name sanitized from firstName or,
|
||||||
// name (firstName, sanitized to the editable format) → the @username taken verbatim
|
// failing that, username (sanitizeDisplayName strips disallowed characters to the
|
||||||
// (already a valid handle, only trimmed and length-capped, never character-stripped)
|
// editable format). When neither yields any letters, it falls back to a generated
|
||||||
// → a generated placeholder in the seeded language (placeholderDisplayName), reached
|
// placeholder in the seeded language (placeholderDisplayName).
|
||||||
// only when firstName has no usable letters and no username is set.
|
|
||||||
func telegramSeed(languageCode, username, firstName string) provisionSeed {
|
func telegramSeed(languageCode, username, firstName string) provisionSeed {
|
||||||
var seed provisionSeed
|
var seed provisionSeed
|
||||||
if lang, _, _ := strings.Cut(strings.ToLower(strings.TrimSpace(languageCode)), "-"); lang == "en" || lang == "ru" {
|
if lang, _, _ := strings.Cut(strings.ToLower(strings.TrimSpace(languageCode)), "-"); lang == "en" || lang == "ru" {
|
||||||
@@ -219,13 +218,7 @@ func telegramSeed(languageCode, username, firstName string) provisionSeed {
|
|||||||
}
|
}
|
||||||
name := sanitizeDisplayName(firstName)
|
name := sanitizeDisplayName(firstName)
|
||||||
if name == "" {
|
if name == "" {
|
||||||
// The real name yielded nothing usable: fall back to the @username verbatim
|
name = sanitizeDisplayName(username)
|
||||||
// (Telegram guarantees a valid handle), only trimmed and capped to the column
|
|
||||||
// width — never character-stripped like the real name.
|
|
||||||
name = strings.TrimSpace(username)
|
|
||||||
if r := []rune(name); len(r) > maxDisplayName {
|
|
||||||
name = strings.TrimRight(string(r[:maxDisplayName]), " ")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = placeholderDisplayName(seed.preferredLanguage)
|
name = placeholderDisplayName(seed.preferredLanguage)
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ import (
|
|||||||
|
|
||||||
// TestTelegramSeed covers the pure mapping from Telegram launch fields to the
|
// TestTelegramSeed covers the pure mapping from Telegram launch fields to the
|
||||||
// create-time account seed: supported-language detection (bare and region-tagged),
|
// create-time account seed: supported-language detection (bare and region-tagged),
|
||||||
// the real-name → @username (verbatim) → placeholder display-name precedence, and
|
// the first-name / username display-name precedence, and the sanitization that
|
||||||
// the sanitization of the real name (emoji, digits, punctuation stripped to the
|
// strips disallowed characters (emoji, digits, punctuation) to the editable format.
|
||||||
// editable format). The username, when used, is kept verbatim.
|
|
||||||
func TestTelegramSeed(t *testing.T) {
|
func TestTelegramSeed(t *testing.T) {
|
||||||
cases := map[string]struct {
|
cases := map[string]struct {
|
||||||
languageCode, username, firstName string
|
languageCode, username, firstName string
|
||||||
@@ -29,7 +28,6 @@ func TestTelegramSeed(t *testing.T) {
|
|||||||
"punct to space": {"en", "user", "John❤Doe", "en", "John Doe"},
|
"punct to space": {"en", "user", "John❤Doe", "en", "John Doe"},
|
||||||
"digits dropped": {"ru", "user", "Маша123", "ru", "Маша"},
|
"digits dropped": {"ru", "user", "Маша123", "ru", "Маша"},
|
||||||
"garbage to username": {"en", "good", "123!@#", "en", "good"},
|
"garbage to username": {"en", "good", "123!@#", "en", "good"},
|
||||||
"username verbatim": {"en", "co_ol99", "🎮🎮", "en", "co_ol99"},
|
|
||||||
}
|
}
|
||||||
for name, tc := range cases {
|
for name, tc := range cases {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
@@ -51,10 +49,10 @@ func TestTelegramSeedPlaceholder(t *testing.T) {
|
|||||||
languageCode, username, firstName string
|
languageCode, username, firstName string
|
||||||
wantRe string
|
wantRe string
|
||||||
}{
|
}{
|
||||||
"en empty": {"en", "", "", `^Player-\d{5}$`},
|
"en empty": {"en", "", "", `^Player-\d{5}$`},
|
||||||
"ru empty": {"ru", "", "", `^Игрок-\d{5}$`},
|
"ru empty": {"ru", "", "", `^Игрок-\d{5}$`},
|
||||||
"default en": {"fr", "", "", `^Player-\d{5}$`},
|
"default en": {"fr", "", "", `^Player-\d{5}$`},
|
||||||
"name garbage, no username": {"ru", "", "!!!", `^Игрок-\d{5}$`},
|
"both garbage": {"ru", "123", "!!!", `^Игрок-\d{5}$`},
|
||||||
}
|
}
|
||||||
for name, tc := range cases {
|
for name, tc := range cases {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const (
|
|||||||
// ActionResign abandons the game.
|
// ActionResign abandons the game.
|
||||||
ActionResign
|
ActionResign
|
||||||
// ActionTimeout is the auto-resignation a missed turn becomes; recorded by
|
// ActionTimeout is the auto-resignation a missed turn becomes; recorded by
|
||||||
// the game domain, never produced by the engine itself.
|
// the game domain in a later stage, never produced by the engine itself.
|
||||||
ActionTimeout
|
ActionTimeout
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
// characters (see decode.go and docs/ARCHITECTURE.md §9.1), so archived games
|
// characters (see decode.go and docs/ARCHITECTURE.md §9.1), so archived games
|
||||||
// replay independently of any dictionary. Second, the engine owns rules and
|
// replay independently of any dictionary. Second, the engine owns rules and
|
||||||
// scoring only: turn scheduling, the 24-hour timeout, persistence and transport
|
// scoring only: turn scheduling, the 24-hour timeout, persistence and transport
|
||||||
// belong to the game domain.
|
// belong to the game domain in a later stage.
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ type entry struct {
|
|||||||
// Registry holds the dictionaries resident in memory, addressed by variant and
|
// Registry holds the dictionaries resident in memory, addressed by variant and
|
||||||
// dictionary version, and the solvers built over them. Several versions of a
|
// dictionary version, and the solvers built over them. Several versions of a
|
||||||
// variant may be resident at once; a game pins the version it started on. The
|
// variant may be resident at once; a game pins the version it started on. The
|
||||||
// admin reload flow registers a new version through Load.
|
// admin reload flow (a later stage) registers a new version through Load.
|
||||||
// Registry is safe for concurrent use.
|
// Registry is safe for concurrent use.
|
||||||
type Registry struct {
|
type Registry struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
|
|||||||
@@ -16,5 +16,5 @@
|
|||||||
// word-check tool with complaint capture, per-player game state, history and GCG
|
// word-check tool with complaint capture, per-player game state, history and GCG
|
||||||
// export, and the per-game turn-timeout sweeper that auto-resigns an overdue
|
// export, and the per-game turn-timeout sweeper that auto-resigns an overdue
|
||||||
// player (honouring their daily away window). The HTTP surface that fronts these
|
// player (honouring their daily away window). The HTTP surface that fronts these
|
||||||
// operations is exposed to the gateway.
|
// operations is added with the gateway in a later stage.
|
||||||
package game
|
package game
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ const MaxActiveQuickGames = 10
|
|||||||
const aiPlayerName = "AI"
|
const aiPlayerName = "AI"
|
||||||
|
|
||||||
// CreateParams describes a new game. Seats lists the seated accounts in turn
|
// CreateParams describes a new game. Seats lists the seated accounts in turn
|
||||||
// order (seat 0 moves first); lobby/matchmaking assembles it.
|
// order (seat 0 moves first); lobby/matchmaking assembles it in a later stage.
|
||||||
type CreateParams struct {
|
type CreateParams struct {
|
||||||
Variant engine.Variant
|
Variant engine.Variant
|
||||||
Seats []uuid.UUID
|
Seats []uuid.UUID
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ func TestEmailConfirmFlow(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TestEmailAlreadyTakenByAnotherAccount refuses to bind an email confirmed by a
|
// TestEmailAlreadyTakenByAnotherAccount refuses to bind an email confirmed by a
|
||||||
// different account (combining two accounts is the separate link/merge flow).
|
// different account (merge is a later stage).
|
||||||
func TestEmailAlreadyTakenByAnotherAccount(t *testing.T) {
|
func TestEmailAlreadyTakenByAnotherAccount(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
store := account.NewStore(testDB)
|
store := account.NewStore(testDB)
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
-- Replace the default (house) ad campaign's single seed tip with the curated,
|
|
||||||
-- language-agnostic Scrabble tip set (one bilingual row per tip; the client picks the
|
|
||||||
-- column for the viewer's language). Data-only — the ad_messages schema is unchanged, so
|
|
||||||
-- a backend image rollback stays DB-safe. The default campaign is the fixed house id seeded
|
|
||||||
-- in 00001; ON DELETE CASCADE is irrelevant here (we only touch its messages).
|
|
||||||
|
|
||||||
-- +goose Up
|
|
||||||
DELETE FROM backend.ad_messages WHERE campaign_id = '00000000-0000-0000-0000-0000000000ad';
|
|
||||||
INSERT INTO backend.ad_messages (message_id, campaign_id, "position", body_en, body_ru) VALUES
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 0, 'Keep a balanced rack — a slight edge of consonants over vowels.', 'Держи на руках баланс — с лёгким перевесом согласных над гласными.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 1, 'Your "leave" (the tiles you keep) sets up your next turn — value it.', '«Остаток» (что оставляешь на руках) готовит следующий ход — цени его.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 2, 'Shed duplicate tiles — repeats clog your options.', 'Сбрасывай дубли фишек — повторы забивают возможности.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 3, 'A slightly consonant-heavy rack builds full-rack plays more easily.', 'Лёгкий перевес согласных проще складывается в выкладку всех фишек.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 4, 'Play several tiles per turn to keep your rack cycling.', 'Выкладывай по нескольку фишек за ход, чтобы рука обновлялась.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 5, 'Don''t hoard hard-to-place duplicates or a lone high-value tile.', 'Не копи труднопристраиваемые дубли или одинокую дорогую фишку.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 6, 'Using all your rack tiles in one move scores a large bonus — chase it.', 'Выкладка всех фишек с рук за ход даёт крупный бонус — стремись к ней.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 7, 'Learn common prefixes and suffixes — they extend words to use every tile.', 'Учи частые приставки и суффиксы — они растягивают слово на все фишки.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 8, '"Fish": play few tiles to keep a near-complete rack when you''re ahead.', '«Рыбачь»: сыграй мало фишек, сохранив почти всю руку, когда ведёшь.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 9, 'Don''t hoard high-value tiles — play them in good time, not at the very end.', 'Не копи дорогие фишки — играй их вовремя, а не под самый конец.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 10, 'Don''t hold a high-value tile waiting for a rare partner — usually a loss.', 'Не держи дорогую фишку ради редкого партнёра — обычно это проигрыш.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 11, 'Land your priciest tile on a premium square for a big single score.', 'Сажай самую дорогую фишку на бонусную клетку ради крупных очков.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 12, 'High-value tiles shine in parallel plays through short words.', 'Дорогие фишки сильны в параллельных выкладках через короткие слова.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 13, 'Stuck with an unplayable high-value tile late? Exchange it.', 'Завис с неиграбельной дорогой фишкой под конец? Обменяй её.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 14, 'The blanks are the most valuable tiles in the bag — guard them.', 'Пустышки — самые ценные фишки в мешке; береги их.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 15, 'Save a blank for a full-rack play or a key premium square.', 'Береги пустышку для выкладки всех фишек или важной бонусной клетки.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 16, 'Don''t spend a blank cheaply — hold it for a much bigger gain.', 'Не трать пустышку по мелочи — придержи ради куда большей выгоды.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 17, 'Put high-value tiles on letter-bonus or word-bonus squares.', 'Клади дорогие фишки на бонус буквы или слова.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 18, 'Stack bonuses — a letter bonus under a word bonus multiplies both.', 'Совмещай бонусы — бонус буквы под бонусом слова умножает оба.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 19, 'Parallel plays can earn nearly half your points — look for them.', 'Параллельные выкладки могут давать почти половину очков — ищи их.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 20, 'A hook adds one tile to an existing word to make a new one.', '«Крючок» — одна фишка к готовому слову, образующая новое.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 21, 'Hooks work at the front or the back of a word.', 'Крючки работают спереди и сзади слова.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 22, 'Short words are the keys to tight parallel plays — memorize them.', 'Короткие слова — ключ к плотным параллелям; выучи их.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 23, 'Your opening word crosses the centre — keep it compact, don''t open up.', 'Первое слово идёт через центр — держи компактным, не раскрывайся.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 24, 'It''s not only your score — limit your opponent''s options too.', 'Это не только твои очки — ограничивай и возможности соперника.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 25, 'Denying a big reply often beats squeezing a few more points yourself.', 'Закрыть крупный ответ часто важнее, чем добрать пару своих очков.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 26, 'When ahead, keep the board tight and closed; avoid open lanes.', 'Ведёшь — держи доску плотной и закрытой, не открывай линии.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 27, 'When behind, open the board up to create high-scoring chances.', 'Отстаёшь — раскрывай доску ради шансов на крупный ход.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 28, 'Don''t leave a word-bonus square open right beside your word.', 'Не оставляй клетку бонуса слова открытой рядом со своим словом.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 29, 'Block a hot square even with a weak word to deny a big play.', 'Закрывай опасную клетку даже слабым словом, чтобы срубить крупный ход.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 30, 'Know words that take no hooks — use them to seal off lines.', 'Знай слова, не берущие крючков — ими запирай линии.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 31, 'Track the tiles played to judge what is still left in the bag.', 'Считай сыгранные фишки — так поймёшь, что осталось в мешке.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 32, 'Exchange when your rack is unbalanced or can only score low.', 'Меняй фишки, когда рука несбалансированна или тянет мало.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 33, 'A good exchange beats a bad play — a clean rack is worth a turn.', 'Хороший обмен лучше плохого хода — чистая рука стоит хода.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 34, 'Swap away a surplus of vowels or consonants to rebalance.', 'Сбрасывай в обмен избыток гласных или согласных, чтобы выровняться.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 35, 'Rare high-value tiles are gone once seen — note them as they appear.', 'Редкие дорогие фишки исчезают, едва мелькнув — отмечай их.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 36, 'Once the bag is empty, deduce your opponent''s remaining tiles.', 'Когда мешок пуст, вычисли оставшиеся фишки соперника.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 37, 'Shed high-value tiles before the bag empties — don''t get stuck with them.', 'Сбрось дорогие фишки до опустения мешка — не зависай с ними.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 38, 'Unplayed tiles count against you at the end — try to go out first.', 'Несыгранные фишки минусуют очки в конце — старайся выйти первым.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 39, 'Going out first adds your opponent''s leftover tiles to your score.', 'Кто вышел первым, добирает очки за оставшиеся фишки соперника.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 40, 'Sometimes leaving one tile in the bag buys you an extra turn.', 'Иногда оставить одну фишку в мешке — это лишний ход.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 41, 'In the endgame, block the exact squares your opponent needs.', 'В эндшпиле блокируй именно те клетки, что нужны сопернику.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 42, 'Shuffle your rack to spot new patterns.', 'Перемешивай фишки на руках — так замечаешь новые сочетания.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 43, 'Separate prefix, suffix and middle tiles to anagram faster.', 'Разнеси приставку, суффикс и середину — анаграммы решаются быстрее.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 44, 'Value board position and future turns over raw points this turn.', 'Цени позицию и будущие ходы выше сиюминутных очков.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 45, 'Early game build position; midgame maximize score; endgame defend.', 'В начале — позиция, в середине — очки, в конце — защита.'),
|
|
||||||
(gen_random_uuid(), '00000000-0000-0000-0000-0000000000ad', 46, 'Learn the short-word lists first — they pay off in every game.', 'Сначала учи списки коротких слов — окупаются в каждой партии.');
|
|
||||||
|
|
||||||
-- +goose Down
|
|
||||||
-- Restore the original single house tip seeded by the baseline.
|
|
||||||
DELETE FROM backend.ad_messages WHERE campaign_id = '00000000-0000-0000-0000-0000000000ad';
|
|
||||||
INSERT INTO backend.ad_messages (message_id, campaign_id, "position", body_en, body_ru)
|
|
||||||
VALUES ('00000000-0000-0000-0000-0000000000a1', '00000000-0000-0000-0000-0000000000ad', 0,
|
|
||||||
'Tip: a play using all 7 tiles earns a +50 bonus.',
|
|
||||||
'Совет: ход всеми 7 фишками приносит бонус +50 очков.');
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
// Package server wires the backend's HTTP listener: the gin engine, its route
|
// Package server wires the backend's HTTP listener: the gin engine, its route
|
||||||
// groups, the per-request telemetry middleware and the start/stop lifecycle.
|
// groups, the per-request telemetry middleware and the start/stop lifecycle.
|
||||||
//
|
//
|
||||||
// The /api/v1 route groups (public, user, internal, admin) attach their endpoints
|
// The /api/v1 route groups (public, user, internal, admin) are created here so
|
||||||
// to a stable structure; the /user group requires the X-User-ID identity header.
|
// later stages attach their endpoints to a stable structure; the /user group
|
||||||
// The probes /healthz (liveness) and /readyz (database + session-cache readiness)
|
// requires the X-User-ID identity header. The probes /healthz (liveness) and
|
||||||
// are unauthenticated.
|
// /readyz (database + session-cache readiness) are unauthenticated.
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -245,7 +245,7 @@ func (s *Server) Invitations() *lobby.InvitationService { return s.invitations }
|
|||||||
func (s *Server) Emails() *account.EmailService { return s.emails }
|
func (s *Server) Emails() *account.EmailService { return s.emails }
|
||||||
|
|
||||||
// Handler returns the underlying HTTP handler. It lets tests drive the server
|
// Handler returns the underlying HTTP handler. It lets tests drive the server
|
||||||
// without binding a socket and lets callers compose the backend behind
|
// without binding a socket and lets later stages compose the backend behind
|
||||||
// another listener.
|
// another listener.
|
||||||
func (s *Server) Handler() http.Handler { return s.http.Handler }
|
func (s *Server) Handler() http.Handler { return s.http.Handler }
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Service mints, resolves, and revokes sessions over the store and the
|
// Service mints, resolves, and revokes sessions over the store and the
|
||||||
// write-through cache. The gateway is its only caller.
|
// write-through cache. The gateway is its only caller (from a later stage); the
|
||||||
|
// HTTP surface is wired then.
|
||||||
type Service struct {
|
type Service struct {
|
||||||
store *Store
|
store *Store
|
||||||
cache *Cache
|
cache *Cache
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
// in as a message kind. It owns the friendships, blocks and chat_messages tables,
|
// in as a message kind. It owns the friendships, blocks and chat_messages tables,
|
||||||
// reads the account-level block toggles through account.Store, and gates chat and
|
// reads the account-level block toggles through account.Store, and gates chat and
|
||||||
// nudge on game state through a GameReader so it never imports the engine. The
|
// nudge on game state through a GameReader so it never imports the engine. The
|
||||||
// live delivery of chat and nudges (push / in-app stream) belongs to the gateway;
|
// live delivery of chat and nudges (push / in-app stream) belongs to the gateway
|
||||||
// this package only persists and reads them.
|
// in a later stage; this package only persists and reads them.
|
||||||
package social
|
package social
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ POSTGRES_PASSWORD=change-me # required
|
|||||||
# the active version lives in the DB. On a live volume a changed value is ignored (the
|
# the active version lives in the DB. On a live volume a changed value is ignored (the
|
||||||
# recorded .seed_version marker wins — the seed-drift guard); change a running
|
# recorded .seed_version marker wins — the seed-drift guard); change a running
|
||||||
# contour's dictionary through /_gm/dictionary (ARCHITECTURE.md §5).
|
# contour's dictionary through /_gm/dictionary (ARCHITECTURE.md §5).
|
||||||
DICT_VERSION=v1.3.0
|
DICT_VERSION=v1.2.1
|
||||||
|
|
||||||
# --- Logging ----------------------------------------------------------------
|
# --- Logging ----------------------------------------------------------------
|
||||||
LOG_LEVEL=info
|
LOG_LEVEL=info
|
||||||
|
|||||||
+1
-23
@@ -80,7 +80,7 @@ without it Docker's resolver handles `otelcol`, `gateway` and `api.telegram.org`
|
|||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| `POSTGRES_DB` | variable | `scrabble` | Database name. |
|
| `POSTGRES_DB` | variable | `scrabble` | Database name. |
|
||||||
| `POSTGRES_USER` | variable | `scrabble` | Database user. |
|
| `POSTGRES_USER` | variable | `scrabble` | Database user. |
|
||||||
| `DICT_VERSION` | variable | `v1.3.0` | `scrabble-dictionary` release tag baked into the backend image as the **seed for a fresh volume** (build-arg). A live contour changes dictionary through the admin console, not this; on a seeded volume a changed value is ignored (the recorded `.seed_version` marker wins — the seed-drift guard, ARCHITECTURE.md §5). Set per contour as `TEST_`/`PROD_DICT_VERSION`. |
|
| `DICT_VERSION` | variable | `v1.2.1` | `scrabble-dictionary` release tag baked into the backend image as the **seed for a fresh volume** (build-arg). A live contour changes dictionary through the admin console, not this; on a seeded volume a changed value is ignored (the recorded `.seed_version` marker wins — the seed-drift guard, ARCHITECTURE.md §5). Set per contour as `TEST_`/`PROD_DICT_VERSION`. |
|
||||||
| `LOG_LEVEL` | variable | `info` | Shared log level for backend / gateway / validator / bot (`debug\|info\|warn\|error`). |
|
| `LOG_LEVEL` | variable | `info` | Shared log level for backend / gateway / validator / bot (`debug\|info\|warn\|error`). |
|
||||||
| `CADDY_SITE_ADDRESS` | variable | `:80` | Caddy site address. Test: `:80` (host caddy terminates TLS). Prod: a domain, so caddy does its own ACME. |
|
| `CADDY_SITE_ADDRESS` | variable | `:80` | Caddy site address. Test: `:80` (host caddy terminates TLS). Prod: a domain, so caddy does its own ACME. |
|
||||||
| `GM_BASICAUTH_USER` | variable | `gm` | Username for the `/_gm` Basic-Auth. |
|
| `GM_BASICAUTH_USER` | variable | `gm` | Username for the `/_gm` Basic-Auth. |
|
||||||
@@ -117,28 +117,6 @@ collector's / gateway's internal IP is fine (connected route), but its `AWG_CONF
|
|||||||
which resolves `otelcol`, `gateway` and `api.telegram.org`. `GATEWAY_ADMIN_*` is
|
which resolves `otelcol`, `gateway` and `api.telegram.org`. `GATEWAY_ADMIN_*` is
|
||||||
intentionally **unset** — caddy owns `/_gm` in the contour.
|
intentionally **unset** — caddy owns `/_gm` in the contour.
|
||||||
|
|
||||||
## Bumping the dictionary version
|
|
||||||
|
|
||||||
The dictionary ships as a versioned **release artifact** (`scrabble-dawg-vX.Y.Z.tar.gz`) from
|
|
||||||
[`scrabble-dictionary`](https://gitea.iliadenisov.ru/developer/scrabble-dictionary). The tag is
|
|
||||||
a build-time input with **no default** in the images, so it is set in exactly two places to
|
|
||||||
move the whole stack — change both to a new release:
|
|
||||||
|
|
||||||
1. **CI tests** — `.gitea/workflows/ci.yaml` `env.DICT_VERSION` (the unit/integration jobs
|
|
||||||
download that dawg).
|
|
||||||
2. **Deploy seed** — the Gitea repo variables `TEST_DICT_VERSION` / `PROD_DICT_VERSION` (the tag
|
|
||||||
the deploy bakes into a **fresh** volume's image; the deploy job feeds it to `compose` as
|
|
||||||
`DICT_VERSION`).
|
|
||||||
|
|
||||||
For local builds set `DICT_VERSION` in `deploy/.env` (template: `.env.example`); a bare
|
|
||||||
`docker build` needs `--build-arg DICT_VERSION=vX.Y.Z`. The Dockerfiles and `compose` carry no
|
|
||||||
default — a missing value fails loudly instead of baking a stale tag.
|
|
||||||
|
|
||||||
Bumping the seed is a **no-op on a live volume** (the `.seed_version` marker wins — the
|
|
||||||
seed-drift guard). A running contour/prod moves to a new release **through the admin console**
|
|
||||||
`/_gm/dictionary` (upload the tarball, preview the per-variant diff, confirm); in-flight games
|
|
||||||
keep their pinned version, new games use the new one (ARCHITECTURE.md §5).
|
|
||||||
|
|
||||||
## Production rollout
|
## Production rollout
|
||||||
|
|
||||||
Prod runs on **two hosts** (main = full stack + ACME on the domain; tg = the bot only,
|
Prod runs on **two hosts** (main = full stack + ACME on the domain; tg = the bot only,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Prod host provisioning
|
# Prod host provisioning (Stage 18)
|
||||||
|
|
||||||
Idempotent Ansible that prepares the two production hosts. It installs Docker, a
|
Idempotent Ansible that prepares the two production hosts. It installs Docker, a
|
||||||
non-sudo `deploy` service account, SSH hardening, a default-deny firewall,
|
non-sudo `deploy` service account, SSH hardening, a default-deny firewall,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
# Production host provisioning. Idempotent: safe to re-run after a host resize.
|
# Stage 18 host provisioning. Idempotent: safe to re-run after a host resize.
|
||||||
# Prepares hosts only (docker, hardening, service account, firewall); the
|
# Prepares hosts only (docker, hardening, service account, firewall); the
|
||||||
# application is deployed separately by .gitea/workflows/prod-deploy.yaml.
|
# application is deployed separately by .gitea/workflows/prod-deploy.yaml.
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# It (1) publishes caddy 80/443 — there is no host caddy in prod, so the contour caddy
|
# It (1) publishes caddy 80/443 — there is no host caddy in prod, so the contour caddy
|
||||||
# owns the edge and does its own ACME on CADDY_SITE_ADDRESS — and the gateway bot-link
|
# owns the edge and does its own ACME on CADDY_SITE_ADDRESS — and the gateway bot-link
|
||||||
# :9443 the remote bot dials in over mTLS; and (2) retunes the baseline limits down for the
|
# :9443 the remote bot dials in over mTLS; and (2) retunes the R7 limits down for the
|
||||||
# 2 vCPU / 1.9 GiB host (GOMAXPROCS=2, smaller memory caps, shorter Prometheus
|
# 2 vCPU / 1.9 GiB host (GOMAXPROCS=2, smaller memory caps, shorter Prometheus
|
||||||
# retention). The contour launches deliberately undersized at zero players; the added
|
# retention). The contour launches deliberately undersized at zero players; the added
|
||||||
# node_exporter + Grafana watch host memory so it can be resized at Selectel when
|
# node_exporter + Grafana watch host memory so it can be resized at Selectel when
|
||||||
@@ -29,7 +29,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "9443:9443"
|
- "9443:9443"
|
||||||
environment:
|
environment:
|
||||||
# 2 vCPU host: align the Go scheduler with the cgroup quota (the baseline's 3-core gateway needs 3 cores).
|
# 2 vCPU host: align the Go scheduler with the cgroup quota (R7's 3 needs 3 cores).
|
||||||
GOMAXPROCS: "2"
|
GOMAXPROCS: "2"
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
|
|||||||
+15
-17
@@ -25,9 +25,9 @@
|
|||||||
# backend admin relay reaches the gateway at `gateway:9092` (plaintext).
|
# backend admin relay reaches the gateway at `gateway:9092` (plaintext).
|
||||||
name: scrabble
|
name: scrabble
|
||||||
|
|
||||||
# Bound every container's json-file logs. The backend emits a per-request latency
|
# Bound every container's json-file logs. R7 measured the backend emitting a
|
||||||
# line at info (~14 MiB / 30 min under the 500-player peak); without rotation the
|
# per-request latency line at info (~14 MiB / 30 min under the 500-player stress
|
||||||
# volume grows unbounded. 10 MiB x 3 files caps each
|
# peak); without rotation the volume grows unbounded. 10 MiB x 3 files caps each
|
||||||
# container at 30 MiB. Applied to every service via the *default-logging alias.
|
# container at 30 MiB. Applied to every service via the *default-logging alias.
|
||||||
x-logging: &default-logging
|
x-logging: &default-logging
|
||||||
driver: json-file
|
driver: json-file
|
||||||
@@ -52,8 +52,8 @@ services:
|
|||||||
retries: 30
|
retries: 30
|
||||||
volumes:
|
volumes:
|
||||||
- postgres-data:/var/lib/postgresql/data
|
- postgres-data:/var/lib/postgresql/data
|
||||||
# 512M leaves headroom over the default 128 MB shared_buffers + per-connection
|
# R7 starting limits: 512M leaves headroom over the default 128 MB shared_buffers +
|
||||||
# memory (the load harness peaked at 28 backends / 69 MiB RSS).
|
# per-connection memory (R2 peaked at 28 backends / 69 MiB RSS); tighten after the run.
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
@@ -68,11 +68,9 @@ services:
|
|||||||
context: ..
|
context: ..
|
||||||
dockerfile: backend/Dockerfile
|
dockerfile: backend/Dockerfile
|
||||||
args:
|
args:
|
||||||
# Seed dictionary for a FRESH volume; required (no default) so the release tag is
|
# Seed dictionary for a FRESH volume; the per-contour value comes from the
|
||||||
# set in exactly one place per context — the deploy env (Gitea TEST_/PROD_DICT_VERSION)
|
# deploy env (Gitea TEST_/PROD_DICT_VERSION). See the volume note below.
|
||||||
# or .env for local builds. See the volume note below + deploy/README.md "Bumping the
|
DICT_VERSION: ${DICT_VERSION:-v1.2.1}
|
||||||
# dictionary version".
|
|
||||||
DICT_VERSION: ${DICT_VERSION:?set DICT_VERSION — the scrabble-dictionary release tag, e.g. in deploy/.env}
|
|
||||||
# Build version stamped into the binary (git tag; see pkg/version).
|
# Build version stamped into the binary (git tag; see pkg/version).
|
||||||
VERSION: ${APP_VERSION:-dev}
|
VERSION: ${APP_VERSION:-dev}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -83,8 +81,8 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
# search_path=backend matches the migrations (00001 creates the schema).
|
# search_path=backend matches the migrations (00001 creates the schema).
|
||||||
BACKEND_POSTGRES_DSN: postgres://${POSTGRES_USER:-scrabble}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-scrabble}?sslmode=disable&search_path=backend
|
BACKEND_POSTGRES_DSN: postgres://${POSTGRES_USER:-scrabble}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-scrabble}?sslmode=disable&search_path=backend
|
||||||
# The pool caps at 25 conns (~28 backends) around 500 players; 40 gives headroom
|
# R7 tuned: the pool sat at its 25-conn cap (28 backends total) at 500 players;
|
||||||
# for bursts. Postgres (2 cores / 512 MiB) handles it.
|
# 40 gives headroom for bursts. Postgres (2 cores / 512 MiB) handles it.
|
||||||
BACKEND_POSTGRES_MAX_OPEN_CONNS: "40"
|
BACKEND_POSTGRES_MAX_OPEN_CONNS: "40"
|
||||||
BACKEND_HTTP_ADDR: ":8080"
|
BACKEND_HTTP_ADDR: ":8080"
|
||||||
BACKEND_GRPC_ADDR: ":9090"
|
BACKEND_GRPC_ADDR: ":9090"
|
||||||
@@ -113,8 +111,8 @@ services:
|
|||||||
- dawg-data:/opt/dawg
|
- dawg-data:/opt/dawg
|
||||||
# No container healthcheck: the distroless image has no shell/wget. Readiness
|
# No container healthcheck: the distroless image has no shell/wget. Readiness
|
||||||
# is covered by the CI post-deploy probe (GET / through caddy).
|
# is covered by the CI post-deploy probe (GET / through caddy).
|
||||||
# Generous over the ~1-core / <=100 MiB measured peak; the prod overlay trims these
|
# R7 starting limits (generous over the R2 ~1-core / <=100 MiB peak); tightened to
|
||||||
# to the launch-host values. deploy.resources.limits is
|
# the agreed prod values after the final stress run. deploy.resources.limits is
|
||||||
# honoured by `docker compose up` (Compose v2), not only by swarm.
|
# honoured by `docker compose up` (Compose v2), not only by swarm.
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
@@ -177,7 +175,7 @@ services:
|
|||||||
# deploy/gen-certs.sh for the test contour; supplied from PROD_ secrets in prod.
|
# deploy/gen-certs.sh for the test contour; supplied from PROD_ secrets in prod.
|
||||||
volumes:
|
volumes:
|
||||||
- ${SCRABBLE_CONFIG_DIR:-.}/certs:/certs:ro
|
- ${SCRABBLE_CONFIG_DIR:-.}/certs:/certs:ro
|
||||||
# The gateway holds one h2c connection per player, so at 500 players it
|
# R7 tuned: the gateway holds one h2c connection per player, so at 500 players it
|
||||||
# bursts into a 2-core cap (~2.49% transport_error on game.state); 3 cores absorbs
|
# bursts into a 2-core cap (~2.49% transport_error on game.state); 3 cores absorbs
|
||||||
# the bursts. Per-connection overhead is the realistic prod cost — size for it.
|
# the bursts. Per-connection overhead is the realistic prod cost — size for it.
|
||||||
deploy:
|
deploy:
|
||||||
@@ -404,8 +402,8 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ${SCRABBLE_CONFIG_DIR:-.}/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
- ${SCRABBLE_CONFIG_DIR:-.}/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro
|
||||||
- tempo-data:/var/tempo
|
- tempo-data:/var/tempo
|
||||||
# Tempo reached the 1 GiB cap under sustained load (446 MiB in earlier runs);
|
# R7 tuned: tempo reached the 1 GiB cap during the final run (446 MiB in R2);
|
||||||
# raised to 2 GiB for headroom against OOM.
|
# raised to 2 GiB for headroom against OOM under sustained tracing load.
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
Source of truth for the platform architecture, transport, security model and
|
Source of truth for the platform architecture, transport, security model and
|
||||||
cross-service contracts. User-visible behaviour per domain lives in
|
cross-service contracts. User-visible behaviour per domain lives in
|
||||||
[`FUNCTIONAL.md`](FUNCTIONAL.md). This document always describes the **current**
|
[`FUNCTIONAL.md`](FUNCTIONAL.md); the staged build order lives in
|
||||||
design, not the history of how it was reached.
|
[`../PLAN.md`](../PLAN.md). This document always describes the **current**
|
||||||
|
design, not the history of how it was reached. Sections describing
|
||||||
|
not-yet-implemented components are marked *(planned)*.
|
||||||
|
|
||||||
## 1. Overview
|
## 1. Overview
|
||||||
|
|
||||||
@@ -1105,7 +1107,7 @@ Two contours, two secret/variable prefixes (`TEST_` / `PROD_`):
|
|||||||
**`prod-rollback`** workflow re-deploys any prior release tag (blank input = the previous
|
**`prod-rollback`** workflow re-deploys any prior release tag (blank input = the previous
|
||||||
deployed version, tracked on the host) over the same rolling, health-gated path — image-only,
|
deployed version, tracked on the host) over the same rolling, health-gated path — image-only,
|
||||||
no DB migration. The main host is
|
no DB migration. The main host is
|
||||||
intentionally **launch-sized** (2 vCPU / 1.9 GiB): the prod overlay trims the baseline limits
|
intentionally **launch-sized** (2 vCPU / 1.9 GiB): the prod overlay trims the R7 limits
|
||||||
(`GOMAXPROCS=2`, smaller caps, 7d Prometheus retention) and a **node_exporter** feeds
|
(`GOMAXPROCS=2`, smaller caps, 7d Prometheus retention) and a **node_exporter** feeds
|
||||||
host-memory metrics to Grafana so it can be resized reactively as players arrive.
|
host-memory metrics to Grafana so it can be resized reactively as players arrive.
|
||||||
`GATEWAY_ABUSE_BAN_ENABLED=true` in prod (the per-IP ban is meaningful only with real
|
`GATEWAY_ABUSE_BAN_ENABLED=true` in prod (the per-IP ban is meaningful only with real
|
||||||
|
|||||||
+6
-5
@@ -121,7 +121,7 @@ tests or touching CI.
|
|||||||
Postgres-backed `inttest` drives the **guest reaper** end to end (an abandoned guest is
|
Postgres-backed `inttest` drives the **guest reaper** end to end (an abandoned guest is
|
||||||
reaped; a too-young guest, a seated guest and a durable account are kept).
|
reaped; a too-young guest, a seated guest and a durable account are kept).
|
||||||
- **Load test & resource baseline** — a reusable `loadtest/` module
|
- **Load test & resource baseline** — a reusable `loadtest/` module
|
||||||
(`scrabble/loadtest`) is the stress/load harness. It **seeds** a large account
|
(`scrabble/loadtest`) is the pre-release stress harness. It **seeds** a large account
|
||||||
population with pre-created sessions directly in Postgres (token hashes matching
|
population with pre-created sessions directly in Postgres (token hashes matching
|
||||||
`backend/internal/session`), **drives** virtual players through the edge protocol —
|
`backend/internal/session`), **drives** virtual players through the edge protocol —
|
||||||
real games assembled via invitations, **mid-ranked** legal moves generated locally by
|
real games assembled via invitations, **mid-ranked** legal moves generated locally by
|
||||||
@@ -154,12 +154,13 @@ tests or touching CI.
|
|||||||
- No network or real platform calls in unit tests; validate platform
|
- No network or real platform calls in unit tests; validate platform
|
||||||
credentials behind an interface seam and test with fixtures.
|
credentials behind an interface seam and test with fixtures.
|
||||||
|
|
||||||
## CI gate
|
## Per-stage CI gate
|
||||||
|
|
||||||
Every change is exercised on `gitea.iliadenisov.ru` before it is merged:
|
Every completed stage is exercised on `gitea.iliadenisov.ru` before it is marked
|
||||||
|
done in [`../PLAN.md`](../PLAN.md):
|
||||||
|
|
||||||
1. Commit the change on its `feature/*` branch.
|
1. Commit the stage on its `feature/*` branch.
|
||||||
2. Push to `origin`.
|
2. Push to `origin`.
|
||||||
3. Watch the run to completion — never hand-roll a poll loop:
|
3. Watch the run to completion — never hand-roll a poll loop:
|
||||||
`python3 ~/.claude/bin/gitea-ci-watch.py` (launch in the background).
|
`python3 ~/.claude/bin/gitea-ci-watch.py` (launch in the background).
|
||||||
4. Only after every workflow that fired is green may the change be merged.
|
4. Only after every workflow that fired is green may the stage be marked done.
|
||||||
|
|||||||
+1
-4
@@ -109,10 +109,7 @@ dismisses as soon as the lobby is ready. The pure layout and timing live in `lib
|
|||||||
## Tiles & board
|
## Tiles & board
|
||||||
|
|
||||||
- **Tiles**: the letter sits in the **top-left** corner (offset a touch more than the
|
- **Tiles**: the letter sits in the **top-left** corner (offset a touch more than the
|
||||||
value), the point value bottom-right; blanks show no value. In **Erudit** the blank is the
|
value), the point value bottom-right; blanks show no value.
|
||||||
"звёздочка" (star) chip: an unplaced blank shows the star (`✻`, U+273B) centred on the rack
|
|
||||||
tile, and a placed blank carries it in the value corner; the Scrabble variants leave the
|
|
||||||
blank unmarked (`usesStarBlank` in `lib/variants.ts`).
|
|
||||||
- **Board zoom** (`Board.svelte`): a two-state zoom (full 15×15 ↔ ~9 cells) by **growing
|
- **Board zoom** (`Board.svelte`): a two-state zoom (full 15×15 ↔ ~9 cells) by **growing
|
||||||
the board's width** inside a fixed-size viewport (a real layout change → native scroll
|
the board's width** inside a fixed-size viewport (a real layout change → native scroll
|
||||||
that works consistently across browsers; no `transform`, which broke scrolling
|
that works consistently across browsers; no `transform`, which broke scrolling
|
||||||
|
|||||||
+1
-2
@@ -12,8 +12,7 @@
|
|||||||
|
|
||||||
# --- dictionary artifact -----------------------------------------------------
|
# --- dictionary artifact -----------------------------------------------------
|
||||||
FROM alpine:3.20 AS dawg
|
FROM alpine:3.20 AS dawg
|
||||||
# Required, no default: the build caller supplies the scrabble-dictionary release tag.
|
ARG DICT_VERSION=v1.2.1
|
||||||
ARG DICT_VERSION
|
|
||||||
RUN apk add --no-cache curl tar
|
RUN apk add --no-cache curl tar
|
||||||
RUN mkdir -p /dawg \
|
RUN mkdir -p /dawg \
|
||||||
&& curl -fsSL -o /tmp/dawg.tar.gz \
|
&& curl -fsSL -o /tmp/dawg.tar.gz \
|
||||||
|
|||||||
+5
-5
@@ -1,6 +1,6 @@
|
|||||||
# loadtest — stress harness
|
# loadtest — stress harness
|
||||||
|
|
||||||
Reusable load/stress harness. It
|
Reusable load harness for the pre-release stress pass. It
|
||||||
seeds a large account population with pre-created sessions, drives virtual players
|
seeds a large account population with pre-created sessions, drives virtual players
|
||||||
through the **gateway edge protocol** in realistic games, hammers the rate limiter,
|
through the **gateway edge protocol** in realistic games, hammers the rate limiter,
|
||||||
and prints a trip-report summary. It stays in the repo for repeats.
|
and prints a trip-report summary. It stays in the repo for repeats.
|
||||||
@@ -35,8 +35,8 @@ The harness reaches Postgres and the gateway directly, so run it as a one-shot
|
|||||||
container on the contour's docker network (this bypasses the host→gateway hairpin):
|
container on the contour's docker network (this bypasses the host→gateway hairpin):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# from the repo root (DICT_VERSION has no default — pass the scrabble-dictionary release tag)
|
# from the repo root
|
||||||
docker build --build-arg DICT_VERSION=v1.3.0 -f loadtest/Dockerfile -t scrabble-loadtest .
|
docker build -f loadtest/Dockerfile -t scrabble-loadtest .
|
||||||
|
|
||||||
docker run --rm --cpus=3 --name scrabble-loadtest --network scrabble-internal \
|
docker run --rm --cpus=3 --name scrabble-loadtest --network scrabble-internal \
|
||||||
-e POSTGRES_PASSWORD="$TEST_POSTGRES_PASSWORD" \
|
-e POSTGRES_PASSWORD="$TEST_POSTGRES_PASSWORD" \
|
||||||
@@ -107,6 +107,6 @@ gateway→backend connection-pool fix, and the revised sizing — are written up
|
|||||||
|
|
||||||
The harness shares the host CPU with the contour, so its own `scrabble-loadtest`
|
The harness shares the host CPU with the contour, so its own `scrabble-loadtest`
|
||||||
container series is read alongside the system under test; capping it with `--cpus`
|
container series is read alongside the system under test; capping it with `--cpus`
|
||||||
keeps the contour's quota. Per-player transports removed the shared-transport
|
keeps the contour's quota. Per-player transports (R7) removed the shared-transport
|
||||||
artifact that previously inflated `transport_error`, so the figures reflect the system. A
|
artifact that inflated R2's `transport_error`, so the figures reflect the system. A
|
||||||
fully isolated ceiling on separate hardware remains future work.
|
fully isolated ceiling on separate hardware remains future work.
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ func cmdRun(ctx context.Context, log *slog.Logger, args []string) error {
|
|||||||
drv.Hammer(ctx, pool.Durables[0], scenario.HammerConfig{Workers: *hammerWorkers, Duration: *hammerDur})
|
drv.Hammer(ctx, pool.Durables[0], scenario.HammerConfig{Workers: *hammerWorkers, Duration: *hammerDur})
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("\n==== load-test report ====")
|
fmt.Println("\n==== R2 load-test report ====")
|
||||||
fmt.Println(rec.Summary())
|
fmt.Println(rec.Summary())
|
||||||
|
|
||||||
if *doCleanup {
|
if *doCleanup {
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ targets, `validator` and `bot`. In the test contour (`deploy/docker-compose.yml`
|
|||||||
for Telegram egress and dials the gateway bot-link by its internal name. The bot-link
|
for Telegram egress and dials the gateway bot-link by its internal name. The bot-link
|
||||||
mTLS material is generated by `deploy/gen-certs.sh`. In prod the bot runs on a separate
|
mTLS material is generated by `deploy/gen-certs.sh`. In prod the bot runs on a separate
|
||||||
host with native Telegram access and dials the gateway's published bot-link port with
|
host with native Telegram access and dials the gateway's published bot-link port with
|
||||||
`PROD_` certificates in production.
|
`PROD_` certificates (the deferred final stage — see `PRERELEASE.md`).
|
||||||
|
|
||||||
A real end-to-end Telegram smoke needs a BotFather bot, its token, a public HTTPS Mini
|
A real end-to-end Telegram smoke needs a BotFather bot, its token, a public HTTPS Mini
|
||||||
App origin, and the bot container; the unit tests cover the wire format, templates,
|
App origin, and the bot container; the unit tests cover the wire format, templates,
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
// A best-move word drawn as a row of game tiles, mirroring the board's placed-tile
|
// A best-move word drawn as a row of game tiles, mirroring the board's placed-tile
|
||||||
// look (letter top-left, point value bottom-right) at a small fixed size. A blank tile
|
// look (letter top-left, point value bottom-right) at a small fixed size. A blank tile
|
||||||
// shows its letter but no value, exactly as on the board; in Erudit it also carries the
|
// shows its letter but no value, exactly as on the board. Letters are upper-cased for
|
||||||
// blank's star (✻) in the value corner. Letters are upper-cased for display. The tile
|
// display. The tile values ride on each tile, so this renders without the variant's
|
||||||
// values ride on each tile, so this needs only the variant id (for the star) — not the
|
// alphabet table (which the statistics screen has not cached).
|
||||||
// variant's alphabet table, which the statistics screen has not cached.
|
import type { BestMoveTile } from '../lib/model';
|
||||||
import type { BestMoveTile, Variant } from '../lib/model';
|
|
||||||
import { usesStarBlank, BLANK_STAR } from '../lib/variants';
|
|
||||||
|
|
||||||
let { word, variant }: { word: BestMoveTile[]; variant: Variant } = $props();
|
let { word }: { word: BestMoveTile[] } = $props();
|
||||||
|
|
||||||
const label = $derived(word.map((t) => t.letter).join('').toUpperCase());
|
const label = $derived(word.map((t) => t.letter).join('').toUpperCase());
|
||||||
</script>
|
</script>
|
||||||
@@ -17,11 +15,7 @@
|
|||||||
{#each word as tile, i (i)}
|
{#each word as tile, i (i)}
|
||||||
<span class="tile" class:blank={tile.blank} aria-hidden="true">
|
<span class="tile" class:blank={tile.blank} aria-hidden="true">
|
||||||
<span class="letter">{tile.letter.toUpperCase()}</span>
|
<span class="letter">{tile.letter.toUpperCase()}</span>
|
||||||
{#if !tile.blank}
|
{#if !tile.blank}<span class="val">{tile.value}</span>{/if}
|
||||||
<span class="val">{tile.value}</span>
|
|
||||||
{:else if usesStarBlank(variant)}
|
|
||||||
<span class="val blankmark">{BLANK_STAR}</span>
|
|
||||||
{/if}
|
|
||||||
</span>
|
</span>
|
||||||
{/each}
|
{/each}
|
||||||
</span>
|
</span>
|
||||||
@@ -56,10 +50,4 @@
|
|||||||
font-size: 7px;
|
font-size: 7px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
/* A placed Erudit blank ("звёздочка") shows its star where the (absent) point value sits,
|
|
||||||
its ink kept on the value digits' line (mirrors the board tile). */
|
|
||||||
.blankmark {
|
|
||||||
font-size: 8px;
|
|
||||||
bottom: 0;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
import type { Premium } from '../lib/premiums';
|
import type { Premium } from '../lib/premiums';
|
||||||
import { valueForLetter } from '../lib/alphabet';
|
import { valueForLetter } from '../lib/alphabet';
|
||||||
import type { Variant } from '../lib/model';
|
import type { Variant } from '../lib/model';
|
||||||
import { usesStarBlank, BLANK_STAR } from '../lib/variants';
|
|
||||||
import { bonusLabel, type BoardLabelMode } from '../lib/boardlabels';
|
import { bonusLabel, type BoardLabelMode } from '../lib/boardlabels';
|
||||||
import type { Locale } from '../lib/i18n/catalog';
|
import type { Locale } from '../lib/i18n/catalog';
|
||||||
|
|
||||||
@@ -255,11 +254,7 @@
|
|||||||
>
|
>
|
||||||
{#if letter}
|
{#if letter}
|
||||||
<span class="letter">{letter}</span>
|
<span class="letter">{letter}</span>
|
||||||
{#if !blank}
|
{#if !blank}<span class="val">{valueForLetter(variant, letter)}</span>{/if}
|
||||||
<span class="val">{valueForLetter(variant, letter)}</span>
|
|
||||||
{:else if usesStarBlank(variant)}
|
|
||||||
<span class="val blankmark">{BLANK_STAR}</span>
|
|
||||||
{/if}
|
|
||||||
{:else if r === centre.row && c === centre.col}
|
{:else if r === centre.row && c === centre.col}
|
||||||
<span class="star">★</span>
|
<span class="star">★</span>
|
||||||
{:else if bl?.kind === 'single'}
|
{:else if bl?.kind === 'single'}
|
||||||
@@ -415,12 +410,6 @@
|
|||||||
font-size: 2.4cqw;
|
font-size: 2.4cqw;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
/* A placed Erudit blank ("звёздочка") shows its star where the (absent) point value sits,
|
|
||||||
its ink centred on the same line as a neighbouring tile's value digit. */
|
|
||||||
.blankmark {
|
|
||||||
font-size: 2.8cqw;
|
|
||||||
bottom: 0;
|
|
||||||
}
|
|
||||||
.star {
|
.star {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
inset: 0;
|
inset: 0;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
import { badgeKind } from '../lib/unread';
|
import { badgeKind } from '../lib/unread';
|
||||||
import { historyGrid } from '../lib/history';
|
import { historyGrid } from '../lib/history';
|
||||||
import { centre, premiumGrid } from '../lib/premiums';
|
import { centre, premiumGrid } from '../lib/premiums';
|
||||||
import { variantNameKey, usesStarBlank, BLANK_STAR } from '../lib/variants';
|
import { variantNameKey } from '../lib/variants';
|
||||||
import { alphabetLetters, hasAlphabet } from '../lib/alphabet';
|
import { alphabetLetters, hasAlphabet } from '../lib/alphabet';
|
||||||
import { hintsLeft } from '../lib/hints';
|
import { hintsLeft } from '../lib/hints';
|
||||||
import { shareOrDownloadGcg } from '../lib/share';
|
import { shareOrDownloadGcg } from '../lib/share';
|
||||||
@@ -1293,7 +1293,7 @@
|
|||||||
|
|
||||||
{#if drag}
|
{#if drag}
|
||||||
<div class="ghost" class:touch={drag.touch} style="left:{drag.x}px; top:{drag.y}px">
|
<div class="ghost" class:touch={drag.touch} style="left:{drag.x}px; top:{drag.y}px">
|
||||||
<span>{drag.blank ? (usesStarBlank(variant) ? BLANK_STAR : '') : drag.letter}</span>
|
<span>{drag.blank ? '' : drag.letter}</span>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
+2
-18
@@ -3,7 +3,6 @@
|
|||||||
import { BLANK } from '../lib/placement';
|
import { BLANK } from '../lib/placement';
|
||||||
import { valueForLetter } from '../lib/alphabet';
|
import { valueForLetter } from '../lib/alphabet';
|
||||||
import type { Variant } from '../lib/model';
|
import type { Variant } from '../lib/model';
|
||||||
import { usesStarBlank, BLANK_STAR } from '../lib/variants';
|
|
||||||
|
|
||||||
let {
|
let {
|
||||||
slots,
|
slots,
|
||||||
@@ -67,12 +66,8 @@
|
|||||||
animate:hop={shuffling}
|
animate:hop={shuffling}
|
||||||
onpointerdown={(e) => ondown(e, slot.index)}
|
onpointerdown={(e) => ondown(e, slot.index)}
|
||||||
>
|
>
|
||||||
{#if slot.letter === BLANK}
|
<span class="letter">{slot.letter === BLANK ? '' : slot.letter}</span>
|
||||||
{#if usesStarBlank(variant)}<span class="star">{BLANK_STAR}</span>{/if}
|
{#if slot.letter !== BLANK}<span class="val">{valueForLetter(variant, slot.letter)}</span>{/if}
|
||||||
{:else}
|
|
||||||
<span class="letter">{slot.letter}</span>
|
|
||||||
<span class="val">{valueForLetter(variant, slot.letter)}</span>
|
|
||||||
{/if}
|
|
||||||
</button>
|
</button>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
@@ -138,15 +133,4 @@
|
|||||||
font-size: 0.7rem;
|
font-size: 0.7rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
/* Erudit's blank ("звёздочка") shows its star horizontally centred on the otherwise empty
|
|
||||||
tile face; the top offset centres its ink against the neighbouring letters' block, nudged
|
|
||||||
up a pixel to sit right by eye (it is slightly larger than them so it reads). */
|
|
||||||
.star {
|
|
||||||
position: absolute;
|
|
||||||
top: calc(0.5% - 1px);
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
text-align: center;
|
|
||||||
font-size: 1.7rem;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { gateway } from './gateway';
|
|||||||
import { GatewayError } from './client';
|
import { GatewayError } from './client';
|
||||||
import { navigate, router } from './router.svelte';
|
import { navigate, router } from './router.svelte';
|
||||||
import { errorKey, localeFrom, setLocale, t, type Locale } from './i18n/index.svelte';
|
import { errorKey, localeFrom, setLocale, t, type Locale } from './i18n/index.svelte';
|
||||||
import { languageNeedsServerSync } from './language';
|
|
||||||
import { applyReduceMotion, applyTelegramTheme, applyTheme, type ThemePref } from './theme';
|
import { applyReduceMotion, applyTelegramTheme, applyTheme, type ThemePref } from './theme';
|
||||||
import {
|
import {
|
||||||
insideTelegram,
|
insideTelegram,
|
||||||
@@ -456,13 +455,6 @@ async function adoptSession(s: Session): Promise<void> {
|
|||||||
// account here. preferred_language stays the user's saved choice (written from Settings,
|
// account here. preferred_language stays the user's saved choice (written from Settings,
|
||||||
// and used for out-of-app push routing), but the Telegram bot a user signs in through must
|
// and used for out-of-app push routing), but the Telegram bot a user signs in through must
|
||||||
// not dictate the UI: a ru-bot launch on an English system stays English.
|
// not dictate the UI: a ru-bot launch on an English system stays English.
|
||||||
//
|
|
||||||
// But the banner and out-of-app push routing ARE resolved from preferred_language, so an
|
|
||||||
// explicit device choice the account has not recorded yet (picked while a guest, or
|
|
||||||
// differing from the Telegram system-language seed) would otherwise leave them in the wrong
|
|
||||||
// language until the next Settings change. Reconcile the account to the saved local choice
|
|
||||||
// here; persistLanguageToServer no-ops for guests and when already equal.
|
|
||||||
if (app.localeLocked) void persistLanguageToServer(app.locale);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
handleError(err);
|
handleError(err);
|
||||||
}
|
}
|
||||||
@@ -483,9 +475,6 @@ export async function applyLinkResult(r: LinkResult): Promise<void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
app.profile = await gateway.profileGet();
|
app.profile = await gateway.profileGet();
|
||||||
// A guest who chose a language and then linked in place now has a durable account: push the
|
|
||||||
// saved choice so the banner + push routing follow it (see adoptSession).
|
|
||||||
if (app.localeLocked) void persistLanguageToServer(app.locale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -767,7 +756,7 @@ export function setLocalePref(locale: Locale): void {
|
|||||||
*/
|
*/
|
||||||
async function persistLanguageToServer(locale: Locale): Promise<void> {
|
async function persistLanguageToServer(locale: Locale): Promise<void> {
|
||||||
const p = app.profile;
|
const p = app.profile;
|
||||||
if (!p || !languageNeedsServerSync(p, locale)) return;
|
if (!p || p.isGuest || p.preferredLanguage === locale) return;
|
||||||
try {
|
try {
|
||||||
app.profile = await gateway.profileUpdate({
|
app.profile = await gateway.profileUpdate({
|
||||||
displayName: p.displayName,
|
displayName: p.displayName,
|
||||||
|
|||||||
@@ -257,7 +257,6 @@ export const en = {
|
|||||||
'invitations.with': 'With {names}',
|
'invitations.with': 'With {names}',
|
||||||
'invitations.accept': 'Accept',
|
'invitations.accept': 'Accept',
|
||||||
'invitations.decline': 'Decline',
|
'invitations.decline': 'Decline',
|
||||||
'invitations.declineConfirm': 'Decline invitation?',
|
|
||||||
'invitations.cancel': 'Cancel',
|
'invitations.cancel': 'Cancel',
|
||||||
'invitations.waiting': 'Waiting for replies',
|
'invitations.waiting': 'Waiting for replies',
|
||||||
|
|
||||||
@@ -265,10 +264,10 @@ export const en = {
|
|||||||
'new.withFriends': 'Play with friends',
|
'new.withFriends': 'Play with friends',
|
||||||
'new.pickFriends': 'Choose who to invite',
|
'new.pickFriends': 'Choose who to invite',
|
||||||
'new.searchFriends': 'Search friends',
|
'new.searchFriends': 'Search friends',
|
||||||
'new.gameType': 'Variant',
|
'new.gameType': 'Game type',
|
||||||
'new.invite': 'Send invitation',
|
'new.invite': 'Send invitation',
|
||||||
'new.moveTime': 'Move time',
|
'new.moveTime': 'Move time',
|
||||||
'new.hintsPerPlayer': 'Hints',
|
'new.hintsPerPlayer': 'Hints per player',
|
||||||
'new.multipleWordsPerTurn': 'Multiple words per turn',
|
'new.multipleWordsPerTurn': 'Multiple words per turn',
|
||||||
'new.start': 'Start game',
|
'new.start': 'Start game',
|
||||||
'new.invited': 'Invitation sent.',
|
'new.invited': 'Invitation sent.',
|
||||||
|
|||||||
@@ -258,7 +258,6 @@ export const ru: Record<MessageKey, string> = {
|
|||||||
'invitations.with': 'С {names}',
|
'invitations.with': 'С {names}',
|
||||||
'invitations.accept': 'Принять',
|
'invitations.accept': 'Принять',
|
||||||
'invitations.decline': 'Отклонить',
|
'invitations.decline': 'Отклонить',
|
||||||
'invitations.declineConfirm': 'Отклонить приглашение?',
|
|
||||||
'invitations.cancel': 'Отменить',
|
'invitations.cancel': 'Отменить',
|
||||||
'invitations.waiting': 'Ожидаем ответы',
|
'invitations.waiting': 'Ожидаем ответы',
|
||||||
|
|
||||||
@@ -266,10 +265,10 @@ export const ru: Record<MessageKey, string> = {
|
|||||||
'new.withFriends': 'Игра с друзьями',
|
'new.withFriends': 'Игра с друзьями',
|
||||||
'new.pickFriends': 'Кого пригласить',
|
'new.pickFriends': 'Кого пригласить',
|
||||||
'new.searchFriends': 'Поиск друзей',
|
'new.searchFriends': 'Поиск друзей',
|
||||||
'new.gameType': 'Вариант',
|
'new.gameType': 'Тип игры',
|
||||||
'new.invite': 'Отправить приглашение',
|
'new.invite': 'Отправить приглашение',
|
||||||
'new.moveTime': 'Время на ход',
|
'new.moveTime': 'Время на ход',
|
||||||
'new.hintsPerPlayer': 'Подсказки',
|
'new.hintsPerPlayer': 'Подсказок на игрока',
|
||||||
'new.multipleWordsPerTurn': 'Несколько слов за ход',
|
'new.multipleWordsPerTurn': 'Несколько слов за ход',
|
||||||
'new.start': 'Начать игру',
|
'new.start': 'Начать игру',
|
||||||
'new.invited': 'Приглашение отправлено.',
|
'new.invited': 'Приглашение отправлено.',
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
import { describe, it, expect } from 'vitest';
|
|
||||||
|
|
||||||
import { languageNeedsServerSync } from './language';
|
|
||||||
import type { Profile } from './model';
|
|
||||||
|
|
||||||
// The reconciler only reads isGuest + preferredLanguage; a partial cast keeps the fixture small.
|
|
||||||
const profile = (over: Partial<Profile>): Profile => ({ isGuest: false, preferredLanguage: 'en', ...over }) as Profile;
|
|
||||||
|
|
||||||
describe('languageNeedsServerSync', () => {
|
|
||||||
it('is false without a profile', () => {
|
|
||||||
expect(languageNeedsServerSync(null, 'ru')).toBe(false);
|
|
||||||
expect(languageNeedsServerSync(undefined, 'ru')).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('is false for a guest — guests keep only the client preference', () => {
|
|
||||||
expect(languageNeedsServerSync(profile({ isGuest: true, preferredLanguage: 'en' }), 'ru')).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('is false when the account already matches the locale', () => {
|
|
||||||
expect(languageNeedsServerSync(profile({ preferredLanguage: 'ru' }), 'ru')).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('is true for a real account whose stored language differs (banner + push follow it)', () => {
|
|
||||||
expect(languageNeedsServerSync(profile({ preferredLanguage: 'en' }), 'ru')).toBe(true);
|
|
||||||
expect(languageNeedsServerSync(profile({ preferredLanguage: 'ru' }), 'en')).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
// Interface-language reconciliation. Kept out of app.svelte.ts (a runes module that the
|
|
||||||
// node-env Vitest layer cannot import) so the decision is unit-testable.
|
|
||||||
|
|
||||||
import type { Locale } from './i18n/catalog';
|
|
||||||
import type { Profile } from './model';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* languageNeedsServerSync reports whether the durable account's `preferred_language` should be
|
|
||||||
* rewritten to the chosen interface `locale`. It is true only for a real (non-guest) account
|
|
||||||
* whose stored language differs from the locale; guests keep only the client-side preference,
|
|
||||||
* and an already-matching account is a no-op.
|
|
||||||
*
|
|
||||||
* The UI language follows the device (the local choice / system guess), but the advertising
|
|
||||||
* banner and out-of-app push routing are resolved server-side from `preferred_language`. A saved
|
|
||||||
* device choice the account has not yet recorded — picked while a guest, or differing from the
|
|
||||||
* Telegram system-language seed — would otherwise leave the banner and pushes in the wrong
|
|
||||||
* language until the next Settings change. Both the Settings control and the on-load reconciler
|
|
||||||
* gate their write on this.
|
|
||||||
*/
|
|
||||||
export function languageNeedsServerSync(profile: Profile | null | undefined, locale: Locale): boolean {
|
|
||||||
return !!profile && !profile.isGuest && profile.preferredLanguage !== locale;
|
|
||||||
}
|
|
||||||
@@ -5,8 +5,6 @@ import {
|
|||||||
availableVariants,
|
availableVariants,
|
||||||
supportsMultipleWordsToggle,
|
supportsMultipleWordsToggle,
|
||||||
multipleWordsForRequest,
|
multipleWordsForRequest,
|
||||||
usesStarBlank,
|
|
||||||
BLANK_STAR,
|
|
||||||
} from './variants';
|
} from './variants';
|
||||||
|
|
||||||
describe('ALL_VARIANTS', () => {
|
describe('ALL_VARIANTS', () => {
|
||||||
@@ -55,16 +53,3 @@ describe('multipleWordsForRequest', () => {
|
|||||||
expect(multipleWordsForRequest('scrabble_en', true)).toBe(true);
|
expect(multipleWordsForRequest('scrabble_en', true)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('usesStarBlank', () => {
|
|
||||||
it('marks the blank with a star for Erudit only', () => {
|
|
||||||
expect(usesStarBlank('erudit_ru')).toBe(true);
|
|
||||||
expect(usesStarBlank('scrabble_ru')).toBe(false);
|
|
||||||
expect(usesStarBlank('scrabble_en')).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('BLANK_STAR is the heavy teardrop-spoked asterisk (U+273B)', () => {
|
|
||||||
expect(BLANK_STAR).toBe('✻');
|
|
||||||
expect(BLANK_STAR.codePointAt(0)).toBe(0x273b);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -48,20 +48,6 @@ export const VARIANT_FLAG: Record<Variant, string> = {
|
|||||||
// ru -> Russian + Эрудит.
|
// ru -> Russian + Эрудит.
|
||||||
export const VARIANT_LANGUAGE: Record<Variant, 'en' | 'ru'> = { scrabble_en: 'en', scrabble_ru: 'ru', erudit_ru: 'ru' };
|
export const VARIANT_LANGUAGE: Record<Variant, 'en' | 'ru'> = { scrabble_en: 'en', scrabble_ru: 'ru', erudit_ru: 'ru' };
|
||||||
|
|
||||||
// BLANK_STAR is the glyph drawn on an Эрудит blank tile: the variant's blank is the
|
|
||||||
// "звёздочка" (star) chip, so it carries a star rather than a bare face. U+273B HEAVY
|
|
||||||
// TEARDROP-SPOKED ASTERISK.
|
|
||||||
export const BLANK_STAR = '✻';
|
|
||||||
|
|
||||||
// usesStarBlank reports whether a variant marks its blank tiles with BLANK_STAR. Only
|
|
||||||
// Эрудит does: an empty rack blank shows the star centred, and a placed blank carries it
|
|
||||||
// in the value corner (the corner is free — a blank has no point value). The Scrabble
|
|
||||||
// variants leave the blank unmarked (an empty rack face; a placed blank shown by its
|
|
||||||
// designated letter alone).
|
|
||||||
export function usesStarBlank(v: Variant): boolean {
|
|
||||||
return v === 'erudit_ru';
|
|
||||||
}
|
|
||||||
|
|
||||||
// availableVariants gates ALL_VARIANTS by the player's variant preferences (the set
|
// availableVariants gates ALL_VARIANTS by the player's variant preferences (the set
|
||||||
// they enabled in Settings). An empty or absent set is ungated (returns every variant)
|
// they enabled in Settings). An empty or absent set is ungated (returns every variant)
|
||||||
// — a safety fallback; a real profile always carries at least one preference.
|
// — a safety fallback; a real profile always carries at least one preference.
|
||||||
|
|||||||
+20
-83
@@ -3,19 +3,17 @@
|
|||||||
import { SvelteMap, SvelteSet } from 'svelte/reactivity';
|
import { SvelteMap, SvelteSet } from 'svelte/reactivity';
|
||||||
import Screen from '../components/Screen.svelte';
|
import Screen from '../components/Screen.svelte';
|
||||||
import TabBar from '../components/TabBar.svelte';
|
import TabBar from '../components/TabBar.svelte';
|
||||||
import Modal from '../components/Modal.svelte';
|
|
||||||
import { app, handleError, refreshFeedbackBadge, seedChatUnread } from '../lib/app.svelte';
|
import { app, handleError, refreshFeedbackBadge, seedChatUnread } from '../lib/app.svelte';
|
||||||
import { connection } from '../lib/connection.svelte';
|
import { connection } from '../lib/connection.svelte';
|
||||||
import { gateway } from '../lib/gateway';
|
import { gateway } from '../lib/gateway';
|
||||||
import { navigate } from '../lib/router.svelte';
|
import { navigate } from '../lib/router.svelte';
|
||||||
import { t } from '../lib/i18n/index.svelte';
|
import { t, type MessageKey } from '../lib/i18n/index.svelte';
|
||||||
import { resultBadge } from '../lib/result';
|
import { resultBadge } from '../lib/result';
|
||||||
import { badgeKind } from '../lib/unread';
|
import { badgeKind } from '../lib/unread';
|
||||||
import { getLobby, setLobby } from '../lib/lobbycache';
|
import { getLobby, setLobby } from '../lib/lobbycache';
|
||||||
import { preloadGames } from '../lib/preload';
|
import { preloadGames } from '../lib/preload';
|
||||||
import { gamePhase, groupGames, orderedSeats, scoreStanding, shouldBlink, type LobbyPhase } from '../lib/lobbysort';
|
import { gamePhase, groupGames, orderedSeats, scoreStanding, shouldBlink, type LobbyPhase } from '../lib/lobbysort';
|
||||||
import type { AccountRef, GameView, Invitation } from '../lib/model';
|
import type { AccountRef, GameView, Invitation } from '../lib/model';
|
||||||
import { VARIANT_FLAG, VARIANT_RULES } from '../lib/variants';
|
|
||||||
|
|
||||||
let games = $state<GameView[]>([]);
|
let games = $state<GameView[]>([]);
|
||||||
let invitations = $state<Invitation[]>([]);
|
let invitations = $state<Invitation[]>([]);
|
||||||
@@ -211,14 +209,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The invitation pending a decline confirmation: the ❌ opens a modal (mirroring the
|
const variantKey: Record<string, MessageKey> = {
|
||||||
// in-game resign confirmation) rather than declining on the first tap.
|
scrabble_en: 'new.english',
|
||||||
let declineTarget = $state<Invitation | null>(null);
|
scrabble_ru: 'new.russian',
|
||||||
function confirmDecline() {
|
erudit_ru: 'new.erudit',
|
||||||
const inv = declineTarget;
|
};
|
||||||
declineTarget = null;
|
|
||||||
if (inv) declineInvite(inv);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Screen title={app.profile?.displayName ?? t('app.title')}>
|
<Screen title={app.profile?.displayName ?? t('app.title')}>
|
||||||
@@ -235,23 +230,16 @@
|
|||||||
<span class="sub">{t('invitations.waiting')}</span>
|
<span class="sub">{t('invitations.waiting')}</span>
|
||||||
{:else}
|
{:else}
|
||||||
<span class="who">{t('invitations.from', { name: inv.inviter.displayName })}</span>
|
<span class="who">{t('invitations.from', { name: inv.inviter.displayName })}</span>
|
||||||
<span class="vrow">
|
<span class="sub">{t(variantKey[inv.variant] ?? 'new.english')}</span>
|
||||||
{#if VARIANT_FLAG[inv.variant]}
|
|
||||||
<span class="vflag">{VARIANT_FLAG[inv.variant]}</span>
|
|
||||||
{:else}
|
|
||||||
<img class="vflag-img" src="flag-ussr.svg" alt="" />
|
|
||||||
{/if}
|
|
||||||
<span class="sub">{t(VARIANT_RULES[inv.variant])}</span>
|
|
||||||
</span>
|
|
||||||
{/if}
|
{/if}
|
||||||
{#if !inv.multipleWordsPerTurn}<span class="sub">{t('game.oneWordRule')}</span>{/if}
|
{#if !inv.multipleWordsPerTurn}<span class="sub">{t('game.oneWordRule')}</span>{/if}
|
||||||
</span>
|
</span>
|
||||||
<span class="acts">
|
<span class="acts">
|
||||||
{#if inv.inviter.accountId === myId}
|
{#if inv.inviter.accountId === myId}
|
||||||
<button class="iconbtn" onclick={() => cancelInvite(inv)} aria-label={t('invitations.cancel')}>❌</button>
|
<button class="ghost" onclick={() => cancelInvite(inv)}>{t('invitations.cancel')}</button>
|
||||||
{:else}
|
{:else}
|
||||||
<button class="iconbtn" onclick={() => acceptInvite(inv)} aria-label={t('invitations.accept')}>✅</button>
|
<button class="btn" onclick={() => acceptInvite(inv)}>{t('invitations.accept')}</button>
|
||||||
<button class="iconbtn" onclick={() => (declineTarget = inv)} aria-label={t('invitations.decline')}>❌</button>
|
<button class="ghost" onclick={() => declineInvite(inv)}>{t('invitations.decline')}</button>
|
||||||
{/if}
|
{/if}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -320,15 +308,6 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if declineTarget}
|
|
||||||
<Modal title={t('invitations.declineConfirm')} onclose={() => (declineTarget = null)}>
|
|
||||||
<div class="confirm-row">
|
|
||||||
<button class="cancel" onclick={() => (declineTarget = null)}>{t('common.cancel')}</button>
|
|
||||||
<button class="danger" onclick={confirmDecline} disabled={!connection.online}>{t('invitations.decline')}</button>
|
|
||||||
</div>
|
|
||||||
</Modal>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#snippet tabbar()}
|
{#snippet tabbar()}
|
||||||
<TabBar>
|
<TabBar>
|
||||||
<button class="tab" disabled={atGameLimit} onclick={() => navigate('/new')}>
|
<button class="tab" disabled={atGameLimit} onclick={() => navigate('/new')}>
|
||||||
@@ -386,40 +365,6 @@
|
|||||||
border-radius: var(--radius);
|
border-radius: var(--radius);
|
||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
/* The middle column grows; the envelope and the action column stay at their natural width. */
|
|
||||||
.invite .info {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
/* The variant row in an invitation: flag + the rules summary (mirrors NewGame). */
|
|
||||||
.vrow {
|
|
||||||
display: flex;
|
|
||||||
align-items: baseline;
|
|
||||||
gap: 6px;
|
|
||||||
}
|
|
||||||
.vflag {
|
|
||||||
font-size: 1.1rem;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
.vflag-img {
|
|
||||||
width: 1.3rem;
|
|
||||||
height: auto;
|
|
||||||
border-radius: 2px;
|
|
||||||
align-self: center;
|
|
||||||
}
|
|
||||||
/* Borderless icon action (✅ / ❌), like the in-game .hicon buttons. */
|
|
||||||
.iconbtn {
|
|
||||||
background: none;
|
|
||||||
border: none;
|
|
||||||
color: var(--text);
|
|
||||||
font-size: 1.3rem;
|
|
||||||
line-height: 1;
|
|
||||||
padding: 4px 6px;
|
|
||||||
border-radius: var(--radius-sm);
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.iconbtn:active {
|
|
||||||
background: var(--bg-elev);
|
|
||||||
}
|
|
||||||
/* Game rows are a compact, flat list: no per-card frame, a hairline divider between
|
/* Game rows are a compact, flat list: no per-card frame, a hairline divider between
|
||||||
consecutive rows. */
|
consecutive rows. */
|
||||||
.list {
|
.list {
|
||||||
@@ -571,31 +516,23 @@
|
|||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* The ✅ / ❌ actions stack vertically with a small gap — a min-width right column. */
|
|
||||||
.acts {
|
.acts {
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 10px;
|
|
||||||
flex: 0 0 auto;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
/* Decline-confirmation modal (mirrors the in-game resign confirm). */
|
|
||||||
.confirm-row {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
|
flex: 0 0 auto;
|
||||||
}
|
}
|
||||||
.confirm-row button {
|
.btn {
|
||||||
flex: 1;
|
padding: 8px 12px;
|
||||||
padding: 11px;
|
border: 1px solid var(--accent);
|
||||||
|
background: var(--accent);
|
||||||
|
color: var(--accent-text);
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
|
}
|
||||||
|
.ghost {
|
||||||
|
padding: 8px 12px;
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
background: var(--surface);
|
background: var(--surface);
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
font-weight: 600;
|
border-radius: var(--radius-sm);
|
||||||
}
|
|
||||||
.danger {
|
|
||||||
background: var(--danger) !important;
|
|
||||||
color: #fff !important;
|
|
||||||
border-color: var(--danger) !important;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -67,12 +67,9 @@
|
|||||||
let friends = $state<AccountRef[]>([]);
|
let friends = $state<AccountRef[]>([]);
|
||||||
let selected = $state<string[]>([]);
|
let selected = $state<string[]>([]);
|
||||||
let friendFilter = $state('');
|
let friendFilter = $state('');
|
||||||
// A lone offered variant is pre-selected and its picker disabled (nothing else to choose);
|
// No default game type yet — the player must pick one (a smarter default from play
|
||||||
// with several, the player picks. '' renders the disabled placeholder option.
|
// history / language would be a future refinement). '' renders the disabled placeholder option.
|
||||||
let inviteVariant = $state<Variant | ''>('');
|
let inviteVariant = $state<Variant | ''>('');
|
||||||
$effect(() => {
|
|
||||||
if (variants.length === 1 && !inviteVariant) inviteVariant = variants[0].id;
|
|
||||||
});
|
|
||||||
let timeoutSecs = $state(86400);
|
let timeoutSecs = $state(86400);
|
||||||
let hints = $state(1);
|
let hints = $state(1);
|
||||||
|
|
||||||
@@ -155,7 +152,6 @@
|
|||||||
<input type="checkbox" bind:checked={multipleWords} />
|
<input type="checkbox" bind:checked={multipleWords} />
|
||||||
</label>
|
</label>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="grow"></div>
|
|
||||||
<p class="movelimit">{opponent === 'ai' ? t('new.aiInactiveLimit') : t('new.moveLimit', { n: AUTO_MATCH_HOURS })}</p>
|
<p class="movelimit">{opponent === 'ai' ? t('new.aiInactiveLimit') : t('new.moveLimit', { n: AUTO_MATCH_HOURS })}</p>
|
||||||
{#if opponent === 'random'}<p class="searchhint">{t('new.searchHint')}</p>{/if}
|
{#if opponent === 'random'}<p class="searchhint">{t('new.searchHint')}</p>{/if}
|
||||||
<button
|
<button
|
||||||
@@ -183,7 +179,7 @@
|
|||||||
<div class="settings-row">
|
<div class="settings-row">
|
||||||
<label class="field">
|
<label class="field">
|
||||||
<span>{t('new.gameType')}</span>
|
<span>{t('new.gameType')}</span>
|
||||||
<select bind:value={inviteVariant} class:placeholder={!inviteVariant} disabled={variants.length === 1}>
|
<select bind:value={inviteVariant} class:placeholder={!inviteVariant}>
|
||||||
<option value="" disabled>—</option>
|
<option value="" disabled>—</option>
|
||||||
{#each variants as v (v.id)}<option value={v.id}>{t(v.label)}</option>{/each}
|
{#each variants as v (v.id)}<option value={v.id}>{t(v.label)}</option>{/each}
|
||||||
</select>
|
</select>
|
||||||
@@ -391,11 +387,6 @@
|
|||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
/* Pushes the auto-match start cluster (move-limit hint + Start button) to the bottom,
|
|
||||||
mirroring the friend-game invite button pinned by the .fg scroll area. */
|
|
||||||
.grow {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
.invite {
|
.invite {
|
||||||
flex: 0 0 auto;
|
flex: 0 0 auto;
|
||||||
padding: 14px;
|
padding: 14px;
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
{#each bestMoves as bm (bm.variant)}
|
{#each bestMoves as bm (bm.variant)}
|
||||||
<span class="variant">{t(variantNameKey(bm.variant))}</span>
|
<span class="variant">{t(variantNameKey(bm.variant))}</span>
|
||||||
<span class="score">{bm.score}</span>
|
<span class="score">{bm.score}</span>
|
||||||
<span class="wordcell"><WordTiles word={bm.word} variant={bm.variant} /></span>
|
<span class="wordcell"><WordTiles word={bm.word} /></span>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user