docs(tests): explain resource sizing and run control lifecycle
This commit is contained in:
@@ -62,6 +62,7 @@ function fixture() {
|
||||
// 简化请求把完整意图放入 payload,并读取参与 canvas 的 ACK 版本,不进行真实 wire 压缩。
|
||||
compile(intent, id, snapshot) { return { payload: { intent, id }, canvasIds: intent.canvasIds, expectedVersions: Object.fromEntries(intent.canvasIds.map(id => [id, snapshot.runtime.versions.get(id)])) }; },
|
||||
// 文档写入应用 changes,递增服务端版本并按 requestId 保存 canonical 回执,供后续接纳恢复使用。
|
||||
// 此替身每次 submit 都应用变化,并未实现同 ID 去重或版本拒绝;重开测试用写入次数检查客户端是否重发。
|
||||
async submit(request) { const { intent } = JSON.parse(request.body); writes.push(request); server = applyChanges(server, intent.changes); receipts.set(request.id, { document: server, versions: new Map([['canvas', ++version]]) }); return { outcome: 'applied' }; },
|
||||
// 文档回执查询与上传回执表分开,存在才表示该文档请求已应用。
|
||||
async query(request) { return receipts.has(request.id) ? { outcome: 'applied' } : { outcome: 'unresolved' }; },
|
||||
@@ -98,6 +99,7 @@ test('automatic image sizing publishes with creation history across intervening
|
||||
engine.editor.dispatch({ type: 'element.data', target, patch: { title: 'Renamed before decode' } });
|
||||
// 记录解码前栈内容;完成后必须还是这几个历史 ID,尺寸补偿不能另塞一个用户撤销条目。
|
||||
const undo = [...engine.getSnapshot().history.undo]; gate.resolve(); await engine.settle();
|
||||
// 解码宽高比 4:2,沿用当前节点宽度 100 得到高度 50;像素元数据不会把节点直接改为 4×2。
|
||||
const root = engine.getSnapshot(); assert.equal(root.document.elements.get('picture').geometry.height, 50);
|
||||
assert.equal(root.document.elements.get('picture').geometry.x, 70); assert.deepEqual(root.history.undo, undo);
|
||||
assert.equal(root.runtime.resources.get(ref.id).sizing.grants[0].status, 'applied');
|
||||
@@ -128,6 +130,7 @@ test('automatic image sizing publishes with creation history across intervening
|
||||
});
|
||||
|
||||
// 用户已提交 resize 即永久撤销默认尺寸授权;即使在解码完成前 undo resize,也不能重新授权自动调整。
|
||||
// undo 恢复几何值,grant 则记录“用户已经接管尺寸”的事实;若一起回退 grant,迟到解码会再次抢走用户控制。
|
||||
test('a committed user resize permanently revokes default sizing even if undone before decoding', async () => {
|
||||
const f = fixture(), gate = deferred(), entered = deferred(), engine = await f.open({ images: { decode: async () => { entered.resolve(); await gate.promise; return { width: 4, height: 2 }; } } });
|
||||
try {
|
||||
@@ -361,6 +364,7 @@ const resourceClock=()=>{let now=1000;return{advance:ms=>{now+=ms;},now:()=>now,
|
||||
async function unreferenceImage(engine){assert.equal(engine.editor.dispatch({type:'element.remove',target:{id:'picture',incarnation:1}}).status,'applied');assert.equal(engine.editor.dispatch({type:'element.data',target:{id:'a',incarnation:1},patch:{title:'evict old image history'}}).status,'applied');await engine.settle();}
|
||||
|
||||
// 无引用资源先保存 soft marker,再满 100ms 宽限期后把文件删除和 purge 墓碑一起保存;重开可用远端 URL,不重新上传。
|
||||
// purge 只回收本地 Blob,不删除已上传资产或 stored 身份;后续显示因此能回退 displayURL。
|
||||
test('local collection persists a soft marker, waits retention and atomically deletes bytes with a v3 recovery tombstone',async()=>{
|
||||
const f=fixture(),clock=resourceClock();let engine=await f.open({historyLimit:1,clock});const ref=addImage(engine);try{
|
||||
await engine.settle();await unreferenceImage(engine);assert.equal(engine.getResourcePins().pins.has(ref.id),false);
|
||||
|
||||
Reference in New Issue
Block a user