okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-023-int into f-023-guifcb0c2d0e

main
2.1 KiB36 linesraw
1// T4 (tools and images review, 2026-10-22): the approval gate fails closed. When the permission mode of a session cannot be read, a call
2// that is not provably read-only asks, as in Manual; it used to run without a card.
3import test from 'node:test';
4import assert from 'node:assert/strict';
5import { apply, MANUAL_PRESET } from '../server/agent/plugins/strata-gate.mjs';
6
7function gate(current) {
8  let handler;
9  apply({ on: (_e, h) => { handler = h; }, inject: () => {}, sessions: new Map(), permissionPresets: { current }, approval: { overrideOf: () => 'never' } });
10  return handler;
11}
12const session = { header: { origin: 'user' } };
13const allow = async () => ({ kind: 'allow' });
14const quiet = async fn => { const warn = console.warn; const lines = []; console.warn = (...a) => lines.push(a.join(' ')); try { return [await fn(), lines]; } finally { console.warn = warn; } };
15
16test('a call that changes things asks when the preset cannot be resolved', async () => {
17  const handler = gate(() => { throw new Error('unknown session'); });
18  const [result, lines] = await quiet(() => handler({ name: 'write', agent: { session }, input: { file_path: 'x' } }, allow));
19  assert.equal(result.kind, 'ask');
20  assert.match(lines.join('\n'), /could not read the permission mode.*unknown session.*Manual/);
21});
22
23test('a provably read-only call still goes through, and a shell write asks', async () => {
24  const handler = gate(() => { throw new Error('gone'); });
25  const [read] = await quiet(() => handler({ name: 'read', agent: { session }, input: { file_path: 'x' } }, allow));
26  assert.equal(read.kind, 'allow');
27  const [shell] = await quiet(() => handler({ name: 'bash', agent: { session }, input: { command: 'rm -rf x' } }, allow));
28  assert.equal(shell.kind, 'ask');
29});
30
31test('with a readable preset nothing changes: Bypass runs, Manual asks', async () => {
32  const bypass = gate(() => 'strata-bypass');
33  assert.equal((await bypass({ name: 'write', agent: { session }, input: { file_path: 'x' } }, allow)).kind, 'allow');
34  const manual = gate(() => MANUAL_PRESET);
35  assert.equal((await manual({ name: 'write', agent: { session }, input: { file_path: 'x' } }, allow)).kind, 'ask');
36});