44 chatSessionListResponse ,
55 createChatFlowE2eSuite ,
66 installMockGateway ,
7+ pauseVirtualClock ,
78 requireRecord ,
89 requireString ,
910 waitForRequests ,
@@ -12,6 +13,112 @@ import {
1213const suite = createChatFlowE2eSuite ( ) ;
1314
1415suite . define ( ( ) => {
16+ it ( "recovers a queued follow-up when terminal events are missed" , async ( ) => {
17+ const artifactDir = process . env . OPENCLAW_UI_E2E_ARTIFACT_DIR ?. trim ( ) ;
18+ const context = await suite . newBrowserContext ( {
19+ locale : "en-US" ,
20+ serviceWorkers : "block" ,
21+ viewport : { height : 900 , width : 1280 } ,
22+ } ) ;
23+ const page = await context . newPage ( ) ;
24+ await page . clock . install ( ) ;
25+ const gateway = await installMockGateway ( page , {
26+ methodResponses : {
27+ "agent.wait" : { status : "ok" , endedAt : Date . now ( ) } ,
28+ } ,
29+ sessionInfo : { hasActiveRun : false , key : "main" , status : "done" } ,
30+ } ) ;
31+
32+ try {
33+ await page . goto ( `${ suite . server . baseUrl } settings/appearance` ) ;
34+ await page . locator ( "[data-settings-follow-up-mode]" ) . selectOption ( "queue" ) ;
35+ await page . goto ( `${ suite . server . baseUrl } chat?session=main` ) ;
36+ await expect . poll ( ( ) => new URL ( page . url ( ) ) . pathname ) . toMatch ( / \/ c h a t \/ m a i n $ / ) ;
37+
38+ await page . locator ( ".agent-chat__composer-combobox textarea" ) . fill ( "finish silently" ) ;
39+ await page . getByRole ( "button" , { name : "Send message" } ) . click ( ) ;
40+ const initialSend = await gateway . waitForRequest ( "chat.send" ) ;
41+ const activeRunId = requireString (
42+ requireRecord ( initialSend . params ) . idempotencyKey ,
43+ "active chat run id" ,
44+ ) ;
45+ await gateway . setMethodResponse ( "chat.history" , {
46+ messages : [
47+ {
48+ __openclaw : { idempotencyKey : `${ activeRunId } :user` } ,
49+ content : [ { text : "finish silently" , type : "text" } ] ,
50+ role : "user" ,
51+ timestamp : Date . now ( ) ,
52+ } ,
53+ ] ,
54+ sessionId : "control-ui-e2e-session" ,
55+ sessionInfo : { hasActiveRun : false , key : "global" , status : "done" } ,
56+ thinkingLevel : null ,
57+ } ) ;
58+ await gateway . emitGatewayEvent ( "session.message" , {
59+ activeRunIds : [ activeRunId ] ,
60+ clientRunId : activeRunId ,
61+ hasActiveRun : true ,
62+ message : {
63+ __openclaw : {
64+ id : "persisted-silent-user" ,
65+ idempotencyKey : `${ activeRunId } :user` ,
66+ seq : 1 ,
67+ } ,
68+ content : [ { text : "finish silently" , type : "text" } ] ,
69+ role : "user" ,
70+ timestamp : Date . now ( ) ,
71+ } ,
72+ messageId : "persisted-silent-user" ,
73+ messageSeq : 1 ,
74+ session : {
75+ activeRunIds : [ activeRunId ] ,
76+ hasActiveRun : true ,
77+ key : "main" ,
78+ kind : "direct" ,
79+ status : "running" ,
80+ updatedAt : Date . now ( ) ,
81+ } ,
82+ sessionKey : "main" ,
83+ } ) ;
84+ await page . getByRole ( "button" , { name : "Stop generating" } ) . waitFor ( { timeout : 10_000 } ) ;
85+ await gateway . setMethodResponse ( "chat.send" , { runId : "recovered-run" , status : "ok" } ) ;
86+
87+ await pauseVirtualClock ( page ) ;
88+ const followUp = "send after the missed terminal" ;
89+ await page . locator ( ".agent-chat__composer-combobox textarea" ) . fill ( followUp ) ;
90+ await page . getByRole ( "button" , { name : "Queue message" } ) . click ( ) ;
91+ const queue = page . locator ( ".chat-queue" ) ;
92+ await queue . getByText ( followUp ) . waitFor ( { timeout : 10_000 } ) ;
93+ expect ( await gateway . getRequests ( "chat.send" ) ) . toHaveLength ( 1 ) ;
94+ if ( artifactDir ) {
95+ await page . screenshot ( {
96+ path : `${ artifactDir } /missed-terminal-queued.png` ,
97+ fullPage : true ,
98+ } ) ;
99+ }
100+
101+ await page . clock . fastForward ( 15_000 ) ;
102+
103+ await gateway . waitForRequest ( "agent.wait" ) ;
104+ await page . clock . runFor ( 1_000 ) ;
105+ const sends = await waitForRequests ( gateway , "chat.send" , 2 ) ;
106+ expect ( requireRecord ( sends [ 1 ] ?. params ) ) . toMatchObject ( {
107+ message : followUp ,
108+ sessionKey : "main" ,
109+ } ) ;
110+ await queue . waitFor ( { state : "detached" , timeout : 10_000 } ) ;
111+ if ( artifactDir ) {
112+ await page . screenshot ( {
113+ path : `${ artifactDir } /missed-terminal-recovered.png` ,
114+ fullPage : true ,
115+ } ) ;
116+ }
117+ } finally {
118+ await suite . closeBrowserContext ( context ) ;
119+ }
120+ } ) ;
121+
15122 it ( "opens a git-backed agent draft from the sidebar new-session action" , async ( ) => {
16123 const context = await suite . newBrowserContext ( {
17124 locale : "en-US" ,
0 commit comments