37 lines
3.2 KiB
JavaScript
37 lines
3.2 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { loadCanvasEntry } from '../../src/lib/canvas-entry.ts';
|
|
import { createRegistry, builtinComponents } from '../../src/lib/canvas-core/index.ts';
|
|
const id = n => `10000000-0000-4000-8000-${String(n).padStart(12, '0')}`;
|
|
const board = { id: id(1), workspace_id: id(2), kind: 'board', title: 'Board', version: 1 };
|
|
const profile = { id: id(3) }, registry = createRegistry(builtinComponents());
|
|
function fixture(response) {
|
|
const calls = [], request = async path => { calls.push(path); if (path === 'profile') return profile; if (path.endsWith('/canvas')) return { version: 1, document: { schema_version: 2, nodes: [], edges: [], viewport: { x: 0, y: 0, zoom: 1 } } }; return board; };
|
|
return { calls, options: { request, workspaceRef: board.workspace_id, boardRef: board.id, registry, transport: accountId => { assert.equal(accountId, profile.id); return async input => { calls.push(input.path); return response; }; } } };
|
|
}
|
|
|
|
test('canonical-first entry never reads a legacy snapshot for an adopted project', async () => {
|
|
const f = fixture({ status: 200, body: { model: { documentFormatVersion: 1, projectId: board.id, complete: true, canvases: [{ id: board.id, parent: null }], elements: [], tombstones: {}, versions: { [board.id]: 1 }, removedCanvasIds: [] } } });
|
|
const result = await loadCanvasEntry(f.options); assert.equal(result.mode, 'headless'); assert.equal(result.model.document.projectId, board.id);
|
|
assert.equal(f.calls.some(path => path.endsWith('/canvas')), false);
|
|
});
|
|
|
|
test('explicit migration requirement or missing deployment keeps legacy reads; permission failure does not fall back', async () => {
|
|
for (const response of [{ status: 404, body: { error: 'not_found' } }, { status: 409, body: { error: 'canonical_migration_required', root_id: board.id, document_format_version: 1, source_versions: { [board.id]: 1 } } }]) {
|
|
const f = fixture(response); assert.equal((await loadCanvasEntry(f.options)).mode, 'legacy'); assert.equal(f.calls.filter(path => path.endsWith('/canvas')).length, 1);
|
|
}
|
|
const f = fixture({ status: 403, body: { error: 'forbidden' } });
|
|
await assert.rejects(() => loadCanvasEntry(f.options), /forbidden/); assert.equal(f.calls.some(path => path.endsWith('/canvas')), false);
|
|
});
|
|
|
|
test('legacy entry retains verified migration root and the full source vector without offering migration for an unavailable API',async()=>{
|
|
const child=id(4),f=fixture({status:409,body:{error:'canonical_migration_required',root_id:board.id,document_format_version:1,source_versions:{[board.id]:3,[child]:7}}});
|
|
const result=await loadCanvasEntry(f.options);
|
|
assert.equal(result.mode,'legacy');assert.equal(result.migration.rootId,board.id);
|
|
assert.deepEqual([...result.migration.sourceVersions],[[board.id,3],[child,7]]);assert.equal(result.migration.sourceVersions.set,undefined);
|
|
assert.equal(result.profile.id,profile.id);assert.ok(result.snapshot);
|
|
assert.equal(f.calls.some(path=>path.endsWith('/migrate')),false);
|
|
const unavailable=await loadCanvasEntry(fixture({status:404,body:{error:'not_found'}}).options);
|
|
assert.equal(unavailable.mode,'legacy');assert.equal(unavailable.migration,undefined);
|
|
});
|