Skip to content

fix(gemini): read export KEY=value lines in ~/.gemini/.env - #8862

Merged
farion1231 merged 1 commit into
farion1231:mainfrom
L4XB:fix/gemini-env-export-lines
Oct 26, 2026
Merged

farion1231 merged 1 commit into
farion1231:mainfrom
L4XB:fix/gemini-env-export-lines

Conversation

@L4XB

@L4XB L4XB commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Summary / 概述

parse_env_file (src-tauri/src/gemini_config.rs) skipped export KEY=value lines, because its key check saw export GEMINI_API_KEY. Importing the live config then stored the default Gemini provider without its key, and switching back to it from another provider removed the key from ~/.gemini/.env. Gemini CLI reads the file with dotenv, which accepts the export prefix, and CC Switch's own .env writer (live/patch/dotenv.rs) handles it too.

  • parse_env_file strips an export prefix before the key check, like the writer's parse_key.

Related Issue / 关联 Issue

Fixes #8861

Testing

~/.gemini/.env = export GEMINI_API_KEY=AIza-user-key, then import, switch to a second provider and back:

main this PR
default provider after import env: {} env: {"GEMINI_API_KEY": "AIza-user-key"}
~/.gemini/.env after switching back empty export GEMINI_API_KEY=AIza-user-key
  • New tests: test_parse_env_file_reads_export_lines (unit) and switching_back_to_imported_gemini_default_keeps_an_export_line_key (integration, in tests/provider_service.rs). On main the integration test fails with an empty .env.
  • cargo test: 4248 passed.
  • cargo fmt --check passes. cargo clippy --all-targets reports nothing in the changed files (Rust 1.99.1).

Checklist / 检查清单

  • cargo clippy passes (if Rust code changed) / 通过 Clippy 检查(如修改了 Rust 代码)
  • Rust-only change: no frontend code or user-facing text changed, so pnpm typecheck, pnpm format:check and the i18n files are not affected.

parse_env_file skipped `export GEMINI_API_KEY=...` because its key check
saw "export GEMINI_API_KEY". Importing the live config then stored the
default provider without the key, and switching back to that provider
from another one removed the key that the .env writer had kept in place.

Gemini CLI reads .env with dotenv, which accepts the export prefix, and
CC Switch's own .env writer (live/patch/dotenv.rs) does too.

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your contribution!

@farion1231
farion1231 merged commit 74a98fd into farion1231:main Oct 26, 2026
18 of 20 checks passed
@farion1231

Copy link
Copy Markdown
Owner

Merged, thanks! Nice catch on the read/write asymmetry: the writer already kept export, so teaching the reader the same rule fixes import, routing reads and the switch-back round trip in one place. The byte-for-byte round-trip test is a great guard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend (Rust/Tauri)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini: an export GEMINI_API_KEY=... line in ~/.gemini/.env is not imported, and switching back to the default provider deletes it

2 participants