test: walls r1 review — tests and tools

Ref #52
This commit is contained in:
2026-11-20 08:59:24 +01:00
parent e1a5b297e4
commit 38941da003
14 changed files with 329 additions and 69 deletions
+20
View File
@@ -88,6 +88,10 @@ suite "migrate":
check db.getValue(sql"SELECT count(*) FROM marker_seen") == "0"
check db.getValue(sql"SELECT sql FROM sqlite_master WHERE name = 'marker_seen'")
.contains("FOREIGN KEY (scene_id, wall_id) REFERENCES wall(scene_id, id) ON DELETE CASCADE")
# The opaque marker id is per player, never shared: (player_id, marker_id) is UNIQUE, and the
# composite FK refuses a marker for a wall that does not exist.
check db.getValue(sql"SELECT sql FROM sqlite_master WHERE name = 'marker_seen'")
.contains("UNIQUE (player_id, marker_id)")
check db.getValue(sql"SELECT count(*) FROM sqlite_master WHERE name = 'wall_v1'") == "0"
test "re-open is a no-op: no step applied, history and timestamps untouched":
@@ -324,6 +328,22 @@ suite "step 8 wall CHECKs (DESIGN 4.4)":
check insert(row(door = "1", open = "1")) # an open door is legal
check db.getValue(sql"SELECT count(*) FROM wall") == "5"
# marker_seen: a marker needs a player and an existing wall, and one player cannot hold the
# same opaque id twice (UNIQUE (player_id, marker_id)), even for a different wall.
db.exec(sql"INSERT INTO player (id, name, role, colour, created_at) VALUES (?, ?, ?, ?, ?)",
20, "Marker", "player", "#fff", "x")
proc marker(wall: int, mid: string): bool =
try:
db.exec(sql"INSERT INTO marker_seen (player_id, scene_id, wall_id, marker_id) VALUES (20, 1, ?, ?)",
wall, mid)
true
except CatchableError:
false
check marker(1, "AAAAAAAAAAAA")
check not marker(99, "BBBBBBBBBBBB") # no such wall: the composite FK refuses it
check not marker(2, "AAAAAAAAAAAA") # the same player's marker id, another wall: UNIQUE
check db.getValue(sql"SELECT count(*) FROM marker_seen") == "1"
test "a failing step 8 rolls back the rebuild, the history row and the version":
let d = tmpDir()
let db = openFresh(d)