docs(tests): explain copy mappings and resumable planning checks

This commit is contained in:
2026-11-12 17:28:04 +08:00
parent 7ed36b1ae0
commit c43af2ccb9
7 changed files with 12 additions and 0 deletions
+2
View File
@@ -16,6 +16,7 @@ const node=i=>({id:`n-${i}`,incarnation:1,ownerCanvasId:'canvas',componentId:'te
// 512 个节点及一个墓碑组成统一快照,既覆盖批量处理,也覆盖删除身份信息。
const document=createDocument('project',[{id:'canvas',parent:null}],Array.from({length:512},(_,i)=>node(i)),new Map([['retired',2]]));
// cheap 时钟固定为零,costly 每次前进 10;记录 yield 次数,区分按预算让出与固定条数休眠。
// yieldTask 只累计次数,不经过真实浏览器帧;cheap/costly 是可重复的调度输入,不是运行耗时基准。
function scheduling(slow=false){let yields=0,tick=0;return{options:{now:()=>slow?(++tick)*10:0,yieldTask:async()=>{yields++;}},get yields(){return yields;}};}
// 普通/索引格式在便宜和昂贵时间切片下编码完全相同;解码保留 512 节点及墓碑,索引格式还读取末项核对内容。
@@ -38,6 +39,7 @@ test('large records consume work budget and coarse clocks still yield without ch
// 拒绝非正或非有限 frameBudgetMs;yieldTask 的宿主错误保留原对象,不转换成伪造的复制取消。
test('copy budget rejects invalid scheduling and preserves host scheduling failures',async()=>{
for(const frameBudgetMs of [0,-1,NaN,Infinity])await assert.rejects(encodeIndexedCopySnapshot(document,signal(),{frameBudgetMs}),error=>error.code==='invalid_copy_budget');
// 用对象身份比较宿主异常,确保调度器错误没有被包装成 copy_aborted 或丢失具体原因。
const failure=Error('host unavailable');let time=0;await assert.rejects(encodeCopySnapshot(document,signal(),{now:()=>time+=10,yieldTask:async()=>{throw failure;}}),error=>error===failure);
});
// 旧式 prepared duplicate 源在不同切片下保持相同字节;预算边界取消时拒绝而非返回部分输出。