@@ -224,6 +224,18 @@ describe('setup_files', () => {
224224 fs . writeFileSync ( path . join ( tmpDir , '.env' ) , 'PERSONAL_ACCESS_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ) ;
225225 expect ( hasValidSetupToken ( tmpDir ) ) . toBe ( true ) ;
226226 } ) ;
227+
228+ it ( 'returns true when valid override is passed (e.g. CLI --token)' , ( ) => {
229+ delete process . env [ ENV_TOKEN_KEY ] ;
230+ expect ( hasValidSetupToken ( tmpDir , 'ghp_override_token_xxxxxxxxxxxxxxxxxx' ) ) . toBe ( true ) ;
231+ } ) ;
232+
233+ it ( 'falls back to env/.env when override is invalid (placeholder or too short)' , ( ) => {
234+ delete process . env [ ENV_TOKEN_KEY ] ;
235+ fs . writeFileSync ( path . join ( tmpDir , '.env' ) , 'PERSONAL_ACCESS_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ) ;
236+ expect ( hasValidSetupToken ( tmpDir , 'github_pat_11..' ) ) . toBe ( true ) ;
237+ expect ( hasValidSetupToken ( tmpDir , 'short' ) ) . toBe ( true ) ;
238+ } ) ;
227239 } ) ;
228240
229241 describe ( 'getSetupToken' , ( ) => {
@@ -244,6 +256,20 @@ describe('setup_files', () => {
244256 fs . writeFileSync ( path . join ( tmpDir , '.env' ) , 'PERSONAL_ACCESS_TOKEN=github_pat_11..' ) ;
245257 expect ( getSetupToken ( tmpDir ) ) . toBeUndefined ( ) ;
246258 } ) ;
259+
260+ it ( 'returns valid override first (CLI token priority)' , ( ) => {
261+ delete process . env [ ENV_TOKEN_KEY ] ;
262+ fs . writeFileSync ( path . join ( tmpDir , '.env' ) , 'PERSONAL_ACCESS_TOKEN=ghp_from_env_file_xxxxxxxxxxxxxxxxxx' ) ;
263+ expect ( getSetupToken ( tmpDir , 'ghp_cli_token_xxxxxxxxxxxxxxxxxxxxxxxx' ) ) . toBe ( 'ghp_cli_token_xxxxxxxxxxxxxxxxxxxxxxxx' ) ;
264+ } ) ;
265+
266+ it ( 'falls back to env then .env when override is invalid' , ( ) => {
267+ process . env [ ENV_TOKEN_KEY ] = 'ghp_from_env_xxxxxxxxxxxxxxxxxxxxxxxxxx' ;
268+ fs . writeFileSync ( path . join ( tmpDir , '.env' ) , 'PERSONAL_ACCESS_TOKEN=ghp_from_file_xxxxxxxxxxxxxxxxxxxx' ) ;
269+ expect ( getSetupToken ( tmpDir , 'github_pat_11..' ) ) . toBe ( 'ghp_from_env_xxxxxxxxxxxxxxxxxxxxxxxxxx' ) ;
270+ delete process . env [ ENV_TOKEN_KEY ] ;
271+ expect ( getSetupToken ( tmpDir , 'short' ) ) . toBe ( 'ghp_from_file_xxxxxxxxxxxxxxxxxxxx' ) ;
272+ } ) ;
247273 } ) ;
248274
249275 describe ( 'setupEnvFileExists' , ( ) => {
0 commit comments