Keep automatic group discovery scoped to shared project clients

This commit is contained in:
Sander Grootendorst
2026-12-01 00:08:10 +01:00
parent b70a7aa5ee
commit 5f43003e32
4 changed files with 34 additions and 25 deletions
+21 -9
View File
@@ -5,6 +5,8 @@ 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 ordinaryCommands = ['open_workspace_folder', 'filesystem_create_folder', 'filesystem_upload_files', 'filesystem_list_dir', 'filesystem_get_files'];
function fixture(options = {}) {
const writes = [];
const files = new Map(['one','two','three'].map(id => [`${project(id).path}/project.json`,{
@@ -43,26 +45,28 @@ function fixture(options = {}) {
},
subscribeKv: options.subscribeKv
};
const client = createProjectClient({bridge,extensionId:'contracts',scope:{workspaceId:'workspace',groupId:'group'},filesystemCommands:options.filesystemCommands,groupFolder:options.groupFolder,sharedProjectsFolder:options.sharedProjectsFolder,beforeSwitch:options.beforeSwitch});
const client = createProjectClient({bridge,extensionId:'contracts',scope:{workspaceId:'workspace',groupId:'group'},filesystem:options.filesystem,filesystemCommands:options.filesystemCommands,groupFolder:options.groupFolder,sharedProjectsFolder:options.sharedProjectsFolder,beforeSwitch:options.beforeSwitch});
return {client,writes,bridge,files};
}
test('the launch group catalog excludes picker history and respects legacy folder archive state', async () => {
test('the shared group catalog excludes picker history and preserves the archived state', async () => {
let available = true;
const {client} = fixture({
filesystemCommands: ['filesystem_list_group_projects', 'filesystem_get_files'],
const {client,files} = fixture({
sharedProjectsFolder: true,
filesystem: {supportsSharedGroupProjects:true, commands:['filesystem_list_group_projects', 'filesystem_get_files']},
invoke(command, args) {
if (command === 'filesystem_list_group_projects') {
assert.deepEqual(args, {workspaceId: 'workspace', groupId: 'group'});
if (!available) throw new Error('Dashboard unavailable');
return {authoritative: true, folders: [
{...project('one'), canWrite: false},
{...project('two'), canWrite: false, archivedAt: '2026-11-03T12:00:00Z'}
{fileId:'one', path:'/shared/one.isap', canWrite:false},
{fileId:'two', path:'/shared/two.isap', canWrite:false, archivedAt:'2026-11-03T12:00:00Z'}
]};
}
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'));
assert.deepEqual((await client.list()).map(row => row.id), ['one']);
const all = await client.list(true);
assert.equal(all.find(row => row.id === 'two').archived, true);
@@ -165,9 +169,10 @@ test('successful transport cannot confirm pending or conflicted project writes',
await client.close();
});
test('a selected container lists valid project manifests and opens them through its existing grant', async () => {
test('a picker client lists, opens and creates in the selected container on a group-catalog host', async () => {
let picks = 0;
const {client,files} = fixture({invoke(command, args) {
const filesystem = {supportsSharedGroupProjects:true, commands:[...ordinaryCommands, ...sharedCommands]};
const {client,files} = fixture({filesystem, invoke(command, args) {
if (command === 'open_workspace_folder') { picks++; return; }
if (command === 'filesystem_list_dir' && args.path === '/projects') {
return {authoritative:true,files:[
@@ -178,6 +183,8 @@ test('a selected container lists valid project manifests and opens them through
]};
}
}});
assert.equal(client.supports('pickFolder'), true);
assert.equal(client.supports('create'), true);
assert.deepEqual(await client.list(),[]);
await client.pickFolder();
const [listed] = await client.list();
@@ -189,6 +196,8 @@ test('a selected container lists valid project manifests and opens them through
files.set(listed.manifestPath,{...manifest,id:'one'});
await assert.rejects(client.openListed(listed),/identity/);
assert.equal(client.active,selected);
const created = await client.create('Ordinary', 'ordinary');
assert.equal(created.project.path, '/projects/ordinary-ordinary.isap');
assert.equal(picks,1);
});
@@ -307,13 +316,16 @@ test('replaced and revoked roots do not hide accessible projects or conceal dash
test('group creation uses the launch group and opening a listed project creates no namespace', async () => {
const commands = [];
const {client} = fixture({groupFolder:true, invoke(command) {
const filesystem = {supportsSharedGroupProjects:true, commands:[...ordinaryCommands, ...sharedCommands, 'filesystem_ensure_group_folder']};
const {client} = fixture({groupFolder:true, filesystem, invoke(command) {
commands.push(command);
if (command === 'filesystem_ensure_group_folder') return {folderId:'parent',path:'/projects'};
if (command === 'open_workspace_folder') assert.fail('Unexpected folder picker');
}});
const session = await client.create('Example', 'sample');
assert.equal(session.project.path, '/projects/example-sample.isap');
assert.equal(client.supports('pickFolder'), true);
assert.deepEqual((await client.list()).map(row => row.path), [session.project.path]);
await client.leave();
commands.length = 0;
await client.openListed(session.project);