tools: the persistence group and six explored mutations (#21)
tools/persistence.test.mjs proves the store end to end over the real binary: a fresh resync round trip, strict per-player separation, SIGTERM and SIGKILL restart equality, a wall removal's revealed cells surviving after the wall returns, chunk rows decoded independently (512 B, blobs), move-ack timing (avg 0.8 ms, p99 2 ms) and a schema-4 fixture DB migrated by the binary. Mutations ag-al pin the bit layout, the chunk coordinate, the restore, the per-player key, the upsert and the dirty-chunk dedupe. smoke.test.mjs moves to version 5.
This commit is contained in:
@@ -49,15 +49,15 @@ test('a fresh DB is created and migrated; re-opening applies nothing', async ()
|
||||
const first = await startServer({ stateDir })
|
||||
const firstLog = first.log()
|
||||
await stopServer(first)
|
||||
assert.match(firstLog, /db_ready .*schema_version=4 applied=4/, firstLog)
|
||||
assert.match(firstLog, /db_ready .*schema_version=5 applied=5/, firstLog)
|
||||
assert.ok(fs.existsSync(first.dbPath), 'state.db was not created')
|
||||
|
||||
const db = new DatabaseSync(first.dbPath)
|
||||
try {
|
||||
assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 4)
|
||||
assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 5)
|
||||
const rows = db.prepare('SELECT version, name FROM schema_migration ORDER BY version').all()
|
||||
assert.deepEqual(rows.map(r => [Number(r.version), r.name]),
|
||||
[[1, 'meta'], [2, 'auth'], [3, 'world'], [4, 'tokens']])
|
||||
[[1, 'meta'], [2, 'auth'], [3, 'world'], [4, 'tokens'], [5, 'explored']])
|
||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM meta').get().n), 0)
|
||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM player').get().n), 0)
|
||||
// step 3 seeds the single v1 scene (Q3) with no walls and a counter at 1
|
||||
@@ -66,6 +66,8 @@ test('a fresh DB is created and migrated; re-opening applies nothing', async ()
|
||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM wall').get().n), 0)
|
||||
// step 4 creates the token table (DESIGN 4.4 `entity`), empty
|
||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM entity').get().n), 0)
|
||||
// step 5 creates the chunked explored store (DESIGN 4.4, #21), empty
|
||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM explored_chunk').get().n), 0)
|
||||
assert.equal(db.prepare('PRAGMA journal_mode').get().journal_mode, 'wal')
|
||||
} finally {
|
||||
db.close()
|
||||
@@ -74,7 +76,7 @@ test('a fresh DB is created and migrated; re-opening applies nothing', async ()
|
||||
const second = await startServer({ stateDir })
|
||||
const secondLog = second.log().slice(firstLog.length)
|
||||
await stopServer(second)
|
||||
assert.match(secondLog, /db_ready .*schema_version=4 applied=0/, secondLog)
|
||||
assert.match(secondLog, /db_ready .*schema_version=5 applied=0/, secondLog)
|
||||
assert.doesNotMatch(secondLog, /applied=[1-9]/)
|
||||
} finally {
|
||||
fs.rmSync(stateDir, { recursive: true, force: true })
|
||||
|
||||
Reference in New Issue
Block a user