/** * The host row: the deployment's policy and its lifetime. * * Short, but it is the half that is easiest to leave untested — it has no * interesting logic and one interesting obligation, which is that a grant must * not outlive the session that asked for it. */ import assert from 'node:assert/strict' import { test } from 'node:test' import { apply, Config } from '../index.js' /** The smallest context this row touches. */ function harness() { const captured = { provided: undefined, onDisposed: undefined } const ctx = { provide: (name, value) => { captured.provided = { name, value } }, on: (event, listener) => { if (event === 'session/disposed') captured.onDisposed = listener }, } apply(ctx, Config({ mode: 'ask' })) return captured } test('the schema fills every default, so a bare row is a working row', () => { const config = Config({}) assert.equal(config.mode, 'ask') assert.deepEqual(config.extraRoots, []) assert.equal(config.sectionOrder, 100) assert.equal(config.contextOrder, 105) }) test('a bad mode fails loudly at load rather than at the first file call', () => { assert.throws(() => Config({ mode: 'maybe' })) }) test('the policy is published under the name the guard injects', () => { const captured = harness() assert.equal(captured.provided.name, 'facetPolicy') assert.equal(captured.provided.value.mode, 'ask') }) test('the service reads the configuration it was given', () => { const provided = [] apply( { provide: (name, value) => provided.push({ name, value }), on: () => {} }, Config({ mode: 'deny', extraRoots: ['../../shared'], sectionOrder: 7, contextOrder: 8 }), ) const policy = provided[0].value assert.equal(policy.mode, 'deny') assert.deepEqual(policy.standing, ['../../shared']) assert.equal(policy.sectionOrder, 7) assert.equal(policy.contextOrder, 8) }) test('a disposed session does not leave its grant behind', () => { const captured = harness() const policy = captured.provided.value policy.grant('session-1', ['../../shared'], '/w/src/room') assert.deepEqual(policy.grantsFor('session-1'), ['/w/shared']) assert.equal(typeof captured.onDisposed, 'function') captured.onDisposed({ id: 'session-1' }) assert.deepEqual(policy.grantsFor('session-1'), []) assert.deepEqual(policy.sessions, []) })