mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-30 10:25:05 +08:00
Refactor Codex live-write routing and cover default auth overwrite
Collapse the two duplicated write_codex_live_atomic branches in
write_codex_live_for_provider into a single should_write_auth guard.
This is behavior-preserving: `if A {X} else if B {X} else {Y}` becomes
`if A || B {X} else {Y}`.
Adapt the Codex switch tests to the new opt-in default for
preserve_codex_official_auth_on_switch (flipped off in 3f59ab37):
add an enable_codex_official_auth_preservation() test helper for the
cases that assert the auth-preserving path, and tag the official login
provider with category="official" so it routes through the official
branch rather than relying on the global preservation flag.
Add a regression test locking the default (preservation off) behavior:
switching to a third-party provider rewrites auth.json with the new
API key and discards the existing ChatGPT OAuth login. This is the
dual of the existing preserve-and-backfill test, which only covered
the opt-in path.
This commit is contained in:
@@ -796,11 +796,11 @@ pub fn write_codex_live_for_provider(
|
||||
auth: &Value,
|
||||
config_text: Option<&str>,
|
||||
) -> Result<(), AppError> {
|
||||
if category == Some("official") && codex_auth_has_login_material(auth) {
|
||||
write_codex_live_atomic(auth, config_text)
|
||||
} else if category != Some("official")
|
||||
&& !crate::settings::preserve_codex_official_auth_on_switch()
|
||||
{
|
||||
let should_write_auth = (category == Some("official") && codex_auth_has_login_material(auth))
|
||||
|| (category != Some("official")
|
||||
&& !crate::settings::preserve_codex_official_auth_on_switch());
|
||||
|
||||
if should_write_auth {
|
||||
write_codex_live_atomic(auth, config_text)
|
||||
} else {
|
||||
let live_config = prepare_codex_provider_live_config(auth, config_text.unwrap_or(""))?;
|
||||
|
||||
Reference in New Issue
Block a user