feat(lobby): enter the game immediately and wait for the opponent inside it
CI / changes (pull_request) Successful in 1s
CI / unit (pull_request) Successful in 8s
CI / integration (pull_request) Successful in 14s
CI / ui (pull_request) Successful in 45s
CI / gate (pull_request) Successful in 1s
CI / deploy (pull_request) Successful in 1m4s

Quick auto-match no longer waits on a separate screen: Enqueue opens a real game seating the caller with an empty opponent seat (new game status 'open') and the player enters it at once. A second human searching the same variant+rule joins that open game; otherwise a background reaper seats a robot after a 90s + random 0-90s wait, pushing a new in-app opponent_joined event that fills the opponent card and re-enables resign and chat in place.

Matchmaking state is now the open games in the database (the in-memory pool, lobby.poll and lobby.cancel are gone), serialised by a per-bucket advisory lock. While a game is open the starter may move on their turn, but resign, chat and nudge are refused; the lobby and opponent card show "searching for opponent".

Schema edited in the baseline (no prod data): 'open' status, nullable game_players.account_id for the empty seat, and a games.open_deadline_at stamp; jet code regenerated.
This commit is contained in:
Ilia Denisov
2026-06-12 16:00:22 +02:00
parent 10dc1f0d48
commit c305363ccd
42 changed files with 1248 additions and 768 deletions
+8 -15
View File
@@ -138,36 +138,29 @@ func TestRobotPlaysAutoMatchToEnd(t *testing.T) {
}
}
// TestMatchmakerSubstitutesRobotEndToEnd checks a waiting human is paired with a
// real robot account after the wait window, discoverable through Poll.
// TestMatchmakerSubstitutesRobotEndToEnd checks the reaper fills an open game's empty
// seat with a real robot account once its wait window has elapsed.
func TestMatchmakerSubstitutesRobotEndToEnd(t *testing.T) {
ctx := context.Background()
clearOpenGames(t)
robots := newRobotService(t, newGameService())
if err := robots.EnsurePool(ctx); err != nil {
t.Fatalf("ensure pool: %v", err)
}
mm := newMatchmaker(t, robots, 10*time.Second)
// Zero wait and jitter so the opened game is immediately due for a robot.
mm := newMatchmaker(t, robots, 0, 0)
human := provisionAccount(t)
before := time.Now()
r, err := mm.Enqueue(ctx, human, engine.VariantEnglish, true)
if err != nil {
t.Fatalf("enqueue: %v", err)
}
if r.Matched {
t.Fatal("first enqueue must wait")
t.Fatal("first enqueue must open a game awaiting an opponent")
}
mm.Reap(ctx, before.Add(11*time.Second))
got, err := mm.Poll(ctx, human)
if err != nil {
t.Fatalf("poll: %v", err)
}
if !got.Matched {
t.Fatal("expected a substituted game after the wait window")
}
seats, _, status, err := newGameService().Participants(ctx, got.Game.ID)
mm.Reap(ctx, time.Now().Add(time.Second)) // past the (zero) wait window
seats, _, status, err := newGameService().Participants(ctx, r.Game.ID)
if err != nil {
t.Fatalf("participants: %v", err)
}