fix: change provider not update without done, update chatbox change provider from MrUbens

This commit is contained in:
sam hoang
2025-01-07 20:16:44 +07:00
committed by Matt Rubens
parent c3fa10b367
commit 3346844584
7 changed files with 121 additions and 33 deletions

View File

@@ -125,6 +125,18 @@ export class ConfigManager {
}
}
/**
* Check if a config exists by name
*/
async HasConfig(name: string): Promise<boolean> {
try {
const config = await this.readConfig()
return name in config.apiConfigs
} catch (error) {
throw new Error(`Failed to check config existence: ${error}`)
}
}
private async readConfig(): Promise<ApiConfigData> {
try {
const configKey = `${this.SCOPE_PREFIX}api_config`

View File

@@ -1,7 +1,6 @@
import { ExtensionContext } from 'vscode'
import { ConfigManager } from '../ConfigManager'
import { ConfigManager, ApiConfigData } from '../ConfigManager'
import { ApiConfiguration } from '../../../shared/api'
import { ApiConfigData } from '../ConfigManager'
// Mock VSCode ExtensionContext
const mockSecrets = {
@@ -345,4 +344,41 @@ describe('ConfigManager', () => {
)
})
})
describe('HasConfig', () => {
it('should return true for existing config', async () => {
const existingConfig: ApiConfigData = {
currentApiConfigName: 'default',
apiConfigs: {
default: {},
test: {
apiProvider: 'anthropic'
}
}
}
mockSecrets.get.mockResolvedValue(JSON.stringify(existingConfig))
const hasConfig = await configManager.HasConfig('test')
expect(hasConfig).toBe(true)
})
it('should return false for non-existent config', async () => {
mockSecrets.get.mockResolvedValue(JSON.stringify({
currentApiConfigName: 'default',
apiConfigs: { default: {} }
}))
const hasConfig = await configManager.HasConfig('nonexistent')
expect(hasConfig).toBe(false)
})
it('should throw error if secrets storage fails', async () => {
mockSecrets.get.mockRejectedValue(new Error('Storage failed'))
await expect(configManager.HasConfig('test')).rejects.toThrow(
'Failed to check config existence: Error: Failed to read config from secrets: Error: Storage failed'
)
})
})
})