This commit is contained in:
2026-10-19 02:34:50 +07:00
parent 06af1e047d
commit e2f8a3302e
15 changed files with 109 additions and 32 deletions
+47
View File
@@ -6,6 +6,7 @@ import { readdirSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { test, type TestContext } from 'node:test'
import { Controller } from './controller.js'
import { buildScreenPackage, parseScreenPackage } from './screen-package.js'
import {
PackageStore,
@@ -570,3 +571,49 @@ test('инкрементальный кеш: ошибка и отмена не
await assert.rejects(f.store.ensureAsset(f.pkg, second!.id, abort.signal))
await assert.rejects(f.store.localFile(f.key, second!.id))
})
test('старый пакет проходит проверку хеша после перезапуска и показывает текст без сети', async (t) => {
const f = await fixture(t)
f.pkg.steps = [3, 5].map((mode) => ({
mode,
text: '',
timerLabel: '',
timerDurationSeconds: 0,
}))
f.pkg.metadataVersion = createHash('sha256')
.update(
JSON.stringify(f.pkg, (key, value: unknown) =>
key === 'metadataVersion' ? undefined : value,
),
)
.digest('hex')
const downloaded = await f.store.download(f.pkg)
const restored = new PackageStore(f.root, {
...f.dependencies,
fetch: async () => {
throw new Error('Нет сети')
},
})
await restored.initialize()
const local = restored.list().find((pkg) => pkg.key === f.key)!
assert.equal(local.version, downloaded.version)
const controller = new Controller(() => {})
controller.selectPackage(local)
assert.deepEqual(
controller.state.catalog.steps.map(({ mode, text }) => ({ mode, text })),
[
{ mode: 8, text: 'Успехов' },
{ mode: 8, text: 'Спасибо за игру!' },
],
)
for (const [index, text] of ['Успехов', 'Спасибо за игру!'].entries()) {
controller.command({
session: controller.state.session,
sequence: controller.state.sequence + 1,
action: 'step',
index,
})
assert.equal(controller.state.scene.mode, 8)
assert.equal(controller.state.scene.text, text)
}
})