Skip to content

test(room): extract the gesture state machine from Space and unit-test it - #63

Merged
kixelated merged 4 commits into
mainfrom
quest/m1/space-gesture-tests
Nov 26, 2026
Merged

kixelated merged 4 commits into
mainfrom
quest/m1/space-gesture-tests

Conversation

@kixelated

@kixelated kixelated commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m1/space-gesture-tests.md.

Problem

app/src/room/space.ts mixed DOM events, WebGL, and peer moves in one 869-line class that no suite could load. As a result, the drag, pinch, and lock fixes from #51 were covered only by tsc and Biome.

Approach

A pure refactor plus tests:

  • room/gesture.ts (new): Gesture owns the gesture state. That covers the held tile, the touch IDs, the pinch baseline, and each remote tile's remembered home. It also owns the peer-move requests that fix(room): make Remote Control stop others from moving you #51 fixed: grab, publish, settle, and revoke on lock. It works on a structural Tile type that Broadcast already satisfies, so tests build tiles from plain signals.
  • Stack (new, in gesture.ts): holds the shared stacking counter that used to be Space.#maxZ, so Space and Gesture raise tiles from the same counter.
  • Space keeps the DOM wiring, hover, and cursor. It converts client coordinates to canvas coordinates and calls Gesture. The file shrinks by about 470 lines.
  • room/gesture.test.ts (new): 9 tests (~100 ms), no WebGL, audio, relay, or clock reads. Gestures read no time, so nothing needs a mocked clock. Covered:
    • a drag that turns into a pinch keeps the placement from before the drag and publishes nothing
    • a lock mid-drag ends the gesture, so the fingers still down move nothing
    • a lock mid-pinch drops its baseline, so a later pinch on another tile can't scale from it
    • a rejected move puts the tile back home, under whatever placement the peer published
    • a lock with no move pending leaves the tile alone
    • re-grabbing a tile with a move still pending keeps the older home
    • lifting one pinch finger hands the drag to another tile under the remaining finger and publishes the first
    • our own tile publishes directly instead of asking a peer
    • a locked tile can't be grabbed or zoomed

Mutation check: reverting each #51 fix one at a time made exactly one test fail. The fixes reverted were: always re-grab on pinch (with and without publishing), keep the pinch baseline on lock, keep dragging on lock, ignore pending moves when remembering a home, ignore the peer's published placement on restore, and restore without a pending move.

Decisions (taken while the maintainer was away; each is easy to undo)

  • Module boundary. The quest plan sketched a module that returns what to apply. Instead, Gesture writes the tile's signals directly and keeps the peer-move carrier inside. Every fix(room): make Remote Control stop others from moving you #51 case depends on whether a move is pending, so returning effects would leave the logic under test split across the two classes.
  • Broadcast.locked() removed. It was used only by Space, so it is replaced by Gesture.locked(tile), which checks role === "watch" without a handle. This is the same test as the old instanceof WatchBroadcast check.
  • Unused per-touch coordinates dropped. #touches stored coordinates that nothing read, so it is now a Set of IDs.
  • Pinch distance in canvas coordinates instead of client pixels. canvas.relative scales both axes by the same factor except for a bordered canvas (the About demo), where the two factors differ by the border's share of the size, so a two-finger rotation there can drift the scale by a fraction of a percent. Not worth passing client distances through Gesture for (review note, round 1).
  • mouseup and mouseleave share one handler. #54 landed first with the same merge and the dropped ?? 1 scale fallbacks; the merge of main keeps this PR's Gesture-based handlers, chore: run the m1 code audit #54's comment placement, and chore: run the m1 code audit #54's render call without the hovering option. Main also dropped Bounds.create, so the tests use new Bounds.
  • Real-surface check without the full just dev. Another session's just dev held the hard-coded API, relay, and auth ports (3000, 4443, 4440), plus 1420. I ran this worktree's Vite on 1421 instead (see Validation).

Impact

  • Public API: none. app is not a published package. Inside the app, Broadcast.locked() is gone (no other caller).
  • Wire: none. Peer-move requests, IDs, and published positions are unchanged.
  • Behavior: none intended.
  • Check time: adds about 0.1 s to bun test.

