|
| 1 | +// test/lwsowner-metadata.test.js |
| 2 | +// Governance round (2026-07-22): .lwsowner sidecar primitives + the |
| 3 | +// read-merge-write marker helper the boot backfill depends on. |
| 4 | +import { describe, it, before } from 'node:test'; |
| 5 | +import assert from 'node:assert/strict'; |
| 6 | +import { startLwsPod } from './helpers.js'; |
| 7 | +import * as storage from '../src/storage/filesystem.js'; |
| 8 | +import { |
| 9 | + ownerStorePath, readOwners, writeOwners, ensureDeclaredType, |
| 10 | + readDeclaredTypes, typeStorePath, LWS_STORAGE, |
| 11 | +} from '../src/lws/type-metadata.js'; |
| 12 | + |
| 13 | +describe('.lwsowner primitives + marker merge', () => { |
| 14 | + let pod, root; |
| 15 | + before(async (t) => { pod = await startLwsPod(t, 'govmeta'); root = `/${pod.podName}/`; }); |
| 16 | + |
| 17 | + it('writeOwners/readOwners round-trip, dedupe, URI-only', async () => { |
| 18 | + await writeOwners(storage, root, [pod.webId, pod.webId, 'not a uri']); |
| 19 | + assert.deepEqual(await readOwners(storage, root), [pod.webId]); |
| 20 | + assert.equal(ownerStorePath(root), `${root}.lwsowner`); |
| 21 | + }); |
| 22 | + |
| 23 | + it('readOwners returns [] for missing/corrupt sidecars', async () => { |
| 24 | + assert.deepEqual(await readOwners(storage, '/nowhere/'), []); |
| 25 | + await storage.write(ownerStorePath(root), Buffer.from('{corrupt')); |
| 26 | + assert.deepEqual(await readOwners(storage, root), []); |
| 27 | + await writeOwners(storage, root, [pod.webId]); // restore |
| 28 | + }); |
| 29 | + |
| 30 | + it('ensureDeclaredType merges, never overwrites, idempotent', async () => { |
| 31 | + await storage.write(typeStorePath(root), Buffer.from(JSON.stringify(['https://example.org/Custom']))); |
| 32 | + assert.equal(await ensureDeclaredType(storage, root, LWS_STORAGE), true); |
| 33 | + const types = await readDeclaredTypes(storage, root); |
| 34 | + assert.ok(types.includes('https://example.org/Custom')); // merge, not overwrite |
| 35 | + assert.ok(types.includes(LWS_STORAGE)); |
| 36 | + assert.equal(await ensureDeclaredType(storage, root, LWS_STORAGE), false); // idempotent |
| 37 | + }); |
| 38 | +}); |
0 commit comments