@@ -17,8 +17,8 @@ interface TestableAgentServer {
1717 options : unknown [ ] ;
1818 toolCall : unknown ;
1919 } ) => Promise < {
20- outcome : { outcome : string } ;
21- _meta ?: { message ?: string } ;
20+ outcome : { outcome : string ; optionId ?: string } ;
21+ _meta ?: { message ?: string ; answers ?: Record < string , string > } ;
2222 } > ;
2323 } ;
2424 questionRelayedToSlack : boolean ;
@@ -281,15 +281,84 @@ describe("Question relay", () => {
281281 delete process . env . POSTHOG_CODE_INTERACTION_ORIGIN ;
282282 } ) ;
283283
284- it ( "auto-approves question tools (no Slack relay)" , async ( ) => {
285- const client = server . createCloudClient ( TEST_PAYLOAD ) ;
284+ it . each ( [
285+ [
286+ "no client can receive them" ,
287+ { eventStreamActive : false , mode : "interactive" } ,
288+ ] ,
289+ [
290+ "the run is in background mode even with the event stream active" ,
291+ { eventStreamActive : true , mode : "background" } ,
292+ ] ,
293+ ] ) ( "parks question tools when %s" , async ( _label , config ) => {
294+ const srv = server as TestableAgentServer & {
295+ eventStreamSender : { enqueue : ReturnType < typeof vi . fn > } | null ;
296+ } ;
297+ if ( config . eventStreamActive ) {
298+ srv . eventStreamSender = { enqueue : vi . fn ( ) } ;
299+ }
286300
301+ const client = srv . createCloudClient ( {
302+ ...TEST_PAYLOAD ,
303+ mode : config . mode ,
304+ } ) ;
287305 const result = await client . requestPermission ( {
288306 options : ALLOW_OPTIONS ,
289307 toolCall : { _meta : QUESTION_META } ,
290308 } ) ;
291309
310+ expect ( result . outcome . outcome ) . toBe ( "cancelled" ) ;
311+ expect ( result . _meta ?. message ) . toContain (
312+ "Do NOT pick an answer yourself" ,
313+ ) ;
314+ } ) ;
315+
316+ it ( "relays question tools when the durable event stream is active" , async ( ) => {
317+ const appendRawLine = vi . fn ( ) ;
318+ const enqueue = vi . fn ( ) ;
319+ const srv = server as TestableAgentServer & {
320+ eventStreamSender : { enqueue : typeof enqueue } | null ;
321+ resolvePermission : (
322+ requestId : string ,
323+ optionId : string ,
324+ customInput ?: string ,
325+ answers ?: Record < string , string > ,
326+ ) => boolean ;
327+ } ;
328+ srv . session = {
329+ payload : TEST_PAYLOAD ,
330+ sseController : null ,
331+ hasDesktopConnected : false ,
332+ logWriter : { appendRawLine } ,
333+ } ;
334+ srv . eventStreamSender = { enqueue } ;
335+
336+ const client = srv . createCloudClient ( TEST_PAYLOAD ) ;
337+ const pending = client . requestPermission ( {
338+ options : ALLOW_OPTIONS ,
339+ toolCall : { toolCallId : "question-1" , _meta : QUESTION_META } ,
340+ } ) ;
341+
342+ const request = appendRawLine . mock . calls
343+ . map ( ( [ , line ] ) => JSON . parse ( line ) )
344+ . find ( ( n ) => n ?. method === "_posthog/permission_request" ) ;
345+ expect ( request ) . toBeDefined ( ) ;
346+ expect ( enqueue ) . toHaveBeenCalledWith (
347+ expect . objectContaining ( { type : "permission_request" } ) ,
348+ ) ;
349+
350+ srv . resolvePermission (
351+ request . params . requestId as string ,
352+ "option_0" ,
353+ undefined ,
354+ { "Which license should I use?" : "MIT" } ,
355+ ) ;
356+
357+ const result = await pending ;
292358 expect ( result . outcome . outcome ) . toBe ( "selected" ) ;
359+ expect ( result . _meta ?. answers ) . toEqual ( {
360+ "Which license should I use?" : "MIT" ,
361+ } ) ;
293362 } ) ;
294363
295364 it ( "keeps auto-approving permissions after SSE send failures" , async ( ) => {
0 commit comments