fix(api): keep rotating API keys out of process env#3391
Open
007M7 wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Author
|
@IceyLiu 我能进入贡献者里面嘛QWQ |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is an atomic follow-up to the API key rotation review. It only changes rotating provider API key handling.
ApiKeyManagerfrom writing rotating keys intoprocess.envApiKeyManagerkey for multi-key rotation instead of preferring environment variablesanyconfig with typed options and the correctapiKeyfieldWhy
Rotating API keys through
process.envcan leak the active key to child processes and can also break rotation when an environment variable is already set. The rotating clients should keep multi-key state in memory and read fromApiKeyManagerdirectly.Verification
Passed:
bunx tsc --noEmitbunx vitest run tests/unit/providers/ApiKeyManager.test.ts tests/unit/providers/RotatingApiClient.test.ts tests/unit/providers/RotatingProviderEnvIsolation.test.ts— 44 tests passedbunx oxlint packages/desktop/src/common/api/ApiKeyManager.ts packages/desktop/src/common/api/OpenAIRotatingClient.ts packages/desktop/src/common/api/AnthropicRotatingClient.ts packages/desktop/src/common/api/GeminiRotatingClient.ts tests/unit/providers/ApiKeyManager.test.ts tests/unit/providers/RotatingProviderEnvIsolation.test.tsbunx oxfmt --check packages/desktop/src/common/api/ApiKeyManager.ts packages/desktop/src/common/api/OpenAIRotatingClient.ts packages/desktop/src/common/api/AnthropicRotatingClient.ts packages/desktop/src/common/api/GeminiRotatingClient.ts tests/unit/providers/ApiKeyManager.test.ts tests/unit/providers/RotatingProviderEnvIsolation.test.tsgit diff --check upstream/main...HEADAlso checked:
bunx vitest run— 214 files passed, 1 skipped, 2 unrelated existing DOM test failures:tests/unit/previews/OfficeWatchViewer.dom.test.tsxtimed out while importing the moduletests/unit/settings/UpdateNotificationCard.dom.test.tsxexpectedupdate.restartNowbut the rendered card showedupdate.downloadButtonbun run lint— 0 errors, 781 existing repo-wide warnings outside this PR's changed files