Commit Graph
36 Commits
Author SHA1 Message Date
SirStone 38941da003 test: walls r1 review — tests and tools
Ref #52
2026-11-20 08:59:24 +01:00
SirStone e1a5b297e4 fix: walls r1 review — server (ref #52) 2026-11-20 08:42:50 +01:00
SirStone edd4437f7e feat(walls): player markers — emission, opaque ids, storage, resync (#59)
A wall that is player_marker:true and derives window sends a player one
anchor (the drawn midpoint, integer px) and an opaque per-player 12-char id
once any point of its segment enters that player's vision polygon. Markers
live in PlayerVision like explored, persist to marker_seen in the same
derived-memory transaction, load before the first connection and resync as a
full set after explored; the GM and other players never receive one.

- markers.nim: emission gate, visible-extent test, id mint, anchor, marker_seen I/O.
- views/main: PlayerView markers + full/diff frames, refresh sync, startup load.
- markers.test.mjs: window preset, switch off, solid wall, any-part anchor,
  walk-away/door/lost sight, full-after-explored, per-player privacy, GM none.
- leakcheck: marker allowed type + independent visible-extent oracle with a
  positive control (a marked window the subject sees).
- restart: marked window in the fixture; marker set and marker_seen rows
  identical before/after SIGTERM and SIGKILL.
- protocol/tviews: catalogue and frame order pin the 16th message.

Retraction, re-earning and MARKER_* faults are #60.

Ref #59
2026-11-19 23:27:26 +01:00
SirStone 9fcbe885c1 feat(walls): one-way sight per-viewer filter and ONEWAY fault (#58)
The vision fan blocks a sight-blocking one-way wall only for a viewer on
its blind side (sight_dir names it; left is the (-dy,dx) normal of a->b),
one sign test inline after the radius cull, so the hoisted wall list stays
viewer-independent. Movement never reads the direction: one-way walls block
both ways. Explored and tiles therefore differ by side and only ever grow.

- geometry: WallDir + Wall.sightDir + blindTo, filter in visibilityPolygon.
- worldmap: sight_dir mapping (movement mapping unchanged).
- vision: the ONEWAY leak-fault build drops sight_dir player-side.
- leakcheck: own side test for the fan and the clear-segment oracle; ONEWAY
  class detected against the sight_dir-dropped fan.
- leak scenario gains a one-way wall the subject sees across; fault test
  asserts exactly ONEWAY.
- oneway.test.mjs: both sides, tile sweep with its own oracle, flip with
  fixed endpoints, monotone explored/tiles, restart, two-way movement.
- docs: DESIGN 5.8 mechanism sentence corrected; TESTING #58 markers built.
- nginx harness: temp dirs created recursively (restart on one state dir).
2026-11-19 22:57:39 +01:00
SirStone 0f3aa2300f feat(walls): door refusals and secret/locked equivalence gate (#56)
- door.set: opening a secret or locked door is invalid; closing either is
  allowed; a fixed window/non-door still has no open state.
- new tools/doors.test.mjs: two fresh servers, one identical script, three
  equivalence pairs (secret/wall, secret+locked/wall, locked/closed door),
  canonicalised frame + full per-player tile sweeps, an open-door positive
  control and a pinned zero-thickness close-push.
- secretgap fault hook (sight-only) makes the pair fail as exactly SECRETGAP;
  the clean pair passes and the shipped binary carries no fault hook.
- docs/TESTING.md T2/T17 and the door-equivalence/10.3 sections: built.

Ref #56
2026-11-19 22:49:39 +01:00
SirStone 484275e8bb feat(walls): presets, label rule and one switch-set validation path (#55)
wall.add/wall.update now take a preset or raw switches, never both:
resolveWall expands the four 5.8 presets to switches before validating, so
a preset never touches geometry and preset+switch or preset+open is invalid.
A raw create starts from the wall defaults; a raw update patches only the
switches it names and {door:false} closes and de-secrets.

The switch-set invariants are enforced by that one path for add and update:
open/secret/locked without a door, a secret door that is open/one-way/not
opaque, open with secret or locked, and a direction with no sight to block
are all invalid. The DB gains the missing open+locked CHECK as the backstop,
and the now-redundant open/door parity test is gone from the server path.

A wall label is now the 6.5 text rule: trimmed, 1..64 code points, no control
characters, null clears, stored verbatim and GM-only. window/one_way presets
are accepted and expanded to their switch sets per DESIGN 5.8/6.1; their
player-facing behaviour stays with #57/#58.

Tests: WS black-box presets/patch semantics/every refusal/label round-trip;
Nim shape pins for expansion, invariants and the label rule.
Nim 385 / Node 117 green.
2026-11-19 22:35:57 +01:00
SirStone 77fa2dfe4c feat(walls): proto 2 typed wall record, inert geometry, derived kind (#54)
wall.add/wall.update take thickness, position, height and the eight raw
switches; kind is output-only and the GM wall frames echo the full typed
record. Geometry is stored but inert (0/full/centre behaviour), and the
legacy kind/open wire adapter is gone. proto is bumped to 2 with the
harness default, and BannedAlways gains every wall field name with a
WALLDATA positive control.

Tests: schema-7 migrated scene vs the same walls authored via raw switches
gives byte-identical player frames, refusals and per-tile statuses.
Nim 382 / Node 113 green.
2026-11-19 22:21:47 +01:00
SirStone c1b1e9cf91 feat(db): typed wall storage, marker_seen and height backfill (#53) 2026-11-19 22:03:11 +01:00
SirStone 08363ef086 fix: stop sharing intent JSON refs with the world across worker threads
Mummy runs websocket handlers on worker threads. Intents are parsed outside
the one global lock, while the world is walked under it; ORC refcounts are
not atomic, so any JsonNode or string payload reachable from both an intent
tree and the world can be freed or leaked by two threads at once.

- Add server/jsonbound.nim: detachedJson/detachedString/detachedProps copies
  that share neither nodes nor string payloads (serialise+parse; std/json's
  copy() would still alias JString payloads).
- Detach every intent value that enters world state: wall.add/wall.update
  flags; token.create flags/props/names/kind/character_id; token.update
  patch fields; prop.set key and value (token and character); character.create
  props/names; scene.set name/extra. Use the world's own id in name.reveal.
- Build wall effects and create acks inside the mutation's critical section
  (settleLocked/settleWorldLocked). Wall/token/character record copies and
  frames no longer outlive the lock; only fresh scalars cross it.
- Move player.remove's in-memory follow-up under the lock (it mutated tokens,
  characters, visions, reveals and encountered outside it).
- Cap mummy at 4 worker threads (default was 10x cores) for a seven-person table.
- Add tests/tdetach.nim: identity and string-payload checks for the boundary
  helpers, plus the parseFlags-returns-the-caller's-node premise. A unit test
  can prove the copy semantics, not the absence of a race.
2026-11-17 23:02:32 +01:00
SirStone f963e8f4d6 main: read the scene once per request, under the lock (#31)
scene.set reassigns app.scene under dbLock while the HTTP handlers read it with
no lock and no stable snapshot: tileGate read it three times (twice outside the
lock) and checkScene read the id unlocked, so a swap could hand a request two
records, or race ORC freeing the old walls seq. tileGate now takes one snapshot
under the lock and uses it for the URL parse, the explored check and the
X-Accel-Redirect; checkScene and scene.set read under the lock; the wall/door
handlers capture sceneId inside their lock for the post-lock log and effect
frame.

Tests: ttiles pins that one record gives one whole answer after a swap;
tiles.test.mjs pins the handler shape (one code read, after the lock) and
interleaves 20 scene.set plus wall edits with 200 tile fetches -- only whole
tiles, no crash.
2026-11-15 14:26:15 +01:00
SirStone e9d5f6815a views: borrow the world in egress instead of copying it (#28)
views.Context held copies of scene, tokens, characters, reveals, encountered
and visions, so every mutation deep-copied each player's explored HashSet under
the global lock; playerView then copied its own PlayerVision again and greyFor
copied one per encountered entry. Context now holds six pointers
(contextOf/borrow), playerView/gmView read a ptr PlayerVision and a view builds
each player's visible-id set once per frame, so grey is a set test.

Measured on this build's types (debug, 6 players, 40 encountered entries, 40
world tokens, 16384 / 262144 explored cells): context construction 0.227 ms /
4.87 ms -> 0.008 us; one getOrDefault of a PlayerVision 28.8 us / 591 us -> gone;
GM egress pass 8.0 ms / 142.8 ms -> 0.79 ms / 0.80 ms; player pass 1.45 ms /
25.7 ms -> 0.32 ms. Behaviour is unchanged (leak/fault suites and tviews green);
tviews pins the borrow by identity, the six-pointer size and both sizes inside
the M5 7.5 ms budget.
2026-11-15 14:26:11 +01:00
SirStone 8e045b0ac8 names: per-player reveal, one encountered write path, link by update (#27, #29, #30)
name.reveal wrote the subject's actual name into the encountered row of every
player who had met it: the SQL had no player predicate, so the leak was silent
live and visible only after a restart. rewriteEncountered is now the one path
that keeps a snapshot in step with its subject: it rewrites the SQLite row and
the live in-memory entry together from the name rule, takes onlyPlayer for
name.reveal (every player for reveal_all), and also runs on a rename, a link
change and an owner change, so the wire and a post-restart reload cannot
disagree (#30). The DB-only renameEncountered*/revealEncountered* helpers are
gone, which is what let the two stores drift.

token.update {character_id} now drops the token's own two names as part of the
link patch (#29): a plain token can be linked, names supplied with a link stay
invalid and unlinking still needs both names.

Tests: tcharacters covers the per-player row, the DB/memory equality, the link
handover; restart.test.mjs builds three named players, reveals to one of them
and asserts the rows directly and the whole resync over SIGTERM/SIGKILL, plus a
mid-session rename; leak.mjs/leakcheck.nim pit two players on the same subject
and pin each entry's expected name (STALE_NAME). Mutations e1-e3 and the
repointed b2 pin the three rules.
2026-11-15 14:26:07 +01:00
SirStone cedb80aa96 tests: the restart and logs groups, the nine-group checklist and the fixture clean-up (#25) 2026-11-15 12:52:20 +01:00
SirStone 70a984c55a server: scene.set closes the 29-intent catalogue, plus a log-leak fault hook (#25) 2026-11-15 12:52:17 +01:00
SirStone 669e47e1ba server: the map-tile gate and the internal X-Accel path (#24) 2026-11-15 12:30:48 +01:00
SirStone 1ad9f724f2 tests: drop the two unused imports (#23) 2026-11-15 12:02:52 +01:00
SirStone f134534c6c tests: characters, names, the encountered list and migration step 7 (#23) 2026-11-15 12:01:30 +01:00
SirStone 20575f2147 tests: props, statuses, the resize rules and migration step 6 (#22)
tests/tprops.nim is new: the caps (per bucket, keys, values), the key rules,
the registry (empty fallback, a registered key's kind and bucket), set/unset
and the clone that keeps an edit away from the original bucket.

ttokens covers radius, the three buckets, the status set (round trip, sorted,
replaced rather than appended, removed by the FK cascade). tmoverules covers
per-token radius, shrink/grow/squeeze, the no-crossing rule, the corner
relaxation and the independence of the two sources; the old `blocked` tests
became `stuckWalls`. tviews covers the bucket and source filtering, one
`token` frame per change and the effective radius. tdb/tdb's fixtures move to
step 6, and tprobing follows the rename.
2026-11-15 11:02:43 +01:00
SirStone 22014a36dc server: the chunked explored store (#21)
Migration step 5 creates explored_chunk: one 512-byte bitmap per (player, scene, 64x64-cell
chunk), both FKs cascading. server/explored.nim owns the format (row-major, LSB-first bits),
dirty-chunk detection, the upsert and the startup restore. tests/texplored.nim pins the layout,
the whole-chunk encoding, the upsert replacement, the per-player keying, the restore and the
write cost (0.015 ms avg / 0.035 ms p99); tests/tdb.nim covers step 5 and a schema-4 fixture.
2026-11-15 09:58:16 +01:00
SirStone 5f5bf3293b server: typed recipient views and the single egress (#20)
server/views.nim is the only place where world state becomes bytes: a Recipient
builds a GmTokenView or a PlayerTokenView first, and only then a frame. Player
frames carry the public props bucket (plus owner for the controller), the
controller's vision_radius, and never kind, controller, gm_only, flags, radius_own
or either raw name; the GM gets all of it plus both names. The per-connection Known
table diffs on the built frame, so token/token_gone are exactly the changes and the
vision frame is re-sent only when the polygons move.

server/faults.nim compiles the negative-control hook only with -d:leakfault; the
shipped binary contains no LEAK_FAULT string and tools/fault.test.mjs asserts it.

hello gains the scene block (and extra for the GM); the protocol's implemented set
now names the four token intents.
2026-11-15 09:35:14 +01:00
SirStone e6b53e06f5 server: per-player vision, explored cells and the one view rule (#20)
server/vision.nim keeps one PlayerVision per player: a visibility polygon per
controlled token carrying the vision flag (range = the token's vision_radius or the
scene default), the explored set as the union of cellsTouched over history (only
grows, cells outside the world dropped), and the fresh cells of the current
mutation. The token-visibility rule of 3.1 (controlled always, otherwise inside own
LOS and not gm_only) exists exactly once there.

server/worldmap.nim translates the authoritative records into the inputs the pure
geometry and move-rule modules take, so those modules never see a wire field.
2026-11-15 09:35:09 +01:00
SirStone d38b871dfa server: token records and the entity migration step (#20)
Migration step 4 ("tokens") creates the entity table: the token id, scene, kind,
both names, position, nullable radius/owner/vision_radius, gm_only and flags. A
NULL owner is GM-controlled, so player.remove hands that player's tokens to the GM
through the FK; radius, props and character_id stay out until slices 7-8.

server/tokens.nim holds the record, the 6.1 field rules (12 CSPRNG characters from
a 64-symbol alphabet, trimmed names, kind, positive vision_radius), the write-through
persistence (FULL for GM authoring, NORMAL for a move) and the loader. db_connector
quotes every argument, so the three nullable columns are emitted as numeric literals
while text still goes through ? arguments.
2026-11-15 09:35:05 +01:00
SirStone a8f508ef2e server: wall and door intents, GM wall snapshot and fan-out (#19)
wall.add, wall.update, wall.remove and door.set leave the unknown-type rollout
list: field shapes and ranges per 6.1 (and the payload rules recorded FIXED in
4.4/6.1), lookup failures not-found, non-GM refused by the existing GM-only
gate. wall.add acks {id} from the scene's next_wall_id; wall.update patches
a/b/kind/flags only (open belongs to door.set); door.set is invalid on a plain
wall. Effects go to every GM connection only: wall / wall_gone, plus one walls
snapshot right after hello (the wall part of the 6.3 resync). Players receive
no wall data in any message (3.1, T2).

protocol.nim gains the wallObject/wallsFrame/wallFrame/wallGoneFrame builders
(no n: the sender stamps it per recipient) and the five wall intents in the
implemented set.
2026-11-15 08:49:20 +01:00
SirStone bf9ab3edfd server: scene and wall state, slice-4 migration (#19)
Migration step 3 ("world") creates scene and wall and seeds the single v1 scene
(id 1, 4096x4096, tile = cell 32, vision 400, token radius 20, art_version 1,
next_wall_id 1). server/world.nim holds the in-memory scene with SQLite as
write-through persistence: per-scene wall ids from next_wall_id (monotonic,
never reused, #3), 6.1 validation (a != b, in bounds, a wall is never open),
flags as an opaque JSON object, and one transaction with synchronous=FULL
around every GM authoring write (Q12); memory follows COMMIT, so a failed
write leaves both sides unchanged.

Tests: tests/tworld.nim (ids, reload, doors, validation, pragma, failed write),
tests/tdb.nim (version 3, history, a slice-2 DB migrating to slice 3).
2026-11-15 08:49:16 +01:00
SirStone 7e2d5b8dc0 server: per-connection wire state and closing frames in the conn registry (#18)
Conn now carries what DESIGN 6/6.4/6.5 need per connection, all under the one
registry lock: the outgoing n counter (starts at 1, server frames only), the intent
token bucket, the malformed-flood window, the player's named flag and the last Pong.
None of it is shared, so the n counter is not a global side channel (H25).

activate/revokePlayer now hand back the doomed Conn values instead of raw sockets:
the caller still has the frame count, so the final closing frame carries the right n
before the close. Tests cover per-connection counters, the bucket and the flood
window in isolation, and that a snapshot survives the lock.
2026-11-15 08:33:07 +01:00
SirStone eb48034eba server: wire protocol module - envelope, frames, rate limit, flood window (#18)
Pure, mummy-free module for the protocol shell: the envelope rules of DESIGN 6.5
step 2 (UTF-8 text, JSON object, string t, integer reqId in 0..2^31-1), the frame
builders of 6.1 including closal/closing, the per-connection intent token bucket
(30/s, burst 100) and the malformed-flood window (10 in any 10 s), plus the FIXED
constants: proto 1, 64 KB inbound, close codes 4001/4002/4003/1008 and their reason
strings. The 29-intent catalogue and the GM-only set live here so 'unknown type'
and role checks have one definition.

Found while testing: std/json parseJson("") returns nil instead of raising, and
node{"t"} is nil for a missing key, so both are guarded (a bare {} would have
crashed the handler).
2026-11-15 08:33:01 +01:00
SirStone e612db5826 server: auth schema, keys, sessions, connection registry (#17) 2026-11-14 22:13:04 +01:00
SirStone f376efdc39 server: config, migrations, redacted logging, /healthz entrypoint (#16) 2026-11-14 21:40:39 +01:00
SirStoneandClaude Sonnet 5.5 8d3b77add4 mutation: parallel jobs in temp copies, per-mutation test files, FFF_MUTATION reduced iterations, trap cleanup, sleep inhibit
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 19:19:58 +01:00
SirStoneandClaude Sonnet 5.5 a29bb0bb46 moverules: door close pushes overlapped tokens aside (valid-side check, blocked only if no side valid); Push list; tests; mutations m-o
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 18:56:06 +01:00
SirStoneandClaude Sonnet 5.5 388e901541 moverules: blocked policy set/keep/clear (GM moves and placements set/clear, KEEP while any wall overlaps); tests; mutations k, l
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 18:47:39 +01:00
SirStoneandClaude Sonnet 5.5 e0705a8533 bench: harness with synthetic 5k-wall scenes (devbox run bench), scenegen + tests
Targets met without a spatial grid: polygon+cells 0.048 ms (<= 0.451) on the prototype scene, polygon 0.083 ms
(< 1 ms) on 5k sparse. 5k dense stress layout reported (1.28 ms). Logs: results/bench.log, nimble-test.log.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 12:15:31 +01:00
SirStoneandClaude Sonnet 5.5 afe84f2add moverules: swept-circle move check, token-on-wall escape, blocked flag, step cap, GM bypass
Pure in-process module (server/moverules.nim, plain data, no IO) per DESIGN 5.5. Replaces moveBlocked tests
(ported at r=0), the KNOWN LIMITATION pin and the Q14 pin with positive escape/capsule assertions and
blocked-policy tests. tests/tprobing.nim: in-process T8 probing test with a concrete bound (stepCap + r).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 12:11:49 +01:00
SirStoneandClaude Sonnet 5.5 67fa96e23d geometry: scanline cellsTouched, differential + independent oracle tests, prototype corpus
cellsTouched is now a scanline over cell rows (prototype per-cell version kept test-only in
tests/refold.nim). Differential tests (random polygons, concave, grid-aligned) and a brute-force
explored oracle (0.5 px tolerance) cover it; regression corpus = prototype leak-run polygons.
moveBlocked leaves geometry.nim (replaced by server/moverules.nim next); geometry primitives exported.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 12:08:21 +01:00
SirStoneandClaude Sonnet 5.5 b8d68cdb3a tests: shared-vertex both-arms test, door-closed-on-token pin (Q14), KNOWN LIMITATION token-on-wall pin
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 10:08:26 +01:00
SirStoneandClaude Sonnet 5.5 547458c37e m1: devbox, nimble, layout; port geometry.nim and 33 tgeometry tests (98 checks)
Fixture tests/fixtures/scene.json copied from prototype data/; seed test no longer skips if missing.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 10:06:58 +01:00