@@ -6,9 +6,11 @@ import { describe, expect, test } from "bun:test";
66import { withTestRenderer } from "./harness" ;
77import {
88 chromeComposeCount ,
9+ clearWorkerWait ,
910 paintChrome ,
1011 setLockupFrame ,
1112 setStatusFlash ,
13+ setWorkerWaitAsks ,
1214} from "./shell/chrome" ;
1315import { createAppShell } from "./shell/index" ;
1416import type { AppShell } from "./shell/internals" ;
@@ -112,4 +114,43 @@ describe("chrome repaint gate", () => {
112114 expect ( chromeComposeCount ( shell ) ) . toBe ( baseline + 2 ) ;
113115 } ) ;
114116 } ) ;
117+
118+ test ( "worker wait snapshots recompose on change and never on a repeat" , async ( ) => {
119+ await withShell ( ( shell ) => {
120+ const ask = {
121+ sessionId : "sess-1" ,
122+ agentId : "builder" ,
123+ description : "copy assets" ,
124+ question : "Which destination path should I use?" ,
125+ questionId : "q1" ,
126+ } ;
127+ paintChrome ( shell ) ;
128+ const baseline = chromeComposeCount ( shell ) ;
129+
130+ setWorkerWaitAsks ( shell , [ ask ] ) ;
131+ const shown = chromeComposeCount ( shell ) ;
132+ expect ( shown ) . toBeGreaterThan ( baseline ) ;
133+ expect ( shell . workerWaitRow . visible ) . toBe ( true ) ;
134+
135+ // Repeat reports of the same identity and idle ticks cost nothing.
136+ setWorkerWaitAsks ( shell , [ ask ] ) ;
137+ setWorkerWaitAsks ( shell , [ { ...ask } ] ) ;
138+ for ( let tick = 0 ; tick < 5 ; tick ++ ) paintChrome ( shell ) ;
139+ expect ( chromeComposeCount ( shell ) ) . toBe ( shown ) ;
140+
141+ // A replacement question changes the composed strip: one recompose.
142+ setWorkerWaitAsks ( shell , [
143+ { ...ask , questionId : "q2" , question : "Overwrite?" } ,
144+ ] ) ;
145+ expect ( chromeComposeCount ( shell ) ) . toBe ( shown + 1 ) ;
146+
147+ // The final removal recomposes and hands the row back.
148+ setWorkerWaitAsks ( shell , [ ] ) ;
149+ expect ( chromeComposeCount ( shell ) ) . toBeGreaterThan ( shown + 1 ) ;
150+ expect ( shell . workerWaitRow . visible ) . toBe ( false ) ;
151+ const cleared = chromeComposeCount ( shell ) ;
152+ clearWorkerWait ( shell ) ;
153+ expect ( chromeComposeCount ( shell ) ) . toBe ( cleared ) ;
154+ } ) ;
155+ } ) ;
115156} ) ;
0 commit comments