feat(m4): playtest friction: perf overlay, fresh import, token seed (#82)
Opt-in ?perf=1 overlay (fps, frame p50/p95, JS p50/p95, tokens, zoom; no node or ticker work when off). fff-vtt import creates and migrates a fresh/empty state dir through the shared server startup path; devbox run serve gains --image. devbox run seed creates deterministic labelled NPC tokens over the real WS (idempotent rerun, --replace), and the GM token form defaults X/Y to the viewport centre.
This commit is contained in:
+32
-14
@@ -8,7 +8,6 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import fs from 'node:fs'
|
||||
import os from 'node:os'
|
||||
import path from 'node:path'
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { createPlayer, freePort, httpsBaseUrl, namePlayer } from './lib.mjs'
|
||||
@@ -137,6 +136,38 @@ test('map import CLI: a fixture slices into v1 tiles, the scene row and a 200 th
|
||||
}
|
||||
})
|
||||
|
||||
test('map import CLI: a fresh/empty state dir is created, migrated and servable (#82)',
|
||||
async () => {
|
||||
const root = makeStateDir()
|
||||
const stateDir = path.join(root, 'fresh')
|
||||
const img = writeFixtureImage(path.join(root, 'map.png'))
|
||||
try {
|
||||
assert.equal(fs.existsSync(stateDir), false, 'the state dir starts absent')
|
||||
const imported = runImport(stateDir, [`--image=${img}`, '--tile-size=64'])
|
||||
assert.equal(imported.status, 0, imported.stderr)
|
||||
assert.match(imported.stderr, /created\/migrated .*schema step/)
|
||||
assert.match(imported.stdout, /256x192 px, tile 64 px, 4x3 tiles/)
|
||||
assert.equal(fs.existsSync(path.join(stateDir, 'state.db')), true, 'the DB is created')
|
||||
assert.equal(tileNames(path.join(stateDir, 'tiles', '1', 'v1')).length, 12,
|
||||
'the imported tile tree exists without a prior server or gm-key run')
|
||||
|
||||
const gmKey = gmKeyOf(stateDir)
|
||||
const s = await startServer({ stateDir })
|
||||
try {
|
||||
const gm = await openAs(s.origin, gmKey)
|
||||
const hello = await gm.ws.waitText('hello')
|
||||
assert.equal(hello.scene.w, 256, 'the server serves the imported scene')
|
||||
assert.equal(hello.scene.h, 192)
|
||||
assert.equal(hello.scene.tile_size, 64)
|
||||
gm.ws.close()
|
||||
} finally {
|
||||
await stopServer(s)
|
||||
}
|
||||
} finally {
|
||||
fs.rmSync(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
test('map import CLI: every refused import exits non-zero with a message and changes nothing',
|
||||
async () => {
|
||||
const stateDir = makeStateDir()
|
||||
@@ -170,19 +201,6 @@ test('map import CLI: every refused import exits non-zero with a message and cha
|
||||
assert.match(help.stdout, /--image=<path>/)
|
||||
assert.match(help.stdout, /state-dir lock is refused/)
|
||||
|
||||
const ghost = path.join(os.tmpdir(), `fffvtt-absent-${process.pid}-${Date.now()}`)
|
||||
const absent = runImport(ghost, [`--image=${img}`])
|
||||
assert.notEqual(absent.status, 0)
|
||||
assert.match(absent.stderr, /does not exist/)
|
||||
assert.equal(fs.existsSync(ghost), false, 'an absent state dir is not created')
|
||||
|
||||
const empty = makeStateDir()
|
||||
const noDb = runImport(empty, [`--image=${img}`])
|
||||
assert.notEqual(noDb.status, 0)
|
||||
assert.match(noDb.stderr, /no state\.db/)
|
||||
assert.equal(fs.existsSync(path.join(empty, 'tiles')), false)
|
||||
fs.rmSync(empty, { recursive: true, force: true })
|
||||
|
||||
// An unreadable DB (the state-dir contents cannot be opened) is a clear runtime error, not a
|
||||
// migration attempt or a partial import.
|
||||
const dbFile = path.join(stateDir, 'state.db')
|
||||
|
||||
Reference in New Issue
Block a user