docs(tests): explain asset authorization and byte retention lifecycle

This commit is contained in:
2026-11-12 17:39:05 +08:00
parent 1c549724e8
commit b768c2d6bf
5 changed files with 11 additions and 1 deletions
+3 -1
View File
@@ -63,6 +63,7 @@ const adopt=(engine,id='picture')=>engine.adoptResource('shared',(handle,tx)=>tx
test('adoption atomically publishes binding/history/ledger and reopens shared bytes without an upload',async()=>{
const f=fixture();let engine=await f.open();try{
assert.equal((await adopt(engine)).status,'applied');assert.equal(engine.getSnapshot().history.undo.length,1);assert.equal(engine.getSnapshot().runtime.resources.size,0);assert.equal(engine.getSnapshot().runtime.assetBindings.get('shared').digest,digest);await engine.settle();
// 检查同一提交 cut 中的 depot 写入、文档、历史和 ledger;显示成功本身不足以证明这些状态一起持久保存。
const image=f.roots.get('p');assert.equal(image.formatVersion,13);decodeRecovery(image,registry);const cut=f.batches.find(batch=>batch.image.payload.runtime.assetBindings);assert.equal(cut.depot.writes[0].bytes,bytes);assert.equal(cut.files.length,0);assert.equal(cut.image.payload.document.elements.length,1);assert.equal(cut.image.payload.history.undo.length,1);assert.equal(cut.image.payload.runtime.ledger.operations.some(([,row])=>row.intent.operationType==='asset.upload'),false);
await engine.close();engine=await f.open();const handle=await engine.displayResource('shared');assert.equal(await(await fetch(handle.url)).text(),'original bytes');handle.release();
assert.equal(engine.editor.history.undo().status,'applied');await engine.settle();assert.equal(engine.getSnapshot().document.elements.size,0);assert.equal(engine.editor.history.redo().status,'applied');await engine.settle();assert.equal(engine.getSnapshot().document.elements.get('picture').incarnation,2);assert.equal(f.calls.filter(v=>v==='read').length,1);assert.equal(f.errors.length,0);
@@ -113,7 +114,8 @@ test('an older Root cannot release newly adopted bytes while its unpinned manife
const ready=new Promise(resolve=>started=resolve),gate=new Promise(resolve=>release=resolve);let once=true;
f.storage.commit=async(leader,batch)=>{if(once){once=false;assert.equal(batch.depot.pins.some(([id])=>id==='shared'),false);started();await gate;}return commit(leader,batch);};
engine.editor.updateRuntime(previous=>({...previous}));await ready;
// GC is allowed here: the old Root has no working/history/ACK/job reference.
// 旧 Root 已没有 working/history/ACK/job 引用,手工清空共享缓存模拟这时发生 GC。
// 随后的 fresh 接纳属于更新的 Root,旧提交结束不能清掉新 Root 仍需落盘的待写字节。
f.cache.clear();assert.equal((await adopt(engine,'fresh')).status,'applied');release();await engine.settle();assert.equal(await f.cache.values().next().value.bytes.text(),'original bytes');assert.equal(f.roots.get('p').payload.document.elements.some(element=>element.id==='fresh'),true);
}finally{release?.();f.storage.commit=commit;await engine.close();}
});