Project format updates

This commit is contained in:
Peter Willemsen
2026-11-30 17:25:03 +01:00
parent 563d1992a2
commit 4822a697bf
11 changed files with 425 additions and 111 deletions
+91 -30
View File
@@ -8,17 +8,35 @@ function fixture(options = {}) {
const files = new Map(['one','two','three'].map(id => [`${project(id).path}/project.json`,{
formatVersion:1,id,name:id,createdAt:'2026-11-03T12:00:00Z',updatedAt:'2026-11-03T12:00:00Z',unknown:{kept:true}
}]));
let saved = null;
const saved = new Map();
const directories = new Set(['/projects']);
const bridge = {
async invoke(command,args) {
if (command.startsWith('localstorage_')) {
assert.equal(Object.hasOwn(args, 'workspaceId'), false, 'Private storage scope is set by the host');
assert.equal(Object.hasOwn(args, 'groupId'), false, 'Private storage scope is set by the host');
}
if (options.invoke) { const result = options.invoke(command,args); if (result !== undefined) return result; }
if (command === 'filesystem_get_files') {
const path = args.files[0].path;
return {items:[files.has(path) ? {status:'ok',path,source:'dashboard',authoritative:true,text:JSON.stringify(files.get(path)),fileId:path,syncRevision:4,contentHash:'a'.repeat(64)} : {status:'absent',path,source:'dashboard',authoritative:true}]};
}
if (command === 'localstorage_get') return saved;
if (command === 'localstorage_put') { saved=args.value;return {ok:true}; }
if (command === 'filesystem_upload_files') { writes.push(args); return {items:[{status:'ok',isComplete:true,path:args.files[0].path,fileId:args.files[0].path}]}; }
if (command === 'localstorage_get') return saved.get(args.key) ?? null;
if (command === 'localstorage_put') { saved.set(args.key,args.value); return {ok:true}; }
if (command === 'open_workspace_folder') return {file:{path:'/projects',id:'parent',kind:'folder',access:'read_write'}};
if (command === 'filesystem_list_dir') return {authoritative:true,files:[...directories]
.filter(path => path === args.path || path.startsWith(args.path + '/'))
.map(path => ({kind:'folder',path,id:path === '/projects' ? 'parent' : path,canWrite:true}))};
if (command === 'filesystem_create_folder') {
directories.add(args.path);
return {status:'ok',path:args.path,fileId:args.path};
}
if (command === 'filesystem_upload_files') {
writes.push(args);
const {path,text}=args.files[0];
files.set(path,JSON.parse(text));
return {items:[{status:'ok',isComplete:true,path,fileId:path}]};
}
throw new Error(`Unexpected command ${command}`);
},
subscribeKv: options.subscribeKv
@@ -74,18 +92,18 @@ test('dirty state blocks switching and unavailable reads never become absence',
await client.close();
});
test('uncertain create retries retain operation identity through manifest recovery', async () => {
const ids=[];
test('uncertain create retains the same folder and manifest identity on retry', async () => {
const paths=[];
const {client}=fixture({invoke:(command,args)=>{
if(command!=='projects_create')return;
ids.push(args.operationId);
if(ids.length===1)throw new Error('Commit outcome unavailable');
return {project:project('one')};
if(command!=='filesystem_upload_files'||!args.files[0].path.endsWith('/project.json'))return;
paths.push(args.files[0].path);
if(paths.length===1)throw new Error('Commit outcome unavailable');
}});
await assert.rejects(client.create('Example'),/unavailable/);
const created=await client.create('Example');
assert.equal(created.project.id,'one');
assert.equal(ids[0],ids[1]);
assert.equal(paths[0],paths[1]);
assert.equal(created.manifest.name,'Example');
assert.equal(created.project.projectIdentity,created.manifest.id);
await client.close();
});
@@ -119,36 +137,39 @@ test('successful transport cannot confirm pending or conflicted project writes',
await client.close();
});
test('a listed group project opens by folder ID on its first use, without a second picker or project creation', async () => {
let reply = project('two');
const commands = [];
const {client} = fixture({invoke(command,args) {
commands.push(command);
if (command === 'get_app_info') return {projects:{commands:['projects_open_listed']}};
if (command === 'projects_list') return {projects:[{...reply, canWrite:false, updatedAt:'2026-09-01'}]};
if (command === 'projects_open_listed') {
assert.deepEqual(args,{projectId:'two'});
return {status:'ok',project:reply};
test('a selected container lists valid project manifests and opens them through its existing grant', async () => {
let picks = 0;
const {client,files} = fixture({invoke(command, args) {
if (command === 'open_workspace_folder') { picks++; return; }
if (command === 'filesystem_list_dir' && args.path === '/projects') {
return {authoritative:true,files:[
{path:'/projects',kind:'folder',fileId:'parent'},
{path:project('two').path,kind:'folder',fileId:'two',canWrite:false},
{path:project('missing').path,kind:'folder',fileId:'incomplete'},
{path:'/projects/not-a-folder.isap',kind:'file',fileId:'file'}
]};
}
}});
assert.deepEqual(await client.list(),[]);
await client.pickFolder();
const [listed] = await client.list();
assert.equal(listed.canWrite,false);
assert.equal(listed.updatedAt,'2026-09-01');
assert.equal(listed.updatedAt,'2026-11-03T12:00:00Z');
const selected = await client.openListed(listed);
assert.equal(selected.project.id,'two');
reply = project('one');
const manifest = files.get(listed.manifestPath);
files.set(listed.manifestPath,{...manifest,id:'one'});
await assert.rejects(client.openListed(listed),/identity/);
assert.equal(client.active,selected);
assert.ok(!commands.some(command => ['projects_open','projects_create','filesystem_upload_files'].includes(command)));
assert.equal(picks,1);
});
test('older hosts reopen an existing grant and report a denied row without reopening the picker', async () => {
test('opening from an existing grant reports a denied row without reopening the picker', async () => {
const {client,files} = fixture({invoke(command, args) {
if (command === 'get_app_info') return {projects:{commands:['projects_open']}};
if (command === 'filesystem_get_files' && args.files[0].path === project('three').path + '/project.json') {
return {items:[{path:args.files[0].path, status:'error', authoritative:false, error:'extension filesystem permission is required'}]};
}
if (command === 'projects_open') assert.fail('Unexpected second project picker');
if (command === 'open_workspace_folder') assert.fail('Unexpected second project picker');
}});
const selected = await client.openListed(project('one'));
files.delete(project('two').path+'/project.json');
@@ -161,8 +182,6 @@ test('a direct grant initializes the extension directory on first writable acces
const selected = {...project('two'), canWrite:true};
const directories = [];
const {client} = fixture({invoke(command, args) {
if (command === 'get_app_info') return {projects:{commands:['projects_open_listed']}};
if (command === 'projects_open_listed') return {status:'ok', project:selected};
if (command === 'filesystem_list_dir') return {authoritative:true, files:[]};
if (command === 'filesystem_create_folder') {
directories.push(args.path);
@@ -215,3 +234,45 @@ test('read-only, archived and uncertain reads cannot seed extension records', as
}
assert.equal(writes.length, 0);
});
test('an archived legacy folder stays in the archive until the manifest explicitly restores it', async () => {
const {client} = fixture({invoke(command,args) {
if (command === 'open_workspace_folder') {
return {file:{path:project('two').path,id:'two',kind:'folder',access:'read_write'}};
}
if (command === 'filesystem_list_dir' && args.path === project('two').path) {
return {authoritative:true,files:[{path:args.path,fileId:'two',kind:'folder',archivedAt:100}]};
}
}});
await client.pickFolder();
assert.deepEqual(await client.list(), []);
const [archived] = await client.list(true);
assert.equal(archived.archived,true);
await client.setArchived(archived,false);
assert.equal((await client.list())[0].archived,false);
});
test('replaced and revoked roots do not hide accessible projects or conceal dashboard outages', async () => {
let offline = false;
const {client} = fixture({invoke(command,args) {
if (command === 'localstorage_get' && args.key.endsWith('folders.v1')) return [
{path:'/revoked',id:'revoked'},
{path:'/replaced',id:'old'},
{path:'/projects',id:'parent'}
];
if (command !== 'filesystem_list_dir') return;
if (args.path === '/revoked') throw new Error('Filesystem path requires a current extension root or picker grant');
if (args.path === '/replaced') return {authoritative:true,files:[
{kind:'folder',path:'/replaced',fileId:'new'},
{kind:'folder',path:'/replaced/other.isap',fileId:'other'}
]};
if (offline) throw new Error('Dashboard unavailable');
return {authoritative:true,files:[
{kind:'folder',path:'/projects',fileId:'workspace_file:parent'},
{kind:'folder',path:project('two').path,fileId:'two'}
]};
}});
assert.deepEqual((await client.list()).map(item => item.id), ['two']);
offline = true;
await assert.rejects(client.list(),/Dashboard unavailable/);
});