@@ -15,14 +15,17 @@ const STARTUP_TIMEOUT_MS = 60_000;
1515const REMEMBERED_SESSION_KEY = "agent:main:picker-target" ;
1616const tempDirs = useAutoCleanupTempDirTracker ( afterEach ) ;
1717
18- async function seedRememberedSession ( stateDir : string ) {
18+ async function seedRememberedSession (
19+ stateDir : string ,
20+ sessionKey : string = REMEMBERED_SESSION_KEY ,
21+ ) {
1922 await writeTuiLastSessionKey ( {
2023 scopeKey : buildTuiLastSessionScopeKey ( {
2124 connectionUrl : "pty-fixture://local" ,
2225 agentId : "main" ,
2326 sessionScope : "per-sender" ,
2427 } ) ,
25- sessionKey : REMEMBERED_SESSION_KEY ,
28+ sessionKey,
2629 stateDir,
2730 } ) ;
2831}
@@ -106,6 +109,47 @@ it("hides a stale approval when startup restores the remembered session", async
106109 }
107110} , 65_000 ) ;
108111
112+ it ( "restores a remembered global session before startup admits the first send" , async ( ) => {
113+ const stateDir = tempDirs . make ( "openclaw-tui-global-session-" ) ;
114+ const marker = "global startup session proof" ;
115+ await seedRememberedSession ( stateDir , "global" ) ;
116+ const fixture = await startTuiFixture ( {
117+ env : {
118+ OPENCLAW_STATE_DIR : stateDir ,
119+ OPENCLAW_TUI_PTY_PICKER_FIXTURE : "1" ,
120+ OPENCLAW_TUI_PTY_PICKER_SESSION_KEY : "global" ,
121+ } ,
122+ } ) ;
123+
124+ try {
125+ const lookup = await fixture . waitForLogEntry (
126+ ( entry ) => entry . method === "listSessions" && objectFieldEquals ( entry , "search" , "global" ) ,
127+ STARTUP_TIMEOUT_MS ,
128+ ) ;
129+ expect ( lookup . payload ) . toMatchObject ( {
130+ search : "global" ,
131+ includeGlobal : true ,
132+ includeUnknown : false ,
133+ agentId : "main" ,
134+ } ) ;
135+
136+ await fixture . run . waitForOutput ( "local ready" , STARTUP_TIMEOUT_MS ) ;
137+ await fixture . run . write ( `${ marker } \r` , { delay : false } ) ;
138+ await fixture . waitForLogEntry (
139+ ( entry ) => entry . method === "sendChat" && objectFieldEquals ( entry , "message" , marker ) ,
140+ STARTUP_TIMEOUT_MS ,
141+ ) ;
142+
143+ const sends = ( await readFixtureLog ( fixture . logPath ) ) . filter (
144+ ( entry ) => entry . method === "sendChat" ,
145+ ) ;
146+ expect ( sends ) . toHaveLength ( 1 ) ;
147+ expect ( sends [ 0 ] ?. payload ) . toMatchObject ( { sessionKey : "global" , agentId : "main" } ) ;
148+ } finally {
149+ await fixture . cleanup ( ) ;
150+ }
151+ } , 65_000 ) ;
152+
109153it ( "keeps startup input editable until the remembered session and history are stable" , async ( ) => {
110154 const stateDir = tempDirs . make ( "openclaw-tui-startup-session-" ) ;
111155 const marker = "startup remembered session proof" ;
0 commit comments