docs(tests): explain editing leases and conditional wire compaction

This commit is contained in:
2026-11-12 17:55:19 +08:00
parent 1defe9db90
commit 93f14af667
2 changed files with 7 additions and 0 deletions
+3
View File
@@ -50,6 +50,7 @@ test('connection drag owns the project gesture, previews without history, commit
const path = { type: 'bezier-chain', knots: [] };
for (let i = 0; i < 20; i++) sessions.updateConnection('one', { ...path, startControl: { x: i, y: 0 } });
assert.equal(editor.getSnapshot().history.undo.length, 0); assert.equal(editor.getSnapshot().operations.size, 0); assert.equal(editor.getSnapshot().document.elements.get('edge').path, null);
// 20 次预览只改会话;commit 将最后一次 x=19 的控制向量提交成一个操作及一个撤销单元。
assert.equal(sessions.commitConnection('one').status, 'applied'); assert.equal(editor.getSnapshot().history.undo.length, 1); assert.equal(editor.getSnapshot().operations.size, 1);
assert.equal(editor.getSnapshot().document.elements.get('edge').path.startControl.x, 19);
sessions.beginConnection('one', target); sessions.updateConnection('one', { ...path, startControl: { x: 99, y: 0 } }); detach();
@@ -94,6 +95,7 @@ test('workspace retains a failed close for retry and stops edits before releasin
await assert.rejects(() => workspace.close(), /workspace_close_failed/); assert.equal(leader.active, true); assert.equal(closed, false);assert.equal(digestClosed,false);
assert.equal(a.editor.dispatch({ type: 'element.data', target: { id: 'outside', incarnation: 1 }, patch: { title: 'late' } }).status, 'rejected');
assert.equal(workspace.getProjects().size, 1);
// 第一次关闭失败后 workspace 仍保留 project 和 leader,供同一 owner 重试保存;成功后才关闭共享资源和存储。
broken = false; await workspace.close(); assert.equal(leader.active, false); assert.equal(closed, true);assert.equal(digestClosed,true);
});
@@ -117,6 +119,7 @@ test('a canceled pointer lease cannot update, finish or cancel a newer gesture i
const lease = () => { const token = sessions.getSnapshot().gesture.token; return guardEditingLease(() => sessions.getSnapshot().gesture?.token === token, { preview: patch => sessions.update('view', target, patch), commit: () => sessions.commit('view'), cancel: () => sessions.cancel('pointer_cancel') }); };
sessions.begin('view', [target]); const first = lease(); first.preview({ x: 100 }); first.cancel();
sessions.begin('view', [target]); const second = lease(); second.preview({ x: 200 });
// 同一 view/element 的第二场手势有新 token;旧 lease 的三个入口都应无效,不能只防止重复 commit。
first.preview({ x: 500 }); first.commit(); first.cancel();
assert.equal(sessions.getSnapshot().gesture.preview.get('outside').x, 200); assert.equal(editor.getSnapshot().history.undo.length, 0);
second.commit(); assert.equal(editor.getSnapshot().document.elements.get('outside').geometry.x, 200); assert.equal(editor.getSnapshot().history.undo.length, 1);