server: scene.set closes the 29-intent catalogue, plus a log-leak fault hook (#25)

This commit is contained in:
2026-11-15 12:52:17 +01:00
parent df2b186267
commit 70a984c55a
7 changed files with 453 additions and 11 deletions
+65 -1
View File
@@ -1,7 +1,7 @@
## Scene and wall state (#19, DESIGN 3.1, 4.1, 4.4, 6.1, 8): wall validation, the per-scene
## never-reused wall ids, the write-through persistence (synchronous=FULL for authoring) and the
## reload that a restart performs. The wire behaviour over a real socket lives in tools/walls.test.mjs.
import std/[json, options, os, sequtils, unittest]
import std/[json, options, os, sequtils, strutils, unittest]
import db_connector/db_sqlite
import db, world
@@ -300,3 +300,67 @@ suite "lookup outcomes (main.nim's 6.5 mapping)":
let id = addWall(conn, sc, wall(1, 1, 2, 2)).get
check id == 1
check wallById(sc, 0).isNone
suite "scene.set (6.1, slice 10 / #25)":
test "a patch changes only the fields it names and the row round-trips":
let (conn, d) = freshScene()
defer:
close(conn)
removeDir(d)
let before = loadScene(conn).get
let p = parseScenePatch(%*{"name": "Cave", "grid_size": 64,
"vision_radius_default": 500, "token_radius_default": 30,
"extra": {"mood": "dark"}})
check p.isSome
let after = patched(before, p.get)
check after.name == "Cave"
check after.gridSize == 64
check after.visionRadiusDefault == 500
check after.tokenRadiusDefault == 30
check after.extra["mood"].getStr == "dark"
# the non-settable columns and the wall counter are untouched (import is the M6 CLI)
check (after.w, after.h) == (before.w, before.h)
check after.tileSize == before.tileSize and after.cell == before.cell
check after.artVersion == before.artVersion
check after.nextWallId == before.nextWallId
storeScene(conn, after)
let back = loadScene(conn).get
check back.name == "Cave"
check back.gridSize == 64
check back.visionRadiusDefault == 500
check back.tokenRadiusDefault == 30
check back.extra["mood"].getStr == "dark"
test "one field is enough; a patch with none is invalid":
check parseScenePatch(%*{"name": "Cave"}).isSome
check parseScenePatch(%*{"grid_size": 0}).isSome
check parseScenePatch(%*{}).isNone
check parseScenePatch(newJNull()).isNone
check parseScenePatch(nil).isNone
check parseScenePatch(%*[1]).isNone
test "the non-settable columns are unknown fields: alone they leave no patch field":
for key in ["w", "h", "tile_size", "cell", "art_version"]:
check parseScenePatch(%*{key: 1}).isNone
# and they are ignored next to a real field (6.2)
let p = parseScenePatch(%*{key: 1, "name": "Cave"})
check p.isSome
check p.get.name.get == "Cave"
test "field shapes: text by the 6.5 rule, numbers finite, extra an object":
check parseScenePatch(%*{"name": ""}).isNone
check parseScenePatch(%*{"name": " padded"}).isNone # trimmed rule, like other names
check parseScenePatch(%*{"name": repeat("x", SceneNameMaxLen + 1)}).isNone
check parseScenePatch(%*{"name": repeat("x", SceneNameMaxLen)}).isSome
check parseScenePatch(%*{"name": 5}).isNone
check parseScenePatch(%*{"name": newJNull()}).isNone # declared, wrong type
check parseScenePatch(%*{"grid_size": -1}).isNone
check parseScenePatch(%*{"grid_size": "60"}).isNone
check parseScenePatch(%*{"grid_size": 0}).isSome
check parseScenePatch(%*{"vision_radius_default": 0}).isNone
check parseScenePatch(%*{"vision_radius_default": -5}).isNone
check parseScenePatch(%*{"token_radius_default": 0}).isNone
check parseScenePatch(%*{"token_radius_default": 20.5}).isSome
check parseScenePatch(%*{"extra": []}).isNone
check parseScenePatch(%*{"extra": newJNull()}).isNone
check parseScenePatch(%*{"extra": {}}).isSome