okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fcb0c2d0e
main
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 ) { 8let handler ; 9apply ({ on :( _e , h ) => { handler = h ; }, inject :() => {}, sessions :new Map (), permissionPresets :{ current}, approval :{ overrideOf :() => 'never' } }); 10return 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 () => { 17const handler = gate (() => { throw new Error ( 'unknown session' ); }); 18const [ result , lines ] = await quiet (() => handler ({ name :'write' , agent :{ session}, input :{ file_path :'x' } }, allow )); 19assert . equal ( result . kind , 'ask' ); 20assert . 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 () => { 24const handler = gate (() => { throw new Error ( 'gone' ); }); 25const [ read ] = await quiet (() => handler ({ name :'read' , agent :{ session}, input :{ file_path :'x' } }, allow )); 26assert . equal ( read . kind , 'allow' ); 27const [ shell ] = await quiet (() => handler ({ name :'bash' , agent :{ session}, input :{ command :'rm -rf x' } }, allow )); 28assert . equal ( shell . kind , 'ask' ); 29}); 30 31test ( 'with a readable preset nothing changes: Bypass runs, Manual asks' , async () => { 32const bypass = gate (() => 'strata-bypass' ); 33assert . equal (( await bypass ({ name :'write' , agent :{ session}, input :{ file_path :'x' } }, allow )). kind , 'allow' ); 34const manual = gate (() => MANUAL_PRESET ); 35assert . equal (( await manual ({ name :'write' , agent :{ session}, input :{ file_path :'x' } }, allow )). kind , 'ask' ); 36});