tests: props, statuses, the resize rules and migration step 6 (#22)

tests/tprops.nim is new: the caps (per bucket, keys, values), the key rules,
the registry (empty fallback, a registered key's kind and bucket), set/unset
and the clone that keeps an edit away from the original bucket.

ttokens covers radius, the three buckets, the status set (round trip, sorted,
replaced rather than appended, removed by the FK cascade). tmoverules covers
per-token radius, shrink/grow/squeeze, the no-crossing rule, the corner
relaxation and the independence of the two sources; the old `blocked` tests
became `stuckWalls`. tviews covers the bucket and source filtering, one
`token` frame per change and the effective radius. tdb/tdb's fixtures move to
step 6, and tprobing follows the rename.
This commit is contained in:
2026-11-15 11:02:43 +01:00
parent 81898ab69c
commit 20575f2147
6 changed files with 537 additions and 95 deletions
+22 -11
View File
@@ -38,9 +38,9 @@ suite "migrate":
check migrate(db) == LatestVersion
check LatestVersion == migrations[^1].version
check schemaVersion(db) == LatestVersion
check LatestVersion == 5
check LatestVersion == 6
let rows = appliedMigrations(db)
check rows.len == 5
check rows.len == 6
check rows[0][0] == 1
check rows[0][1] == "meta"
check rows[1][0] == 2
@@ -51,6 +51,8 @@ suite "migrate":
check rows[3][1] == "tokens"
check rows[4][0] == 5
check rows[4][1] == "explored"
check rows[5][0] == 6
check rows[5][1] == "token details"
# the steps' own DDL ran: meta and the auth tables exist and are empty
check db.getValue(sql"SELECT count(*) FROM meta") == "0"
check db.getValue(sql"SELECT count(*) FROM player") == "0"
@@ -63,12 +65,16 @@ suite "migrate":
check db.getValue(sql"SELECT count(*) FROM entity") == "0"
# step 5 creates the explored chunk store (DESIGN 4.4), empty
check db.getValue(sql"SELECT count(*) FROM explored_chunk") == "0"
# step 6 adds the three prop buckets and the status table (DESIGN 5.5, 8), empty
check db.getValue(sql"SELECT count(*) FROM entity_status") == "0"
for col in ["props_public", "props_owner", "props_gm"]:
check db.getValue(sql("SELECT count(*) FROM pragma_table_info('entity') WHERE name = '" & col & "'")) == "1"
test "re-open is a no-op: no step applied, history and timestamps untouched":
let d = tmpDir()
block:
let db = openFresh(d)
check migrate(db) == 5
check migrate(db) == 6
close(db)
let db = openFresh(d)
defer:
@@ -77,7 +83,7 @@ suite "migrate":
let before = appliedMigrations(db)
check migrate(db) == 0
check migrate(db) == 0
check schemaVersion(db) == 5
check schemaVersion(db) == 6
check appliedMigrations(db) == before
test "history and user_version must agree":
@@ -151,16 +157,17 @@ suite "migrate":
check schemaVersion(db) == 2
check db.getValue(sql"SELECT count(*) FROM sqlite_master WHERE name = 'scene'") == "0"
check migrate(db) == 3 # steps 3, 4 and 5 run
check schemaVersion(db) == 5
check migrate(db) == 4 # steps 3, 4, 5 and 6 run
check schemaVersion(db) == 6
check db.getValue(sql"SELECT count(*) FROM scene") == "1"
check db.getValue(sql"SELECT next_wall_id FROM scene WHERE id = 1") == "1"
check db.getValue(sql"SELECT count(*) FROM player WHERE role = 'gm'") == "1"
check db.getValue(sql"SELECT count(*) FROM entity") == "0"
test "a slice-5 DB migrates on: explored_chunk appears and the world survives":
test "a schema-4 DB migrates on: explored_chunk and entity_status appear, the world survives":
# A fixture DB from the previous schema version (4, the slice-5 server): scene, a player, a key
# and a token already in it. Step 5 must add the explored store and leave all of it alone.
# and a token already in it. Steps 5 and 6 must add the explored store, the prop buckets and the
# status table, and leave all of it alone.
let d = tmpDir()
let db = openFresh(d)
defer:
@@ -183,10 +190,14 @@ suite "migrate":
check schemaVersion(db) == 4
check db.getValue(sql"SELECT count(*) FROM sqlite_master WHERE name = 'explored_chunk'") == "0"
check migrate(db) == 1 # only step 5 runs
check schemaVersion(db) == 5
check appliedMigrations(db).len == 5
check migrate(db) == 2 # steps 5 and 6 run
check schemaVersion(db) == 6
check appliedMigrations(db).len == 6
check appliedMigrations(db)[4] == (version: 5, name: "explored")
check appliedMigrations(db)[5] == (version: 6, name: "token details")
# step 6: the status table exists, and the old token's buckets default to empty objects
check db.getValue(sql"SELECT count(*) FROM entity_status") == "0"
check db.getValue(sql"SELECT props_public || props_owner || props_gm FROM entity") == "{}{}{}"
# the explored store exists, with both FKs and the 512-byte chunk invariant
check db.getValue(sql"SELECT count(*) FROM explored_chunk") == "0"
check db.getValue(sql"SELECT sql FROM sqlite_master WHERE name = 'explored_chunk'").contains("length(bits) = 512")