@@ -8,7 +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 > ( ( ) => { } ) ,
11+ waitForThreadShell : ( ) : Promise < boolean > => new Promise ( ( ) => { } ) ,
1212 } ,
1313 settingsHydration : {
1414 hydrated : true ,
@@ -27,7 +27,7 @@ vi.mock("~/state/entities", () => ({
2727 readProjects : ( ) => entities . projects ,
2828 useProjects : ( ) => entities . projects ,
2929 useQuietThreadShell : ( ) => null ,
30- waitForThreadShell : ( ) => entities . shellArrived ,
30+ waitForThreadShell : ( ) => entities . waitForThreadShell ( ) ,
3131 waitForProject : ( ) => new Promise ( ( ) => { } ) ,
3232} ) ) ;
3333vi . mock ( "./hooks/useSettings" , async ( ) => {
@@ -66,7 +66,7 @@ beforeEach(() => {
6666 readPreparedConnection . mockReturnValue ( null ) ;
6767 entities . projects = [ ] ;
6868 entities . shellProjectId = null ;
69- entities . shellArrived = new Promise < boolean > ( ( ) => { } ) ;
69+ entities . waitForThreadShell = ( ) => new Promise ( ( ) => { } ) ;
7070 settingsHydration . hydrated = true ;
7171 settingsHydration . promise = Promise . resolve ( ) ;
7272 useComposerDraftStore . setState ( { draftThreadsByThreadKey : { } } ) ;
@@ -304,22 +304,38 @@ describe("thread project resolution", () => {
304304 ) . toEqual ( [ "http://b.test/" , "http://a.test/" ] ) ;
305305 } ) ;
306306
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 ;
307+ it ( "lands visits queued before the thread loaded when the thread arrives after a timed-out wait" , async ( ) => {
308+ const waits : Array < ( found : boolean ) => void > = [ ] ;
309+ let retried = ( ) => { } ;
310+ const retry = new Promise < void > ( ( resolve ) => {
311+ retried = resolve ;
312+ } ) ;
313+ entities . waitForThreadShell = ( ) =>
314+ new Promise < boolean > ( ( resolve ) => {
315+ waits . push ( resolve ) ;
316+ if ( waits . length === 2 ) retried ( ) ;
317+ } ) ;
318+ const landed = new Promise < void > ( ( resolve ) => {
319+ const unsubscribe = useBrowserHistoryStore . subscribe ( ( state ) => {
320+ if ( ! state . byProjectKey [ "env-1:/repo" ] ) return ;
321+ unsubscribe ( ) ;
322+ resolve ( ) ;
323+ } ) ;
311324 } ) ;
312325 recordVisitForThread ( threadRef , "http://a.test/" , 1 ) ;
313- expect ( useBrowserHistoryStore . getState ( ) . byProjectKey ) . toEqual ( { } ) ;
326+ recordVisitForThread ( threadRef , "http://b.test/" , 2 ) ;
327+ expect ( waits ) . toHaveLength ( 1 ) ;
314328
329+ waits [ 0 ] ?.( false ) ;
330+ await retry ;
315331 entities . projects = [ repoProject ] ;
316332 entities . shellProjectId = "project-1" ;
317- shellArrives ( true ) ;
318- await entities . shellArrived ;
333+ waits [ 1 ] ?. ( true ) ;
334+ await landed ;
319335
320- expect ( useBrowserHistoryStore . getState ( ) . byProjectKey ) . toEqual ( {
321- "env-1:/repo" : [ { url : "http://a.test/" , lastVisitedAt : 1 } ] ,
322- } ) ;
336+ expect (
337+ useBrowserHistoryStore . getState ( ) . byProjectKey [ "env-1:/repo" ] ?. map ( ( entry ) => entry . url ) ,
338+ ) . toEqual ( [ "http://b.test/" , "http://a.test/" ] ) ;
323339 expect ( useBrowserHistoryStore . getState ( ) . pendingVisitsByThreadKey ) . toEqual ( { } ) ;
324340 } ) ;
325341} ) ;
0 commit comments