feat(game): tasks table + schema v7 backfill, admin registry (#44)

This commit is contained in:
2026-10-02 13:08:53 +00:00
parent f52a59c5fc
commit 6c51c3cec8
6 changed files with 78 additions and 1 deletions
+23
View File
@@ -379,6 +379,29 @@ describe('backfill (old saves)', () => {
expect((await db.db.select().from(schema.planets)).length).toBe(planetCount)
})
it('v7: a v6-stamped save gets an empty tasks table without touching state; idempotent across restart', async () => {
const { db, file } = await freshFile()
const world = await getWorldState(db) // fresh game, stamped at the current version
const crewBefore = await db.db.select().from(schema.crew)
const invBefore = await db.db.select().from(schema.inventoryItems)
await db.db.update(schema.saves).set({ schemaVersion: 6 }) // simulate a save stamped by v0.9.12
const world2 = await getWorldState(db) // ensureSave → backfill v6 → v7
expect(world2).toEqual(world) // turn, systems, edges — untouched (Review Focus 1)
expect((await db.db.select().from(schema.saves))[0].schemaVersion).toBe(7)
expect(await db.db.select().from(schema.crew)).toEqual(crewBefore)
expect(await db.db.select().from(schema.inventoryItems)).toEqual(invBefore)
const tables = db.raw.exec("SELECT name FROM sqlite_master WHERE type = 'table'")
expect(tables[0].values.map((v) => v[0])).toContain('tasks')
expect(Number(db.raw.exec('SELECT COUNT(*) FROM tasks')[0]?.values[0][0] ?? 0)).toBe(0) // empty queue after upgrade
const reopened = await openGameDb(file) // restart: the backfill must be a no-op
await getWorldState(reopened)
expect((await reopened.db.select().from(schema.saves))[0].schemaVersion).toBe(7)
expect(Number(reopened.raw.exec('SELECT COUNT(*) FROM tasks')[0]?.values[0][0] ?? 0)).toBe(0)
})
it('seeds the starting ship on a new game: core types built at base values, WEAPONS unbuilt', async () => {
const { db } = await freshFile()
await getWorldState(db)