From 8f183308e03b67d15587b649dc5b960475796bf0 Mon Sep 17 00:00:00 2001 From: ege-arhan Date: Wed, 30 Sep 2026 16:17:35 +0000 Subject: [PATCH 1/2] fix(storage): deserialize legacy ChatGPT auth mode and data variants (#58) Add serde aliases for legacy ChatGPT auth enum variants (chat_gpt, chatgpt, chat_g_pt) on AuthMode and AuthData. Prevents accounts.json parsing failures on upgrades from older versions. --- src-tauri/src/types.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src-tauri/src/types.rs b/src-tauri/src/types.rs index 235a7666..1ae3a1e8 100644 --- a/src-tauri/src/types.rs +++ b/src-tauri/src/types.rs @@ -239,6 +239,7 @@ pub enum AuthMode { /// Using an OpenAI API key ApiKey, /// Using ChatGPT OAuth tokens + #[serde(alias = "chat_gpt", alias = "chatgpt", alias = "chat_g_pt")] ChatGPT, } @@ -252,6 +253,7 @@ pub enum AuthData { key: String, }, /// ChatGPT OAuth authentication + #[serde(alias = "chat_gpt", alias = "chatgpt", alias = "chat_g_pt")] ChatGPT { /// JWT ID token containing user info id_token: String, @@ -547,3 +549,42 @@ mod tests { assert!(settings.close_behavior_prompt_enabled); } } + +#[cfg(test)] +mod auth_deserialization_tests { + use super::*; + + #[test] + fn test_legacy_chatgpt_spellings_deserialize() { + let legacy_spellings = ["chat_g_p_t", "chat_g_pt", "chat_gpt", "chatgpt"]; + + for spelling in legacy_spellings { + let mode_json = format!(""{}"", spelling); + let mode: Result = serde_json::from_str(&mode_json); + assert_eq!( + mode.expect(&format!("Failed to deserialize AuthMode for {}", spelling)), + AuthMode::ChatGPT + ); + + let data_json = format!( + r#"{{"type": "{}", "id_token": "id", "access_token": "acc", "refresh_token": "ref", "account_id": null}}"#, + spelling + ); + let data: Result = serde_json::from_str(&data_json); + match data.expect(&format!("Failed to deserialize AuthData for {}", spelling)) { + AuthData::ChatGPT { + id_token, + access_token, + refresh_token, + account_id, + } => { + assert_eq!(id_token, "id"); + assert_eq!(access_token, "acc"); + assert_eq!(refresh_token, "ref"); + assert!(account_id.is_none()); + } + _ => panic!("Expected AuthData::ChatGPT"), + } + } + } +} From 7df3e9feb89e5684d0721c3b00b08e02b317afc4 Mon Sep 17 00:00:00 2001 From: ege-arhan Date: Thu, 1 Oct 2026 09:32:57 +0000 Subject: [PATCH 2/2] fix(tests): correct string quote escaping in auth deserialization test --- src-tauri/src/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/src/types.rs b/src-tauri/src/types.rs index 1ae3a1e8..4c7f0014 100644 --- a/src-tauri/src/types.rs +++ b/src-tauri/src/types.rs @@ -559,7 +559,7 @@ mod auth_deserialization_tests { let legacy_spellings = ["chat_g_p_t", "chat_g_pt", "chat_gpt", "chatgpt"]; for spelling in legacy_spellings { - let mode_json = format!(""{}"", spelling); + let mode_json = format!("\"{}\"", spelling); let mode: Result = serde_json::from_str(&mode_json); assert_eq!( mode.expect(&format!("Failed to deserialize AuthMode for {}", spelling)),