use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct OmpConfiguration {
pub alias_name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub openai_api_key: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub base_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub slow_model: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub smol_model: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub plan_model: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_serialize_openai() {
let config = OmpConfiguration {
alias_name: "test".to_string(),
openai_api_key: Some("sk-test".to_string()),
base_url: None,
slow_model: Some("openai/gpt-5.3-codex:high".to_string()),
smol_model: Some("openai/gpt-4o-mini".to_string()),
plan_model: None,
};
let json = serde_json::to_string(&config).expect("Should serialize");
assert!(json.contains("\"openai_api_key\":\"sk-test\""));
assert!(json.contains("\"slow_model\":\"openai/gpt-5.3-codex:high\""));
assert!(!json.contains("plan_model"));
assert!(!json.contains("auth_mode"));
assert!(!json.contains("anthropic"));
}
#[test]
fn test_deserialize_openai() {
let json = r#"{
"alias_name": "test",
"openai_api_key": "sk-test",
"slow_model": "openai/gpt-5.3-codex:high"
}"#;
let config: OmpConfiguration = serde_json::from_str(json).expect("Should deserialize");
assert_eq!(config.openai_api_key, Some("sk-test".to_string()));
assert_eq!(
config.slow_model,
Some("openai/gpt-5.3-codex:high".to_string())
);
assert_eq!(config.base_url, None);
}
#[test]
fn test_deserialize_ignores_legacy_anthropic_fields() {
let json = r#"{
"alias_name": "legacy",
"auth_mode": "anthropic",
"anthropic_api_key": "sk-ant-old",
"anthropic_oauth_token": "oauth-old"
}"#;
let config: OmpConfiguration = serde_json::from_str(json).expect("Should deserialize");
assert_eq!(config.alias_name, "legacy");
assert_eq!(config.openai_api_key, None);
}
#[test]
fn test_roundtrip_serialization() {
let original = OmpConfiguration {
alias_name: "work".to_string(),
openai_api_key: Some("sk-work".to_string()),
base_url: Some("https://api.example.com/v1".to_string()),
slow_model: Some("gpt-4o".to_string()),
smol_model: Some("gpt-4o-mini".to_string()),
plan_model: Some("gpt-4o".to_string()),
};
let json = serde_json::to_string(&original).expect("Should serialize");
let deserialized: OmpConfiguration =
serde_json::from_str(&json).expect("Should deserialize");
assert_eq!(original, deserialized);
}
}