@@ -240,6 +240,62 @@ test.skipIf(process.platform === 'win32')(
240240) ;
241241
242242describe ( 'managed local runtime owner' , ( ) => {
243+ test ( 'dispatches the real operation inside admission before authority can be fenced' , async ( ) => {
244+ const events : string [ ] = [ ] ;
245+ const cancellation = new AbortController ( ) ;
246+ let cancelOnAdmission = false ;
247+ const family = localFamilyRuntimeFixture ( { family : 'apple' , device } ) ;
248+ const local = await family . module . loadRuntime ( { } as PlatformRuntimeHost ) ;
249+ const owner = createManagedLocalRuntimeOwner ( {
250+ owner : managed ,
251+ loadLocal : async ( ) => ( {
252+ ...local ,
253+ bind : async ( request ) => {
254+ const binding = await local . bind ( request ) ;
255+ return {
256+ ...binding ,
257+ operations : {
258+ ...binding . operations ,
259+ readClipboard : async ( ) => {
260+ events . push ( 'native' ) ;
261+ expect ( events . at ( - 2 ) ) . toBe ( 'admitted' ) ;
262+ return 'clipboard' ;
263+ } ,
264+ } ,
265+ } ;
266+ } ,
267+ } ) ,
268+ } ) ;
269+ const binding = await owner . bind ( {
270+ device,
271+ intent : exactly ( ) ,
272+ scope : {
273+ ...scope ,
274+ signal : cancellation . signal ,
275+ managedDevice : {
276+ ...scope . managedDevice ! ,
277+ admit : async ( task ) => {
278+ events . push ( 'admitted' ) ;
279+ if ( cancelOnAdmission ) cancellation . abort ( new Error ( 'cancelled during admission' ) ) ;
280+ try {
281+ return await task ( ) ;
282+ } finally {
283+ events . push ( 'fenced' ) ;
284+ }
285+ } ,
286+ } ,
287+ } ,
288+ } ) ;
289+ expect ( await binding . operations . readClipboard ! ( { } ) ) . toBe ( 'clipboard' ) ;
290+ cancelOnAdmission = true ;
291+ await expect ( binding . operations . readClipboard ! ( { } ) ) . rejects . toThrow (
292+ 'cancelled during admission' ,
293+ ) ;
294+ await binding [ Symbol . asyncDispose ] ( ) ;
295+ expect ( events ) . toEqual ( [ 'admitted' , 'native' , 'fenced' , 'admitted' , 'fenced' ] ) ;
296+ expect ( family . calls . disposals ) . toBe ( 1 ) ;
297+ } ) ;
298+
243299 test ( 'exposes only reviewed operations even when the local family offers every cell' , async ( ) => {
244300 const { owner } = managedOwnerFixture ( ) ;
245301
0 commit comments