feat(canvas): elide closed unsent lifetimes with durable local proofs
This commit is contained in:
@@ -217,6 +217,82 @@ test('one transaction captures the first presence baseline even when its created
|
||||
const operation = engine.getSnapshot().runtime.ledger.operations.get(result.operationIds[0]);
|
||||
assert.equal(operation.basePresence.temporary, 'absent');
|
||||
assert.equal(engine.getSnapshot().document.tombstones.get(node.id), 1);
|
||||
await engine.settle(); assert.equal(port.calls.length, 1);
|
||||
await engine.settle(); assert.equal(port.calls.length, 0);
|
||||
assert.equal(engine.getSnapshot().runtime.ledger.operations.get(result.operationIds[0]).resolution, 'elided');
|
||||
assert.equal(engine.getSnapshot().runtime.acknowledged.tombstones.has(node.id), false);
|
||||
} finally { await engine.close(); }
|
||||
});
|
||||
|
||||
|
||||
test('unsent create/delete retires locally, survives unrelated ACK and reopening, and undo restores a fresh incarnation', async () => {
|
||||
const storage = storageFixture(), port = persistenceFixture(); let next=0, engine;
|
||||
const reopen=async()=>{if(engine)await engine.close();engine=(await open(storage,port,{createId:()=>`elision-${++next}`})).engine;};
|
||||
try {
|
||||
await reopen();const node={...original.elements.get('a'),id:'temporary'};
|
||||
const created=engine.editor.dispatch({type:'element.create',element:node});
|
||||
const removed=engine.editor.dispatch({type:'element.remove',target:{id:node.id,incarnation:1}});
|
||||
await engine.settle();assert.equal(port.calls.length,0);assert.equal(engine.getSnapshot().history.undo.length,2);
|
||||
for(const id of [...created.operationIds,...removed.operationIds])assert.equal(engine.getSnapshot().runtime.ledger.operations.get(id).resolution,'elided');
|
||||
engine.editor.dispatch({type:'element.data',target,patch:{title:'unrelated'}});await engine.settle();assert.equal(port.calls.length,1);
|
||||
assert.equal(engine.getSnapshot().document.tombstones.get(node.id),1);assert.equal(engine.getSnapshot().runtime.acknowledged.tombstones.has(node.id),false);
|
||||
await reopen();assert.equal(engine.getSnapshot().document.tombstones.get(node.id),1);
|
||||
assert.equal(engine.editor.history.undo().status,'applied');await engine.settle();
|
||||
assert.equal(engine.editor.history.undo().status,'applied');await engine.settle();
|
||||
assert.equal(engine.getSnapshot().document.elements.get(node.id).incarnation,2);assert.equal(port.calls.length,3);
|
||||
assert.equal(engine.editor.history.redo().status,'applied');await engine.settle();assert.equal(engine.getSnapshot().document.elements.has(node.id),false);assert.equal(engine.getSnapshot().document.tombstones.get(node.id),2);
|
||||
await reopen();assert.equal(engine.getSnapshot().document.tombstones.get(node.id),2);
|
||||
} finally { await engine?.close(); }
|
||||
});
|
||||
|
||||
|
||||
test('recovery rejects forged or unsupported local completion proofs and missing working lifecycle marks', async () => {
|
||||
const storage=storageFixture(),port=persistenceFixture(),{engine}=await open(storage,port);
|
||||
try {
|
||||
const n={...original.elements.get('a'),id:'temporary'};
|
||||
engine.editor.dispatch({type:'element.create',element:n});engine.editor.dispatch({type:'element.remove',target:{id:n.id,incarnation:1}});await engine.settle();
|
||||
const image=storage.image(),anchorIndex=image.payload.runtime.ledger.operations.findIndex(([,record])=>record.elision);
|
||||
for(const corrupt of [
|
||||
image=>{image.payload.runtime.ledger.operations[anchorIndex][1].elision.tombstones.temporary=2;},
|
||||
image=>{image.payload.document.tombstones=[];},
|
||||
image=>{image.payload.operations[0][1].changes[0].after.data.title='different historical content';},
|
||||
]){const bad=structuredClone(image);corrupt(bad);assert.throws(()=>decodeRecovery(bad,registry),/corrupt_recovery_image/);}
|
||||
const future=structuredClone(image);future.payload.runtime.ledger.operations[anchorIndex][1].elision.version=2;assert.throws(()=>decodeRecovery(future,registry),/elision_interpreter_unavailable/);
|
||||
assert.equal(decodeRecovery(image,registry).document.tombstones.get(n.id),1);
|
||||
}finally{await engine.close();}
|
||||
});
|
||||
|
||||
|
||||
test('failed durability keeps a local elision in memory without inventing a network success, then persists the same proof', async () => {
|
||||
const storage=storageFixture(),port=persistenceFixture();let engine=(await open(storage,port)).engine;
|
||||
try{
|
||||
await engine.persist();storage.broken=true;const n={...original.elements.get('a'),id:'temporary'};
|
||||
engine.editor.dispatch({type:'element.create',element:n});engine.editor.dispatch({type:'element.remove',target:{id:n.id,incarnation:1}});await tick();
|
||||
await assert.rejects(engine.persist(),/quota/);assert.equal(port.calls.length,0);
|
||||
const anchor=[...engine.getSnapshot().runtime.ledger.operations.values()].find(record=>record.elision),proof=JSON.stringify(anchor.elision);assert.equal(anchor.resolution,'elided');assert.equal(engine.getSnapshot().runtime.receipts.size,0);
|
||||
storage.broken=false;await engine.persist();await engine.close();engine=(await open(storage,port)).engine;await engine.settle();
|
||||
assert.equal(port.calls.length,0);assert.equal(JSON.stringify(engine.getSnapshot().runtime.ledger.operations.get(anchor.intent.id).elision),proof);
|
||||
}finally{storage.broken=false;await engine.close();}
|
||||
});
|
||||
|
||||
|
||||
test('repeated unsent undo/redo pairs remain local and the first published restore skips all canceled incarnations',async()=>{
|
||||
const storage=storageFixture(),port=persistenceFixture();let next=0,engine=(await open(storage,port,{createId:()=>`repeat-${++next}`})).engine;
|
||||
try{
|
||||
const n={...original.elements.get('a'),id:'temporary'};engine.editor.dispatch({type:'element.create',element:n});engine.editor.dispatch({type:'element.remove',target:{id:n.id,incarnation:1}});await engine.settle();
|
||||
for(let incarnation=2;incarnation<=3;incarnation++){
|
||||
assert.equal(engine.editor.history.undo().status,'applied');assert.equal(engine.getSnapshot().document.elements.get(n.id).incarnation,incarnation);assert.equal(engine.editor.history.redo().status,'applied');await engine.settle();assert.equal(port.calls.length,0);assert.equal(engine.getSnapshot().document.tombstones.get(n.id),incarnation);
|
||||
await engine.close();engine=(await open(storage,port,{createId:()=>`repeat-${++next}`})).engine;
|
||||
}
|
||||
assert.equal(engine.editor.history.undo().status,'applied');await engine.settle();assert.equal(port.calls.length,1);assert.equal(engine.getSnapshot().document.elements.get(n.id).incarnation,4);assert.equal(engine.getSnapshot().runtime.acknowledged.elements.get(n.id).incarnation,4);
|
||||
}finally{await engine.close();}
|
||||
});
|
||||
|
||||
|
||||
test('batch-capable persistence sends an earlier real edit separately and never freezes the later closed lifetime',async()=>{
|
||||
const storage=storageFixture(),port=persistenceFixture({compileBatch(){throw Error('closed lifetime entered the wire batch');}}),{engine,errors}=await open(storage,port);
|
||||
try{
|
||||
engine.editor.dispatch({type:'element.data',target,patch:{title:'prefix'}});const n={...original.elements.get('a'),id:'temporary'},created=engine.editor.dispatch({type:'element.create',element:n}),removed=engine.editor.dispatch({type:'element.remove',target:{id:n.id,incarnation:1}});
|
||||
await engine.settle();assert.equal(errors.length,0);assert.equal(port.calls.length,1);assert.equal(engine.getSnapshot().runtime.acknowledged.elements.get('a').data.title,'prefix');
|
||||
for(const id of [...created.operationIds,...removed.operationIds])assert.equal(engine.getSnapshot().runtime.ledger.operations.get(id).resolution,'elided');assert.equal(engine.getSnapshot().runtime.acknowledged.tombstones.has(n.id),false);
|
||||
}finally{await engine.close();}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user