@@ -56,9 +56,12 @@ const destructiveRequest = (subject: string): PermissionRequest => ({
5656 scopes : [ ] ,
5757} ) ;
5858
59- /** Accept the highlighted choice after moving to `index` (0 Reject, 1 Accept once). */
60- function acceptChoice ( shell : AppShell , index : 0 | 1 | 2 ) : void {
61- for ( let i = 0 ; i < index ; i ++ ) moveOverlaySelection ( shell , 1 ) ;
59+ /** Move the highlight to the row labelled `label`, then accept it. */
60+ function acceptChoice ( shell : AppShell , label : string ) : void {
61+ const target = shell . overlayItems . indexOf ( label ) ;
62+ if ( target < 0 ) throw new Error ( `no overlay row labelled ${ label } ` ) ;
63+ const list = defined ( shell . overlayList , "overlayList" ) ;
64+ moveOverlaySelection ( shell , target - list . activeIndex ) ;
6265 acceptOverlaySelection ( shell ) ;
6366}
6467
@@ -151,7 +154,7 @@ describe("CL-8792 gate level: a second destructive evaluation re-prompts after a
151154 const first = gate . evaluate ( shellCall ( command ) ) ;
152155 await flushGateRaise ( ) ;
153156 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
154- acceptChoice ( shell , 1 ) ;
157+ acceptChoice ( shell , "Accept once" ) ;
155158 const firstVerdict = await settledWithin ( first , 500 ) ;
156159 expect ( firstVerdict . settled ) . toBe ( true ) ;
157160 if ( ! firstVerdict . settled ) throw new Error ( "first evaluation hung" ) ;
@@ -161,7 +164,7 @@ describe("CL-8792 gate level: a second destructive evaluation re-prompts after a
161164 await flushGateRaise ( ) ;
162165 // A grant would auto-allow with no overlay; allow-once must re-prompt.
163166 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
164- acceptChoice ( shell , 1 ) ;
167+ acceptChoice ( shell , "Accept once" ) ;
165168 const verdict = await settledWithin ( second , 500 ) ;
166169 expect ( verdict . settled ) . toBe ( true ) ;
167170 if ( ! verdict . settled ) throw new Error ( "second evaluation hung" ) ;
@@ -186,12 +189,12 @@ describe("CL-8792 gate level: a second destructive evaluation re-prompts after a
186189
187190 // Accept once on the first card: the queued card must take the host
188191 // before the deferred slash, and both evaluations must settle.
189- acceptChoice ( shell , 1 ) ;
192+ acceptChoice ( shell , "Accept once" ) ;
190193 const firstVerdict = await settledWithin ( first , 500 ) ;
191194 expect ( firstVerdict . settled ) . toBe ( true ) ;
192195
193196 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
194- acceptChoice ( shell , 1 ) ;
197+ acceptChoice ( shell , "Accept once" ) ;
195198 const secondVerdict = await settledWithin ( second , 500 ) ;
196199 expect ( secondVerdict . settled ) . toBe ( true ) ;
197200 if ( ! secondVerdict . settled ) throw new Error ( "second evaluation hung" ) ;
@@ -224,12 +227,12 @@ describe("CL-8792 overlay host: queued cards outrank deferred surfaces", () => {
224227 } ,
225228 } ) ;
226229
227- acceptChoice ( shell , 1 ) ;
230+ acceptChoice ( shell , "Accept once" ) ;
228231 expect ( resolvedA ) . toEqual ( { allow : true } ) ;
229232 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
230233 expect ( shell . overlayItems ) . toContain ( "Accept once" ) ;
231234
232- acceptChoice ( shell , 1 ) ;
235+ acceptChoice ( shell , "Accept once" ) ;
233236 expect ( resolvedB ) . toEqual ( { allow : true } ) ;
234237
235238 // With every gate settled, the deferred slash finally takes the host.
@@ -259,11 +262,11 @@ describe("CL-8792 overlay host: queued cards outrank deferred surfaces", () => {
259262 } ,
260263 } ) ;
261264
262- acceptChoice ( shell , 0 ) ;
265+ acceptChoice ( shell , "Reject" ) ;
263266 expect ( resolvedA ) . toEqual ( { allow : false } ) ;
264267 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
265268
266- acceptChoice ( shell , 1 ) ;
269+ acceptChoice ( shell , "Accept once" ) ;
267270 expect ( resolvedB ) . toEqual ( { allow : true } ) ;
268271 } ) ;
269272 } ) ;
@@ -299,14 +302,14 @@ describe("CL-8792 overlay host: queued cards outrank deferred surfaces", () => {
299302 } ,
300303 } ) ;
301304
302- acceptChoice ( shell , 2 ) ;
305+ acceptChoice ( shell , "Allow rm *" ) ;
303306 expect ( resolvedA ) . toMatchObject ( {
304307 allow : true ,
305308 persist : { id : "scope-a" } ,
306309 } ) ;
307310 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
308311
309- acceptChoice ( shell , 1 ) ;
312+ acceptChoice ( shell , "Accept once" ) ;
310313 expect ( resolvedB ) . toEqual ( { allow : true } ) ;
311314 } ) ;
312315 } ) ;
@@ -326,7 +329,7 @@ describe("CL-8792 overlay host: queued cards outrank deferred surfaces", () => {
326329 } ) ;
327330 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
328331
329- acceptChoice ( shell , 1 ) ;
332+ acceptChoice ( shell , "Accept once" ) ;
330333 expect ( resolved ) . toEqual ( { allow : true } ) ;
331334 expect ( shell . overlayKind ) . toBe ( "help" ) ;
332335 expect ( shell . overlayItems ) . toEqual ( [ "Help" ] ) ;
@@ -363,7 +366,7 @@ describe("CL-8792 overlay host: queued cards outrank deferred surfaces", () => {
363366 await new Promise ( ( resolve ) => setTimeout ( resolve , 80 ) ) ;
364367 expect ( resolvedB ) . toBeUndefined ( ) ;
365368
366- acceptChoice ( shell , 1 ) ;
369+ acceptChoice ( shell , "Accept once" ) ;
367370 expect ( resolvedA ) . toEqual ( { allow : true } ) ;
368371 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
369372
@@ -441,7 +444,7 @@ describe("CL-8792 elapsed: pending tool row freezes while a gate is outstanding
441444 await h . renderOnce ( ) ;
442445 expect ( stat ( ) ) . toBe ( "0:10" ) ;
443446
444- acceptChoice ( shell , 1 ) ;
447+ acceptChoice ( shell , "Accept once" ) ;
445448 expect ( resolved ) . toEqual ( { allow : true } ) ;
446449 bridge . gateClosed ( ) ;
447450 } finally {
@@ -479,7 +482,7 @@ describe("CL-8792 overlay host: suspend preserves the surface instead of dismiss
479482 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
480483 expect ( events ) . toEqual ( [ ] ) ;
481484
482- acceptChoice ( shell , 1 ) ;
485+ acceptChoice ( shell , "Accept once" ) ;
483486 expect ( resolved ) . toEqual ( { allow : true } ) ;
484487 expect ( shell . overlayKind ) . toBe ( "help" ) ;
485488 expect ( events ) . toEqual ( [ ] ) ;
@@ -506,7 +509,7 @@ describe("CL-8792 overlay host: suspend preserves the surface instead of dismiss
506509 } ) ;
507510 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
508511
509- acceptChoice ( shell , 1 ) ;
512+ acceptChoice ( shell , "Accept once" ) ;
510513 expect ( resolved ) . toEqual ( { allow : true } ) ;
511514 expect ( shell . overlayKind ) . toBe ( "help" ) ;
512515 expect ( shell . overlayList ) . toBe ( list ) ;
@@ -551,7 +554,7 @@ describe("CL-8792 overlay host: suspend preserves the surface instead of dismiss
551554 expect ( shell . overlayKind ) . toBe ( "permissions" ) ;
552555 expect ( shell . overlayItems ) . toContain ( "Accept once" ) ;
553556
554- acceptChoice ( shell , 1 ) ;
557+ acceptChoice ( shell , "Accept once" ) ;
555558 expect ( resolved ) . toEqual ( { allow : true } ) ;
556559 expect ( cancelOpens ) . toBe ( 0 ) ;
557560 expect ( shell . overlayKind ) . toBe ( "mcp" ) ;
0 commit comments