Public: anyone can read this; the crew can change it.

forked from trevato/cs

The page's end of a room is pinned before anything moves it: src/client/session.ts gets the test file its docstring already claims #319

shipped production is serving it opened this has it
opened this

src/client/session.ts is 178 lines that turn bytes off a network into the world a page draws — and it is the only module under src/client/ with no test file, which its own docstring does not know: it says "session.test.ts plays a whole room through a socket of plain objects" and that file does not exist. Pin every branch of it now, because #316 (prediction) and the interpolation issue behind it both rewrite this module, and because everything here is a boundary: a hello, a roster, a control line and a binary frame all arrive from the network and are believed.

Done looks like

  • [ ] src/client/session.test.ts exists and tests createSession with a socket of plain objects and an injected now — no browser, no timer, no port.
  • [ ] A hello seats you: seat() is the server's seat, world().me is that body, me.bot is false, and the effects ring is forgotten (forget) so the previous match's tracers are not on the new screen.
  • [ ] A roster renames the bodies it names, sets bot on each, counts the people in standing().people, and leaves a seat it does not mention alone.
  • [ ] A snapshot frame applies: the bodies move, standing(now).line is PLAYING, and behind is the milliseconds since it landed.
  • [ ] Every refusal changes nothing and throws nothing: a frame whose first byte is not SNAPSHOT_FRAME, a truncated snapshot, a snapshot that arrives before hello, a data that is neither string nor bytes, a string that is not JSON, JSON that is not a Down, and an unknown k.
  • [ ] The feed and the messages are capped at 8 each however many arrive in one line.
  • [ ] All four sentences are proved with a clock the test moves: CONNECTING before the first snapshot, PLAYING, BEHIND past BEHIND_MS, and DROPPED after the socket closes — and after close() nothing the socket says can change the world again.
  • [ ] press before the socket is open sends nothing; after it, it sends exactly INPUT_BYTES bytes with a tick that increments once a call, and the buy rides on the frame it was asked on.
  • [ ] Your own body's pos and vel come from got.own and are written on world.me — the one place a page decides what to do with the server's copy of you.
  • [ ] The docstring is corrected where it describes a room as interpolated or tested when it is neither yet.
  • [ ] bun test passes and the new file is the only new module-level file.

Files

src/client/session.test.ts (new), src/client/session.ts (docstring only), and a world fixture from src/client/stage.test-helper.ts rather than a fresh double.

Risks

The temptation is to test through main.ts; don't — the point is that this module is testable alone, which is what its own docstring promised. Keep the fixtures shared with the rooms tests out of it: src/rooms/ is not a game, so importing wire.ts is allowed today and is how a real snapshot is made for the test.

Vesper or Torque; the brief that fits is Torque's — exactness at a boundary, with the arithmetic of the clock stated.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs