Fix empty cloud API key routing#379
Conversation
🎨 Storybook previewUpdated for 04f7db3 |
📋 PR Overview
🔬 Coverage
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 889282b629
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| return Ok(Some((key, OPENAI_BASE_URL))); | ||
| Ok(select_openai_compatible_credential( | ||
| get_effective_openrouter_api_key(app)?, | ||
| get_effective_openai_api_key(app)?, |
There was a problem hiding this comment.
Preserve short-circuiting when OpenRouter credentials win
When OPENROUTER_API_KEY or a stored OpenRouter key is present, this eager argument evaluation still calls get_effective_openai_api_key(app)?, which can touch the OpenAI keychain and return an error or trigger an OS prompt before select_openai_compatible_credential ever sees that OpenRouter should win. The previous inline if let returned immediately after the OpenRouter lookup, matching the env-first comment that avoids unnecessary keychain access; keep this branch lazy so OpenRouter-only environments do not fail because the unrelated OpenAI credential store is unavailable.
Useful? React with 👍 / 👎.
Juanpe Bolívar (arximboldi)
left a comment
There was a problem hiding this comment.
This normalizes values on write. This means that existing broken configurations stay broken. It is also not so robust (what happens if you write the config from a different place, forgetting about the "normalization".
We should instead normalize the values on read (e.g. by having a get_secret_pref_non_empty or get_secret_pref_normalized that is used when reading the keys from the config).
| fn set_secret_pref<R: Runtime>(app: &AppHandle<R>, key: &'static str, value: &str) -> Result<()> { | ||
| if e2e_mock_system_enabled() { | ||
| return set_string_pref(app, key, value); | ||
| let normalized = value.trim(); |
There was a problem hiding this comment.
Should this use normalize_secret so if the rules changes this stays consistent?
889282b to
04f7db3
Compare
|
Rebased onto current What changed:
Local verification:
|
Summary
origin/develop.Fixes ENG-558
Fixes #368
Supersedes draft PR #370; this keeps the same backend direction but avoids the weaker duplicated routing test and preserves Scott's committed import ordering.
Test Plan
rustfmt --check --edition 2021 --config style_edition=2024,skip_children=true apps/native/src-tauri/src/storage/store.rs apps/native/src-tauri/src/state/mod.rs apps/native/src-tauri/src/evolve/edit_nix_file.rs apps/native/src-tauri/src/evolve/tools/edit_nix_file.rscargo test --manifest-path apps/native/src-tauri/Cargo.toml storage::store::tests -- --nocapturecargo check --manifest-path apps/native/src-tauri/Cargo.tomlgit diff --checkDocs