@@ -16,6 +16,8 @@ const state = vi.hoisted(() => ({
1616 confirm : vi . fn ( async ( _message : string ) => true ) ,
1717 connectPairing : vi . fn ( async ( _input : { pairingUrl : string } ) => ( { _tag : "Success" } ) ) ,
1818 localEnvironmentDisabled : false ,
19+ catalogReady : true ,
20+ environmentIds : [ "local" ] as string [ ] ,
1921} ) ) ;
2022
2123// One connected primary environment that can read pull requests. Its project list and
@@ -31,6 +33,10 @@ vi.mock(import("@tanstack/react-router"), async (original) => ({
3133vi . mock ( import ( "../../state/environments" ) , async ( original ) => ( {
3234 ...( await original ( ) ) ,
3335 usePrimaryEnvironmentId : ( ) => "local" as EnvironmentId ,
36+ useEnvironments : ( ( ) => ( {
37+ isReady : state . catalogReady ,
38+ environments : state . environmentIds . map ( ( environmentId ) => ( { environmentId } ) ) ,
39+ } ) ) as never ,
3440 usePrimaryEnvironment : ( ( ) =>
3541 state . localEnvironmentDisabled
3642 ? null
@@ -147,6 +153,8 @@ function setup() {
147153 vi . clearAllMocks ( ) ;
148154 state . confirm . mockResolvedValue ( true ) ;
149155 state . localEnvironmentDisabled = false ;
156+ state . catalogReady = true ;
157+ state . environmentIds = [ "local" ] ;
150158 state . projects = [ ] ;
151159 state . routeParams = { } ;
152160 state . preview
@@ -175,14 +183,21 @@ async function mount(...urls: string[]) {
175183 } ,
176184 } ) ,
177185 ) ;
178- stack . use (
186+ const screen = stack . use (
179187 await render (
180188 < AppAtomRegistryProvider >
181189 < DesktopWebLinkCoordinator />
182190 </ AppAtomRegistryProvider > ,
183191 ) ,
184192 ) ;
185- return stack . move ( ) ;
193+ return Object . assign ( stack . move ( ) , {
194+ rerender : ( ) =>
195+ screen . rerender (
196+ < AppAtomRegistryProvider >
197+ < DesktopWebLinkCoordinator />
198+ </ AppAtomRegistryProvider > ,
199+ ) ,
200+ } ) ;
186201}
187202
188203it ( "holds a launch PR link until project discovery settles, then opens the PR view" , async ( ) => {
@@ -335,3 +350,28 @@ it("does not hold a PR link for project discovery that never settles with Local
335350 await using _coordinator = await mount ( pullRequestUrl ) ;
336351 await vi . waitFor ( ( ) => expect ( state . openScratchProject ) . toHaveBeenCalledOnce ( ) ) ;
337352} ) ;
353+
354+ it . each ( [ false , true ] ) (
355+ "keeps a saved remote startup thread link queued until its catalog loads (local disabled: %s)" ,
356+ async ( localEnvironmentDisabled ) => {
357+ setup ( ) ;
358+ state . localEnvironmentDisabled = localEnvironmentDisabled ;
359+ state . catalogReady = false ;
360+ state . environmentIds = [ ] ;
361+ await using coordinator = await mount ( "t3code://threads/remote/thread" ) ;
362+ expect ( state . navigate ) . not . toHaveBeenCalled ( ) ;
363+ expect ( state . openScratchProject ) . not . toHaveBeenCalled ( ) ;
364+ expect ( state . openLink ) . not . toHaveBeenCalled ( ) ;
365+
366+ const navigated = new Promise < void > ( ( resolve ) => {
367+ state . navigate . mockImplementationOnce ( async ( ) => resolve ( ) ) ;
368+ } ) ;
369+ state . environmentIds = [ "remote" ] ;
370+ state . catalogReady = true ;
371+ await coordinator . rerender ( ) ;
372+ await navigated ;
373+ expect ( state . navigate ) . toHaveBeenCalledExactlyOnceWith ( { href : "/remote/thread" } ) ;
374+ expect ( state . openScratchProject ) . not . toHaveBeenCalled ( ) ;
375+ expect ( state . openLink ) . not . toHaveBeenCalled ( ) ;
376+ } ,
377+ ) ;
0 commit comments