feat(walls): marker retraction, re-earn and marker fault classes (#60)

Retract a player marker when the GM removes the wall, clears
player_marker, makes the wall stop deriving window, or moves its
geometry (a/b, thickness, position). Retraction emits del only and
never the new anchor; a re-earned marker gets a fresh id. The
marker_seen deletes ride the same derived-memory NORMAL transaction as
the explored chunks, after the wall row commits and before the ack.

Replace the leak checker's aggregate MARKER class with MARKER_EARLY,
MARKER_EXTRA and MARKER_OFF, add their leakfault hooks and exact-class
fault tests, and extend the leak scenario with an unseen marked window
and a marked solid wall as the negative controls. WS black-box tests
cover all four causes, fresh re-earns, no untouched re-send, no
set/del for one id in a frame, no explored write from a retraction,
and delete/cascade durability across a restart.
This commit is contained in:
2026-11-19 23:43:44 +01:00
parent edd4437f7e
commit c3c0a39188
9 changed files with 425 additions and 60 deletions
+74 -19
View File
@@ -27,9 +27,11 @@
## CHAR_OWNER_PROP a character's owner bucket reached a player who does not own it (8)
## GEOMETRY the recomputed polygon disagrees with the clear-segment oracle (sanity)
## ONEWAY the subject's fan ignores `sight_dir` (the two-way fan; TESTING 10.3, #58)
## MARKER a marker frame disagrees with the independent visible-extent oracle, or its shape
## is wrong (the exact MARKER_EARLY/EXTRA/OFF classes are #60's fault builds; #59
## proves the allowed type and the oracle with a positive control)
## MARKER_EARLY a marker arrived before the subject had seen that wall's extent (the extent
## gate was dropped: it reveals a position early; TESTING 10.3, #60)
## MARKER_EXTRA a marker exists for a wall that should never produce one (the derived-`window`
## gate was dropped, or the wall is not a marker candidate at all; #60)
## MARKER_OFF a marker the visible-extent oracle expects was never sent (#60)
## PROTOCOL a frame the catalogue does not allow, a bad `n` sequence, a missing hello block
##
## One-way sight (DESIGN 5.8, TESTING 10.3): the checker reads `sight_dir` from the GM's frames and
@@ -39,7 +41,7 @@
## evaluate that two-way perspective so the fault is reported as exactly ONEWAY.
##
## usage: leakcheck <transcript.jsonl> <SUBJECT> exit 0 = clean
import std/[algorithm, json, math, options, os, sets, strutils, tables]
import std/[algorithm, json, math, options, os, sequtils, sets, strutils, tables]
import geometry
const
@@ -90,9 +92,18 @@ type
## keeps the geometry and the id from the GM's frames and does its own visible-extent test.
id: int
a, b: Vec
thickness: float
position: string
playerMarker: bool
isWindow: bool
ExpectedMarker = object
## The oracle's accumulated memory for one wall: the anchor the subject should hold and the
## marker signature it was earned for. A cause change (5.8: gone, switch off, not a window,
## geometry moved) drops the entry, mirroring the server's retraction (#60).
anchor: (int, int)
sig: string
Group = object
label: string
gmMsgs: seq[JsonNode]
@@ -150,13 +161,22 @@ proc readGroups(path, subject: string): seq[Group] =
# Truth from the GM socket (walls and every token)
proc markerWallOf(id: int, w: JsonNode): MarkerWall =
## The marker-relevant projection of a GM wall frame (5.8): the derived `window` gate and the switch.
## The marker-relevant projection of a GM wall frame (5.8): the derived `window` gate, the switch
## and the geometry whose change retracts (#60).
MarkerWall(id: id, a: vec(w["a"]), b: vec(w["b"]),
thickness: w["thickness"].getFloat,
position: w["position"].getStr,
playerMarker: w["player_marker"].getBool,
isWindow: not w["blocks_sight"].getBool and w["blocks_movement"].getBool)
proc isMarkerCandidate(m: MarkerWall): bool = m.playerMarker and m.isWindow
proc markerSig(m: MarkerWall): string =
## The oracle's own copy of the retraction signature: endpoints, thickness, placement, switch and
## the derived window gate. Height and label have no marker consequence (5.8, #60).
$m.a.x & "," & $m.a.y & "," & $m.b.x & "," & $m.b.y & "," & $m.thickness & "," &
m.position & "," & $m.playerMarker & "," & $m.isWindow
proc setMarkerWall(truth: var Truth, mw: MarkerWall) =
## Upsert by wall id, so a `wall` update replaces the marker projection in place.
for i in 0 ..< truth.markerWalls.len:
@@ -447,7 +467,7 @@ proc main() =
var viewCharacters: HashSet[string] # character ids the subject was sent
var prevController: Table[string, int] # controller of each token at the previous group
var markers: Table[string, (int, int)] # marker id -> anchor, what the subject was sent
var expectedMarkers: Table[int, (int, int)] # wall id -> anchor, accumulated memory (#59)
var expectedMarkers: Table[int, ExpectedMarker] # wall id -> accumulated memory (#59/#60)
var markerPositive = false # the scenario exercised the oracle at least once
for g in groups:
@@ -748,7 +768,7 @@ proc main() =
# `full:true` is the resync set and must follow `explored` full (the client draws it over the
# fog just rebuilt); a diff adds ids in `set` and (from #60) retracts in `del`.
if not markerShapeOk(m):
fail "MARKER", "malformed marker frame (group " & g.label & ")"
fail "PROTOCOL", "malformed marker frame (group " & g.label & ")"
elif m["full"].getBool and not sawExploredFull:
fail "PROTOCOL", "marker full before explored full (group " & g.label & ")"
else:
@@ -756,33 +776,68 @@ proc main() =
for e in m["set"]:
let id = e["id"].getStr
if markers.hasKey(id):
fail "MARKER", "duplicate marker id " & id & " (group " & g.label & ")"
fail "PROTOCOL", "duplicate marker id " & id & " (group " & g.label & ")"
markers[id] = (e["pos"][0].getInt, e["pos"][1].getInt)
if m.hasKey("del"):
for d in m["del"]:
let id = d.getStr
if not markers.hasKey(id):
fail "MARKER", "del for a marker the subject never had: " & id
fail "PROTOCOL", "del for a marker the subject never had: " & id
markers.del id
else: discard
# --- player markers (5.8, TESTING 10.3 #59) -------------------------------------------------
# --- player markers (5.8, TESTING 10.3 #59/#60) ---------------------------------------------
# The oracle's own memory: a marked window enters `expectedMarkers` once any part of its drawn
# extent is inside the subject's polygons, and stays (walking away, a door, lost sight never
# retract it). It never calls vision.nim: `polysChecks` is this file's recomputed fan.
# extent is inside the subject's polygons, and stays while the cause is unchanged. The four
# retraction causes (wall gone, switch off, no longer a window, geometry moved) drop it, which
# is the server's rule read independently from the GM's truth. It never calls vision.nim:
# `polysChecks` is this file's recomputed fan.
for id in expectedMarkers.keys.toSeq:
var match = none(MarkerWall)
for mw in truth.markerWalls:
if mw.id == id: match = some(mw)
if match.isNone or markerSig(match.get) != expectedMarkers[id].sig:
expectedMarkers.del id
for mw in truth.markerWalls:
if expectedMarkers.hasKey(mw.id): continue
if extentSeen(polysChecks, mw.a, mw.b): expectedMarkers[mw.id] = anchorOf(mw)
if extentSeen(polysChecks, mw.a, mw.b):
expectedMarkers[mw.id] = ExpectedMarker(anchor: anchorOf(mw), sig: markerSig(mw))
var wantPos: seq[(int, int)]
for _, pos in expectedMarkers: wantPos.add pos
for _, em in expectedMarkers: wantPos.add em.anchor
var gotPos: seq[(int, int)]
for _, pos in markers: gotPos.add pos
wantPos.sort()
gotPos.sort()
if gotPos != wantPos:
fail "MARKER", "marker set " & $gotPos & " != visible-extent oracle " & $wantPos &
" (group " & g.label & ")"
elif wantPos.len > 0:
# Multiset difference: `missing` markers the memory expects, `extra` ones it does not. An
# extra at a marker candidate's anchor was sent before its extent was seen (EARLY); an extra
# with no candidate wall at all must never exist (EXTRA).
var missingMarkers, extraMarkers: seq[(int, int)]
var wi = 0
var gi = 0
while wi < wantPos.len or gi < gotPos.len:
if wi >= wantPos.len:
extraMarkers.add gotPos[gi]; inc gi
elif gi >= gotPos.len:
missingMarkers.add wantPos[wi]; inc wi
elif wantPos[wi] == gotPos[gi]:
inc wi; inc gi
elif wantPos[wi] < gotPos[gi]:
missingMarkers.add wantPos[wi]; inc wi
else:
extraMarkers.add gotPos[gi]; inc gi
if missingMarkers.len > 0:
fail "MARKER_OFF", "marker " & $missingMarkers[0] & " was never sent (" &
$missingMarkers.len & " missing; group " & g.label & ")"
var candidateAnchors: seq[(int, int)]
for mw in truth.markerWalls: candidateAnchors.add anchorOf(mw)
for pos in extraMarkers:
if pos in candidateAnchors:
fail "MARKER_EARLY", "marker " & $pos & " sent before its wall was seen (group " &
g.label & ")"
else:
fail "MARKER_EXTRA", "marker " & $pos & " has no marker candidate wall (group " &
g.label & ")"
if wantPos.len > 0:
markerPositive = true
# --- CONTROLLER_CHANGE (10.3) ----------------------------------------------------------------
@@ -883,7 +938,7 @@ proc main() =
if removes == 0: fail "NO_REMOVE", "the scenario never withdrew a token (harness coverage)"
if seenAny.len < 3: fail "WITHHELD", "the scenario never showed the subject 3 tokens"
if not markerPositive:
fail "MARKER", "the scenario never produced a marker the visible-extent oracle expects"
fail "PROTOCOL", "the scenario never produced a marker the visible-extent oracle expects"
for cls, n in classes: echo "FAILCLASS ", cls, " ", n
echo "leakcheck: subject ", subject, " (player ", me, "), ", groupsSeen, " groups, ",