@@ -131,10 +131,67 @@ describe.sequential("TUI PTY harness", () => {
131131 STARTUP_TEST_TIMEOUT_MS ,
132132 ) ;
133133
134+ it (
135+ "keeps session modes scoped while trace changes and delivery stays process-owned" ,
136+ async ( ) => {
137+ const modeFixture = await startTuiFixture ( {
138+ env : {
139+ OPENCLAW_TUI_PTY_DELIVER : "1" ,
140+ OPENCLAW_TUI_PTY_MODEL : "fixture-model" ,
141+ } ,
142+ } ) ;
143+ try {
144+ await modeFixture . run . waitForOutput ( "deliver:on" , STARTUP_TIMEOUT_MS ) ;
145+ await modeFixture . run . write ( "/session agent:main:mode-source\r" , { delay : false } ) ;
146+ await modeFixture . waitForLogEntry (
147+ ( entry ) =>
148+ entry . method === "loadHistory" &&
149+ objectFieldEquals ( entry , "sessionKey" , "agent:main:mode-source" ) ,
150+ ) ;
151+ await modeFixture . run . waitForOutput (
152+ "trace:raw | reasoning:stream | deliver:on" ,
153+ STARTUP_TIMEOUT_MS ,
154+ ) ;
155+
156+ const targetOutputOffset = modeFixture . run . visibleOutput ( ) . length ;
157+ await modeFixture . run . write ( "/session agent:main:mode-target\r" , { delay : false } ) ;
158+ await modeFixture . waitForLogEntry (
159+ ( entry ) =>
160+ entry . method === "loadHistory" &&
161+ objectFieldEquals ( entry , "sessionKey" , "agent:main:mode-target" ) ,
162+ ) ;
163+ await modeFixture . run . waitForOutput ( "session mode-target" , STARTUP_TIMEOUT_MS ) ;
164+ const targetOutput = modeFixture . run . visibleOutput ( ) . slice ( targetOutputOffset ) ;
165+ expect ( targetOutput ) . toContain ( "deliver:on" ) ;
166+ expect ( targetOutput ) . not . toContain ( "fast:auto" ) ;
167+ expect ( targetOutput ) . not . toContain ( "verbose full" ) ;
168+ expect ( targetOutput ) . not . toContain ( "trace:raw" ) ;
169+ expect ( targetOutput ) . not . toContain ( "reasoning:stream" ) ;
170+
171+ await modeFixture . run . write ( "/trace on\r" , { delay : false } ) ;
172+ await modeFixture . waitForLogEntry (
173+ ( entry ) =>
174+ entry . method === "patchSession" && objectFieldEquals ( entry , "traceLevel" , "on" ) ,
175+ ) ;
176+ await modeFixture . run . waitForOutput ( "trace | deliver:on" , STARTUP_TIMEOUT_MS ) ;
177+
178+ await modeFixture . run . write ( "delivery proof\r" , { delay : false } ) ;
179+ const sent = await modeFixture . waitForLogEntry (
180+ ( entry ) =>
181+ entry . method === "sendChat" && objectFieldEquals ( entry , "message" , "delivery proof" ) ,
182+ ) ;
183+ expect ( sent . payload ) . toMatchObject ( { deliver : true } ) ;
184+ } finally {
185+ await modeFixture . cleanup ( ) ;
186+ }
187+ } ,
188+ STARTUP_TEST_TIMEOUT_MS ,
189+ ) ;
190+
134191 it (
135192 "keeps the launch thinking override active across session-level changes" ,
136193 async ( ) => {
137- const footerNeedle = "fixture-provider/fixture-model high | tokens" ;
194+ const footerNeedle = "fixture-provider/fixture-model high | deliver:off | tokens" ;
138195 await thinkingOverrideFixture . run . waitForOutput ( footerNeedle , STARTUP_TIMEOUT_MS ) ;
139196 await thinkingOverrideFixture . run . waitForOutput (
140197 "PTY_RESPONSE: thinking override proof" ,
@@ -167,9 +224,11 @@ describe.sequential("TUI PTY harness", () => {
167224 . visibleOutput ( )
168225 . slice ( sessionChangeOutputOffset ) ;
169226 expect ( outputAfterSessionChange ) . toContain ( footerNeedle ) ;
170- expect ( outputAfterSessionChange ) . not . toContain ( "fixture-provider/fixture-model low | tokens" ) ;
171227 expect ( outputAfterSessionChange ) . not . toContain (
172- "fixture-provider/fixture-model medium | tokens" ,
228+ "fixture-provider/fixture-model low | deliver:off | tokens" ,
229+ ) ;
230+ expect ( outputAfterSessionChange ) . not . toContain (
231+ "fixture-provider/fixture-model medium | deliver:off | tokens" ,
173232 ) ;
174233 } ,
175234 STARTUP_TEST_TIMEOUT_MS ,
0 commit comments