Built the whole app from an empty repo: a multiplayer online version… #1

Merged
cmoriarty merged 4 commits from osf/174-build-scratch-a-multiplayer-online-card into main 2026-11-06 05:17:51 -05:00
Owner

What was done

  • Built the whole app from an empty repo: a multiplayer online version of Scratch (an Oh Hell–family trick-taking card game) playable in real time across browser tabs.
  • Added a pure, framework-free rules engine (shared by server and client) covering 2–5 players, both round schedules, trump, bidding, play, scratch scoring, winner determination, and both house rules, fully unit-tested.
  • Added a Socket.IO server that owns rooms and authoritative game state, enforces legal moves, auto-plays for disconnected players so a game never stalls, and supports rematch.
  • Added the lobby (create a room, join by 4-letter code, or browse open rooms with live updates) and the game table UI (felt table, SVG cards, animations, scoreboard, synthesized sound, phone-portrait layout).
  • Added an end screen with the winner and rematch, a help modal with the full rules, and a README plus a single-image Dockerfile for deployment.
  • Fixed a defect found in review: leaving a room before the game started left the leaver stuck on the waiting screen; it now returns them to the landing page.
  • The full test suite (npm test) passed after the fix, and a judge played a complete game in the browser — create room, play all rounds to a winner, accept a rematch — and confirmed it works end to end.
  • Not done: an automated text-contrast probe flags the SVG card text as low-contrast, but that is a false positive — the probe reads the CSS colour property while the visible colour is the SVG fill, and the cards are plainly readable.

How to review

  1. Install dependencies with npm install (the repo pins Node 26 in .nvmrc; nvm use selects it).
  2. Run the whole suite with npm test — it should report all green (rules-engine unit tests, server integration tests, and client tests).
  3. Start the app with npm start and open http://127.0.0.1:3000 — it typechecks and builds the client first, then prints Scratch server listening on http://127.0.0.1:3000.
  4. Play in two tabs: create a room in one, join by code in the other, then press Start — you should see both seats, then the table with the trump card and a fanned hand.
  5. Read packages/shared/src/engine.ts for the rules and packages/server/src/gameServer.ts for the authoritative session — these two hold the core of the change.

Code review

Reviewed the full Scratch monorepo (shared rules engine, Socket.IO server, React client, tests, README, Dockerfile) against the proposal, delta specs, design, and tasks. The engine, server, and client are clean, well-tested, and match the spec: no secrets, no build artifacts committed (dist/node_modules are gitignored), no debug leftovers, and the tests assert the spec scenarios. I made two small fixes: renamed the live lobby socket event from lobby to lobby:update to match the name documented in the design and task 2.9, and made the server emit a readable error for malformed bid/play payloads instead of silently dropping them. I left two minor, intentional items in place (a documented fill:bots test hook and the by-design no-timer room lifecycle) and recorded them as findings.

Left for you

  • minor, packages/shared/src/protocol.ts:41: The protocol includes a fill:bots intent that is not in task 2.9's intent list or any spec. It is an intentional, documented test/judge hook (README, the window.__app surface, and the server integration tests all use it) that seats auto-played bot players. Harmless and in use by the change's own tests, so left in place rather than removed.
  • minor, packages/server/src/gameServer.ts:226: A room in the playing phase whose players all disconnect auto-plays itself to game-over (advanceAuto) and then remains in memory indefinitely if nobody reconnects, since rejoin is supported and the design deliberately avoids timers. This is a slow, small memory leak in a long-running process rather than a correctness bug; left as-is to stay consistent with the no-timer design.

Fixed before the commit

  • minor, packages/shared/src/protocol.ts:47: The live open-rooms push was emitted/listened to as the socket event lobby, but the design doc and task 2.9 document it as lobby:update. Renamed the event across protocol.ts, gameServer.ts (both emits), useGameSocket.ts (listener), and rooms.test.ts (three waits) so the wire protocol matches the documented name.
  • minor, packages/server/src/gameServer.ts:385: A game:bid with a non-numeric bid and a game:play with an unparseable card id were silently ignored with no response. Now each emits a readable error ("Bids must be whole numbers" / "That is not a valid card"), consistent with the spec's "reject with a readable error" and the other illegal-action paths. State was already unchanged in both cases.

