@@ -339,7 +339,6 @@ describe('makeHttpClient - API key validation', () => {
339339 [ 'smart dash' , 'sk-user-abc\u2013def' ] ,
340340 [ 'smart quote' , 'sk-user-\u201cabc\u201d' ] ,
341341 [ 'emoji' , 'sk-user-abc\u{1f600}' ] ,
342- [ 'whitespace-only' , ' ' ] ,
343342 ] ) ( 'rejects a malformed configured API key with %s before fetch/retry' , ( _label , apiKey ) => {
344343 const fetchImpl = vi . fn ( ) ;
345344 let caught : unknown ;
@@ -362,6 +361,26 @@ describe('makeHttpClient - API key validation', () => {
362361 expect ( apiErr . exitCode ) . toBe ( 5 ) ;
363362 expect ( apiErr . nextAction ) . toContain ( 'api-key' ) ;
364363 } ) ;
364+
365+ it ( 'treats a whitespace-only TESTSPRITE_API_KEY env var as unset (AUTH_REQUIRED)' , ( ) => {
366+ const fetchImpl = vi . fn ( ) ;
367+ let caught : unknown ;
368+ try {
369+ makeHttpClient (
370+ { profile : 'default' , output : 'json' , debug : false , dryRun : false } ,
371+ {
372+ env : { TESTSPRITE_API_KEY : ' ' } as NodeJS . ProcessEnv ,
373+ credentialsPath : NO_CREDS_PATH ,
374+ fetchImpl,
375+ } ,
376+ ) ;
377+ } catch ( err ) {
378+ caught = err ;
379+ }
380+ expect ( fetchImpl ) . not . toHaveBeenCalled ( ) ;
381+ expect ( caught ) . toBeInstanceOf ( ApiError ) ;
382+ expect ( ( caught as ApiError ) . code ) . toBe ( 'AUTH_REQUIRED' ) ;
383+ } ) ;
365384} ) ;
366385
367386describe ( 'assertValidApiKeyHeaderValue' , ( ) => {
0 commit comments