Project format updates
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {openPriceAsset} from '../src/prices.js';
|
||||
|
||||
test('workspace writers can backfill the same observation concurrently without replacing edits or creating duplicates',async () => {
|
||||
let revision = 0, conflict = true;
|
||||
const records = new Map(), writes = [];
|
||||
const identity = {storeId:'s',incarnation:'i',supportsExpectedRevision:true};
|
||||
const scope = {workspaceId:'w',groupId:'g'};
|
||||
const bridge = {async invoke(command,args) {
|
||||
if(command === 'filesystem_open_workspace_asset') return {...scope,asset:'prices',folderId:'f',path:'/shared/prices',canWrite:true};
|
||||
if(command === 'kv_store_open') return {...identity,revision};
|
||||
if(command === 'kv_store_query_list') return {...identity,revision,page:{items:args.ids.filter(id=>records.has(id)).map(id=>({id,value:records.get(id)}))}};
|
||||
if(command === 'kv_store_apply') {
|
||||
if(conflict) {
|
||||
records.set('a',{description:'Manual correction',supplier:'A',unitPrice:0});
|
||||
revision++; conflict = false; throw Error('revision_conflict');
|
||||
}
|
||||
assert.equal(args.expectedRevision,revision);
|
||||
for(const row of args.operations) records.set(row.id,row.value);
|
||||
writes.push(args.operations.length);
|
||||
return {...identity,pending:false,acceptedRevision:++revision};
|
||||
}
|
||||
assert.fail(command);
|
||||
}};
|
||||
const asset = await openPriceAsset({bridge,scope});
|
||||
const rows = [{id:'a',value:{description:'old',supplierId:'supplier-a',unitPrice:0}}];
|
||||
await asset.importRows(rows); await asset.importRows(rows);
|
||||
assert.deepEqual(records.get('a'), {description:'Manual correction',supplier:'A',unitPrice:0,supplierId:'supplier-a'});
|
||||
assert.deepEqual(writes,[1]);
|
||||
});
|
||||
|
||||
test('a read-only open distinguishes a genuinely empty asset from an inaccessible inventory and creates no KV file', async () => {
|
||||
const scope = {workspaceId:'w',groupId:'g'}; let denied = false;
|
||||
const bridge = {async invoke(command) {
|
||||
if(command === 'filesystem_open_workspace_asset') return {...scope,asset:'prices',folderId:'f',path:'/shared/prices',canWrite:false};
|
||||
if(command === 'filesystem_list_dir') {
|
||||
if(denied) throw Error('access revoked');
|
||||
return {authoritative:true,files:[]};
|
||||
}
|
||||
assert.fail(command);
|
||||
}};
|
||||
const asset = await openPriceAsset({bridge,scope,access:'read'});
|
||||
assert.deepEqual((await asset.query()).items,[]);
|
||||
denied = true;
|
||||
await assert.rejects(asset.query(), /access revoked/);
|
||||
});
|
||||
@@ -1,6 +1,22 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {createSharedFolderReader} from '../src/shared-folder.js';
|
||||
import {createSharedFolderReader, openWorkspaceAsset} from '../src/shared-folder.js';
|
||||
|
||||
test('opening a workspace asset rejects cross-group, cross-asset and overprivileged replies', async () => {
|
||||
const scope = {workspaceId: 'company', groupId: 'estimators'};
|
||||
const grant = {...scope, asset: 'suppliers', folderId: 'folder-1', path: '/shared/suppliers', canWrite: false};
|
||||
const open = reply => openWorkspaceAsset({scope, asset: 'suppliers', access: 'read', bridge: {
|
||||
async invoke(command, args) {
|
||||
assert.equal(command, 'filesystem_open_workspace_asset');
|
||||
assert.deepEqual(args, {asset: 'suppliers', access: 'read'});
|
||||
return reply;
|
||||
}
|
||||
}});
|
||||
assert.deepEqual(await open(grant), grant);
|
||||
for (const patch of [{groupId:'other'}, {asset:'prices'}, {path:'/shared'}, {canWrite:true}]) {
|
||||
await assert.rejects(open({...grant, ...patch}), /Invalid workspace asset grant/);
|
||||
}
|
||||
});
|
||||
|
||||
test('specialist and other viewers read the same existing supplier register and price book', async () => {
|
||||
const root='/Shared/Registers';
|
||||
|
||||
Reference in New Issue
Block a user