@@ -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)
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
## Player marker memory in process (DESIGN 5.8, 6.1, ADR-0015; #59/#60): the emission gate, the
|
||||
## opaque per-player id, the fixed anchor, and the retraction rule. The wire, storage, resync and
|
||||
## privacy are proven by tools/markers.test.mjs; this file pins the rule the mutation suite can
|
||||
## mutate: a marker is memory, so only a cause change (wall gone, switch off, no longer a window,
|
||||
## geometry moved) retracts it, and the signature is exactly those causes.
|
||||
import std/[options, tables, unittest]
|
||||
import geometry, markers, vision, world
|
||||
|
||||
proc sceneWith(walls: varargs[WallRec]): SceneRec =
|
||||
SceneRec(id: 1, w: 4096, h: 4096, tileSize: 32, cell: 32, walls: @walls)
|
||||
|
||||
proc windowWall(id: int, a, b: Vec): WallRec =
|
||||
## The `window` preset's switch set at the given geometry (an opening window, marker on).
|
||||
result = defaultWall(a, b)
|
||||
result.id = id
|
||||
result.blocksSight = false
|
||||
result.blocksMovement = true
|
||||
result.door = true
|
||||
result.playerMarker = true
|
||||
|
||||
proc poly(pts: varargs[Vec]): seq[Poly] =
|
||||
@[Poly(tokenId: "tok000000001", pts: @pts)]
|
||||
|
||||
const Covered = @[(0.0, 0.0), (400.0, 0.0), (400.0, 400.0), (0.0, 400.0)]
|
||||
|
||||
suite "player markers (5.8, #59/#60)":
|
||||
test "a marked window seen by any part of its extent mints one anchor marker":
|
||||
var pv = PlayerVision(polys: poly(Covered))
|
||||
let w = windowWall(1, (100.0, 100.0), (100.0, 300.0))
|
||||
check syncMarkers(pv, sceneWith(w)) == 1
|
||||
check pv.markers.len == 1
|
||||
check pv.markers[1].id.len == 12
|
||||
check (pv.markers[1].x, pv.markers[1].y) == (100, 200) # the drawn midpoint
|
||||
check pv.markerFresh.len == 1 and pv.markerDead.len == 0
|
||||
|
||||
test "an untouched marker survives a refresh: it is memory, not current sight":
|
||||
var pv = PlayerVision(polys: poly(Covered))
|
||||
let sc = sceneWith(windowWall(1, (100.0, 100.0), (100.0, 300.0)))
|
||||
check syncMarkers(pv, sc) == 1
|
||||
let earned = pv.markers[1].id
|
||||
pv.polys = poly(@[(2000.0, 2000.0), (2200.0, 2000.0), (2200.0, 2200.0)])
|
||||
check syncMarkers(pv, sc) == 0 # walking away mints and retracts nothing
|
||||
check pv.markers.hasKey(1) and pv.markers[1].id == earned
|
||||
check pv.markerDead.len == 0
|
||||
|
||||
test "a geometry change retracts the marker and a re-earn gets a fresh id":
|
||||
var pv = PlayerVision(polys: poly(Covered))
|
||||
var w = windowWall(1, (100.0, 100.0), (100.0, 300.0))
|
||||
check syncMarkers(pv, sceneWith(w)) == 1
|
||||
let earned = pv.markers[1].id
|
||||
w.thickness = 7 # thickness is a retraction cause
|
||||
check syncMarkers(pv, sceneWith(w)) == 1
|
||||
check pv.markerDead == @[earned]
|
||||
check pv.markers[1].id != earned # a re-earned marker is a new id
|
||||
check (pv.markers[1].x, pv.markers[1].y) == (100, 200)
|
||||
|
||||
test "a placement change retracts too; height and label never do":
|
||||
var pv = PlayerVision(polys: poly(Covered))
|
||||
var w = windowWall(1, (100.0, 100.0), (100.0, 300.0))
|
||||
check syncMarkers(pv, sceneWith(w)) == 1
|
||||
let earned = pv.markers[1].id
|
||||
w.height = some(1.0) # no marker consequence
|
||||
w.label = some("railing")
|
||||
check syncMarkers(pv, sceneWith(w)) == 0
|
||||
check pv.markers[1].id == earned
|
||||
w.position = wpLeft # placement is a retraction cause
|
||||
check syncMarkers(pv, sceneWith(w)) == 1
|
||||
check pv.markerDead == @[earned]
|
||||
|
||||
test "a solid wall with the switch on mints nothing; clearing the switch retracts":
|
||||
var pv = PlayerVision(polys: poly(Covered))
|
||||
var solid = defaultWall((100.0, 100.0), (100.0, 300.0))
|
||||
solid.id = 1
|
||||
solid.playerMarker = true
|
||||
check syncMarkers(pv, sceneWith(solid)) == 0 # a solid wall never qualifies as a window
|
||||
var w = windowWall(2, (150.0, 100.0), (150.0, 300.0))
|
||||
check syncMarkers(pv, sceneWith(solid, w)) == 1
|
||||
let earned = pv.markers[2].id
|
||||
w.playerMarker = false
|
||||
check syncMarkers(pv, sceneWith(solid, w)) == 0
|
||||
check pv.markerDead == @[earned]
|
||||
@@ -347,6 +347,18 @@ suite "validation (DESIGN 6.1 `wall.*`)":
|
||||
check resolveWall(plain, none(Preset),
|
||||
WallSettings(blocksSight: some(false), sightDir: some(sdLeft))).isNone
|
||||
|
||||
test "storable is the last gate: a secret or locked non-door is refused":
|
||||
# `resolveWall` already refuses a named door-only setting on a non-door; `storable` is the
|
||||
# backstop for every other caller (the importer, a future entry point), so it must say no to a
|
||||
# record no path could build.
|
||||
var r = defaultWall((0.0, 0.0), (10.0, 0.0))
|
||||
check storable(r)
|
||||
r.secret = true
|
||||
check not storable(r)
|
||||
r.secret = false
|
||||
r.locked = true
|
||||
check not storable(r)
|
||||
|
||||
test "a label is 1..64 code points, trimmed and free of control characters (#55)":
|
||||
let (conn, d) = freshScene()
|
||||
defer:
|
||||
|
||||
Reference in New Issue
Block a user