fix(storage): 库文件禁止写 undefined;assets 写前并集恢复(跨机器丢图库映射)

This commit is contained in:
qiqi committed 2026-12-05 20:19:48 +08:00
1 parent 623e76b3b4
commit 3d785e39fd
9 files changed
+78 -8

No files matched your search

+8 -1
View File
@@ -60,8 +60,15 @@ const mkAssets = (n) => { const a = {}; for (let i = 0; i < n; i++) a['imgblob_k
const log = fs.existsSync(path.join(R2, '_boot.log')) ? fs.readFileSync(path.join(R2, '_boot.log'), 'utf8') : ''
assert.ok(log.indexOf('assets-regress-load') >= 0, '② 必须留下 assets-regress-load 日志')
// ③ 并集恢复:写盘前用 bak 快照把丢失的 assets 补回来(不把坏版本写回去)
F2.storage().setItem('iwb_web_config', '{"x":1}')
await F2.flush()
assert.ok(F2.stats().images >= 40, '写盘前应从 bak 快照并集恢复 assets')
const after = JSON.parse(fs.readFileSync(path.join(R2, 'data.json'), 'utf8'))
assert.ok(Object.keys(after.assets || {}).length >= 40, '恢复后的 assets 应写回 data.json')
fs.rmSync(R1, { recursive: true, force: true })
fs.rmSync(R2, { recursive: true, force: true })
console.log('storage-assets-guard: 5 通过 / 0 失败')
console.log('storage-assets-guard: 7 通过 / 0 失败')
})().catch((e) => { console.error('storage-assets-guard FAILED:', e && (e.stack || e.message)); process.exit(1) })
+21 -1
View File
@@ -170,7 +170,27 @@ const boot = async () => {
await new Promise((r) => setTimeout(r, 4600))
assert.ok(readFile('canvases/ws1.json').includes('hello-retry'), '⑤ 失败键应在重试后落盘(否则等于一次失败永久丢)')
// 2026-12-05 事故回归:库文件绝不能写出 "undefined"
F1.storage().setItem('iwb_web_prompts', '[{"id":"keep"}]')
await F1.flush()
assert.ok(readFile('library/prompts.json').includes('keep'), '库文件正常写入')
F1.storage().setItem('iwb_web_prompts', undefined)
await F1.flush()
assert.ok(readFile('library/prompts.json').includes('keep'), 'setItem(undefined) 不得改动库文件')
F1.storage().removeItem('iwb_web_prompts')
await F1.flush()
assert.ok(!fs.existsSync(path.join(ROOT, 'library/prompts.json')), 'removeItem 后应删除库文件而不是写 undefined')
F1.storage().setItem('iwb_web_groups', '[{"id":"g1"}]')
await F1.flush()
F1.storage().clear()
await F1.flush()
const gtxt = fs.existsSync(path.join(ROOT, 'library/groups.json')) ? readFile('library/groups.json') : ''
assert.ok(gtxt.indexOf('undefined') < 0, 'clear 后库文件不得是 undefined(应写空数组或删除)')
fs.rmSync(ROOT, { recursive: true, force: true })
console.log('storage-flush-persist: 11 通过 / 0 失败')
console.log('storage-flush-persist: 15 通过 / 0 失败')
})().catch((e) => { console.error('storage-flush-persist FAILED:', e && (e.stack || e.message)); process.exit(1) })