@@ -8,6 +8,7 @@ const { readPreparedConnection, entities, settingsHydration } = vi.hoisted(() =>
88 entities : {
99 projects : [ ] as Array < Record < string , unknown > > ,
1010 shellProjectId : null as string | null ,
11+ shellArrived : new Promise < boolean > ( ( ) => { } ) ,
1112 } ,
1213 settingsHydration : {
1314 hydrated : true ,
@@ -26,6 +27,8 @@ vi.mock("~/state/entities", () => ({
2627 readProjects : ( ) => entities . projects ,
2728 useProjects : ( ) => entities . projects ,
2829 useQuietThreadShell : ( ) => null ,
30+ waitForThreadShell : ( ) => entities . shellArrived ,
31+ waitForProject : ( ) => new Promise ( ( ) => { } ) ,
2932} ) ) ;
3033vi . mock ( "./hooks/useSettings" , async ( ) => {
3134 const { DEFAULT_CLIENT_SETTINGS } = await import ( "@t3tools/contracts/settings" ) ;
@@ -63,6 +66,7 @@ beforeEach(() => {
6366 readPreparedConnection . mockReturnValue ( null ) ;
6467 entities . projects = [ ] ;
6568 entities . shellProjectId = null ;
69+ entities . shellArrived = new Promise < boolean > ( ( ) => { } ) ;
6670 settingsHydration . hydrated = true ;
6771 settingsHydration . promise = Promise . resolve ( ) ;
6872 useComposerDraftStore . setState ( { draftThreadsByThreadKey : { } } ) ;
@@ -299,6 +303,25 @@ describe("thread project resolution", () => {
299303 useBrowserHistoryStore . getState ( ) . byProjectKey [ "env-1:/repo" ] ?. map ( ( entry ) => entry . url ) ,
300304 ) . toEqual ( [ "http://b.test/" , "http://a.test/" ] ) ;
301305 } ) ;
306+
307+ it ( "lands a visit queued before the thread loaded once the thread arrives" , async ( ) => {
308+ let shellArrives = ( _found : boolean ) => { } ;
309+ entities . shellArrived = new Promise < boolean > ( ( resolve ) => {
310+ shellArrives = resolve ;
311+ } ) ;
312+ recordVisitForThread ( threadRef , "http://a.test/" , 1 ) ;
313+ expect ( useBrowserHistoryStore . getState ( ) . byProjectKey ) . toEqual ( { } ) ;
314+
315+ entities . projects = [ repoProject ] ;
316+ entities . shellProjectId = "project-1" ;
317+ shellArrives ( true ) ;
318+ await entities . shellArrived ;
319+
320+ expect ( useBrowserHistoryStore . getState ( ) . byProjectKey ) . toEqual ( {
321+ "env-1:/repo" : [ { url : "http://a.test/" , lastVisitedAt : 1 } ] ,
322+ } ) ;
323+ expect ( useBrowserHistoryStore . getState ( ) . pendingVisitsByThreadKey ) . toEqual ( { } ) ;
324+ } ) ;
302325} ) ;
303326
304327describe ( "pendingVisitsByThreadKey" , ( ) => {
0 commit comments