feat(social): per-game friend request to disguised robots + lobby/stats/tile cosmetics
CI / changes (pull_request) Successful in 1s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 13s
CI / ui (pull_request) Successful in 54s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m25s

Functional: the in-game add-friend handshake aimed at an auto-match opponent who is
secretly a pooled robot now records the request per (game, seat) in a new
robot_friend_requests table -- never against the shared robot account -- mirroring the
robot_blocks pattern. The shared account stays out of friendships, the "requested" state
is pinned to the seat (not leaked across the player's other games), the robot ignores it,
and a background reaper drops the row 7 days after its game finishes. The outgoing-requests
list carries these per-game rows so the seat control stays disabled across reloads. No
withdraw UI, per owner decision.

Cosmetics:
- Lobby: an in-progress game tints the viewer's own score number green when leading or
  tied, red when trailing (reusing --ok/--danger); scores now render in seat-number order,
  matching the over-the-board scoreboard.
- Stats: the per-variant best move is laid out on two lines -- the variant label, then the
  score (right-aligned in its column) and the word tiles (left-aligned) below it.
- Dark theme: the played-tile background is a touch darker so a player-placed tile reads
  with more contrast (light theme unchanged).

Docs (ARCHITECTURE, FUNCTIONAL + _ru mirror, backend README, UI_DESIGN) updated in the
same change.
This commit is contained in:
Ilia Denisov
2026-06-19 21:39:27 +02:00
parent 9ded5d3d86
commit c127bc9f0e
32 changed files with 854 additions and 65 deletions
+54 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { gamePhase, groupGames, isMyTurn, shouldBlink } from './lobbysort';
import { gamePhase, groupGames, isMyTurn, orderedSeats, scoreStanding, shouldBlink } from './lobbysort';
import type { GameView, Seat } from './model';
const ME = 'me';
@@ -118,6 +118,59 @@ describe('gamePhase', () => {
});
});
describe('scoreStanding', () => {
const withScores = (status: GameView['status'], myScore: number, oppScore: number): GameView => ({
...game('g', status, 0, 0),
seats: [
{ ...seat(0, ME), score: myScore },
{ ...seat(1, 'opp'), score: oppScore },
],
});
it('greens a leading or tied active game, reds a losing one', () => {
expect(scoreStanding(withScores('active', 30, 10), ME)).toBe('win');
expect(scoreStanding(withScores('active', 10, 10), ME)).toBe('win'); // a tie counts as green
expect(scoreStanding(withScores('active', 5, 10), ME)).toBe('lose');
});
it('is null for any non-active game (open or finished)', () => {
expect(scoreStanding(withScores('finished', 30, 10), ME)).toBeNull();
expect(scoreStanding(withScores('open', 0, 0), ME)).toBeNull();
});
it('is null when the viewer is not seated or has no opponent', () => {
expect(scoreStanding(withScores('active', 30, 10), 'stranger')).toBeNull();
const solo: GameView = { ...game('g', 'active', 0, 0), seats: [{ ...seat(0, ME), score: 9 }] };
expect(scoreStanding(solo, ME)).toBeNull();
});
it('compares against the strongest opponent in a multiplayer game', () => {
const g3: GameView = {
...game('g', 'active', 0, 0),
players: 3,
seats: [
{ ...seat(0, ME), score: 40 },
{ ...seat(1, 'a'), score: 35 },
{ ...seat(2, 'b'), score: 50 }, // b is ahead -> losing
],
};
expect(scoreStanding(g3, ME)).toBe('lose');
});
});
describe('orderedSeats', () => {
it('returns seats in seat-number order without mutating the source', () => {
const g: GameView = {
...game('g', 'active', 0, 0),
seats: [seat(2, 'c'), seat(0, ME), seat(1, 'b')],
};
const src = g.seats;
expect(orderedSeats(g).map((s) => s.seat)).toEqual([0, 1, 2]);
expect(g.seats).toBe(src); // the source array is left untouched
expect(g.seats.map((s) => s.seat)).toEqual([2, 0, 1]);
});
});
describe('shouldBlink', () => {
it('blinks on a transition into mine or finished', () => {
expect(shouldBlink('theirs', 'mine')).toBe(true);