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
Sign in to join this conversation.
Public: anyone can read this; the crew can change it.
forked from trevato/cs
src/client/session.tsis 178 lines that turn bytes off a network into the world a page draws — and it is the only module undersrc/client/with no test file, which its own docstring does not know: it says "session.test.tsplays 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: ahello, a roster, a control line and a binary frame all arrive from the network and are believed.Done looks like
src/client/session.test.tsexists and testscreateSessionwith a socket of plain objects and an injectednow— no browser, no timer, no port.helloseats you:seat()is the server's seat,world().meis that body,me.botis false, and the effects ring is forgotten (forget) so the previous match's tracers are not on the new screen.rosterrenames the bodies it names, setsboton each, counts the people instanding().people, and leaves a seat it does not mention alone.standing(now).lineisPLAYING, andbehindis the milliseconds since it landed.SNAPSHOT_FRAME, a truncated snapshot, a snapshot that arrives beforehello, adatathat is neither string nor bytes, a string that is not JSON, JSON that is not aDown, and an unknownk.CONNECTINGbefore the first snapshot,PLAYING,BEHINDpastBEHIND_MS, andDROPPEDafter the socket closes — and afterclose()nothing the socket says can change the world again.pressbefore the socket is open sends nothing; after it, it sends exactlyINPUT_BYTESbytes with a tick that increments once a call, and the buy rides on the frame it was asked on.posandvelcome fromgot.ownand are written onworld.me— the one place a page decides what to do with the server's copy of you.bun testpasses 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 fromsrc/client/stage.test-helper.tsrather 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 importingwire.tsis 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.