feat(offline): implicit net-state model, two-tier version gate, unified lobby
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 19s
CI / ui (pull_request) Successful in 1m13s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Failing after 20s

Land the offline-model redesign (ANDROID_PLAN.md O1-O7): replace the explicit offline toggle with a single detected net-state machine, unify the lobby, and add a two-tier client-version gate. Contour-safe: both version vars empty => dormant, the wire change is additive, so web/pwa/vk/tg behaviour is unchanged unless the gate is deliberately configured.

O1 net-state reducer (test-first). O2 store + wiring (connection/offline shims; +@capacitor/network). O3 remove the offline toggle + migrate the pref. O4 two-tier gate: hard update_required degrades to an offline Update/Play-offline notice (not terminal); soft GATEWAY_RECOMMENDED_CLIENT_VERSION -> X-Update-Recommended nudge. O5 unified lobby (device-local + greyed-from-cache server games; self-set identity; closes G-step-0). O6 create flows (with-friends online/offline segment + offline dict guard). O7 docs.

Wire the version gate through the deploy: GATEWAY_MIN_CLIENT_VERSION + GATEWAY_RECOMMENDED_CLIENT_VERSION are plain (unprefixed) Gitea vars, passed via compose + ci.yaml (test) + prod-deploy.yaml + write-prod-env.sh (prod) + .env.example, so the gate is live when set (a test-contour commit-hash version fails open; empty => dormant). Disable the manual android-build CI workflow for now (rename .disabled). Bump the app bundle budget 127->130 KB for the added always-loaded wiring.

Tests: gateway go green (incl. two-tier gate over a real HTTP handler), compose --no-interpolate confirms the gateway env, svelte-check 0/0, vitest 617, e2e 122/122 (chromium + webkit).
This commit is contained in:
Ilia Denisov
2026-07-13 01:44:28 +02:00
parent 09e05eef18
commit 872804e02e
53 changed files with 1979 additions and 973 deletions
+46 -30
View File
@@ -3,6 +3,9 @@ import { gamePhase, groupGames, isMyTurn, orderedSeats, scoreStanding, shouldBli
import type { GameView, Seat } from './model';
const ME = 'me';
// The self-id set the lobby passes (server user id + device-local guest id); ME is used as a bare seat
// id where a single seat is built, MINE where a function takes the whole "you" set.
const MINE = [ME];
const seat = (s: number, accountId: string): Seat => ({
seat: s,
accountId,
@@ -41,7 +44,7 @@ describe('groupGames', () => {
game('b', 'active', 1, 100), // their turn
game('c', 'finished', 0, 100),
],
ME,
MINE,
{},
);
expect(g.yourTurn.map((x) => x.id)).toEqual(['a']);
@@ -59,7 +62,7 @@ describe('groupGames', () => {
game('f_new', 'finished', 0, 200),
game('f_old', 'finished', 0, 100),
],
ME,
MINE,
{},
);
expect(g.yourTurn.map((x) => x.id)).toEqual(['y_old', 'y_new']);
@@ -77,7 +80,7 @@ describe('groupGames', () => {
game('f_unread', 'finished', 0, 100),
game('f_new', 'finished', 0, 300), // finished ignores unread, stays newest-first
],
ME,
MINE,
{ y_unread: true, t_unread: true, f_unread: true },
);
// Unread is the primary key, so it overrides the within-section activity order.
@@ -88,9 +91,9 @@ describe('groupGames', () => {
});
it('isMyTurn is false for a finished game even at my seat', () => {
expect(isMyTurn(game('x', 'finished', 0, 0), ME)).toBe(false);
expect(isMyTurn(game('x', 'active', 0, 0), ME)).toBe(true);
expect(isMyTurn(game('x', 'active', 1, 0), ME)).toBe(false);
expect(isMyTurn(game('x', 'finished', 0, 0), MINE)).toBe(false);
expect(isMyTurn(game('x', 'active', 0, 0), MINE)).toBe(true);
expect(isMyTurn(game('x', 'active', 1, 0), MINE)).toBe(false);
});
it('treats an open game (awaiting an opponent) as in progress, not finished', () => {
@@ -99,23 +102,36 @@ describe('groupGames', () => {
game('open_mine', 'open', 0, 100), // my turn while waiting
game('open_wait', 'open', 1, 100), // the empty seat's turn
],
ME,
MINE,
{},
);
expect(g.yourTurn.map((x) => x.id)).toEqual(['open_mine']);
expect(g.theirTurn.map((x) => x.id)).toEqual(['open_wait']);
expect(g.finished).toEqual([]);
expect(isMyTurn(game('x', 'open', 0, 0), ME)).toBe(true);
expect(isMyTurn(game('x', 'open', 0, 0), MINE)).toBe(true);
});
it('recognises "you" under any of the self ids (local game under localGuestId, server under userId)', () => {
// After reconciliation a device-local game seats you under the local guest id and a server game
// under the user id; the two differ (ids never collide) and both must count as your turn.
const localGame: GameView = { ...game('local', 'active', 0, 100), seats: [seat(0, 'guest'), seat(1, 'robot')] };
const serverGame: GameView = { ...game('server', 'active', 0, 100), seats: [seat(0, ME), seat(1, 'opp')] };
const both = ['guest', ME];
expect(isMyTurn(localGame, both)).toBe(true);
expect(isMyTurn(serverGame, both)).toBe(true);
expect(isMyTurn(localGame, [ME])).toBe(false); // a single id misses the other source's game
const g = groupGames([localGame, serverGame], both, {});
expect(g.yourTurn.map((x) => x.id).sort()).toEqual(['local', 'server']);
});
});
describe('gamePhase', () => {
it('maps each game to its lobby bucket (open folds into mine/theirs like active)', () => {
expect(gamePhase(game('x', 'active', 0, 0), ME)).toBe('mine');
expect(gamePhase(game('x', 'active', 1, 0), ME)).toBe('theirs');
expect(gamePhase(game('x', 'open', 0, 0), ME)).toBe('mine');
expect(gamePhase(game('x', 'open', 1, 0), ME)).toBe('theirs');
expect(gamePhase(game('x', 'finished', 0, 0), ME)).toBe('finished');
expect(gamePhase(game('x', 'active', 0, 0), MINE)).toBe('mine');
expect(gamePhase(game('x', 'active', 1, 0), MINE)).toBe('theirs');
expect(gamePhase(game('x', 'open', 0, 0), MINE)).toBe('mine');
expect(gamePhase(game('x', 'open', 1, 0), MINE)).toBe('theirs');
expect(gamePhase(game('x', 'finished', 0, 0), MINE)).toBe('finished');
});
});
@@ -131,38 +147,38 @@ describe('scoreStanding', () => {
it('greens the leading viewer and reds a trailing one; the opponent stays muted', () => {
const lead = withScores('active', 30, 10);
expect(scoreStanding(lead, ME, at(lead, ME))).toBe('win');
expect(scoreStanding(lead, ME, at(lead, 'opp'))).toBeNull(); // a trailing opponent is not coloured
expect(scoreStanding(lead, MINE, at(lead, ME))).toBe('win');
expect(scoreStanding(lead, MINE, at(lead, 'opp'))).toBeNull(); // a trailing opponent is not coloured
const behind = withScores('active', 5, 10);
expect(scoreStanding(behind, ME, at(behind, ME))).toBe('lose');
expect(scoreStanding(behind, ME, at(behind, 'opp'))).toBeNull(); // a leading opponent is not coloured
expect(scoreStanding(behind, MINE, at(behind, ME))).toBe('lose');
expect(scoreStanding(behind, MINE, at(behind, 'opp'))).toBeNull(); // a leading opponent is not coloured
});
it('greens both seats on an equal non-zero score', () => {
const tie = withScores('active', 10, 10);
expect(scoreStanding(tie, ME, at(tie, ME))).toBe('win');
expect(scoreStanding(tie, ME, at(tie, 'opp'))).toBe('win');
expect(scoreStanding(tie, MINE, at(tie, ME))).toBe('win');
expect(scoreStanding(tie, MINE, at(tie, 'opp'))).toBe('win');
});
it('leaves a fresh 0:0 board muted (nobody has scored yet)', () => {
const fresh = withScores('active', 0, 0);
expect(scoreStanding(fresh, ME, at(fresh, ME))).toBeNull();
expect(scoreStanding(fresh, ME, at(fresh, 'opp'))).toBeNull();
expect(scoreStanding(fresh, MINE, at(fresh, ME))).toBeNull();
expect(scoreStanding(fresh, MINE, at(fresh, 'opp'))).toBeNull();
});
it('is null for any non-active game (open or finished)', () => {
const fin = withScores('finished', 30, 10);
expect(scoreStanding(fin, ME, at(fin, ME))).toBeNull();
expect(scoreStanding(fin, MINE, at(fin, ME))).toBeNull();
const op = withScores('open', 0, 0);
expect(scoreStanding(op, ME, at(op, ME))).toBeNull();
expect(scoreStanding(op, MINE, at(op, ME))).toBeNull();
});
it('is null when the viewer is not seated or has no opponent', () => {
const g = withScores('active', 30, 10);
expect(scoreStanding(g, 'stranger', at(g, ME))).toBeNull();
expect(scoreStanding(g, ['stranger'], at(g, ME))).toBeNull();
const solo: GameView = { ...game('g', 'active', 0, 0), seats: [{ ...seat(0, ME), score: 9 }] };
expect(scoreStanding(solo, ME, solo.seats[0])).toBeNull();
expect(scoreStanding(solo, MINE, solo.seats[0])).toBeNull();
});
it('compares against the strongest opponent in a multiplayer game', () => {
@@ -175,8 +191,8 @@ describe('scoreStanding', () => {
{ ...seat(2, 'b'), score: 50 }, // b is ahead -> the viewer is losing
],
};
expect(scoreStanding(g3, ME, at(g3, ME))).toBe('lose');
expect(scoreStanding(g3, ME, at(g3, 'b'))).toBeNull(); // a leading opponent is not coloured
expect(scoreStanding(g3, MINE, at(g3, ME))).toBe('lose');
expect(scoreStanding(g3, MINE, at(g3, 'b'))).toBeNull(); // a leading opponent is not coloured
});
it('greens every seat tied with the viewer for the lead in a multiplayer game', () => {
@@ -189,9 +205,9 @@ describe('scoreStanding', () => {
{ ...seat(2, 'b'), score: 20 }, // trailing -> muted
],
};
expect(scoreStanding(g3, ME, at(g3, ME))).toBe('win');
expect(scoreStanding(g3, ME, at(g3, 'a'))).toBe('win');
expect(scoreStanding(g3, ME, at(g3, 'b'))).toBeNull();
expect(scoreStanding(g3, MINE, at(g3, ME))).toBe('win');
expect(scoreStanding(g3, MINE, at(g3, 'a'))).toBe('win');
expect(scoreStanding(g3, MINE, at(g3, 'b'))).toBeNull();
});
});