docs(tests): explain legacy history and subgraph synchronization fixtures

This commit is contained in:
2026-11-12 17:17:43 +08:00
parent 2dbe68c6aa
commit ad20013f0f
3 changed files with 16 additions and 0 deletions
+6
View File
@@ -19,12 +19,14 @@ test("serialized autosaves use successive versions and coalesce queued documents
const calls = [], first = deferred();
const writer = new CanvasSync(async (path, options) => {
calls.push({ path, ...options });
// 首次响应手动释放,后续立即 ACK,便于检查下一次发送使用首个 ACK 返回的版本。
if (calls.length === 1) return first.promise;
return { version: 3 };
}, canvasPath("space", "board"), { version: 1, document: emptyCanvas() }, () => {});
const a = writer.enqueue(document("A")); await tick();
writer.enqueue(document("B")); writer.enqueue(document("C"));
assert.equal(calls.length, 1);
// 等待保存泵排空,核对最终发出 C 而非中间 B。
first.resolve({ version: 2 }); await a;
assert.equal(calls.length, 2);
assert.equal(calls[0].headers["If-Match"], '"1"'); assert.equal(calls[1].headers["If-Match"], '"2"');
@@ -79,6 +81,8 @@ test("failed snapshot loads and mismatched boards prevent editing rather than cr
test("dirty local recovery and legacy drafts are offered for explicit migration; clean backups never replace server data", () => {
const remote = { version: 3, document: document("server") };
const local = document("local");
// getItem 内存替身::recovery 存 dirty 封装,裸 key 存旧草稿。
// 同时提供 clean recovery 和旧草稿,检查 clean 记录不会被旧键绕过。
const storage = (values) => ({ getItem: (key) => values[key] || null });
assert.equal(readLocalRecovery(storage({ key: JSON.stringify(local) }), "key", remote).nodes[0].data.text, "local");
assert.equal(readLocalRecovery(storage({ "key:recovery": JSON.stringify({ document: local, dirty: true, baseVersion: 2 }) }), "key", remote).nodes[0].data.text, "local");
@@ -130,6 +134,8 @@ test("editable local uploads and touching edges never enter transport snapshots"
const other=makeCanvasNode("text",{x:1,y:2});
const edited={...local,nodes:[pending,other],edges:[{id:"pending-edge",source:pending.id,target:other.id}]};await writer.enqueue(edited);
assert.equal(calls.length,1);assert.equal(calls[0].nodes.length,1);assert.equal(calls[0].edges.length,0);assert.ok(!JSON.stringify(calls[0]).includes("blob:"));assert.ok(!writer.document.nodes.some(node=>node.pendingUpload));
// 固定 HTTPS 地址模拟可传输节点,没有执行真实上传确认;保留 ID 并去掉本地占位标记。
// 最新位置和此前被过滤的附边应随节点一起发送。
const {pendingUpload,...ready}=pending;ready.data={...ready.data,src:"https://example.com/original.png"};ready.position={x:300,y:400};
await writer.enqueue({...edited,nodes:[ready,other]});assert.equal(calls.length,2);assert.equal(calls[1].nodes.find(node=>node.id===ready.id).position.x,300);assert.equal(calls[1].edges.length,1);
});