@@ -217,15 +217,39 @@ test('a cancelled caller leaves discovery running for the next capture', async (
217217 await withAppleToolProvider ( fixture . provider , async ( ) => {
218218 const controller = new AbortController ( ) ;
219219 const cancelled = fixture . resolve ( ios , app , controller . signal ) ;
220- controller . abort ( new Error ( 'request-ended' ) ) ;
221- await expect ( cancelled ) . rejects . toThrow ( 'request-ended' ) ;
220+ const reason = new Error ( 'request-ended' ) ;
221+ controller . abort ( reason ) ;
222+ // The caller spent its time waiting on discovery, so its cancellation names that readiness
223+ // work (#2343) and keeps the caller's own reason as the cause.
224+ await expect ( cancelled ) . rejects . toMatchObject ( {
225+ details : { reason : 'request_canceled' , readinessPhase : 'target-discovery' } ,
226+ cause : reason ,
227+ } ) ;
222228
223229 release ( ) ;
224230 expect ( await fixture . resolve ( ios , app , signal ( ) ) ) . toMatchObject ( { pid : 42 } ) ;
225231 expect ( fixture . discoveryCount ( ) ) . toBe ( 1 ) ;
226232 } ) ;
227233} ) ;
228234
235+ test ( 'a cancelled re-check of a known target keeps it and names no readiness work' , async ( ) => {
236+ const fixture = targetFixture ( ) ;
237+ await withAppleToolProvider ( fixture . provider , async ( ) => {
238+ await fixture . resolve ( ios , app , signal ( ) ) ;
239+ const controller = new AbortController ( ) ;
240+ const reason = new Error ( 'wait-deadline' ) ;
241+ fixture . runCommand . mockImplementationOnce ( async ( ) => {
242+ controller . abort ( reason ) ;
243+ return { stdout : '' , stderr : '' , exitCode : 1 } ;
244+ } ) ;
245+
246+ await expect ( fixture . resolve ( ios , app , controller . signal ) ) . rejects . toBe ( reason ) ;
247+
248+ expect ( await fixture . resolve ( ios , app , signal ( ) ) ) . toMatchObject ( { pid : 42 } ) ;
249+ expect ( fixture . discoveryCount ( ) ) . toBe ( 1 ) ;
250+ } ) ;
251+ } ) ;
252+
229253test ( 'one discovery shares a single deadline across its simctl probes and the identity read' , async ( ) => {
230254 const fixture = targetFixture ( ) ;
231255 const release = deferredSpawn ( fixture ) ;
0 commit comments