@@ -1036,42 +1036,39 @@ it("keeps concurrent approvals actionable outside collapsed work and restores se
10361036 responseCapability : "live" ,
10371037 } ,
10381038 ] ;
1039- const entries = deriveTimelineEntriesFromVisibleTurnItems ( {
1040- visibleTurnItems : [
1041- source ,
1042- ...approvals . map ( ( approval , index ) => ( {
1043- ...source ,
1044- position : source . position + index + 1 ,
1045- sourceItemId : TurnItemId . make ( `approval-${ index } ` ) ,
1046- item : {
1047- ...sourceItem ,
1048- id : TurnItemId . make ( `approval-${ index } ` ) ,
1049- type : "approval_request" as const ,
1050- status : "waiting" as const ,
1051- requestId : approval . requestId ,
1052- requestKind : approval . requestKind ,
1053- prompt : approval . detail ,
1054- } ,
1055- } ) ) ,
1056- ] ,
1057- optimisticMessages : [ ] ,
1058- } ) ;
1039+ const entries = ( completed = false ) =>
1040+ deriveTimelineEntriesFromVisibleTurnItems ( {
1041+ visibleTurnItems : [
1042+ { ...source , item : { ...sourceItem , status : completed ? "completed" : sourceItem . status } } ,
1043+ ...approvals . map ( ( approval , index ) => ( {
1044+ ...source ,
1045+ position : source . position + index + 1 ,
1046+ sourceItemId : TurnItemId . make ( `approval-${ index } ` ) ,
1047+ item : {
1048+ ...sourceItem ,
1049+ id : TurnItemId . make ( `approval-${ index } ` ) ,
1050+ type : "approval_request" as const ,
1051+ status : completed ? ( "completed" as const ) : ( "waiting" as const ) ,
1052+ requestId : approval . requestId ,
1053+ requestKind : approval . requestKind ,
1054+ prompt : approval . detail ,
1055+ } ,
1056+ } ) ) ,
1057+ ] ,
1058+ optimisticMessages : [ ] ,
1059+ } ) ;
10591060 const props = baseProps ( ) ;
10601061 const onRespondToApproval = vi . fn ( async ( ) => { } ) ;
1061- const ui = (
1062- pendingApprovals = approvals ,
1063- canOperateThread = true ,
1064- respondingRequestIds : RuntimeRequestId [ ] = [ ] ,
1065- ) => (
1062+ const ui = ( overrides : Partial < TimelineProps > = { } ) => (
10661063 < MessagesTimeline
10671064 { ...props }
1068- timelineEntries = { entries }
1069- pendingApprovals = { pendingApprovals }
1070- respondingRequestIds = { respondingRequestIds }
1071- canOperateThread = { canOperateThread }
1065+ timelineEntries = { entries ( ) }
1066+ pendingApprovals = { approvals }
1067+ canOperateThread
10721068 onRespondToApproval = { onRespondToApproval }
10731069 isWorking
10741070 runningRunId = { fixture . runId }
1071+ { ...overrides }
10751072 />
10761073 ) ;
10771074 await using screen = await renderElement ( ui ( ) ) ;
@@ -1081,6 +1078,12 @@ it("keeps concurrent approvals actionable outside collapsed work and restores se
10811078 . toBeVisible ( ) ;
10821079 await expect . element ( screen . getByText ( approvals [ 0 ] ! . detail ! , { exact : true } ) ) . toBeVisible ( ) ;
10831080 await expect . element ( screen . getByText ( "Needs permission to run the command" ) ) . toBeVisible ( ) ;
1081+ expect (
1082+ getComputedStyle ( screen . getByLabelText ( "Command" , { exact : true } ) . element ( ) ) . userSelect ,
1083+ ) . toBe ( "text" ) ;
1084+ expect (
1085+ getComputedStyle ( screen . getByText ( "Needs permission to run the command" ) . element ( ) ) . userSelect ,
1086+ ) . toBe ( "text" ) ;
10841087 await expect . element ( screen . getByText ( "Safari" , { exact : true } ) ) . toBeVisible ( ) ;
10851088 await click ( screen . button ( "Why am I being asked this?" ) ) ;
10861089 await expect . element ( page . getByText ( / a n a s k r u l e i n t h e a g e n t ' s o w n s e t t i n g s / ) ) . toBeVisible ( ) ;
@@ -1097,24 +1100,66 @@ it("keeps concurrent approvals actionable outside collapsed work and restores se
10971100 expect ( onRespondToApproval ) . toHaveBeenLastCalledWith ( commandRequest , "decline" ) ;
10981101 await click ( screen . button ( "Allow once" ) ) ;
10991102 expect ( onRespondToApproval ) . toHaveBeenLastCalledWith ( appRequest , "accept" ) ;
1100- await screen . rerender ( ui ( approvals , false ) ) ;
1103+ for ( const timelineEntries of [ entries ( ) , [ ] ] ) {
1104+ await screen . rerender (
1105+ ui ( { timelineEntries, heldApprovalRequestIds : new Set ( [ commandRequest ] ) } ) ,
1106+ ) ;
1107+ await expect
1108+ . element ( screen . getByRole ( "group" , { name : "Command approval" } ) )
1109+ . not . toBeInTheDocument ( ) ;
1110+ expect ( screen . buttons ( "Approve" ) ) . toHaveLength ( 0 ) ;
1111+ await expect
1112+ . element ( screen . getByRole ( "button" , { name : "Allow once" , exact : true } ) )
1113+ . toBeVisible ( ) ;
1114+ await screen . rerender ( ui ( { timelineEntries } ) ) ;
1115+ await expect . element ( screen . getByRole ( "group" , { name : "Command approval" } ) ) . toBeVisible ( ) ;
1116+ expect ( screen . buttons ( "Approve" ) ) . toHaveLength ( 1 ) ;
1117+ }
1118+ await screen . rerender ( ui ( { timelineEntries : [ ] , isWorking : false } ) ) ;
1119+ await expect . element ( screen . getByRole ( "group" , { name : "Command approval" } ) ) . toBeVisible ( ) ;
1120+ await click ( screen . button ( "Approve" ) ) ;
1121+ expect ( onRespondToApproval ) . toHaveBeenLastCalledWith ( commandRequest , "accept" ) ;
1122+ await click ( screen . button ( "Deny" ) ) ;
1123+ expect ( onRespondToApproval ) . toHaveBeenLastCalledWith ( appRequest , "decline" ) ;
1124+ await screen . rerender (
1125+ ui ( {
1126+ timelineEntries : [ ] ,
1127+ isWorking : false ,
1128+ pendingApprovals : [ { ...approvals [ 0 ] ! , detail : "" } ] ,
1129+ } ) ,
1130+ ) ;
1131+ await expect
1132+ . element ( screen . getByLabelText ( "Command" , { exact : true } ) )
1133+ . toHaveTextContent ( "Command approval" ) ;
1134+ await screen . rerender ( ui ( { canOperateThread : false } ) ) ;
11011135 await expect . element ( screen . getByRole ( "button" , { name : "Approve" , exact : true } ) ) . toBeDisabled ( ) ;
11021136 expect (
11031137 screen . buttons ( "More approval options" ) . every ( ( button ) => button . hasAttribute ( "disabled" ) ) ,
11041138 ) . toBe ( true ) ;
1105- await screen . rerender ( ui ( approvals , true , [ commandRequest ] ) ) ;
1139+ await screen . rerender ( ui ( { respondingRequestIds : [ commandRequest ] } ) ) ;
11061140 await expect . element ( screen . getByRole ( "button" , { name : "Approve" , exact : true } ) ) . toBeDisabled ( ) ;
11071141 await expect
11081142 . element ( screen . getByRole ( "button" , { name : "Allow once" , exact : true } ) )
11091143 . toBeEnabled ( ) ;
1110- await screen . rerender ( ui ( [ { ...approvals [ 0 ] ! , responseCapability : "not_resumable" } ] ) ) ;
1144+ await screen . rerender (
1145+ ui ( { pendingApprovals : [ { ...approvals [ 0 ] ! , responseCapability : "not_resumable" } ] } ) ,
1146+ ) ;
11111147 await expect
11121148 . element ( screen . getByText ( "Provider process is gone. Interrupt or restart the run to respond." ) )
11131149 . toBeVisible ( ) ;
11141150 expect ( screen . buttons ( "Approve" ) ) . toHaveLength ( 0 ) ;
1115- await screen . rerender ( ui ( [ ] ) ) ;
1151+ await screen . rerender (
1152+ ui ( { pendingApprovals : [ ] , timelineEntries : entries ( true ) , isWorking : false } ) ,
1153+ ) ;
11161154 await expect
11171155 . element ( screen . getByRole ( "group" , { name : "Command approval" } ) )
11181156 . not . toBeInTheDocument ( ) ;
11191157 expect ( screen . text ( ) ) . not . toContain ( "Waiting for approval" ) ;
1158+ await screen . getByRole ( "button" , { expanded : false } ) . click ( ) ;
1159+ await expect
1160+ . element ( screen . getByRole ( "button" , { name : approvals [ 0 ] ! . detail ! , exact : true } ) )
1161+ . toBeVisible ( ) ;
1162+ await expect
1163+ . element ( screen . getByRole ( "button" , { name : "Open the current tab" , exact : true } ) )
1164+ . toBeVisible ( ) ;
11201165} ) ;
0 commit comments