refactor(codex): unify custom model_provider routing key to "custom"

- Always emit `model_provider = "custom"` from deep link, UniversalProvider, and the universal form modal so future writes share one stable routing key.
- Add `codex_provider_template_v1` local migration that rewrites legacy keys (aihubmix/ccswitch/...) under `[model_providers.custom]`, updates profile refs, and backs up the original settings_config under `~/.cc-switch/backups/<timestamp>/providers/`.
- Tighten history migration source detection to a whitelist plus `[model_providers.<id>]` existence check so user-authored keys are never rewritten in jsonl/state DB.
- Encode deep link name/model/endpoint through `toml_edit::Value` so display names containing quotes or backslashes no longer break the generated config.toml.
- Stabilize provider settings backup filename hash with Sha256 (was process-random SipHash).
This commit is contained in:
Jason
2026-05-28 17:30:44 +08:00
parent 3d6fb894b5
commit fc0433f2f4
8 changed files with 1075 additions and 99 deletions
+20 -2
View File
@@ -34,6 +34,10 @@ fn merge_settings_for_save(
.codex_third_party_history_provider_bucket_v1
.clone();
}
if incoming_migrations.codex_provider_template_v1.is_none() {
incoming_migrations.codex_provider_template_v1 =
existing_migrations.codex_provider_template_v1.clone();
}
}
incoming
}
@@ -98,8 +102,8 @@ pub async fn set_auto_launch(enabled: bool) -> Result<bool, String> {
mod tests {
use super::merge_settings_for_save;
use crate::settings::{
AppSettings, CodexThirdPartyHistoryProviderBucketMigration, LocalMigrations,
WebDavSyncSettings,
AppSettings, CodexProviderTemplateMigration, CodexThirdPartyHistoryProviderBucketMigration,
LocalMigrations, WebDavSyncSettings,
};
#[test]
@@ -236,6 +240,10 @@ mod tests {
scanned_history_files: true,
},
),
codex_provider_template_v1: Some(CodexProviderTemplateMigration {
completed_at: "2026-05-20T00:01:00Z".to_string(),
migrated_provider_ids: vec!["legacy".to_string()],
}),
}),
..AppSettings::default()
};
@@ -255,6 +263,16 @@ mod tests {
assert_eq!(migration.target_provider_id, "custom");
assert_eq!(migration.migrated_jsonl_files, 2);
assert_eq!(migration.migrated_state_rows, 3);
let template_migration = merged
.local_migrations
.as_ref()
.and_then(|migrations| migrations.codex_provider_template_v1.as_ref())
.expect("template migration marker should be preserved");
assert_eq!(
template_migration.migrated_provider_ids,
vec!["legacy".to_string()]
);
}
}