Files
SirStone fcd90529b6 test(m4): finish audit, measurement and archive (#76)
- client/e2e/audit.test.mjs: independent player-browser traffic audit (own
  frame catalogue and banned-key list, never leakcheck.nim), with a
  -d:leakfault/otherVision negative control.
- client/e2e/fogbench.test.mjs + tools/fogbench.nim: 50 tokens on a
  16384 px map (server move path and headless SwiftShader cadence);
  results/m4-fog-bench.md records both honestly (SW is not the phone gate).
- Archive prototype-* under docs/archive/prototypes (Q24); DESIGN 13 M4
  done, TESTING 13 M4 accept result, HANDOFF-M4 close-out.
- mutation.sh c1/c2 patch the post-#65 tile-gate line again (they had
  silently become sed no-ops).
2026-11-21 15:43:08 +01:00

11 KiB

M3: test harness WebSocket options (#8 "Test tools check")

Date: 2026-11-10. Scope: facts and tradeoffs only; no decision, no repo code changed. Part of #2 (map). Question: what can the test harnesses use to speak WebSocket with control of Cookie + Origin headers, raw oversized frames, and floods, inside devbox.

Pins used below: treeform/ws c9c0c7b (v0.6.0), guzba/whisky 494fb10, status-im/nim-websock 703f8f4 (v0.5.0), guzba/mummy 01deb1f (repo pin). Local Nim 2.2.4 (system), devbox lock nim 2.2.12.

1. Summary

  1. Current prototype WS harnesses are plain Node .mjs using only Node built-ins plus the global WebSocket. No npm ws package, no package.json for tools. 302 lines of WS-touching code.
  2. Node global WebSocket accepts a non-standard {headers} 2nd arg. Verified locally: Cookie and Origin both reach the wire (node v24.22.1). Cannot send raw/malformed frames.
  3. Main repo devbox.json has no node. Prototype devbox.json uses nodejs: latest, which the lock resolves to nodejs_26 26.11.1. lib.mjs comment says "Node 22" (stale vs lock). Node 26 not tested.
  4. Nim 2.2.4 stdlib has no WebSocket module. httpclient.getSocket exists, so a hand-rolled handshake is possible.
  5. treeform/ws (Nim 2.x compatible, active): no header injection API; WebSocket.tcpSocket* is exported, so raw bytes can be written after handshake. Type-checks on Nim 2.2.4.
  6. nim-websock (active): header control via Hook (Cookie/Origin possible); 20 MB frame cap; but internal write procs are not exported (no raw frames) and it needs nim >= 2.2.14, above both pinned Nim versions.
  7. whisky: archived, blocking, no header API. Not a fit for floods or header control.
  8. Raw node:net gives full control (any bytes, any header) with zero deps. Nim rewrite = hand-rolled handshake + frame codec (roughly 150-250 lines, estimate).
  9. Server side: mummy default maxMessageLen = 64 KB (server.nim does not override), so oversized-frame tests have a concrete server limit to probe.

2. Prototype harnesses (a)

file lines WS? deps
tools/leak.mjs 65 yes (via lib.mjs) node:fs, lib.mjs
tools/lib.mjs 17 yes: new WebSocket(url, {headers:{Cookie}}) node:fs; global fetch/WebSocket
tools/smoke.mjs 53 yes: {headers: {Cookie}}, bad/absent cookie checks node:fs
tools/restart.mjs 85 yes (via lib.mjs) node:fs, node:child_process
tools/concurrency.mjs 82 yes (via lib.mjs) lib.mjs
tools/genmap.mjs 106 no (map gen) node:fs, node:zlib
tools/leakcheck.nim 154 no: replays JSONL transcript std/[json,tables,sets,strutils,os,math], geometry
tools/faulttest.sh 36 no: shell; runs leak.mjs under withserver.sh sh, nim, node
tools/withserver.sh / leaktest.sh 17 / 11 no: shell orchestration sh, nginx
  • lib.mjs comment: "Node 22 WebSocket (undici) accepts {headers}" [L1].
  • Only package.json in prototype is client/package.json (pixi.js, vite, typescript, @types/node). Tools do not import it.
  • ws npm package: not used and not evaluated.

Sources: [P1] /home/davide/Projects/GDR/FFF_vtt/docs/archive/prototypes/server-vision/tools/lib.mjs; [P2] .../tools/smoke.mjs L9; [P3] .../tools/leak.mjs, .../tools/leakcheck.nim (under docs/archive/prototypes/server-vision/tools/); [P4] docs/archive/prototypes/server-vision/devbox.json; [P5] docs/archive/prototypes/server-vision/client/package.json.

3. Node availability and deps (b)

  • Main devbox.json packages: nim 2, nimble, coreutils, gnused, diffutils, gnugrep. No node, no nginx. [M1] /home/davide/Projects/GDR/FFF_vtt/devbox.json
  • Prototype devbox.json: nodejs: "latest", nginx, sqlite. [P4]
  • Prototype devbox.lock L300-303: nodejs@latest resolved to nixpkgs 8edc0c7#nodejs_26, version 26.11.1. [P6] docs/archive/prototypes/server-vision/devbox.lock
  • System node (outside devbox): v24.22.1, /run/current-system/sw/bin/node. Not the devbox version.
  • Node WebSocket header option: tested by capturing raw upgrade on a local net server. Wire request contained Cookie: sid=abc and Origin: https://evil.example. Test script: <scratchpad>/nodetest/hdr.mjs. Node docs for the headers option were not checked; behavior is observed, not documented.
  • Browser-standard WebSocket has no headers arg; this path depends on Node/undici.
  • Deps reproducibility: tools use only built-ins, so no npm install step. Pin comes from devbox.lock.

4. Nim WebSocket client options (c)

Nim 2.2.4 stdlib: no WebSocket module (grep of lib/pure for "websocket" is empty). httpclient/asynchttpclient expose getSocket [S-httpclient]. treeform/ws uses that exact trick for the handshake [T-ws-connect].

lib commit / date async header control (Cookie/Origin) raw/malformed frames oversize Nim 2.2.4
treeform/ws c9c0c7b, v0.6.0, pushed 2026-05-25, MIT async only (asyncdispatch) no: newWebSocket(url, protocols); fixed headers tcpSocket* exported, so raw writes possible after handshake; send always masks on client, no rsv/len override no client-side cap; receivePacket accumulates fragments unbounded; 64-bit len reads only bytes 4-7 (ok < 4 GB) nim check rc=0 (warnings only)
status-im/nim-websock 703f8f4, v0.5.0, pushed 2026-10-29, Apache/MIT chronos async yes: connect(..., hooks); Hook.append(headers var HttpTable) no: writeMessage/writeControl not exported WSMaxMessageSize 20 MB hard cap (frame.nim); frameSize 1 MB chunking not compatible: requires nim >= 2.2.14, plus bearssl, chronicles, chronos 4.4-4.6, httputils, nimcrypto, results, stew, zlib
guzba/whisky 494fb10, archived per GitHub API blocking only no: newWebSocket(url) not reviewed beyond framing no cap seen in receiveFrame nim check rc=0
niv/websocket.nim last push 2022-12-04, license NOASSERTION - - - - not evaluated (stale; treeform derives from it)
mummy 01deb1f (repo pin) server only - - - n/a (server, not client)

Key source facts:

  • treeform/ws: newWebSocket builds headers only from WS fields plus optional Sec-WebSocket-Protocol [T-ws-connect]. WebSocket object has tcpSocket*, masked* fields [T-ws-type]. Receive path rejects rsv bits and mask mismatch [T-ws-recv].
  • nim-websock: connect takes hooks: seq[Hook], calls hp.append(hp, headers) before the upgrade request [NW-connect]. frame.nim L200 raises above WSMaxMessageSize (20 MB) [NW-frame]. types.nim L26-27 defines WSDefaultFrameSize (1 MB) and WSMaxMessageSize (20 MB) [NW-types].
  • Nim version drift: devbox pins nim 2.2.12; system nim is 2.2.4. nim-websock would need >= 2.2.14. Upgrading the pin is a separate decision.
  • Hand-rolled Nim client: handshake via stdlib asyncnet/httpclient (or raw asyncnet sending the upgrade request, which gives full header control) plus frame encode/decode. Size is an estimate: 150-250 lines.

5. Node raw sockets vs global WebSocket (what each can do)

need global WebSocket (Node 24 tested) node:net + hand-rolled frames npm ws
Cookie + Origin yes ({headers}, observed) yes (raw handshake) not evaluated
floods yes (send loop; existing concurrency.mjs does it) yes not evaluated
oversized frame (>64 KB) sends big strings; fragments per undici yes (set any length) not evaluated
malformed frames (rsv, unmasked, bad len, bad opcode) no yes not evaluated
extra deps none none would need lock file

6. Effort: port .mjs vs rewrite in Nim (d)

Rough estimates, not measured.

  • Port as-is to main repo: add nodejs to root devbox.json (one package line, lock regen). Copy tools/lib.mjs + the 4 WS scripts (~300 lines). Still need the prototype's run layout (run/invites.txt, nginx conf via withserver.sh, ports 18088/19000). Low effort, but the harnesses are tied to the prototype's layout and env.
  • Rewrite in Nim: needs a WS client. Options: (i) hand-rolled client on stdlib (~150-250 lines, full control, no dep); (ii) treeform/ws + patch for headers (header patch on a fork, plus raw frames via tcpSocket); (iii) nim-websock (hooks and cap ok, but requires Nim upgrade). Floods and async fine in all Nim options.
  • Hybrid: keep Node for the scenario drivers, Nim for the checker (leakcheck.nim already Nim, reads transcript, no WS). Adds no WS dep to Nim.

7. Open facts not yet verified

  • Node 26 (devbox pin) header behavior: not tested.
  • Node WebSocket headers option in official docs: not checked.
  • treeform/ws and whisky runtime behavior: only nim check, not run against a server.
  • niv/websocket.nim: not evaluated.
  • npm ws package: not evaluated.

Sources

Pinned upstream (commit links):