@@ -64,7 +64,6 @@ interface ListenerDiagnostics {
6464}
6565
6666async function withListener (
67- sandboxBaseRef : { value : string } ,
6867 run : (
6968 url : string ,
7069 db : ReturnType < typeof openAgentDatabase > ,
@@ -83,7 +82,6 @@ async function withListener(
8382 } ) ;
8483 const listener = new AgentHookListener ( {
8584 lifecycle,
86- getSandboxBaseDirectory : ( ) => sandboxBaseRef . value ,
8785 log : ( message ) => diagnostics . logs . push ( message ) ,
8886 port : 0 ,
8987 } ) ;
@@ -108,17 +106,15 @@ function assertNoWritesOrEmits(
108106}
109107
110108test ( "listener: GET /api/health returns 200 ok" , async ( ) => {
111- const sandbox = { value : "/work" } ;
112- await withListener ( sandbox , async ( url ) => {
109+ await withListener ( async ( url ) => {
113110 const res = await request ( `${ url } /api/health` , "GET" ) ;
114111 assert . equal ( res . status , 200 ) ;
115112 assert . deepEqual ( res . body , { ok : true } ) ;
116113 } ) ;
117114} ) ;
118115
119- test ( "listener: in-sandbox SessionStart writes a session with harness=claude" , async ( ) => {
120- const sandbox = { value : "/work" } ;
121- await withListener ( sandbox , async ( url , db , diagnostics ) => {
116+ test ( "listener: SessionStart writes a session with harness=claude" , async ( ) => {
117+ await withListener ( async ( url , db , diagnostics ) => {
122118 const res = await request ( `${ url } /api/hooks/event` , "POST" , {
123119 hook_type : "SessionStart" ,
124120 data : { session_id : "s1" , cwd : "/work/project" } ,
@@ -132,8 +128,7 @@ test("listener: in-sandbox SessionStart writes a session with harness=claude", a
132128} ) ;
133129
134130test ( "listener: Codex route stamps harness=codex without payload provider hint" , async ( ) => {
135- const sandbox = { value : "/work" } ;
136- await withListener ( sandbox , async ( url , db , diagnostics ) => {
131+ await withListener ( async ( url , db , diagnostics ) => {
137132 const res = await request ( `${ url } /api/hooks/codex/event` , "POST" , {
138133 hook_type : "SessionStart" ,
139134 data : { session_id : "cx1" , cwd : "/work/project" } ,
@@ -145,8 +140,7 @@ test("listener: Codex route stamps harness=codex without payload provider hint",
145140} ) ;
146141
147142test ( "listener: payload provider hints are rejected before writes on every hook route" , async ( ) => {
148- const sandbox = { value : "/work" } ;
149- await withListener ( sandbox , async ( url , db , diagnostics ) => {
143+ await withListener ( async ( url , db , diagnostics ) => {
150144 for ( const route of [ "/api/hooks/event" , "/api/hooks/codex/event" ] ) {
151145 const res = await request ( `${ url } ${ route } ` , "POST" , {
152146 hook_type : "SessionStart" ,
@@ -160,8 +154,7 @@ test("listener: payload provider hints are rejected before writes on every hook
160154} ) ;
161155
162156test ( "listener: malformed, invalid, and oversized payloads fail soft without writes" , async ( ) => {
163- const sandbox = { value : "/work" } ;
164- await withListener ( sandbox , async ( url , db , diagnostics ) => {
157+ await withListener ( async ( url , db , diagnostics ) => {
165158 const malformed = await requestRaw (
166159 `${ url } /api/hooks/event` ,
167160 "POST" ,
@@ -198,28 +191,16 @@ test("listener: malformed, invalid, and oversized payloads fail soft without wri
198191 } ) ;
199192} ) ;
200193
201- test ( "listener: out-of-sandbox event is dropped (no write)" , async ( ) => {
202- const sandbox = { value : "/work" } ;
203- await withListener ( sandbox , async ( url , db , diagnostics ) => {
194+ test ( "listener: sessions from any directory are captured (no sandbox gating)" , async ( ) => {
195+ await withListener ( async ( url , db , diagnostics ) => {
204196 const res = await request ( `${ url } /api/hooks/event` , "POST" , {
205197 hook_type : "SessionStart" ,
206- data : { session_id : "outside" , cwd : "/somewhere/else" } ,
207- } ) ;
208- assert . equal ( res . status , 200 , "still acks so the hook never blocks" ) ;
209- assert . deepEqual ( res . body , { ok : true , skipped : "out-of-sandbox" } ) ;
210- assertNoWritesOrEmits ( db , diagnostics ) ;
211- } ) ;
212- } ) ;
213-
214- test ( "listener: empty sandbox captures nothing (fail-closed)" , async ( ) => {
215- const sandbox = { value : "" } ;
216- await withListener ( sandbox , async ( url , db , diagnostics ) => {
217- const res = await request ( `${ url } /api/hooks/event` , "POST" , {
218- hook_type : "SessionStart" ,
219- data : { session_id : "s1" , cwd : "/work/project" } ,
198+ data : { session_id : "anywhere" , cwd : "/somewhere/else" } ,
220199 } ) ;
221200 assert . equal ( res . status , 200 ) ;
222- assert . deepEqual ( res . body , { ok : true , skipped : "out-of-sandbox" } ) ;
223- assertNoWritesOrEmits ( db , diagnostics ) ;
201+ assert . deepEqual ( res . body , { ok : true } ) ;
202+ const session = db . sessions . getById ( "anywhere" ) ;
203+ assert . ok ( session , "session from any directory is imported" ) ;
204+ assert . deepEqual ( diagnostics . emits , [ "anywhere" ] ) ;
224205 } ) ;
225206} ) ;
0 commit comments