Tests

89 of 96 scenarios of build-scratch-a-multiplayer-online-card-w17hrv have a tagged test. No test carries the spec: tag of these:

  • game-lobby/Selecting an entry joins
  • game-table/Consistent card design
  • game-table/Deal animation
  • game-table/Play and trick sweep
  • game-table/Portrait play
  • game-table/Scratch effect
  • game-table/Trump flip

The test lint found, in the run's tests on the last check:

Recorded, not decided

  • packages/shared/src/createGame.test.ts:107 B3 in rejects games with fewer than 2 or more than 5 players: bare toThrow(): require toThrow(TypeName) or toThrow(/message/)
  • packages/shared/src/createGame.test.ts:108 B3 in rejects games with fewer than 2 or more than 5 players: bare toThrow(): require toThrow(TypeName) or toThrow(/message/)

Braid run

  • Workflow: Braid's OpenSpec flow, change build-scratch-a-multiplayer-online-card-w17hrv (38 steps, 1 retried)
  • Model: vLLM · qwen3.8-27b
  • Time: 3 h 22 m from start to this pull request, 3 h 50 m of it in the model
  • Tokens: 77.8M input, 248k output, 552k reasoning, over 878 model calls
  • Pre-flight estimate: fits, p50 191k / p80 311k tokens against a 240k-token step allowance
  • CI: no CI ran on the checked code: the project has no CI (no workflow under .forgejo/workflows, .gitea/workflows or .github/workflows); what only CI tests went unverified
  • Run: run_01M6QT8MNGPTTE2TRXVTW17HRV

Opened by Braid.