Validation

  • quest gate just check: passes (quest check, tsc, Biome, API, app, and media tests), on the merge with main too, including the room-canvas browser smoke from #62.
  • In a real browser (private headless Chromium through agent-browser, against this worktree's Vite dev server):
    • On the About page demo, mouse drag, wheel zoom-out to the 0.25 floor, and touch drag visibly moved and scaled the fake tiles, with no page errors.
    • The demo's timeline keeps re-laying out the room, so I also built a FakeRoom harness in the page from the dev server's /src/room/*.ts modules. Real DOM MouseEvent, WheelEvent, and TouchEvent events drove the real Space, and I read the tile positions directly:
      • mouse drag to (600, 450) → (0.25, 0.25), cursor grabbing then default
      • wheel deltaY −500 → scale 1.5, cursor zoom-in
      • touch drag → (−0.25, −0.25)
      • pinch from 100 px to 200 px apart → scale 2
      • lifting one finger → the remaining finger keeps dragging; moves after release are ignored
  • Not run: a remote-peer drag between two real clients, which needs the API, relay, and auth stack. That path is the moved-verbatim peer-move code, which the unit tests above cover.

Follow-ups

None.

Models

  • Size: M
  • Implementer: Claude Code, claude-opus-5-5, high
  • Implementer: Claude Code, claude-opus-5-5, medium effort (iterate, S)

🤖 Generated with Claude Code

(Written by Claude Opus 5.5 with high; merge of main by Claude Opus 5.5 with medium)

Review

Rewritten by quest review after each round.

  • Head: f3bb9c0

  • Base: origin/main at 405221c

  • Risk: medium, the base has no RISK.md to name what is always high or customer-facing, so every change is medium

  • Classified: medium by default

  • Risk file: none

  • Reviewer: Codex, gpt-6.2-sol, high effort

  • Session: 01a219b4-837a-7633-81b8-5d7ea6ed09cf, round 1

  • Score: 9/10, The extraction preserves the lock, stacking, and move-publication contracts, with a minor pinch-zoom regression when the canvas scales its axes differently.

  • Rounds: 1; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

  • Notes, the author's to take or leave:

    • app/src/room/space.ts:154: Measure pinch distance in client coordinates

kixelated and others added 2 commits November 25, 2026 23:11
…t it

Space's drag, wheel, touch, pinch, and lock handling moves into
room/gesture.ts, which Space feeds canvas-relative points. The suite
covers the #51 cases: a drag turning into a pinch keeps its home, a lock
ends the gesture and drops its pinch baseline, a rejected move restores
the home under the peer's placement, and a re-grab with a move pending
keeps the older home.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Test the room's drag, pinch, and lock gestures test(room): extract the gesture state machine from Space and unit-test it Nov 26, 2026
@kixelated
kixelated marked this pull request as ready for review November 26, 2026 07:30
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3551be72-6b16-4850-9a96-d11d041c48e0
Commits

Reviewing files that changed from the base of the PR and between 405221c and f3bb9c0.

Files selected for processing: 5

  • app/src/room/broadcast.ts
  • app/src/room/gesture.test.ts
  • app/src/room/gesture.ts
  • app/src/room/space.ts
  • quest/m1/space-gesture-tests.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@kixelated

Copy link
Copy Markdown
Collaborator Author

Maintainer decision (via /quest-run): ✅ /quest-merge this PR (rejected: iterate, skip). Land order: #63 first, then #68 adapted onto #63's Gesture.

(Written by Claude Opus 5.5)

kixelated and others added 2 commits November 26, 2026 13:11
…e-tests

# Conflicts:
#	app/src/room/space.ts
#	quest/m1/room-browser-smoke.md
#	quest/m1/space-gesture-tests.md
Main dropped Bounds.create in the code audit (#54).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated merged commit 51647b2 into main Nov 26, 2026
3 checks passed
@kixelated
kixelated deleted the quest/m1/space-gesture-tests branch November 26, 2026 21:20
kixelated added a commit that referenced this pull request Nov 26, 2026
Streams the drag that #63's Gesture holds (gesture.dragging) instead of
Space's removed #dragging, keeps clearing the pointer on mouseleave now
that mouseup and mouseleave share a release handler, and takes the live
track name beside @moq/room's TRACK and PRIORITY constants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated added a commit that referenced this pull request Nov 26, 2026
Move the located check into Gesture.locked(), which main's gesture extraction (#63) took from
Broadcast.locked(), so a tile from OBS or the CLI still drags locally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant