prototype-server-vision: geometry corner tests ('<' apex, endpoint vertices, +-eps rays, shared vertex) + mutation check (devbox run mutation, results/mutation-{a,b,c}.log)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-07 16:10:38 +01:00
co-authored by Claude Sonnet 5.5
parent a865b39657
commit 6449c2cf5e
7 changed files with 264 additions and 5 deletions
+1
View File
@@ -25,6 +25,7 @@ Browser rendering was NOT verified (no browser in the build environment): only H
| `devbox run faulttest` | deliberate leaks: builds the server with `-d:leakfault` (hook absent from the normal build, asserted by grepping the clean binary for `LEAK_FAULT`), injects 8 faults one at a time (`LEAK_FAULT=`): hidden token sent (`hidden`), wall data to player (`walls`), unexplored tile 200 (`tile`), visible token withheld (`withhold`), B's vision / explored / ownership sent to A (`other-vision`, `other-explored`, `other-owner`), missing `remove` (`noremove`). Passes only if the checker fails each with exactly the expected failure-class set (classes: HIDDEN_TOKEN WALLDATA TILE WITHHELD OTHER_PLAYER NO_REMOVE, plus collateral OWN_VIEW / EXPLORED) and the clean build still passes. Details in `results/faults.log` (gitignored) |
| `devbox run restart` | isolated server, moves A/B/monsters, toggles doors, A explores a new area; stops with SIGTERM then (second round of changes) SIGKILL, restarts on the same DB; asserts invite secrets, token positions, doors, vision, explored grids per role and the full hello+state a reconnecting client receives are identical (gseq excluded: in-memory). Note: the server has no SIGTERM handler, so SIGTERM is as abrupt as SIGKILL; durability rests on SQLite WAL commit before ack |
| `devbox run concurrency` | 60 s (`DUR=` secs) A, B, GM(6 monsters + doors) at 20-50 ms per token; logs `results/concurrency-<DUR>s.log` + `...-server.log` (server STATS) |
| `devbox run mutation` | geometry mutation check on a temp copy (`tools/mutation.sh`): (a) no ±RayEps rays, (b) upper segment end exclusive, (c) lower end exclusive; control must pass, each mutation must fail a corner test. Logs `results/mutation-{a,b,c}.log` |
| `devbox run bench` | vision microbench, log `results/bench.log` |
Tests are isolated: `tools/withserver.sh` uses `run/test/` (own DB, invites, nginx conf/logs) and ports 18088 (nginx) / 19000 (server), overridable via `TEST_PORT`/`TEST_BACKEND_PORT`; the live session on 8088/9000 and `run/` are never touched. Server stats print on stop into `run/test/server.log`.
+3
View File
@@ -56,6 +56,9 @@
"smoke": [
"tools/withserver.sh node tools/smoke.mjs"
],
"mutation": [
"tools/mutation.sh"
],
"bench": [
"mkdir -p results; nim c -d:release --hints:off -r -o:run/bench tools/bench.nim | tee results/bench.log"
]
@@ -0,0 +1,57 @@
# mutation a: remove the +-RayEps rays
# run on a temp copy; diff orig -> mutated src/geometry.nim:
# 50,51d49
# < angles.add ang - RayEps
# < angles.add ang + RayEps
[Suite] visibility
[OK] open space is a circle
[OK] wall blocks
[OK] shared endpoint: no leak at the vertex
[OK] '<' apex: ray through the shared tip must not leak
[OK] every segment endpoint is a polygon vertex (lower and upper end inclusive)
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(65, 14): Check failed: sees(w, (0.0, 7.4), (100.0, -6.0))
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(69, 14): Check failed: sees(m, (0.0, -7.4), (100.0, 6.0))
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(73, 14): Check failed: sees(b, (0.0, -24.0), (200.0, 130.0))
[FAILED] rays nudged past a corner: area just beyond a wall end is visible
[OK] shared endpoint: closed corner of box has no crack
[OK] collinear walls act as one
[OK] collinear walls with a gap let light through
[OK] T-junction: no leak and correct shadow
[OK] pillar mid-room casts a shadow, sides visible
[OK] closed door blocks, open door passes
[OK] token exactly at wall endpoint
[OK] token at endpoint of free-standing wall sees along it
[OK] long thin corridor
[OK] wall endpoints behind the viewer: fan stays angularly ordered
[OK] radius clips
[Suite] moves
[OK] crossing blocked, parallel ok
[OK] grazing an endpoint is blocked
[OK] no leak through shared vertex
[OK] diagonal squeeze through corner vertex of L
[OK] moving along a collinear wall is blocked
[OK] doors
[OK] zero-length move
[Suite] cells
[OK] square polygon
[OK] tiny polygon inside one cell
[OK] polygon spanning a cell with no vertex in it
[OK] big polygon includes fully covered interior cells
[Suite] seed
[OK] every token in seed sees itself and is not walled in
[Suite] token clearance (r=20)
[OK] near pillar: circle overlapping blocked, clear ok
[OK] near closed door blocks, open door passes
[OK] 64px corridor and doorway passable on centerline
[OK] legacy overlap can escape, not stay overlapped
Error: execution of an external program failed: '/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry'
# test exit=1
# NEW tests failed:
[FAILED] rays nudged past a corner: area just beyond a wall end is visible
@@ -0,0 +1,63 @@
# mutation b: upper segment end exclusive
# run on a temp copy; diff orig -> mutated src/geometry.nim:
# 27c27
# < if t > Eps and u >= -Eps and u <= 1 + Eps: t else: Inf
# ---
# > if t > Eps and u >= -Eps and u < 1 - Eps: t else: Inf
[Suite] visibility
[OK] open space is a circle
[OK] wall blocks
[OK] shared endpoint: no leak at the vertex
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(45, 59): Check failed: visibilityPolygon((0.0, 0.0), w, 500).hasVertex((100.0, 0.0))
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(46, 12): Check failed: not sees(w, (0.0, 0.0), (150.0, 0.0))
sees(w, (0.0, 0.0), (150.0, 0.0)) was true
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(47, 12): Check failed: not sees(w, (0.0, 0.0), (300.0, 0.0))
sees(w, (0.0, 0.0), (300.0, 0.0)) was true
[FAILED] '<' apex: ray through the shared tip must not leak
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(55, 24): Check failed: poly.hasVertex((80.0, 10.0))
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(58, 22): Check failed: pr.hasVertex((50.0, -30.0))
[FAILED] every segment endpoint is a polygon vertex (lower and upper end inclusive)
[OK] rays nudged past a corner: area just beyond a wall end is visible
[OK] shared endpoint: closed corner of box has no crack
[OK] collinear walls act as one
[OK] collinear walls with a gap let light through
[OK] T-junction: no leak and correct shadow
[OK] pillar mid-room casts a shadow, sides visible
[OK] closed door blocks, open door passes
[OK] token exactly at wall endpoint
[OK] token at endpoint of free-standing wall sees along it
[OK] long thin corridor
[OK] wall endpoints behind the viewer: fan stays angularly ordered
[OK] radius clips
[Suite] moves
[OK] crossing blocked, parallel ok
[OK] grazing an endpoint is blocked
[OK] no leak through shared vertex
[OK] diagonal squeeze through corner vertex of L
[OK] moving along a collinear wall is blocked
[OK] doors
[OK] zero-length move
[Suite] cells
[OK] square polygon
[OK] tiny polygon inside one cell
[OK] polygon spanning a cell with no vertex in it
[OK] big polygon includes fully covered interior cells
[Suite] seed
[OK] every token in seed sees itself and is not walled in
[Suite] token clearance (r=20)
[OK] near pillar: circle overlapping blocked, clear ok
[OK] near closed door blocks, open door passes
[OK] 64px corridor and doorway passable on centerline
[OK] legacy overlap can escape, not stay overlapped
Error: execution of an external program failed: '/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry'
# test exit=1
# NEW tests failed:
[FAILED] '<' apex: ray through the shared tip must not leak
[FAILED] every segment endpoint is a polygon vertex (lower and upper end inclusive)
@@ -0,0 +1,63 @@
# mutation c: lower segment end exclusive
# run on a temp copy; diff orig -> mutated src/geometry.nim:
# 27c27
# < if t > Eps and u >= -Eps and u <= 1 + Eps: t else: Inf
# ---
# > if t > Eps and u > Eps and u <= 1 + Eps: t else: Inf
[Suite] visibility
[OK] open space is a circle
[OK] wall blocks
[OK] shared endpoint: no leak at the vertex
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(45, 59): Check failed: visibilityPolygon((0.0, 0.0), w, 500).hasVertex((100.0, 0.0))
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(46, 12): Check failed: not sees(w, (0.0, 0.0), (150.0, 0.0))
sees(w, (0.0, 0.0), (150.0, 0.0)) was true
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(47, 12): Check failed: not sees(w, (0.0, 0.0), (300.0, 0.0))
sees(w, (0.0, 0.0), (300.0, 0.0)) was true
[FAILED] '<' apex: ray through the shared tip must not leak
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(54, 24): Check failed: poly.hasVertex((50.0, -30.0))
/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry.nim(59, 22): Check failed: pr.hasVertex((80.0, 10.0))
[FAILED] every segment endpoint is a polygon vertex (lower and upper end inclusive)
[OK] rays nudged past a corner: area just beyond a wall end is visible
[OK] shared endpoint: closed corner of box has no crack
[OK] collinear walls act as one
[OK] collinear walls with a gap let light through
[OK] T-junction: no leak and correct shadow
[OK] pillar mid-room casts a shadow, sides visible
[OK] closed door blocks, open door passes
[OK] token exactly at wall endpoint
[OK] token at endpoint of free-standing wall sees along it
[OK] long thin corridor
[OK] wall endpoints behind the viewer: fan stays angularly ordered
[OK] radius clips
[Suite] moves
[OK] crossing blocked, parallel ok
[OK] grazing an endpoint is blocked
[OK] no leak through shared vertex
[OK] diagonal squeeze through corner vertex of L
[OK] moving along a collinear wall is blocked
[OK] doors
[OK] zero-length move
[Suite] cells
[OK] square polygon
[OK] tiny polygon inside one cell
[OK] polygon spanning a cell with no vertex in it
[OK] big polygon includes fully covered interior cells
[Suite] seed
[OK] every token in seed sees itself and is not walled in
[Suite] token clearance (r=20)
[OK] near pillar: circle overlapping blocked, clear ok
[OK] near closed door blocks, open door passes
[OK] 64px corridor and doorway passable on centerline
[OK] legacy overlap can escape, not stay overlapped
Error: execution of an external program failed: '/tmp/tmp.hrEZipnqQ0/w/tests/tgeometry'
# test exit=1
# NEW tests failed:
[FAILED] '<' apex: ray through the shared tip must not leak
[FAILED] every segment endpoint is a polygon vertex (lower and upper end inclusive)
+48 -5
View File
@@ -10,6 +10,10 @@ proc box(x0, y0, x1, y1: float): seq[Wall] =
proc sees(walls: openArray[Wall], o, p: Vec, r = 500.0): bool =
visibilityPolygon(o, walls, r).inside(p)
proc hasVertex(poly: openArray[Vec], p: Vec): bool =
for v in poly:
if abs(v.x - p.x) < 1e-6 and abs(v.y - p.y) < 1e-6: return true
suite "visibility":
test "open space is a circle":
let poly = visibilityPolygon((0.0, 0.0), @[], 100)
@@ -23,15 +27,54 @@ suite "visibility":
check sees(w, (0.0, 0.0), (40.0, 0.0))
test "shared endpoint: no leak at the vertex":
# L corner at (50,0); point diagonally behind the vertex
# L corner at (50,0): vertical arm (50,-50)-(50,0), horizontal arm (50,0)-(100,0)
let w = @[W(50, -50, 50, 0), W(50, 0, 100, 0)]
check not sees(w, (0.0, -20.0), (70.0, -20.0))
check sees(w, (0.0, 20.0), (70.0, 20.0))
# token on the line of the horizontal arm (restored phase-1 probe, with the right expectation): a point just
# below the line is visible past the arm's end-on edge, just above it is shadowed by the vertical arm
# viewer on the diagonal through the shared vertex: the ray touches both arms' endpoint
let v: Vec = (0.0, -25.0)
check visibilityPolygon(v, w, 500).hasVertex((50.0, 0.0))
check not sees(w, v, (70.0, 9.0)) # just above the ray through the vertex: vertical arm shadows it
check sees(w, v, (70.0, 11.0)) # just below the ray: past the vertex, the corner is not a crack
# token on the line of the horizontal arm: a point just below the line is visible past the arm's end-on
# edge, just above it is shadowed by the vertical arm
check sees(w, (0.0, 0.0), (70.0, 5.0))
check not sees(w, (0.0, 0.0), (70.0, -5.0))
test "'<' apex: ray through the shared tip must not leak":
for flip in [false, true]: # each wall in both directions: the tip is an upper end of one and a lower end of the other
let w = if flip: @[W(100, 0, 50, -40), W(100, 0, 50, 40)] else: @[W(50, -40, 100, 0), W(50, 40, 100, 0)]
check visibilityPolygon((0.0, 0.0), w, 500).hasVertex((100.0, 0.0))
check not sees(w, (0.0, 0.0), (150.0, 0.0))
check not sees(w, (0.0, 0.0), (300.0, 0.0))
check sees(w, (0.0, 0.0), (90.0, 0.0))
test "every segment endpoint is a polygon vertex (lower and upper end inclusive)":
# free-standing wall, nothing else shares the endpoints: an exclusive end would drop the exact-endpoint ray
let w = @[W(50, -30, 80, 10)]
let poly = visibilityPolygon((0.0, 0.0), w, 500)
check poly.hasVertex((50.0, -30.0)) # lower end (u = 0)
check poly.hasVertex((80.0, 10.0)) # upper end (u = 1)
let r = @[W(80, 10, 50, -30)] # same wall, ends swapped
let pr = visibilityPolygon((0.0, 0.0), r, 500)
check pr.hasVertex((50.0, -30.0))
check pr.hasVertex((80.0, 10.0))
test "rays nudged past a corner: area just beyond a wall end is visible":
# viewer heights are chosen so the corner ray sits mid-way between two circle rays: no other ray can mask a missing nudge ray
# wall (50,-50)-(50,0) seen from (0,7.4): the ray through the end (50,0) continues to (100,-7.4)
let w = @[W(50, -50, 50, 0)]
check sees(w, (0.0, 7.4), (100.0, -6.0)) # lit side of that ray
check not sees(w, (0.0, 7.4), (100.0, -9.0)) # shadow side
# mirror: wall (50,0)-(50,50) seen from (0,-7.4)
let m = @[W(50, 0, 50, 50)]
check sees(m, (0.0, -7.4), (100.0, 6.0))
check not sees(m, (0.0, -7.4), (100.0, 9.0))
# box (pillar) seen from (0,-24): the rays through corners (100,50) and (100,-50) continue to (200,124) and (200,-76)
let b = box(100, -50, 150, 50)
check sees(b, (0.0, -24.0), (200.0, 130.0))
check not sees(b, (0.0, -24.0), (200.0, 118.0))
check sees(b, (0.0, -24.0), (200.0, -85.0))
check not sees(b, (0.0, -24.0), (200.0, -70.0))
test "shared endpoint: closed corner of box has no crack":
let w = box(-100, -100, 100, 100)
check not sees(w, (0.0, 0.0), (130.0, 130.0), 1000)
+29
View File
@@ -0,0 +1,29 @@
#!/bin/sh
# usage: tools/mutation.sh mutation check of src/geometry.nim on a TEMP COPY (src/ is never touched).
# Control (unmutated copy) must pass; each mutation must fail >=1 of the corner tests in $NEW.
# Logs: results/mutation-{a,b,c}.log (a: no +-RayEps rays; b: upper segment end exclusive; c: lower end exclusive).
# Segment-end inclusion lives only in rayHit (visibility); moveBlocked's segsCross is a separate, intentionally inclusive test.
cd "$(dirname "$0")/.." || exit 1
mkdir -p results
NEW="shared endpoint: no leak at the vertex|'<' apex|every segment endpoint|rays nudged past a corner"
T=$(mktemp -d); trap 'rm -rf $T' EXIT
rc=0
run() { # $1 id $2 title $3 sed script ("" = control)
rm -rf $T/w; mkdir -p $T/w; cp -r src tests data nim.cfg $T/w/; rm -f $T/w/tests/tgeometry
[ -n "$3" ] && sed -i "$3" $T/w/src/geometry.nim
L=results/mutation-$1.log
{ echo "# mutation $1: $2"; echo "# run on a temp copy; diff orig -> mutated src/geometry.nim:"
diff src/geometry.nim $T/w/src/geometry.nim | sed 's/^/# /'; echo; } > $L
(cd $T/w && nim c -r --hints:off --nimcache:$T/nc tests/tgeometry.nim) >> $L 2>&1; r=$?
F=$(grep '\[FAILED\]' $L | grep -E "$NEW")
{ echo; echo "# test exit=$r"; echo "# NEW tests failed:"; echo "${F:-(none)}"; } >> $L
if [ -z "$3" ]; then [ $r -eq 0 ] || { echo "control FAILED"; rc=1; }
else [ -n "$F" ] || { echo "mutation $1 SURVIVED"; rc=1; }; fi
echo "$1: exit=$r newfailed=$(echo "$F" | grep -c .)"
}
run control "unmutated copy (must pass)" ""
run a "remove the +-RayEps rays" '/angles.add ang [-+] RayEps/d'
run b "upper segment end exclusive" 's/u <= 1 + Eps/u < 1 - Eps/'
run c "lower segment end exclusive" 's/u >= -Eps/u > Eps/'
rm -f results/mutation-control.log
exit $rc