## What was done - Built the whole app from an empty repo: a multiplayer online version of Scratch (an Oh Hell–family trick-taking card game) playable in real time across browser tabs. - Added a pure, framework-free rules engine (shared by server and client) covering 2–5 players, both round schedules, trump, bidding, play, scratch scoring, winner determination, and both house rules, fully unit-tested. - Added a Socket.IO server that owns rooms and authoritative game state, enforces legal moves, auto-plays for disconnected players so a game never stalls, and supports rematch. - Added the lobby (create a room, join by 4-letter code, or browse open rooms with live updates) and the game table UI (felt table, SVG cards, animations, scoreboard, synthesized sound, phone-portrait layout). - Added an end screen with the winner and rematch, a help modal with the full rules, and a README plus a single-image Dockerfile for deployment. - Fixed a defect found in review: leaving a room before the game started left the leaver stuck on the waiting screen; it now returns them to the landing page. - The full test suite (`npm test`) passed after the fix, and a judge played a complete game in the browser — create room, play all rounds to a winner, accept a rematch — and confirmed it works end to end. - **Not done:** an automated text-contrast probe flags the SVG card text as low-contrast, but that is a false positive — the probe reads the CSS colour property while the visible colour is the SVG fill, and the cards are plainly readable. ## How to review 1. Install dependencies with `npm install` (the repo pins Node 26 in `.nvmrc`; `nvm use` selects it). 2. Run the whole suite with `npm test` — it should report all green (rules-engine unit tests, server integration tests, and client tests). 3. Start the app with `npm start` and open `http://127.0.0.1:3000` — it typechecks and builds the client first, then prints `Scratch server listening on http://127.0.0.1:3000`. 4. Play in two tabs: create a room in one, join by code in the other, then press Start — you should see both seats, then the table with the trump card and a fanned hand. 5. Read `packages/shared/src/engine.ts` for the rules and `packages/server/src/gameServer.ts` for the authoritative session — these two hold the core of the change. ## Code review Reviewed the full Scratch monorepo (shared rules engine, Socket.IO server, React client, tests, README, Dockerfile) against the proposal, delta specs, design, and tasks. The engine, server, and client are clean, well-tested, and match the spec: no secrets, no build artifacts committed (dist/node_modules are gitignored), no debug leftovers, and the tests assert the spec scenarios. I made two small fixes: renamed the live lobby socket event from `lobby` to `lobby:update` to match the name documented in the design and task 2.9, and made the server emit a readable error for malformed bid/play payloads instead of silently dropping them. I left two minor, intentional items in place (a documented `fill:bots` test hook and the by-design no-timer room lifecycle) and recorded them as findings. **Left for you** - minor, `packages/shared/src/protocol.ts:41`: The protocol includes a `fill:bots` intent that is not in task 2.9's intent list or any spec. It is an intentional, documented test/judge hook (README, the window.__app surface, and the server integration tests all use it) that seats auto-played bot players. Harmless and in use by the change's own tests, so left in place rather than removed. - minor, `packages/server/src/gameServer.ts:226`: A room in the playing phase whose players all disconnect auto-plays itself to game-over (advanceAuto) and then remains in memory indefinitely if nobody reconnects, since rejoin is supported and the design deliberately avoids timers. This is a slow, small memory leak in a long-running process rather than a correctness bug; left as-is to stay consistent with the no-timer design. **Fixed before the commit** - minor, `packages/shared/src/protocol.ts:47`: The live open-rooms push was emitted/listened to as the socket event `lobby`, but the design doc and task 2.9 document it as `lobby:update`. Renamed the event across protocol.ts, gameServer.ts (both emits), useGameSocket.ts (listener), and rooms.test.ts (three waits) so the wire protocol matches the documented name. - minor, `packages/server/src/gameServer.ts:385`: A `game:bid` with a non-numeric bid and a `game:play` with an unparseable card id were silently ignored with no response. Now each emits a readable `error` ("Bids must be whole numbers" / "That is not a valid card"), consistent with the spec's "reject with a readable error" and the other illegal-action paths. State was already unchanged in both cases. ## Tests 89 of 96 scenarios of `build-scratch-a-multiplayer-online-card-w17hrv` have a tagged test. No test carries the `spec:` tag of these: - `game-lobby/Selecting an entry joins` - `game-table/Consistent card design` - `game-table/Deal animation` - `game-table/Play and trick sweep` - `game-table/Portrait play` - `game-table/Scratch effect` - `game-table/Trump flip` The test lint found, in the run's tests on the last check: **Recorded, not decided** - `packages/shared/src/createGame.test.ts:107` B3 in `rejects games with fewer than 2 or more than 5 players`: bare toThrow(): require toThrow(TypeName) or toThrow(/message/) - `packages/shared/src/createGame.test.ts:108` B3 in `rejects games with fewer than 2 or more than 5 players`: bare toThrow(): require toThrow(TypeName) or toThrow(/message/) ## Braid run - **Workflow:** Braid's OpenSpec flow, change `build-scratch-a-multiplayer-online-card-w17hrv` (38 steps, 1 retried) - **Model:** vLLM · qwen3.8-27b - **Time:** 3 h 22 m from start to this pull request, 3 h 50 m of it in the model - **Tokens:** 77.8M input, 248k output, 552k reasoning, over 878 model calls - **Pre-flight estimate:** fits, p50 191k / p80 311k tokens against a 240k-token step allowance - **CI:** no CI ran on the checked code: the project has no CI (no workflow under `.forgejo/workflows`, `.gitea/workflows` or `.github/workflows`); what only CI tests went unverified - **Run:** [run_01M6QT8MNGPTTE2TRXVTW17HRV](http://openspecflow.internal.underthere.xyz/run/run_01M6QT8MNGPTTE2TRXVTW17HRV) _Opened by Braid._
cmoriarty deleted branch osf/174-build-scratch-a-multiplayer-online-card 2026-11-06 05:17:51 -05:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
cmoriarty/scratch-vllm-fp8!1
No description provided.