@@ -35,6 +35,15 @@ function openRequest(flags: CommandFlags): DaemonRequest {
3535 } ;
3636}
3737
38+ function beginWait (
39+ params : Omit < Parameters < typeof beginOpenDeviceWait > [ 0 ] , 'budgetMs' > ,
40+ ) : ReturnType < typeof beginOpenDeviceWait > {
41+ return beginOpenDeviceWait ( {
42+ ...params ,
43+ budgetMs : readOpenWaitBudgetMs ( params . req ) ,
44+ } ) ;
45+ }
46+
3847function session ( address : string ) : SessionState {
3948 return {
4049 name : 'default' ,
@@ -102,23 +111,17 @@ test('the daemon holds a budget to the bounds its own option declares', () => {
102111 code : 'INVALID_ARGS' ,
103112 } ) ;
104113 }
105-
106- // A budget that cannot be spent is refused before the device it was meant for is even in play.
107- expect (
108- thrownBy ( ( ) =>
109- beginOpenDeviceWait ( {
110- req : openRequest ( { waitMs : ( max ?? 0 ) + 1 } ) ,
111- sessionName : OPENER_ADDRESS ,
112- sessionStore : new SessionStore ( '/tmp/ad-wait-unresolved' ) ,
113- deviceId : undefined ,
114- } ) ,
115- ) ,
116- ) . toMatchObject ( { code : 'INVALID_ARGS' } ) ;
117114} ) ;
118115
119116test ( 'a refusal offers the flag only to a caller that did not arrive carrying it' , ( ) => {
120117 expect ( describeOpenWaitForRefusal ( openRequest ( { } ) ) ) . toEqual ( { offersDeviceWait : true } ) ;
121118
119+ // An interaction has no `--wait` of its own, even though the shared refusal builder may one day
120+ // receive its request.
121+ expect ( describeOpenWaitForRefusal ( { ...openRequest ( { } ) , command : 'tap' } ) ) . toEqual ( {
122+ offersDeviceWait : false ,
123+ } ) ;
124+
122125 // The open that passed `--wait` and still hit a busy device is not being sent off to run the
123126 // same open with the flag it used.
124127 const carried = openRequest ( { waitMs : 1_000 } ) ;
@@ -133,23 +136,23 @@ test('only a fresh open with a budget and a resolved device gets a wait', () =>
133136 const budget = openRequest ( { waitMs : 5_000 } ) ;
134137
135138 expect (
136- beginOpenDeviceWait ( {
139+ beginWait ( {
137140 req : { ...budget , command : 'tap' } ,
138141 sessionName : OPENER_ADDRESS ,
139142 sessionStore,
140143 deviceId : IOS_SIMULATOR . id ,
141144 } ) ,
142145 ) . toBeUndefined ( ) ;
143146 expect (
144- beginOpenDeviceWait ( {
147+ beginWait ( {
145148 req : budget ,
146149 sessionName : OPENER_ADDRESS ,
147150 sessionStore,
148151 deviceId : undefined ,
149152 } ) ,
150153 ) . toBeUndefined ( ) ;
151154 expect (
152- beginOpenDeviceWait ( {
155+ beginWait ( {
153156 req : openRequest ( { } ) ,
154157 sessionName : OPENER_ADDRESS ,
155158 sessionStore,
@@ -160,7 +163,7 @@ test('only a fresh open with a budget and a resolved device gets a wait', () =>
160163 // An open onto a session that already exists is bound to a device nobody else is refused for.
161164 sessionStore . set ( OPENER_ADDRESS , session ( OPENER_ADDRESS ) ) ;
162165 expect (
163- beginOpenDeviceWait ( {
166+ beginWait ( {
164167 req : budget ,
165168 sessionName : OPENER_ADDRESS ,
166169 sessionStore,
@@ -174,7 +177,7 @@ test('a free device is read once in the store and records no wait', async () =>
174177 const store = makeSessionStore ( 'agent-device-open-wait-' ) ;
175178 const looks = vi . spyOn ( store , 'findByDevice' ) ;
176179
177- const wait = beginOpenDeviceWait ( {
180+ const wait = beginWait ( {
178181 req,
179182 sessionName : OPENER_ADDRESS ,
180183 sessionStore : store ,
@@ -194,7 +197,7 @@ test('a device that frees up ends the wait without claiming a spent budget', asy
194197
195198 await waitUntil (
196199 ( ) =>
197- beginOpenDeviceWait ( {
200+ beginWait ( {
198201 req,
199202 sessionName : OPENER_ADDRESS ,
200203 sessionStore : store ,
@@ -212,7 +215,7 @@ test('an open yields the device lock to a session that took the device after the
212215 vi . useFakeTimers ( ) ;
213216 const req = openRequest ( { waitMs : 30_000 } ) ;
214217 const store = makeSessionStore ( 'agent-device-open-wait-' ) ;
215- const wait = beginOpenDeviceWait ( {
218+ const wait = beginWait ( {
216219 req,
217220 sessionName : OPENER_ADDRESS ,
218221 sessionStore : store ,
@@ -253,7 +256,7 @@ test('a budget that runs out busy costs the whole budget, then lets the open ref
253256 const req = openRequest ( { waitMs : 1000 } ) ;
254257 const store = storeWithHolder ( ) ;
255258 const looks = vi . spyOn ( store , 'findByDevice' ) ;
256- const wait = beginOpenDeviceWait ( {
259+ const wait = beginWait ( {
257260 req,
258261 sessionName : OPENER_ADDRESS ,
259262 sessionStore : store ,
@@ -289,7 +292,7 @@ test('a request the client gave up on stops waiting at its next poll', async ()
289292 vi . useFakeTimers ( ) ;
290293 const req = openRequest ( { waitMs : 60_000 } ) ;
291294 markRequestCanceled ( 'req-open-wait' ) ;
292- const wait = beginOpenDeviceWait ( {
295+ const wait = beginWait ( {
293296 req,
294297 sessionName : OPENER_ADDRESS ,
295298 sessionStore : storeWithHolder ( ) ,
0 commit comments