mutation: run all test files, add mutations e-j (scanline fill, escape crossing, GM bypass, capsule, step cap, blocked trigger); header limitations updated
Control passes; a-d still caught (1,2,2,1,1 expected tests), new e-j each caught. Logs regenerated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+901
-76
File diff suppressed because it is too large
Load Diff
+11
-8
@@ -1,12 +1,15 @@
|
||||
## 2D vision geometry. Pure, stdlib only. Ported from prototype-server-vision/src/geometry.nim.
|
||||
## Known limitations (see prototype-server-vision/HANDOFF.md, docs/DESIGN.md 5.4 / 12):
|
||||
## - token exactly on a wall cannot move off it (inclusive segsCross); pinned by a KNOWN LIMITATION test.
|
||||
## - closing a door on a token: policy open, DESIGN Q14 (5.4 vs H2 conflict); behaviour pinned in tests.
|
||||
## 2D vision geometry. Pure, stdlib only. Ported from prototype-server-vision/src/geometry.nim (M1), revised in M2.
|
||||
## Move rules (swept circle, token-on-wall escape, step cap, `blocked`) live in server/moverules.nim, not here.
|
||||
## Fixed in M2 (DESIGN 5.5): token exactly on a wall can move off it (moverules escape rule); the move check is the
|
||||
## swept circle, not centre path + destination only; `moveBlocked` is gone from this module; cellsTouched is a scanline
|
||||
## (prototype per-cell version kept test-only in tests/refold.nim, differential-tested).
|
||||
## Known limitations (DESIGN 5.4 / 12):
|
||||
## - boundary epsilon ambiguity: RayEps 1e-4 rad, inclusive tests; token on a vision boundary is ambiguous
|
||||
## (leak checker uses a 0.5 px neighbourhood).
|
||||
## - move collision = centre path a->b + destination circle only, NOT the swept circle (corner clipping possible).
|
||||
## - vision is O(rays x walls) per token, bbox cull only.
|
||||
## - cellsTouched costs ~12x a polygon (results/bench.log in the prototype).
|
||||
## (leak checker and explored oracle use a 0.5 px neighbourhood).
|
||||
## - cellsTouched keeps a prototype quirk on purpose: a cell touching the polygon only along its bbox minimum x / y line
|
||||
## is not marked (every other touch is). The regression corpus has such polygons (walls on x = 256).
|
||||
## - vision is O(rays x walls in bbox): bbox cull, no spatial grid (H3: not built, 5k bench met target; results/bench.log).
|
||||
## A dense 5k layout (4096 px world, ~200 walls per vision box) costs ~1.3 ms per polygon.
|
||||
## - circle range limit is an inscribed 64-gon: error <= ~0.12% of R.
|
||||
import std/[math, algorithm]
|
||||
|
||||
|
||||
+26
-8
@@ -1,9 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
# usage: devbox run mutation (or tools/mutation.sh inside devbox shell)
|
||||
# Mutation check on a TEMP COPY of server/ + tests/ (the tree is never touched). One mutation per run.
|
||||
# Control must pass; every mutation must fail >=1 expected test; a sed that changes nothing is an error.
|
||||
# a: no +-RayEps rays | b: upper segment end exclusive | c: lower segment end exclusive (rayHit only;
|
||||
# moveBlocked's segsCross is a separate, intentionally inclusive test) | d1/d2: drop arm 1/2 of the shared-vertex fixture.
|
||||
# Mutation check on a TEMP COPY of server/ + tests/ + tools/ (the tree is never touched). One mutation per run, ALL
|
||||
# tests/t*.nim are run. Control must pass; every mutation must fail >=1 expected test; a sed that changes nothing is an error.
|
||||
# a: no +-RayEps rays | b: upper segment end exclusive | c: lower segment end exclusive (rayHit only)
|
||||
# d1/d2: drop arm 1/2 of the shared-vertex fixture
|
||||
# e: cellsTouched without the fill spans | f: escape rule without the crossing check | g: GM moves checked against walls
|
||||
# h: capsule reduced to centre path + destination circle (prototype H10) | i: no step cap | j: blocked trigger needs centre-on-wall
|
||||
# Log: results/mutation.log
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
mkdir -p results
|
||||
@@ -11,11 +13,17 @@ LOG=$PWD/results/mutation.log
|
||||
T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
|
||||
NEW="shared endpoint: no leak at the vertex|'<' apex|every segment endpoint|rays nudged past a corner"
|
||||
D="shared vertex: both arms required"
|
||||
E="random visibility polygons|random simple polygons|corpus|prototype scene, all tokens|random wall fields|concave polygon|square polygon"
|
||||
F="exactly on a wall: can step off|overlapping 10 px off|escape from a closed door|GM placement and GM move onto a wall"
|
||||
G="GM: ignores walls, step cap and blocked"
|
||||
H="corner clipping|leg of the path|diagonal squeeze past"
|
||||
I="step cap|over-cap, blocked-by-wall|P1:|P2:"
|
||||
J="wall added within r of the circle|Q14: a door closed"
|
||||
rc=0
|
||||
: > "$LOG"
|
||||
run() { # $1 id $2 title $3 file (server/geometry.nim | tests/tgeometry.nim) $4 sed script ("" = control) $5 expected-failure regex
|
||||
run() { # $1 id $2 title $3 file to mutate $4 sed script ("" = control) $5 expected-failure regex
|
||||
local id=$1 title=$2 file=$3 sedscr=$4 expect=$5 w=$T/w
|
||||
rm -rf "$w"; mkdir -p "$w"; cp -r server tests nim.cfg "$w"/
|
||||
rm -rf "$w"; mkdir -p "$w"; cp -r server tests tools nim.cfg "$w"/
|
||||
find "$w/tests" -maxdepth 1 -type f ! -name '*.nim' -delete
|
||||
{ echo "## $id: $title"
|
||||
if [ -n "$sedscr" ]; then
|
||||
@@ -24,8 +32,12 @@ run() { # $1 id $2 title $3 file (server/geometry.nim | tests/tgeometry.nim)
|
||||
echo "# diff $file -> mutated copy:"; diff "$file" "$w/$file" | sed 's/^/# /'
|
||||
fi
|
||||
} >> "$LOG"
|
||||
local out="$T/out-$id.txt" r F
|
||||
(cd "$w" && nim c -r --hints:off --nimcache:"$T/nc" tests/tgeometry.nim) > "$out" 2>&1; r=$?
|
||||
local out="$T/out-$id.txt" r=0 rr tf F
|
||||
: > "$out"
|
||||
for tf in tests/t*.nim; do
|
||||
(cd "$w" && nim c -r --hints:off --nimcache:"$T/nc-$(basename "$tf" .nim)" "$tf") >> "$out" 2>&1; rr=$?
|
||||
[ $rr -eq 0 ] || r=$rr
|
||||
done
|
||||
grep -E '\[(OK|FAILED)\]|Success|Failure|Error' "$out" | sed 's/^ *\.* */ /' >> "$LOG"
|
||||
F=$(grep '\[FAILED\]' "$out" | grep -E "$expect")
|
||||
{ echo "# test exit=$r; expected tests failed: $(printf '%s' "$F" | grep -c .)"; [ -n "$F" ] && echo "$F"; echo; } >> "$LOG"
|
||||
@@ -40,5 +52,11 @@ run b "upper segment end exclusive" server/geometry.nim 's/u <= 1 + Eps/u < 1 -
|
||||
run c "lower segment end exclusive" server/geometry.nim 's/u >= -Eps/u > Eps/' "$NEW"
|
||||
run d1 "shared-vertex fixture without arm 1" tests/tgeometry.nim 's/@\[arm1, arm2\] *# SHARED-VERTEX/@[arm2]/' "$D"
|
||||
run d2 "shared-vertex fixture without arm 2" tests/tgeometry.nim 's/@\[arm1, arm2\] *# SHARED-VERTEX/@[arm1]/' "$D"
|
||||
run e "cellsTouched without fill spans" server/geometry.nim '/for k in countup(0, xs\[row\].len - 2, 2)/d' "$E"
|
||||
run f "escape rule without the crossing check" server/moverules.nim 's/if pathCrosses(s, d, w.a, w.b) or segDist(d, w.a, w.b) < r: return false/if segDist(d, w.a, w.b) < r: return false/' "$F"
|
||||
run g "GM moves checked against walls" server/moverules.nim 's/^ if not inBounds(sc, d): return nack(s)$/ if not inBounds(sc, d) or not pathClear(sc.walls, s, d, sc.tokenRadius): return nack(s)/' "$G"
|
||||
run h "capsule = centre path + destination circle (prototype)" server/moverules.nim 's/elif segsCross(s, d, w.a, w.b) or segSegDist(s, d, w.a, w.b) < r: return false/elif segsCross(s, d, w.a, w.b) or segDist(d, w.a, w.b) < r: return false/' "$H"
|
||||
run i "no step cap" server/moverules.nim '/if hypot(dd.x, dd.y) > stepCap(sc, sc.tokens\[ti\]): return nack(s)/d' "$I"
|
||||
run j "blocked trigger needs the centre on the wall" server/moverules.nim 's/segDist(t.pos, w.a, w.b) < sc.tokenRadius/segDist(t.pos, w.a, w.b) < 1e-9/' "$J"
|
||||
echo "exit=$rc" | tee -a "$LOG"
|
||||
exit $rc
|
||||
|
||||
Reference in New Issue
Block a user