mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-18 13:23:33 +08:00
Clear stale provider env for ChatGPT Official activation
Switching from a saved provider to the built-in ChatGPT provider must remove previously managed Anthropic env without writing any OpenAI runtime env yet. This keeps Task 1 metadata-only while preventing stale provider settings from surviving the switch. Constraint: Task 1 still must not write ChatGPT OAuth runtime env Rejected: Return without touching settings.json | stale ANTHROPIC_* env survives from the previous provider Confidence: high Scope-risk: narrow Tested: bun test src/server/__tests__/providers.test.ts --test-name-pattern "ChatGPT Official" Tested: bun test src/server/__tests__/providers.test.ts Tested: git diff --check
This commit is contained in:
parent
072b913fd2
commit
238ab65cf3
@ -320,10 +320,30 @@ describe('ProviderService', () => {
|
||||
await svc.activateProvider('openai-official')
|
||||
|
||||
const config = await readProvidersConfig()
|
||||
const settings = await readSettings()
|
||||
expect(config.activeId).toBe('openai-official')
|
||||
await expect(
|
||||
fs.readFile(path.join(tmpDir, 'cc-haha', 'settings.json'), 'utf-8'),
|
||||
).rejects.toThrow()
|
||||
expect(settings.env).toBeUndefined()
|
||||
})
|
||||
|
||||
test('activating ChatGPT Official clears stale managed provider env', async () => {
|
||||
const svc = new ProviderService()
|
||||
const provider = await svc.addProvider(sampleInput({
|
||||
apiFormat: 'openai_responses',
|
||||
baseUrl: 'https://api.example.com/openai',
|
||||
models: {
|
||||
main: 'provider-main',
|
||||
haiku: 'provider-haiku',
|
||||
sonnet: 'provider-sonnet',
|
||||
opus: 'provider-opus',
|
||||
},
|
||||
}))
|
||||
await svc.activateProvider(provider.id)
|
||||
expect(((await readSettings()).env as Record<string, string>).ANTHROPIC_BASE_URL).toContain('/proxy')
|
||||
|
||||
await svc.activateProvider('openai-official')
|
||||
|
||||
const settings = await readSettings()
|
||||
expect(settings.env).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -359,6 +359,7 @@ export class ProviderService {
|
||||
await this.writeIndex(index)
|
||||
|
||||
if (isOpenAIOfficialProviderId(id)) {
|
||||
await this.clearProviderFromSettings()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user