docs(tests): clarify editor publication and service receipt assertions

This commit is contained in:
2026-11-12 18:00:29 +08:00
parent 05a41813f3
commit 245f6e3254
2 changed files with 7 additions and 0 deletions
+4
View File
@@ -34,6 +34,7 @@ test('runtime preparation shares the document publication boundary; metadata has
assert.equal(editor.updateRuntime(value => ({ ...value, ready: true }), old.rootRevision).status, 'applied');
assert.equal(editor.getSnapshot().rootRevision, 2); assert.equal(editor.getSnapshot().revision, 1);
assert.equal(editor.updateRuntime(value => value, old.rootRevision).code, 'stale_plan');
// ack 在此只是命令来源标签:检查它不新增用户操作/历史,未经过真实回执或网络协调。
editor.dispatch({ type: 'element.data', target: target('a'), patch: { title: 'canonical' } }, { origin: 'ack' });
assert.equal(editor.getSnapshot().operations.size, 1); assert.equal(editor.getSnapshot().history.undo.length, 1);
});
@@ -165,6 +166,7 @@ test('async transactions reject, close their draft, and never publish the asynch
await Promise.resolve();
tx.dispatch({ type: 'element.data', target: target('a'), patch: { title: 'after await' } });
});
// 在拒绝后推进微任务,让 async 回调尝试执行后半段;关闭的 tx 应挡住迟到写入。
assert.equal(result.status, 'rejected'); await Promise.resolve(); await Promise.resolve();
assert.strictEqual(editor.getSnapshot(), before);
assert.throws(() => captured.dispatch({ type: 'element.remove', target: target('a') }), /transaction_closed/);
@@ -253,6 +255,7 @@ test('cross-child connection belongs to the common ancestor; cyclic canvas owner
const canvases = [{ id: 'root', parent: null }, { id: 'child', parent: { canvasId: 'root', entryElementId: 'f' } }, { id: 'sibling', parent: { canvasId: 'root', entryElementId: 'g' } }];
const registry = createRegistry(builtinComponents());
const document = createDocument('p', canvases, elements);
// 这里只调用归属查询 commonCanvas,没有真的创建兄弟分区连线;随后独立检查循环 reparent 拒绝。
assert.equal(commonCanvas(document, 'child', 'sibling'), 'root');
const editor = setup(elements, { registry, document }); const before = editor.getSnapshot();
assert.equal(editor.dispatch({ type: 'canvas.reparent', canvasId: 'root', parent: { canvasId: 'child', entryElementId: 'a' } }).status, 'rejected');
@@ -312,6 +315,7 @@ test('growing grouped history can yield during recovery encoding without alterin
for(let i=0;i<300;i++)assert.equal(editor.dispatch({type:'element.data',target:target('a'),patch:{title:'step-'+i}},{groupId:'large-history'}).status,'applied');
const entry=editor.getSnapshot().history.entries.get(editor.getSnapshot().history.undo.at(-1));
assert.equal(entry.changes.length,300);let tick=0,yields=0;
// 编码拿到旧 entry 后再追加同组输入,检查历史扩展不会原地改写已捕获的 300 项前缀。
const pending=sealRecoveryImageAsync(17,1,1,entry,{now:()=>tick++,frameBudgetMs:1,yieldTask:async()=>{yields++;}});
assert.equal(editor.dispatch({type:'element.data',target:target('a'),patch:{title:'later'}},{groupId:'large-history'}).status,'applied');
const image=await pending;assert.ok(yields>0);assert.deepEqual(image.payload,JSON.parse(JSON.stringify(entry)));assert.equal(image.payload.changes.length,300);