mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-28 08:44:41 +08:00
refactor(codex): stop force-rewriting user's model_provider field in live config
The one-time history migration already consolidates legacy provider IDs into a single bucket; there is no need to normalize on every write. This preserves user-chosen provider identities through the full write/backup/restore cycle.
This commit is contained in:
@@ -187,8 +187,8 @@ impl ConfigService {
|
||||
&provider.settings_config,
|
||||
restore_provider_token,
|
||||
)?;
|
||||
// 必须同时写回 auth 和 config: backfill 会恢复 stored provider id,
|
||||
// 并把 live 的 experimental_bearer_token 移到 restored.auth.OPENAI_API_KEY。
|
||||
// 必须同时写回 auth 和 config: backfill 会把 live 的
|
||||
// experimental_bearer_token 移到 restored.auth.OPENAI_API_KEY。
|
||||
if let Some(restored_obj) = restored.as_object() {
|
||||
if let Some(auth_value) = restored_obj.get("auth") {
|
||||
obj.insert("auth".to_string(), auth_value.clone());
|
||||
|
||||
@@ -1774,11 +1774,6 @@ impl ProxyService {
|
||||
existing_value,
|
||||
)?;
|
||||
}
|
||||
|
||||
crate::codex_config::normalize_codex_settings_config_model_provider(
|
||||
&mut effective_settings,
|
||||
)
|
||||
.map_err(|e| format!("归一化 Codex restore backup 失败: {e}"))?;
|
||||
}
|
||||
|
||||
let backup_json = match app_type_enum {
|
||||
@@ -3566,7 +3561,7 @@ base_url = "https://new.example/v1"
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn hot_switch_codex_provider_keeps_model_provider_stable_in_backup_and_restore() {
|
||||
async fn hot_switch_codex_provider_preserves_provider_model_provider_in_backup_and_restore() {
|
||||
let _home = TempHome::new();
|
||||
crate::settings::reload_settings().expect("reload settings");
|
||||
|
||||
@@ -3663,21 +3658,21 @@ requires_openai_auth = true
|
||||
toml::from_str(backup_config).expect("parse backup config");
|
||||
assert_eq!(
|
||||
parsed_backup.get("model_provider").and_then(|v| v.as_str()),
|
||||
Some("custom"),
|
||||
"provider-derived restore backup should retain stable Codex model_provider"
|
||||
Some("aihubmix"),
|
||||
"provider-derived restore backup should preserve the provider's model_provider"
|
||||
);
|
||||
let backup_model_providers = parsed_backup
|
||||
.get("model_providers")
|
||||
.and_then(|v| v.as_table())
|
||||
.expect("backup model_providers");
|
||||
assert!(backup_model_providers.get("aihubmix").is_none());
|
||||
assert!(backup_model_providers.get("custom").is_none());
|
||||
assert_eq!(
|
||||
backup_model_providers
|
||||
.get("custom")
|
||||
.get("aihubmix")
|
||||
.and_then(|v| v.get("base_url"))
|
||||
.and_then(|v| v.as_str()),
|
||||
Some("https://aihubmix.example/v1"),
|
||||
"stable provider id should point at the hot-switched provider endpoint"
|
||||
"provider id should point at the hot-switched provider endpoint"
|
||||
);
|
||||
|
||||
service
|
||||
@@ -3693,8 +3688,8 @@ requires_openai_auth = true
|
||||
let parsed_live: toml::Value = toml::from_str(live_config).expect("parse live config");
|
||||
assert_eq!(
|
||||
parsed_live.get("model_provider").and_then(|v| v.as_str()),
|
||||
Some("custom"),
|
||||
"restored Codex live config should not switch history buckets"
|
||||
Some("aihubmix"),
|
||||
"restored Codex live config should preserve the provider's model_provider"
|
||||
);
|
||||
assert_eq!(
|
||||
live.get("auth")
|
||||
@@ -3802,7 +3797,7 @@ requires_openai_auth = true
|
||||
|
||||
assert_eq!(
|
||||
parsed_live.get("model_provider").and_then(|v| v.as_str()),
|
||||
Some("custom")
|
||||
Some("stable")
|
||||
);
|
||||
assert_eq!(
|
||||
parsed_live.get("model").and_then(|v| v.as_str()),
|
||||
|
||||
Reference in New Issue
Block a user