fix(gemini): correctly write custom provider env to .env file

write_live_snapshot was incorrectly passing the already-extracted env
sub-field to json_to_env, which expects the full settings_config object.
This caused json_to_env to look for env.env (nested), returning an empty
HashMap and writing an empty .env file.

Fix by delegating to write_gemini_live which correctly handles env file
writing and security flag configuration in one place.
This commit is contained in:
Jason
2025-11-27 09:48:37 +08:00
parent dc79e3a3da
commit a1e7961af3
2 changed files with 3 additions and 35 deletions

View File

@@ -117,25 +117,8 @@ pub(crate) fn write_live_snapshot(app_type: &AppType, provider: &Provider) -> Re
.map_err(|e| AppError::io(&config_path, e))?;
}
AppType::Gemini => {
use crate::gemini_config::{
get_gemini_settings_path, json_to_env, write_gemini_env_atomic,
};
// Extract env and config from provider settings
let env_value = provider.settings_config.get("env");
let config_value = provider.settings_config.get("config");
// Write env file
if let Some(env) = env_value {
let env_map = json_to_env(env)?;
write_gemini_env_atomic(&env_map)?;
}
// Write settings file
if let Some(config) = config_value {
let settings_path = get_gemini_settings_path();
write_json_file(&settings_path, config)?;
}
// Delegate to write_gemini_live which handles env file writing correctly
write_gemini_live(provider)?;
}
}
Ok(())

View File

@@ -28,7 +28,6 @@ pub use live::{import_default_config, read_live_settings, sync_current_from_db};
pub(crate) use live::write_live_snapshot;
// Internal re-exports
use gemini_auth::{detect_gemini_auth_type, ensure_google_oauth_security_flag, GeminiAuthType};
use live::write_gemini_live;
use usage::validate_usage_script;
@@ -196,23 +195,9 @@ impl ProviderService {
// Set current
state.db.set_current_provider(app_type.as_str(), id)?;
// Sync to live
// Sync to live (write_gemini_live handles security flag internally for Gemini)
write_live_snapshot(&app_type, provider)?;
// Gemini needs additional security flag handling
// - Google Official: uses OAuth authentication
// - All others (PackyCode, Generic): use API Key authentication
if matches!(app_type, AppType::Gemini) {
let auth_type = detect_gemini_auth_type(provider);
match auth_type {
GeminiAuthType::GoogleOfficial => ensure_google_oauth_security_flag(provider)?,
GeminiAuthType::Packycode | GeminiAuthType::Generic => {
// All non-Google providers use API Key mode
crate::gemini_config::write_packycode_settings()?;
}
}
}
// Sync MCP
McpService::sync_all_enabled(state)?;