Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ function applyProviderChange(config: Config, provider: Config['provider']): Conf
}

function updateConfigFromRawValue(config: Config, key: ConfigSetKey, rawValue: string): Config {
if (key === 'provider') {
return applyProviderChange(config, parseConfigSetValue('provider', rawValue));
const updatedConfig =
key === 'provider'
? applyProviderChange(config, parseConfigSetValue('provider', rawValue))
: updateConfigField(config, key, parseConfigSetValue(key, rawValue));

if (updatedConfig.provider === CUSTOM_PROVIDER_KEY && !updatedConfig.baseUrl) {
throw new Error('Custom provider requires a configured baseUrl. Set baseUrl before selecting __custom__.');
Comment on lines +109 to +110

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor environment-provided custom endpoints

When COMMIT_ECHO_BASE_URL supplies the custom endpoint, config set provider __custom__ now fails because configSetCommand constructs this value from loadRawConfig(), so updatedConfig.baseUrl ignores the environment override. The same check also blocks every config set operation for an existing raw custom-provider config whose endpoint is environment-only, even though loadConfig() produces a valid runtime configuration. Accept the effective environment endpoint for validation without persisting it, since all config keys, including baseUrl, are supported through COMMIT_ECHO_* overrides.

AGENTS.md reference: AGENTS.md:L60-L60

Useful? React with 👍 / 👎.

}

return updateConfigField(config, key, parseConfigSetValue(key, rawValue));
return updatedConfig;
}

/** Masks a stored API key while leaving enough prefix to identify which key is configured. */
Expand Down
16 changes: 16 additions & 0 deletions tests/config-command.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,22 @@ test('config set clears stale baseUrl when switching between built-in providers'
});
});

test('config set requires a baseUrl before switching to the custom provider', async () => {
await withTempHome(async (homeDir) => {
writeConfig(homeDir, { baseUrl: undefined, provider: 'openai' });

await assert.rejects(
() => runConfigWithArgs(homeDir, ['set', 'provider', '__custom__']),
(error) => {
assert.equal(error.code, 1);
assert.match(error.stdout + error.stderr, /Custom provider requires a configured baseUrl/);
assert.equal(readConfig(homeDir).provider, 'openai');
return true;
},
);
});
});

test('config set preserves baseUrl when switching to custom provider', async () => {
await withTempHome(async (homeDir) => {
writeConfig(homeDir, {
Expand Down