@@ -327,6 +327,135 @@ test("sends one permission reply and closes the dock when it lands, before permi
327327 expect ( replies ) . toEqual ( [ { decision : "once" } ] )
328328} )
329329
330+ test ( "shows an auto-accepted permission in the dock once its replies stop answering" , async ( { page } ) => {
331+ const permissionID = "permission-hung"
332+ const attempts = { count : 0 }
333+ await page . clock . install ( )
334+ await mockWorkspace ( page , {
335+ name : "RequestDocks" ,
336+ directory,
337+ sessions : [ { id : sessionID , title } ] ,
338+ sessionPermissions : {
339+ [ sessionID ] : [
340+ { id : permissionID , sessionID, action : "shell" , resources : [ "git status" ] , metadata : { } , save : [ ] } ,
341+ ] ,
342+ } ,
343+ seed : { settings : { permissions : { autoApprove : true } } } ,
344+ } )
345+ // Every reply reaches the server and never answers.
346+ await page . route ( new RegExp ( `/api/session/${ sessionID } /permission/${ permissionID } /reply(\\?|$)` ) , ( route ) => {
347+ if ( route . request ( ) . method ( ) !== "POST" ) return route . fallback ( )
348+ attempts . count ++
349+ } )
350+
351+ await page . goto ( sessionHref ( sessionID ) )
352+ await expectSessionTitle ( page , title )
353+ const permission = page . locator ( '[data-component="dock-prompt"][data-kind="permission"]' )
354+
355+ // Each reply times out, then the next one starts after its retry delay.
356+ await expect . poll ( ( ) => attempts . count ) . toBe ( 1 )
357+ await page . clock . fastForward ( 15_000 )
358+ await page . clock . fastForward ( 1_000 )
359+ await expect . poll ( ( ) => attempts . count ) . toBe ( 2 )
360+ await page . clock . fastForward ( 15_000 )
361+ await page . clock . fastForward ( 2_000 )
362+ await expect . poll ( ( ) => attempts . count ) . toBe ( 3 )
363+ await expect ( permission ) . toHaveCount ( 0 )
364+
365+ await page . clock . fastForward ( 15_000 )
366+ await expect ( permission . getByText ( "git status" ) ) . toBeVisible ( )
367+ expect ( attempts . count ) . toBe ( 3 )
368+ } )
369+
370+ test ( "keeps a typed MCP elicitation answer across a session switch and submits it once" , async ( { page } ) => {
371+ const other = { id : "ses_request_docks_other" , title : "Other request session" }
372+
373+ const form = {
374+ id : "frm_mcp_draft" ,
375+ sessionID,
376+ title : "Deploy" ,
377+ metadata : { kind : "mcp-elicitation" , server : "release" } ,
378+ fields : [ { key : "env" , type : "string" , title : "Environment" } ] ,
379+ }
380+
381+ const replies : unknown [ ] = [ ]
382+ await mockWorkspace ( page , {
383+ name : "RequestDocks" ,
384+ directory,
385+ sessions : [ { id : sessionID , title } , other ] ,
386+ forms : ( ) => ( replies . length > 0 ? [ ] : [ form ] ) ,
387+ onFormReply : ( reply ) => replies . push ( reply . body ) ,
388+ seed : { tabs : [ sessionID , other . id ] } ,
389+ } )
390+
391+ await page . goto ( sessionHref ( sessionID ) )
392+ await expectSessionTitle ( page , title )
393+ const dock = page . locator ( '[data-component="session-elicitation-dock"]' )
394+ const input = dock . getByRole ( "textbox" , { name : "Environment" , exact : true } )
395+ await input . fill ( "staging" )
396+
397+ await page . locator ( `[data-titlebar-tab-slot]:has(a[href="${ sessionHref ( other . id ) } "])` ) . click ( )
398+ await expectSessionTitle ( page , other . title )
399+ await expect ( dock ) . toHaveCount ( 0 )
400+ await page . locator ( `[data-titlebar-tab-slot]:has(a[href="${ sessionHref ( sessionID ) } "])` ) . click ( )
401+ await expectSessionTitle ( page , title )
402+ await expect ( input ) . toHaveValue ( "staging" )
403+
404+ await dock . getByRole ( "button" , { name : "Submit" , exact : true } ) . dblclick ( )
405+ await expect ( dock ) . toHaveCount ( 0 )
406+ await expect ( page . locator ( '[data-component="composer"]' ) ) . toBeVisible ( )
407+ expect ( replies ) . toEqual ( [ { answer : { env : "staging" } } ] )
408+ } )
409+
410+ test ( "gives a Location elicitation's hung reply back after 30 s and closes it on form.replied" , async ( { page } ) => {
411+ const form = {
412+ id : "frm_mcp_global" ,
413+ sessionID : "global" ,
414+ title : "Deploy" ,
415+ metadata : { kind : "mcp-elicitation" , server : "release" } ,
416+ fields : [ { key : "env" , type : "string" , title : "Environment" } ] ,
417+ }
418+
419+ const replies : { body : unknown ; directory : string | undefined } [ ] = [ ]
420+ const transport = await installSseTransport ( page , { server : SERVER , retry : 20 } )
421+ await page . clock . install ( )
422+ await mockServer ( page , { forms : [ form ] } )
423+ // The server takes the reply and never answers it.
424+ await page . route ( / \/ a p i \/ s e s s i o n \/ g l o b a l \/ f o r m \/ f r m _ m c p _ g l o b a l \/ r e p l y ( \? | $ ) / , ( route ) => {
425+ if ( route . request ( ) . method ( ) !== "POST" ) return route . fallback ( )
426+ replies . push ( { body : route . request ( ) . postDataJSON ( ) , directory : route . request ( ) . headers ( ) [ "x-opencode-directory" ] } )
427+ } )
428+
429+ await page . goto ( sessionHref ( sessionID ) )
430+ await transport . waitForConnection ( )
431+ await expectSessionTitle ( page , title )
432+ const dock = page . locator ( '[data-component="session-elicitation-dock"]' )
433+ const input = dock . getByRole ( "textbox" , { name : "Environment" , exact : true } )
434+ const submit = dock . getByRole ( "button" , { name : "Submit" , exact : true } )
435+ await input . fill ( "prod" )
436+
437+ await submit . dblclick ( )
438+ await expect . poll ( ( ) => replies . length ) . toBe ( 1 )
439+ await expect ( submit ) . toBeDisabled ( )
440+ expect ( replies ) . toEqual ( [ { body : { answer : { env : "prod" } } , directory : encodeURIComponent ( directory ) } ] )
441+
442+ await page . clock . fastForward ( 30_000 )
443+ await expect ( submit ) . toBeEnabled ( )
444+ await expect ( input ) . toHaveValue ( "prod" )
445+ await expect ( page . getByText ( "Request failed" , { exact : true } ) ) . toBeVisible ( )
446+
447+ await transport . send ( {
448+ id : "evt_form_replied_global" ,
449+ created : 1700000004000 ,
450+ type : "form.replied" ,
451+ location : { directory } ,
452+ data : { sessionID : "global" , id : "frm_mcp_global" , answer : { env : "prod" } } ,
453+ } )
454+ await expect ( dock ) . toHaveCount ( 0 )
455+ await expect ( page . locator ( '[data-component="composer"]' ) ) . toBeVisible ( )
456+ expect ( replies ) . toHaveLength ( 1 )
457+ } )
458+
330459test ( "names the MCP tool, the hook's message and the full input in the permission dock" , async ( { page } ) => {
331460 const body = "x" . repeat ( 3000 )
332461 await mockServer ( page , {
0 commit comments