Import ISA Project Format 1.1.0

This commit is contained in:
Peter Willemsen
2026-11-30 12:07:49 +00:00
commit 563d1992a2
32 changed files with 2308 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {createSharedFolderReader} from '../src/shared-folder.js';
test('specialist and other viewers read the same existing supplier register and price book', async () => {
const root='/Shared/Registers';
const scope={workspaceId:'w',groupId:'g'};
const folder={path:root,...scope};
const register={format:'isa-match-workspace-suppliers-v1',workspaceId:'w',id:'abc',suppliers:[{id:'supplier-1',name:'Voorbeeld',administration:'',number:''}]};
const row={supplier:'Voorbeeld',unit:'m²',unitPrice:42,currency:'EUR'};
const commands=[];
function viewer(extension) {
return createSharedFolderReader({folder,scope,bridge:{
async invoke(command,args) {
commands.push([extension,command]);
if (command === 'filesystem_list_dir') {
assert.equal(args.path,root);
return {authoritative:true,files:[{kind:'file',path:root+'/isa-match-suppliers.json'}]};
}
assert.equal(command,'filesystem_get_files');
assert.equal(args.groupId,'g');
const [{path,cachePolicy}]=args.files;
assert.equal(path,root+'/isa-match-suppliers.json');
assert.equal(cachePolicy,'dashboard-required');
return {items:[{path,source:'dashboard',authoritative:true,status:'ok',fileId:'index',syncRevision:1,...(extension==='other-viewer'?{bytesBase64:Buffer.from(JSON.stringify(register)).toString('base64')}:{text:JSON.stringify(register)})}]};
},
async snapshotKv(args) {
commands.push([extension,'snapshot']);
assert.equal(args.path,root+'/isa-match-prices-abc.kv');
return {revision:2,snapshotId:'snapshot',storeId:'store',incarnation:'1',entries:[{status:'found',kind:'value',key:'price/g/1',value:row}]};
}
}});
}
for(const reader of [viewer('supplier-viewer'),viewer('other-viewer')]) {
assert.equal((await reader.listFiles()).length,1);
const index=await reader.readJson('isa-match-suppliers.json');
assert.deepEqual(index.value,register);
const result=await reader.readKv('isa-match-prices-'+index.value.id+'.kv');
assert.deepEqual(result.entries[0].value,row);
await assert.rejects(reader.readKv('../other.kv'),/Unsafe/);
}
assert.equal(commands.length,6);
});
test('revocation and mismatched launch scopes never resolve to empty or initialized data',async () => {
const scope={workspaceId:'w',groupId:'g'};
const bridge={invoke:async()=>{throw new Error('Access revoked');}};
assert.throws(()=>createSharedFolderReader({scope,bridge,folder:{path:'/Shared',groupId:'other'}}),/Invalid shared folder/);
const reader=createSharedFolderReader({scope,bridge,folder:{path:'/Shared'}});
await assert.rejects(reader.readJson('isa-match-suppliers.json'),/Access revoked/);
});