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

38 lines
1.9 KiB
Nim

## One-off corpus extractor (dev-time only; tests never read prototype paths).
## usage: nim c -r tools/mkcorpus.nim docs/archive/prototypes/server-vision/results/leak-A.jsonl docs/archive/prototypes/server-vision/results/leak-B.jsonl > tests/fixtures/corpus.jsonl
## Replays the GM socket (token positions, door states per gseq) and emits one line per player `vision` message:
## {"src":"A|B","g":gseq,"id":"A|B","pos":[x,y],"open":[door ids],"poly":[[x,y]..]} (poly = what the prototype server sent,
## computed by the old geometry.nim; "open" = ALL open doors, initial states included). The scene (walls, radius, cell) is tests/fixtures/scene.json.
import std/[json, os, tables, algorithm]
for fi, path in commandLineParams():
let src = if fi == 0: "A" else: "B"
var pos: Table[string, JsonNode]
var open: Table[int, bool] # initial door states from the scene fixture, then the GM log
for w in parseFile("tests/fixtures/scene.json")["walls"]:
if w{"door"}.getBool: open[w["id"].getInt] = w["open"].getBool
var msgs: seq[JsonNode]
for line in lines(path):
let j = parseJson(line)
if j["k"].getStr == "msg": msgs.add j
# GM log first (gseq-ordered), then answer each vision message from the truth at its gseq
var gm: seq[JsonNode]
for j in msgs:
if j["who"].getStr == "GM": gm.add j["m"]
var gi = 0
for j in msgs:
let who = j["who"].getStr
let m = j["m"]
if who in ["A", "B"] and m["t"].getStr == "vision":
let g = m["gseq"].getInt
while gi < gm.len and gm[gi]["gseq"].getInt <= g:
let x = gm[gi]; inc gi
case x["t"].getStr
of "token": pos[x["id"].getStr] = x["pos"]
of "door": open[x["id"].getInt] = x["open"].getBool
else: discard
var ids: seq[int]
for k, v in open:
if v: ids.add k
ids.sort
echo $(%*{"src": src, "g": g, "id": who, "pos": pos[who], "open": ids, "poly": m["polys"][0]})