Project format updates

This commit is contained in:
Sander Grootendorst
2026-12-01 10:10:05 +01:00
parent 5f43003e32
commit 8d0a531084
13 changed files with 170 additions and 96 deletions
+39 -14
View File
@@ -5,7 +5,7 @@ import { importProject } from '../src/transfer.js';
import { strToU8, zipSync } from 'fflate';
const project = id => ({id,folderId:id,name:id,path:`/projects/${id}.isap`,projectIdentity:id,formatVersion:1});
const sharedCommands = ['filesystem_list_group_projects', 'filesystem_create_group_project'];
const sharedCommands = ['filesystem_list_group_projects', 'filesystem_open_group_project', 'filesystem_create_group_project'];
const ordinaryCommands = ['open_workspace_folder', 'filesystem_create_folder', 'filesystem_upload_files', 'filesystem_list_dir', 'filesystem_get_files'];
function fixture(options = {}) {
const writes = [];
@@ -49,27 +49,40 @@ function fixture(options = {}) {
return {client,writes,bridge,files};
}
const groupProjectsPath = '/groups/_group_ids/' + 'a'.repeat(64) + '/projects';
test('the shared group catalog excludes picker history and preserves the archived state', async () => {
let available = true;
const calls = [];
const {client,files} = fixture({
sharedProjectsFolder: true,
filesystem: {supportsSharedGroupProjects:true, commands:['filesystem_list_group_projects', 'filesystem_get_files']},
filesystem: {supportsSharedGroupProjects:true, commands:['filesystem_list_group_projects', 'filesystem_open_group_project', 'filesystem_get_files']},
invoke(command, args) {
calls.push(command);
if (command === 'filesystem_list_group_projects') {
assert.deepEqual(args, {workspaceId: 'workspace', groupId: 'group'});
if (!available) throw new Error('Dashboard unavailable');
return {authoritative: true, folders: [
{fileId:'one', path:'/shared/one.isap', canWrite:false},
{fileId:'two', path:'/shared/two.isap', canWrite:false, archivedAt:'2026-11-03T12:00:00Z'}
{fileId:'one', path:groupProjectsPath + '/one.isap', canWrite:false, hasInstance:false, manifest:files.get(groupProjectsPath + '/one.isap/project.json')},
{fileId:'two', path:groupProjectsPath + '/two.isap', canWrite:false, hasInstance:true, archivedAt:'2026-11-03T12:00:00Z', manifest:files.get(groupProjectsPath + '/two.isap/project.json')},
{fileId:'incomplete', path:groupProjectsPath + '/incomplete.isap', canWrite:true, manifest:null}
]};
}
if (command === 'filesystem_open_group_project') {
assert.deepEqual(args, {workspaceId:'workspace',groupId:'group',folderId:'one'});
return {fileId:'one', path:groupProjectsPath + '/one.isap', canWrite:false};
}
if (command === 'localstorage_get' || command === 'open_workspace_folder') assert.fail(command);
}
});
for (const id of ['one','two']) files.set(`/shared/${id}.isap/project.json`, files.get(project(id).path + '/project.json'));
for (const id of ['one','two']) files.set(`${groupProjectsPath}/${id}.isap/project.json`, files.get(project(id).path + '/project.json'));
assert.deepEqual((await client.list()).map(row => row.id), ['one']);
const all = await client.list(true);
assert.deepEqual(calls, ['filesystem_list_group_projects', 'filesystem_list_group_projects']);
assert.equal(all.find(row => row.id === 'one').hasInstance, false);
assert.equal(all.find(row => row.id === 'two').hasInstance, true);
assert.equal(all.find(row => row.id === 'two').archived, true);
await assert.rejects(client.openListed({...all[0], path:groupProjectsPath + '/another.isap'}), /identity changed/);
await client.withListedProject(all[0], async session => assert.equal(session.project.canWrite, false));
assert.equal(client.active, null);
assert.deepEqual(client.state.recents, []);
@@ -335,14 +348,15 @@ test('group creation uses the launch group and opening a listed project creates
});
test('group members open the same writable projects independently of picker history', async () => {
const commands = ['filesystem_list_group_projects', 'filesystem_create_group_project', 'filesystem_upload_files', 'filesystem_create_folder'];
const commands = [...sharedCommands, 'filesystem_upload_files', 'filesystem_create_folder'];
const {bridge: storage, files} = fixture();
const catalog = new Map();
let loseAcknowledgement = true;
function launch(extensionId, groupId = 'demo', writable = true) {
const opened = new Set();
return createProjectClient({
extensionId, scope: {workspaceId: 'w', groupId}, sharedProjectsFolder: true,
filesystem: { supportsSharedGroupProjects: true, commands: writable ? commands : ['filesystem_list_group_projects'] },
filesystem: { supportsSharedGroupProjects: true, commands: writable ? commands : ['filesystem_list_group_projects', 'filesystem_open_group_project'] },
bridge: {async invoke(command, args) {
if (command.startsWith('localstorage_')) {
assert.equal(args.key, 'isa-project-format.recents.v1', 'A previous read-only picker grant must not participate');
@@ -351,24 +365,34 @@ test('group members open the same writable projects independently of picker hist
assert.equal(args.workspaceId, 'w');
assert.equal(args.groupId, groupId);
if (command === 'filesystem_list_group_projects') return {authoritative:true, folders:[
...[...catalog.values()].filter(row => row.groupId === groupId),
...[...catalog.values()].filter(row => row.groupId === groupId).map(row => ({
...row, canWrite:writable, manifest:files.get(row.path + '/project.json')
})),
{fileId:'private', path:'/groups/demo/extensions/quote/private.isap', canWrite:true},
{fileId:'nested', path:'/shared/elsewhere/nested.isap', canWrite:true}
{fileId:'nested', path:groupProjectsPath + '/elsewhere/nested.isap', canWrite:true}
]};
if (command === 'filesystem_open_group_project') {
const row = catalog.get(args.folderId);
if (!row || row.groupId !== groupId) throw new Error('Project unavailable in this group');
opened.add(row.path);
return {...row, canWrite:writable};
}
if (command === 'filesystem_create_group_project') {
assert.ok(writable);
const path = '/shared/' + args.projectId + '.isap';
const path = groupProjectsPath + '/' + args.projectId + '.isap';
const row = {fileId:'folder-' + args.projectId, path, groupId, canWrite:true};
if (!catalog.has(row.fileId)) {
catalog.set(row.fileId, row);
files.set(path + '/project.json', { ...files.get('/projects/one.isap/project.json'), id:args.projectId, name:args.name, importPending:args.importPending });
for (const dir of [path, path + '/extensions', path + '/assets']) await storage.invoke('filesystem_create_folder',{path:dir});
await storage.invoke('filesystem_create_folder',{path});
}
if (loseAcknowledgement) { loseAcknowledgement = false; throw new Error('Acknowledgement lost'); }
opened.add(row.path);
return row;
}
const path = args.path ?? args.files?.[0]?.path;
assert.ok([...opened].some(root => path === root || path?.startsWith(root + '/')), 'Filesystem request requires opening that project');
assert.ok(!['open_workspace_folder','filesystem_ensure_group_folder'].includes(command), command);
if (command === 'filesystem_get_files') assert.match(args.files[0].path, /^\/shared\/[^/]+\.isap\//);
if (command === 'filesystem_get_files') assert.match(args.files[0].path, /^\/groups\/_group_ids\/[a-f0-9]{64}\/projects\/[^/]+\.isap\//);
return storage.invoke(command, args);
}}
});
@@ -391,6 +415,7 @@ test('group members open the same writable projects independently of picker hist
await reopened.ensureExtensionJson('data.json', () => assert.fail('Duplicated board'));
const otherGroup = launch('isa-projects', 'another-group');
assert.deepEqual(await otherGroup.list(), []);
await assert.rejects(otherGroup.activate(row), /unavailable in this group/);
const reader = launch('read-only', 'demo', false);
assert.equal(reader.supports('create'), false);
assert.equal((await reader.openListed((await reader.list())[0])).project.canWrite, false);
@@ -408,7 +433,7 @@ test('group members open the same writable projects independently of picker hist
});
test('older shared-project hosts report the required update without opening a picker', async () => {
const filesystem = {commands:['filesystem_list_group_projects','filesystem_create_folder','filesystem_upload_files','open_workspace_folder']};
const filesystem = {supportsSharedGroupProjects:true, commands:['filesystem_list_group_projects','filesystem_create_group_project','filesystem_create_folder','filesystem_upload_files','open_workspace_folder']};
const client = createProjectClient({bridge:{invoke:() => assert.fail('Unexpected host operation')}, filesystem,
sharedProjectsFolder:true, extensionId:'reader', scope:{workspaceId:'w',groupId:'g'}});
for (const action of ['pickFolder','create','archive']) assert.equal(client.supports(action), false);