@@ -154,3 +154,46 @@ test('direct daemon requests apply strip lock policy for existing sessions befor
154154 assert . equal ( action ?. flags . target , undefined ) ;
155155 assert . equal ( action ?. flags . device , 'iPhone 16' ) ;
156156} ) ;
157+
158+ test ( 'batch preserves tenant-scoped session names across nested requests' , async ( ) => {
159+ const sessionStore = makeStore ( ) ;
160+ sessionStore . set ( 'tenant-a:default' , makeIosSession ( 'tenant-a:default' ) ) ;
161+ const leaseRegistry = new LeaseRegistry ( ) ;
162+ const lease = leaseRegistry . allocateLease ( {
163+ tenantId : 'tenant-a' ,
164+ runId : 'run-1' ,
165+ } ) ;
166+ let dispatchCalls = 0 ;
167+
168+ const handler = createRequestHandler ( {
169+ logPath : path . join ( os . tmpdir ( ) , 'daemon.log' ) ,
170+ token : 'test-token' ,
171+ sessionStore,
172+ leaseRegistry,
173+ trackDownloadableArtifact : ( ) => 'artifact-id' ,
174+ dispatchCommand : async ( ) => {
175+ dispatchCalls += 1 ;
176+ return { } ;
177+ } ,
178+ } ) ;
179+
180+ const response = await handler ( {
181+ token : 'test-token' ,
182+ session : 'default' ,
183+ command : 'batch' ,
184+ positionals : [ ] ,
185+ flags : {
186+ batchSteps : [ { command : 'home' } ] ,
187+ } ,
188+ meta : {
189+ tenantId : 'tenant-a' ,
190+ runId : 'run-1' ,
191+ leaseId : lease . leaseId ,
192+ sessionIsolation : 'tenant' ,
193+ } ,
194+ } ) ;
195+
196+ assert . equal ( response . ok , true ) ;
197+ assert . equal ( dispatchCalls , 1 ) ;
198+ assert . equal ( sessionStore . get ( 'tenant-a:default' ) ?. actions . at ( - 1 ) ?. command , 'home' ) ;
199+ } ) ;
0 commit comments