File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,6 +55,23 @@ describe('loadConfig', () => {
5555 ) . toBe ( 'option-profile' ) ;
5656 } ) ;
5757
58+ it ( 'treats empty TESTSPRITE_PROFILE as unset (falls back to default)' , ( ) => {
59+ expect ( loadConfig ( { env : { TESTSPRITE_PROFILE : '' } , credentialsPath } ) . profile ) . toBe (
60+ 'default' ,
61+ ) ;
62+ } ) ;
63+
64+ it ( 'treats whitespace-only TESTSPRITE_PROFILE as unset (falls back to default)' , ( ) => {
65+ const config = loadConfig ( { env : { TESTSPRITE_PROFILE : ' ' } , credentialsPath } ) ;
66+ expect ( config . profile ) . toBe ( 'default' ) ;
67+ } ) ;
68+
69+ it ( 'reads credentials from the default profile when TESTSPRITE_PROFILE is blank' , ( ) => {
70+ writeProfile ( 'default' , { apiKey : 'sk-default' } , { path : credentialsPath } ) ;
71+ const config = loadConfig ( { env : { TESTSPRITE_PROFILE : ' ' } , credentialsPath } ) ;
72+ expect ( config . apiKey ) . toBe ( 'sk-default' ) ;
73+ } ) ;
74+
5875 it ( 'option.endpointUrl overrides everything' , ( ) => {
5976 writeProfile ( 'default' , { apiUrl : 'https://file' } , { path : credentialsPath } ) ;
6077 const config = loadConfig ( {
Original file line number Diff line number Diff line change @@ -39,13 +39,17 @@ export function defaultConfigPath(): string {
3939 */
4040export function loadConfig ( options : LoadConfigOptions = { } ) : Config {
4141 const env = options . env ?? process . env ;
42- const profile = options . profile ?? env . TESTSPRITE_PROFILE ?? DEFAULT_PROFILE ;
42+ const profile = options . profile ?? normalizeEnvVar ( env . TESTSPRITE_PROFILE ) ?? DEFAULT_PROFILE ;
4343 const credentialsPath = options . credentialsPath ?? defaultCredentialsPath ( ) ;
4444 const fileEntry = readProfile ( profile , { path : credentialsPath } ) ;
4545
4646 // Empty / whitespace-only env vars are treated as unset so they do not
47- // short-circuit the `??` chain (e.g. `export TESTSPRITE_API_URL=` in a shell
48- // profile). Matches the normalization in auth configure and init/setup.
47+ // short-circuit the `??` chain (e.g. `export TESTSPRITE_API_URL=` or
48+ // `export TESTSPRITE_PROFILE=` in a shell profile). For the profile this
49+ // also avoids a confusing VALIDATION_ERROR: an empty name fails the INI
50+ // section-name guard, so without normalization a blank env var would break
51+ // every command instead of falling back to the default profile. Matches the
52+ // normalization in auth configure and init/setup.
4953 const envApiUrl = normalizeEnvVar ( env . TESTSPRITE_API_URL ) ;
5054 const envApiKey = normalizeEnvVar ( env . TESTSPRITE_API_KEY ) ;
5155
You can’t perform that action at this time.
0 commit comments