@@ -44,9 +44,12 @@ const destructiveRequest = (subject: string): PermissionRequest => ({
4444 scopes : [ ] ,
4545} ) ;
4646
47- /** Accept the highlighted choice after moving to `index` (0 Reject, 1 Accept once). */
48- function acceptChoice ( shell : AppShell , index : 0 | 1 | 2 ) : void {
49- for ( let i = 0 ; i < index ; i ++ ) moveOverlaySelection ( shell , 1 ) ;
47+ /** Move the highlight to the row labelled `label`, then accept it. */
48+ function acceptChoice ( shell : AppShell , label : string ) : void {
49+ const target = shell . overlayItems . indexOf ( label ) ;
50+ if ( target < 0 ) throw new Error ( `no overlay row labelled ${ label } ` ) ;
51+ const list = defined ( shell . overlayList , "overlayList" ) ;
52+ moveOverlaySelection ( shell , target - list . activeIndex ) ;
5053 acceptOverlaySelection ( shell ) ;
5154}
5255
@@ -138,7 +141,7 @@ describe("CL-8792 gate level: a second destructive evaluation re-prompts after a
138141 const first = gate . evaluate ( shellCall ( command ) ) ;
139142 await flushGateRaise ( ) ;
140143 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
141- acceptChoice ( shell , 1 ) ;
144+ acceptChoice ( shell , "Accept once" ) ;
142145 const firstVerdict = await settledWithin ( first , 500 ) ;
143146 expect ( firstVerdict . settled ) . toBe ( true ) ;
144147 if ( ! firstVerdict . settled ) throw new Error ( "first evaluation hung" ) ;
@@ -148,7 +151,7 @@ describe("CL-8792 gate level: a second destructive evaluation re-prompts after a
148151 await flushGateRaise ( ) ;
149152 // A grant would auto-allow with no overlay; allow-once must re-prompt.
150153 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
151- acceptChoice ( shell , 1 ) ;
154+ acceptChoice ( shell , "Accept once" ) ;
152155 const verdict = await settledWithin ( second , 500 ) ;
153156 expect ( verdict . settled ) . toBe ( true ) ;
154157 if ( ! verdict . settled ) throw new Error ( "second evaluation hung" ) ;
@@ -173,12 +176,12 @@ describe("CL-8792 gate level: a second destructive evaluation re-prompts after a
173176
174177 // Accept once on the first card: the queued card must take the host
175178 // before the deferred slash, and both evaluations must settle.
176- acceptChoice ( shell , 1 ) ;
179+ acceptChoice ( shell , "Accept once" ) ;
177180 const firstVerdict = await settledWithin ( first , 500 ) ;
178181 expect ( firstVerdict . settled ) . toBe ( true ) ;
179182
180183 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
181- acceptChoice ( shell , 1 ) ;
184+ acceptChoice ( shell , "Accept once" ) ;
182185 const secondVerdict = await settledWithin ( second , 500 ) ;
183186 expect ( secondVerdict . settled ) . toBe ( true ) ;
184187 if ( ! secondVerdict . settled ) throw new Error ( "second evaluation hung" ) ;
@@ -211,12 +214,12 @@ describe("CL-8792 overlay host: queued cards outrank deferred surfaces", () => {
211214 } ,
212215 } ) ;
213216
214- acceptChoice ( shell , 1 ) ;
217+ acceptChoice ( shell , "Accept once" ) ;
215218 expect ( resolvedA ) . toEqual ( { allow : true } ) ;
216219 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
217220 expect ( shell . overlayItems ) . toContain ( "Accept once" ) ;
218221
219- acceptChoice ( shell , 1 ) ;
222+ acceptChoice ( shell , "Accept once" ) ;
220223 expect ( resolvedB ) . toEqual ( { allow : true } ) ;
221224
222225 // With every gate settled, the deferred slash finally takes the host.
@@ -246,11 +249,11 @@ describe("CL-8792 overlay host: queued cards outrank deferred surfaces", () => {
246249 } ,
247250 } ) ;
248251
249- acceptChoice ( shell , 0 ) ;
252+ acceptChoice ( shell , "Reject" ) ;
250253 expect ( resolvedA ) . toEqual ( { allow : false } ) ;
251254 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
252255
253- acceptChoice ( shell , 1 ) ;
256+ acceptChoice ( shell , "Accept once" ) ;
254257 expect ( resolvedB ) . toEqual ( { allow : true } ) ;
255258 } ) ;
256259 } ) ;
@@ -286,14 +289,14 @@ describe("CL-8792 overlay host: queued cards outrank deferred surfaces", () => {
286289 } ,
287290 } ) ;
288291
289- acceptChoice ( shell , 2 ) ;
292+ acceptChoice ( shell , "Allow rm *" ) ;
290293 expect ( resolvedA ) . toMatchObject ( {
291294 allow : true ,
292295 persist : { id : "scope-a" } ,
293296 } ) ;
294297 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
295298
296- acceptChoice ( shell , 1 ) ;
299+ acceptChoice ( shell , "Accept once" ) ;
297300 expect ( resolvedB ) . toEqual ( { allow : true } ) ;
298301 } ) ;
299302 } ) ;
@@ -313,7 +316,7 @@ describe("CL-8792 overlay host: queued cards outrank deferred surfaces", () => {
313316 } ) ;
314317 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
315318
316- acceptChoice ( shell , 1 ) ;
319+ acceptChoice ( shell , "Accept once" ) ;
317320 expect ( resolved ) . toEqual ( { allow : true } ) ;
318321 expect ( shell . overlayKind ) . toBe ( "help" ) ;
319322 expect ( shell . overlayItems ) . toEqual ( [ "Help" ] ) ;
@@ -350,7 +353,7 @@ describe("CL-8792 overlay host: queued cards outrank deferred surfaces", () => {
350353 await new Promise ( ( resolve ) => setTimeout ( resolve , 80 ) ) ;
351354 expect ( resolvedB ) . toBeUndefined ( ) ;
352355
353- acceptChoice ( shell , 1 ) ;
356+ acceptChoice ( shell , "Accept once" ) ;
354357 expect ( resolvedA ) . toEqual ( { allow : true } ) ;
355358 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
356359
@@ -428,7 +431,7 @@ describe("CL-8792 elapsed: pending tool row freezes while a gate is outstanding
428431 await h . renderOnce ( ) ;
429432 expect ( stat ( ) ) . toBe ( "0:10" ) ;
430433
431- acceptChoice ( shell , 1 ) ;
434+ acceptChoice ( shell , "Accept once" ) ;
432435 expect ( resolved ) . toEqual ( { allow : true } ) ;
433436 bridge . gateClosed ( ) ;
434437 } finally {
@@ -466,7 +469,7 @@ describe("CL-8792 overlay host: suspend preserves the surface instead of dismiss
466469 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
467470 expect ( events ) . toEqual ( [ ] ) ;
468471
469- acceptChoice ( shell , 1 ) ;
472+ acceptChoice ( shell , "Accept once" ) ;
470473 expect ( resolved ) . toEqual ( { allow : true } ) ;
471474 expect ( shell . overlayKind ) . toBe ( "help" ) ;
472475 expect ( events ) . toEqual ( [ ] ) ;
@@ -493,7 +496,7 @@ describe("CL-8792 overlay host: suspend preserves the surface instead of dismiss
493496 } ) ;
494497 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
495498
496- acceptChoice ( shell , 1 ) ;
499+ acceptChoice ( shell , "Accept once" ) ;
497500 expect ( resolved ) . toEqual ( { allow : true } ) ;
498501 expect ( shell . overlayKind ) . toBe ( "help" ) ;
499502 expect ( shell . overlayList ) . toBe ( list ) ;
@@ -538,7 +541,7 @@ describe("CL-8792 overlay host: suspend preserves the surface instead of dismiss
538541 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
539542 expect ( shell . overlayItems ) . toContain ( "Accept once" ) ;
540543
541- acceptChoice ( shell , 1 ) ;
544+ acceptChoice ( shell , "Accept once" ) ;
542545 expect ( resolved ) . toEqual ( { allow : true } ) ;
543546 expect ( cancelOpens ) . toBe ( 0 ) ;
544547 expect ( shell . overlayKind ) . toBe ( "mcp" ) ;
0 commit comments