docs(tests): explain model preview dependencies and loading completion

This commit is contained in:
2026-11-12 17:44:25 +08:00
parent ea3df9877d
commit 535d963eaa
4 changed files with 8 additions and 0 deletions
+2
View File
@@ -26,6 +26,7 @@ test('partial model waits for entry/owner/port cycles and edge endpoints; publis
const preview=createModelPreview(registry);const first=preview.update(head());validateDocument(first.document,registry);assert.equal(first.document.canvases.size,1);
const second=preview.update(delta([a,edge],2));assert.equal(second.document.elements.size,0);assert.equal(second.waitingElements,2);assert.strictEqual(second.document,first.document);
const third=preview.update(delta([b],3));assert.deepEqual([...third.document.elements.keys()],['B']);assert.equal(third.waitingElements,2);
// F 是入口、端口又引用 A;只有这一批到来,canvas/节点/边的依赖闭环才一起满足。
const fourth=preview.update(delta([frame],4));validateDocument(fourth.document,registry);assert.equal(fourth.document.elements.size,4);assert.equal(fourth.document.canvases.size,2);assert.equal(fourth.waitingElements,0);assert.equal(fourth.document.elements.get('E').ownerCanvasId,root);
assert.equal(first.document.elements.size,0);assert.equal(third.document.elements.size,1);assert.equal(fourth.complete,false);preview.close();assert.throws(()=>preview.update(delta([],4)),{code:'model_preview_closed'});
});
@@ -53,6 +54,7 @@ test('bad topology and version/source switches cannot silently alter a preview',
test('owned preview records do not freeze or retain mutable caller payloads; final completion must match',()=>{
const preview=createModelPreview(registry),header=structuredClone(head(1)),element=node('one');preview.update(header);const state=preview.update(delta([element],1,1));
element.data.text='changed by caller';header.canvases[0].id='changed';assert.equal(state.document.elements.get('one').data.text,'');assert.equal(state.document.canvases.has(root),true);
// 最终输入沿用已被调用者改过的 element;与捕获前缀的正文不同,必须拒绝而不是悄悄覆盖预览。
const final=createDocument(root,[{id:root,parent:null},{id:child,parent:{canvasId:root,entryElementId:'F'}}],[element]);assert.throws(()=>preview.update({status:'ready',document:final,versions}),{code:'model_preview_changed'});
});
// 后续块重复已发布 ID 属于非法输入,并使投影关闭;之后即使给合法新项也不能继续同一预览。