1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
9pub struct OmpConfiguration {
10 pub alias_name: String,
12 #[serde(skip_serializing_if = "Option::is_none")]
14 pub openai_api_key: Option<String>,
15 #[serde(skip_serializing_if = "Option::is_none")]
17 pub base_url: Option<String>,
18 #[serde(skip_serializing_if = "Option::is_none")]
20 pub slow_model: Option<String>,
21 #[serde(skip_serializing_if = "Option::is_none")]
23 pub smol_model: Option<String>,
24 #[serde(skip_serializing_if = "Option::is_none")]
26 pub plan_model: Option<String>,
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn test_serialize_openai() {
35 let config = OmpConfiguration {
36 alias_name: "test".to_string(),
37 openai_api_key: Some("sk-test".to_string()),
38 base_url: None,
39 slow_model: Some("openai/gpt-5.3-codex:high".to_string()),
40 smol_model: Some("openai/gpt-4o-mini".to_string()),
41 plan_model: None,
42 };
43
44 let json = serde_json::to_string(&config).expect("Should serialize");
45 assert!(json.contains("\"openai_api_key\":\"sk-test\""));
46 assert!(json.contains("\"slow_model\":\"openai/gpt-5.3-codex:high\""));
47 assert!(!json.contains("plan_model"));
48 assert!(!json.contains("auth_mode"));
49 assert!(!json.contains("anthropic"));
50 }
51
52 #[test]
53 fn test_deserialize_openai() {
54 let json = r#"{
55 "alias_name": "test",
56 "openai_api_key": "sk-test",
57 "slow_model": "openai/gpt-5.3-codex:high"
58 }"#;
59
60 let config: OmpConfiguration = serde_json::from_str(json).expect("Should deserialize");
61 assert_eq!(config.openai_api_key, Some("sk-test".to_string()));
62 assert_eq!(
63 config.slow_model,
64 Some("openai/gpt-5.3-codex:high".to_string())
65 );
66 assert_eq!(config.base_url, None);
67 }
68
69 #[test]
70 fn test_deserialize_ignores_legacy_anthropic_fields() {
71 let json = r#"{
74 "alias_name": "legacy",
75 "auth_mode": "anthropic",
76 "anthropic_api_key": "sk-ant-old",
77 "anthropic_oauth_token": "oauth-old"
78 }"#;
79
80 let config: OmpConfiguration = serde_json::from_str(json).expect("Should deserialize");
81 assert_eq!(config.alias_name, "legacy");
82 assert_eq!(config.openai_api_key, None);
83 }
84
85 #[test]
86 fn test_roundtrip_serialization() {
87 let original = OmpConfiguration {
88 alias_name: "work".to_string(),
89 openai_api_key: Some("sk-work".to_string()),
90 base_url: Some("https://api.example.com/v1".to_string()),
91 slow_model: Some("gpt-4o".to_string()),
92 smol_model: Some("gpt-4o-mini".to_string()),
93 plan_model: Some("gpt-4o".to_string()),
94 };
95
96 let json = serde_json::to_string(&original).expect("Should serialize");
97 let deserialized: OmpConfiguration =
98 serde_json::from_str(&json).expect("Should deserialize");
99 assert_eq!(original, deserialized);
100 }
101}