@@ -114,6 +114,62 @@ func TestFirstRunShowsEmulatorSelectionPrompt(t *testing.T) {
114114 <- outputCh
115115}
116116
117+ func TestFirstRunPromptsForLoginBeforeEmulatorSelection (t * testing.T ) {
118+ t .Parallel ()
119+ if runtime .GOOS == "windows" {
120+ t .Skip ("PTY not supported on Windows" )
121+ }
122+
123+ mockServer := createMockAPIServer (t , "test-license-token" , true )
124+ defer mockServer .Close ()
125+
126+ tmpHome := t .TempDir ()
127+ require .NoError (t , os .MkdirAll (filepath .Join (tmpHome , ".config" ), 0755 ))
128+ e := env .Environ (testEnvWithHome (tmpHome , tmpHome )).
129+ Without (env .AuthToken ).
130+ With (env .APIEndpoint , mockServer .URL ).
131+ With (env .DisableEvents , "1" )
132+
133+ // No config exists so this is a first run; no token means login fires before emulator selection.
134+ configPath , _ , err := runLstk (t , testContext (t ), "" , e , "config" , "path" )
135+ require .NoError (t , err )
136+ require .NoFileExists (t , configPath )
137+
138+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
139+ defer cancel ()
140+
141+ cmd := exec .CommandContext (ctx , binaryPath (), "start" )
142+ cmd .Env = e
143+
144+ ptmx , err := pty .Start (cmd )
145+ require .NoError (t , err , "failed to start lstk in PTY" )
146+ defer func () { _ = ptmx .Close () }()
147+
148+ out := & syncBuffer {}
149+ outputCh := make (chan struct {})
150+ go func () {
151+ _ , _ = io .Copy (out , ptmx )
152+ close (outputCh )
153+ }()
154+
155+ require .Eventually (t , func () bool {
156+ return bytes .Contains (out .Bytes (), []byte ("Press any key when complete" ))
157+ }, 10 * time .Second , 100 * time .Millisecond , "auth prompt should appear on first run when no token is set" )
158+
159+ assert .NotContains (t , out .String (), "Which emulator would you like to use?" ,
160+ "emulator selection prompt must not appear before auth completes" )
161+
162+ _ , err = ptmx .Write ([]byte ("\r " ))
163+ require .NoError (t , err )
164+
165+ require .Eventually (t , func () bool {
166+ return bytes .Contains (out .Bytes (), []byte ("Which emulator would you like to use?" ))
167+ }, 10 * time .Second , 100 * time .Millisecond , "emulator selection prompt should appear after auth completes" )
168+
169+ cancel ()
170+ <- outputCh
171+ }
172+
117173func TestFirstRunNonInteractiveEmitsDefaultEmulatorNote (t * testing.T ) {
118174 t .Parallel ()
119175 tmpHome := t .TempDir ()
0 commit comments