forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 fix: fix issues for client fetch (lobehub#2753)
* 🚸 feat: improve UX for clientfetch * 🚨 fix: circular dependence * 💡 docs: update comments * ✅ test: client fetch enabled * ✅ test: client fetch * ?? fix: wrong condition * ✅ test: update tests * 🐛 fix: wrong selector * ♻️ refactor: modify vaults selectors * ⏪ revert: style changed * ⏪ revert: cancel style fix * 🧪 test: isProviderEndpointNotEmpty * 🧪 test: isProviderApiKeyNotEmpty * ✅ test: isProviderEndpointNotEmpty * ♻️ refactor: endpoint for aws bedrock --------- Co-authored-by: Arvin Xu <arvinx@foxmail.com>
- Loading branch information
Showing
9 changed files
with
281 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,4 +81,4 @@ tags: | |
|
||
### Zeabur 将开始自动构建,您应该可以在一段时间后通过您选择的域名访问它。 | ||
|
||
</Steps> | ||
</Steps> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
src/store/user/slices/modelList/selectors/keyVaults.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { UserStore } from '@/store/user'; | ||
import { | ||
AWSBedrockKeyVault, | ||
AzureOpenAIKeyVault, | ||
OpenAICompatibleKeyVault, | ||
} from '@/types/user/settings'; | ||
import { merge } from '@/utils/merge'; | ||
|
||
import { initialSettingsState } from '../../settings/initialState'; | ||
import { keyVaultsConfigSelectors } from './keyVaults'; | ||
|
||
describe('keyVaultsConfigSelectors', () => { | ||
describe('isProviderEndpointNotEmpty', () => { | ||
describe('OpenAICompatibleKeyVault', () => { | ||
it('should return true if provider endpoint is not empty', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
openai: { | ||
endpoint: 'endpoint', | ||
} as OpenAICompatibleKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderEndpointNotEmpty('openai')(s)).toBe(true); | ||
}); | ||
|
||
it('should return false if provider endpoint is empty', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
openai: { | ||
endpoint: undefined, | ||
} as OpenAICompatibleKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderEndpointNotEmpty('openai')(s)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('AzureOpenAIKeyVault', () => { | ||
it('should return true if provider endpoint is not empty', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
azure: { | ||
baseURL: 'baseURL', | ||
} as AzureOpenAIKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderEndpointNotEmpty('azure')(s)).toBe(true); | ||
}); | ||
|
||
it('should return false if provider endpoint is empty', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
azure: { | ||
baseURL: undefined, | ||
} as AzureOpenAIKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderEndpointNotEmpty('azure')(s)).toBe(false); | ||
}); | ||
}); | ||
|
||
// Always return false for AWSBedrockKeyVault | ||
describe('AWSBedrockKeyVault', () => { | ||
it('should return false if provider region is not empty for AWSBedrockKeyVault', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
bedrock: { | ||
region: 'region', | ||
} as AWSBedrockKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderEndpointNotEmpty('bedrock')(s)).toBe(false); | ||
}); | ||
|
||
it('should return false if provider region is empty for AWSBedrockKeyVault', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
bedrock: { | ||
region: undefined, | ||
} as AWSBedrockKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderEndpointNotEmpty('bedrock')(s)).toBe(false); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('isProviderApiKeyNotEmpty', () => { | ||
describe('OpenAICompatibleKeyVault', () => { | ||
it('should return true if provider apikey is not empty', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
openai: { | ||
apiKey: 'apikey', | ||
} as OpenAICompatibleKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('openai')(s)).toBe(true); | ||
}); | ||
|
||
it('should return false if provider apikey is empty', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
openai: { | ||
apiKey: undefined, | ||
} as OpenAICompatibleKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('openai')(s)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('AzureOpenAIKeyVault', () => { | ||
it('should return true if provider apikey is not empty', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
azure: { | ||
apiKey: 'apikey', | ||
} as AzureOpenAIKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('azure')(s)).toBe(true); | ||
}); | ||
|
||
it('should return false if provider apikey is empty', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
azure: { | ||
apiKey: undefined, | ||
} as AzureOpenAIKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('azure')(s)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('AWSBedrockKeyVault', () => { | ||
it('should return true if provider accessKeyId is not empty for AWSBedrockKeyVault', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
bedrock: { | ||
accessKeyId: 'accessKeyId', | ||
} as AWSBedrockKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('bedrock')(s)).toBe(true); | ||
}); | ||
|
||
it('should return true if provider secretAccessKey is not empty for AWSBedrockKeyVault', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
bedrock: { | ||
secretAccessKey: 'secretAccessKey', | ||
} as AWSBedrockKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('bedrock')(s)).toBe(true); | ||
}); | ||
|
||
it('should return false if provider accessKeyId and secretAccessKey are both empty for AWSBedrockKeyVault', () => { | ||
const s = merge(initialSettingsState, { | ||
settings: { | ||
keyVaults: { | ||
bedrock: { | ||
accessKeyId: undefined, | ||
secretAccessKey: undefined, | ||
} as AWSBedrockKeyVault, | ||
}, | ||
}, | ||
}) as unknown as UserStore; | ||
expect(keyVaultsConfigSelectors.isProviderApiKeyNotEmpty('bedrock')(s)).toBe(false); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters