@@ -129,8 +129,9 @@ describe.each(["all", "selected"] as const)("created initial target in %s mode",
129129 expect ( harness . tabsRemove ) . not . toHaveBeenCalled ( ) ;
130130 } ) ;
131131
132- it ( "composes the real relay and background policy for blank-first CDP creation" , async ( ) => {
132+ it ( "keeps a blank-first CDP target alive when earlier discovery resolves after creation" , async ( ) => {
133133 const harness = await createHarness ( mode ) ;
134+ harness . tabGroupsQuery . mockResolvedValue ( [ { id : 7 , windowId : 1 } ] ) ;
134135 const bridge = new ExtensionRelayBridge ( ) ;
135136 const extension = bridge . attachExtensionSocket ( {
136137 send : ( raw ) => harness . socket . receive ( JSON . parse ( raw ) ) ,
@@ -157,12 +158,28 @@ describe.each(["all", "selected"] as const)("created initial target in %s mode",
157158 } ;
158159 try {
159160 await request ( "Target.setAutoAttach" , { autoAttach : true , flatten : true } ) ;
161+ const staleTabs = await harness . tabsQuery ( ) ;
162+ const inventory = deferred ( staleTabs ) ;
163+ let inspecting = false ;
164+ harness . tabsQuery . mockImplementationOnce ( async ( ) => {
165+ inspecting = true ;
166+ return await inventory . promise ;
167+ } ) ;
168+ harness . updateTab ( 100 , { url : "about:blank" } ) ;
169+ await vi . waitFor ( ( ) => expect ( inspecting ) . toBe ( true ) ) ;
160170 expect ( await request ( "Target.createTarget" , { url : "about:blank" } ) ) . toEqual ( {
161171 targetId : "tab-101" ,
162172 } ) ;
163173 const attached = frames . find ( ( frame ) => frame . method === "Target.attachedToTarget" )
164174 ?. params as { sessionId : string } ;
165175 expect ( attached . sessionId ) . toBeTruthy ( ) ;
176+ const inventoryCount = harness . frames ( ) . filter ( ( frame ) => frame . type === "tabs" ) . length ;
177+ inventory . resolve ( ) ;
178+ await vi . waitFor ( ( ) =>
179+ expect ( harness . frames ( ) . filter ( ( frame ) => frame . type === "tabs" ) . length ) . toBeGreaterThan (
180+ inventoryCount ,
181+ ) ,
182+ ) ;
166183 await request ( "Page.enable" , { } , attached . sessionId ) ;
167184 harness . debuggerSendCommand . mockImplementationOnce ( async ( ) => {
168185 harness . updateTab ( 101 , { url : "https://example.com/" } ) ;
0 commit comments