|
| 1 | +use super::*; |
| 2 | +use crate::legacy_core::config::ConfigBuilder; |
| 3 | +use codex_protocol::openai_models::ReasoningEffort; |
| 4 | +use pretty_assertions::assert_eq; |
| 5 | + |
| 6 | +async fn test_config() -> Config { |
| 7 | + let codex_home = tempfile::tempdir().expect("tempdir").keep(); |
| 8 | + ConfigBuilder::default() |
| 9 | + .codex_home(codex_home) |
| 10 | + .build() |
| 11 | + .await |
| 12 | + .expect("config") |
| 13 | +} |
| 14 | + |
| 15 | +fn defaults() -> NewThreadModelDefaults { |
| 16 | + NewThreadModelDefaults { |
| 17 | + model: Some("managed-model".to_string()), |
| 18 | + model_reasoning_effort: Some(ReasoningEffort::High), |
| 19 | + service_tier: Some("fast".to_string()), |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +#[tokio::test] |
| 24 | +async fn applies_managed_defaults_to_a_new_thread_config() { |
| 25 | + let mut actual = test_config().await; |
| 26 | + actual.model = Some("configured-model".to_string()); |
| 27 | + actual.model_reasoning_effort = Some(ReasoningEffort::Low); |
| 28 | + actual.service_tier = Some("flex".to_string()); |
| 29 | + let mut expected = actual.clone(); |
| 30 | + expected.model = Some("managed-model".to_string()); |
| 31 | + expected.model_reasoning_effort = Some(ReasoningEffort::High); |
| 32 | + expected.service_tier = Some(ServiceTier::Fast.request_value().to_string()); |
| 33 | + |
| 34 | + apply_managed_new_thread_defaults( |
| 35 | + &mut actual, |
| 36 | + Some(&defaults()), |
| 37 | + &[], |
| 38 | + &ConfigOverrides::default(), |
| 39 | + ); |
| 40 | + |
| 41 | + assert_eq!(actual, expected); |
| 42 | +} |
| 43 | + |
| 44 | +#[tokio::test] |
| 45 | +async fn explicit_model_skips_managed_model_and_reasoning_effort() { |
| 46 | + let mut actual = test_config().await; |
| 47 | + actual.model = Some("explicit-model".to_string()); |
| 48 | + actual.model_reasoning_effort = None; |
| 49 | + actual.service_tier = Some("flex".to_string()); |
| 50 | + let mut expected = actual.clone(); |
| 51 | + expected.service_tier = Some(ServiceTier::Fast.request_value().to_string()); |
| 52 | + let harness_overrides = ConfigOverrides { |
| 53 | + model: Some("explicit-model".to_string()), |
| 54 | + ..ConfigOverrides::default() |
| 55 | + }; |
| 56 | + |
| 57 | + apply_managed_new_thread_defaults(&mut actual, Some(&defaults()), &[], &harness_overrides); |
| 58 | + |
| 59 | + assert_eq!(actual, expected); |
| 60 | +} |
| 61 | + |
| 62 | +#[tokio::test] |
| 63 | +async fn explicit_reasoning_effort_skips_managed_model_and_reasoning_effort() { |
| 64 | + let mut actual = test_config().await; |
| 65 | + actual.model = Some("configured-model".to_string()); |
| 66 | + actual.model_reasoning_effort = Some(ReasoningEffort::Low); |
| 67 | + actual.service_tier = Some("flex".to_string()); |
| 68 | + let mut expected = actual.clone(); |
| 69 | + expected.service_tier = Some(ServiceTier::Fast.request_value().to_string()); |
| 70 | + let cli_kv_overrides = vec![( |
| 71 | + "model_reasoning_effort".to_string(), |
| 72 | + TomlValue::String("low".to_string()), |
| 73 | + )]; |
| 74 | + |
| 75 | + apply_managed_new_thread_defaults( |
| 76 | + &mut actual, |
| 77 | + Some(&defaults()), |
| 78 | + &cli_kv_overrides, |
| 79 | + &ConfigOverrides::default(), |
| 80 | + ); |
| 81 | + |
| 82 | + assert_eq!(actual, expected); |
| 83 | +} |
| 84 | + |
| 85 | +#[tokio::test] |
| 86 | +async fn explicit_launch_overrides_take_precedence() { |
| 87 | + let mut actual = test_config().await; |
| 88 | + actual.model = Some("explicit-model".to_string()); |
| 89 | + actual.model_reasoning_effort = Some(ReasoningEffort::Low); |
| 90 | + actual.service_tier = Some("flex".to_string()); |
| 91 | + let expected = actual.clone(); |
| 92 | + let cli_kv_overrides = vec![( |
| 93 | + "model_reasoning_effort".to_string(), |
| 94 | + TomlValue::String("low".to_string()), |
| 95 | + )]; |
| 96 | + let harness_overrides = ConfigOverrides { |
| 97 | + model: Some("explicit-model".to_string()), |
| 98 | + service_tier: Some(Some("flex".to_string())), |
| 99 | + ..ConfigOverrides::default() |
| 100 | + }; |
| 101 | + |
| 102 | + apply_managed_new_thread_defaults( |
| 103 | + &mut actual, |
| 104 | + Some(&defaults()), |
| 105 | + &cli_kv_overrides, |
| 106 | + &harness_overrides, |
| 107 | + ); |
| 108 | + |
| 109 | + assert_eq!(actual, expected); |
| 110 | +} |
0 commit comments