Files
scrabble-game/backend/internal/game/seatname_test.go
T
Ilia Denisov 183e08ec80
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 15s
CI / ui (pull_request) Successful in 48s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m10s
feat(robot): per-game display names from a wide name corpus
Decouple the displayed opponent name from the small pool of durable robot
accounts: the disguised auto-match robot now gets a freshly composed name each
game, stamped on a new game_players.display_name seat snapshot. The snapshot
also captures humans' names, freezing what an opponent sees for the life of a
game (a later rename no longer rewrites past games); readers fall back to the
account's current name for pre-migration rows.

Names come from a wide composed corpus (internal/robot/namevariety.go): Western
locales (EN/DE/ES/IT/FR/PT), native Japanese/Chinese names, a gender-agreed
Russian pool, and human-style handles. Routing keeps Pick's spirit -- a Russian
game draws Cyrillic + <=20% Latin and never a CJK script; an English game the
full corpus -- via robot.PickNamed.

Loosen account.ValidateDisplayName (and the UI mirror) to admit a trailing run
of up to five digits, so "Player2007"-style handles are valid for humans too
and the disguised robot stays indistinguishable.

Migration 00007 adds game_players.display_name (additive, NOT NULL DEFAULT '');
jet regenerated. Docs (ARCHITECTURE 7, FUNCTIONAL + _ru, PLAN, README) updated.
2026-06-16 12:28:04 +02:00

41 lines
1.4 KiB
Go

package game
import (
"context"
"testing"
"github.com/google/uuid"
)
// TestSeatNamesUsesSnapshot checks seatNames returns each seat's stored display-name
// snapshot directly, without consulting the account store (svc.accounts is nil here, so
// any lookup would be skipped or panic).
func TestSeatNamesUsesSnapshot(t *testing.T) {
svc := &Service{}
g := Game{
Players: 2,
Seats: []Seat{
{Seat: 0, AccountID: uuid.New(), DisplayName: "Аня2007"},
{Seat: 1, AccountID: uuid.New(), DisplayName: "DarkWolf"},
},
}
got := svc.seatNames(context.Background(), g)
want := []string{"Аня2007", "DarkWolf"}
if len(got) != len(want) || got[0] != want[0] || got[1] != want[1] {
t.Fatalf("seatNames = %v, want %v", got, want)
}
}
// TestSeatDisplayNameFallbackEmpty checks the resolver yields "" — rather than panicking
// — for a seat with no snapshot when no account store is available (the empty open seat
// and pre-snapshot legacy-row paths).
func TestSeatDisplayNameFallbackEmpty(t *testing.T) {
svc := &Service{}
if got := svc.seatDisplayName(context.Background(), Seat{Seat: 0, AccountID: uuid.New()}); got != "" {
t.Errorf("seatDisplayName with no snapshot and no store = %q, want empty", got)
}
if got := svc.seatDisplayName(context.Background(), Seat{Seat: 1, AccountID: uuid.Nil}); got != "" {
t.Errorf("empty-seat name = %q, want empty", got)
}
}