@@ -18,6 +18,8 @@ import { createRequestHandler } from './test-device-runtime-gateway.ts';
1818import type { DaemonRequest } from '../daemon-request.ts' ;
1919import type { SessionState } from '../session-state.ts' ;
2020import type { DeviceInfo } from '@agent-device/kernel/device' ;
21+ import { resolveEffectiveSessionName } from '../session-routing.ts' ;
22+ import { scopeRequestSession } from '../request-admission.ts' ;
2123import { LeaseRegistry } from '../lease-registry.ts' ;
2224import { makeSessionStore } from '../../__tests__/test-utils/store-factory.ts' ;
2325import { inspectAdReplay } from '@agent-device/ad-replay' ;
@@ -170,3 +172,45 @@ test('a replay --from continuation on a reaped repair session gets REPAIR_SESSIO
170172
171173 fs . rmSync ( root , { recursive : true , force : true } ) ;
172174} ) ;
175+
176+ test . each ( [ 'cwd' , 'tenant' ] as const ) (
177+ 'repair markers use the resolved %s address for expiry and commit failure' ,
178+ async ( scope ) => {
179+ for ( const failedCommit of [ false , true ] ) {
180+ const { sessionStore, handler } = makeHandler ( `router-repair-${ scope } -` ) ;
181+ const req = closeRequest ( 'default' ) ;
182+ req . meta =
183+ scope === 'cwd'
184+ ? { cwd : mkdtempForTestSync ( 'repair-workspace-' ) }
185+ : { tenantId : 'tenant-a' , sessionIsolation : 'tenant' } ;
186+ const address = resolveEffectiveSessionName ( scopeRequestSession ( req ) , sessionStore , {
187+ attachesToSession : false ,
188+ } ) ;
189+ expect ( address ) . not . toBe ( 'default' ) ;
190+ const ref = sessionStore . publish ( address , tombstonedSession ( 'default' ) ) ;
191+ sessionStore . writeRepairTombstone (
192+ ref ,
193+ undefined ,
194+ failedCommit ? { code : 'EACCES' , message : 'script publication denied' } : undefined ,
195+ ) ;
196+ sessionStore . retire ( ref ) ;
197+ const response = await handler ( req ) ;
198+ expect ( response ) . toMatchObject ( {
199+ ok : false ,
200+ error : { code : failedCommit ? 'REPAIR_COMMIT_FAILED' : 'REPAIR_SESSION_EXPIRED' } ,
201+ } ) ;
202+ if ( ! response . ok && failedCommit )
203+ expect ( response . error . message ) . toContain ( 'script publication denied' ) ;
204+ }
205+ } ,
206+ ) ;
207+
208+ test ( 'a raw default repair marker cannot explain a different workspace session' , async ( ) => {
209+ const { sessionStore, handler } = makeHandler ( 'router-repair-workspace-isolation-' ) ;
210+ const ref = sessionStore . publish ( 'default' , tombstonedSession ( 'default' ) ) ;
211+ sessionStore . writeRepairTombstone ( ref ) ;
212+ sessionStore . retire ( ref ) ;
213+ const req = closeRequest ( 'default' ) ;
214+ req . meta = { cwd : mkdtempForTestSync ( 'different-repair-workspace-' ) } ;
215+ expect ( await handler ( req ) ) . toMatchObject ( { ok : false , error : { code : 'SESSION_NOT_FOUND' } } ) ;
216+ } ) ;
0 commit comments