use crate::brain::agent::service::plan_mode_provider::{ModeOverride, PlanModeSwap, override_for};
use crate::config::types::AgentConfig;
use crate::utils::plan_files::PlanModeState;
const EVERY_STATE: [PlanModeState; 4] = [
PlanModeState::NoPlan,
PlanModeState::PreInitEditing,
PlanModeState::PostInitEditing,
PlanModeState::Active,
];
fn planning(provider: Option<&str>, model: Option<&str>) -> AgentConfig {
AgentConfig {
plan_provider: provider.map(str::to_string),
plan_model: model.map(str::to_string),
..Default::default()
}
}
#[test]
fn an_unconfigured_install_never_overrides() {
let agent = AgentConfig::default();
for state in EVERY_STATE {
assert_eq!(
override_for(state, &agent),
None,
"unset config must not override in {state:?}"
);
}
}
#[test]
fn drafting_uses_the_plan_pair() {
let agent = planning(Some("anthropic"), Some("claude-opus-4-6"));
for state in [
PlanModeState::PreInitEditing,
PlanModeState::PostInitEditing,
] {
assert_eq!(
override_for(state, &agent),
Some(ModeOverride {
provider: Some("anthropic".to_string()),
model: Some("claude-opus-4-6".to_string()),
}),
"{state:?} must use the plan pair"
);
}
}
#[test]
fn a_session_with_no_plan_is_untouched() {
let agent = planning(Some("anthropic"), Some("claude-opus-4-6"));
assert_eq!(override_for(PlanModeState::NoPlan, &agent), None);
}
#[test]
fn a_provider_alone_means_that_providers_default_model() {
let agent = planning(Some("anthropic"), None);
assert_eq!(
override_for(PlanModeState::PostInitEditing, &agent),
Some(ModeOverride {
provider: Some("anthropic".to_string()),
model: None,
})
);
}
#[test]
fn a_model_alone_keeps_the_current_provider() {
let agent = planning(None, Some("claude-opus-4-6"));
assert_eq!(
override_for(PlanModeState::PostInitEditing, &agent),
Some(ModeOverride {
provider: None,
model: Some("claude-opus-4-6".to_string()),
})
);
}
#[test]
fn plan_keys_do_not_leak_into_execution() {
let agent = planning(Some("anthropic"), Some("claude-opus-4-6"));
assert_eq!(override_for(PlanModeState::Active, &agent), None);
}
fn executing(provider: Option<&str>, model: Option<&str>) -> AgentConfig {
AgentConfig {
execute_provider: provider.map(str::to_string),
execute_model: model.map(str::to_string),
..Default::default()
}
}
#[test]
fn executing_uses_the_execute_pair() {
let agent = executing(Some("openrouter"), Some("qwen3.8-max"));
assert_eq!(
override_for(PlanModeState::Active, &agent),
Some(ModeOverride {
provider: Some("openrouter".to_string()),
model: Some("qwen3.8-max".to_string()),
})
);
}
#[test]
fn execute_keys_do_not_leak_into_drafting() {
let agent = executing(Some("openrouter"), Some("qwen3.8-max"));
for state in [
PlanModeState::PreInitEditing,
PlanModeState::PostInitEditing,
] {
assert_eq!(
override_for(state, &agent),
None,
"{state:?} must not use the execute pair"
);
}
}
#[test]
fn drafting_and_executing_route_independently() {
let agent = AgentConfig {
plan_provider: Some("anthropic".to_string()),
plan_model: Some("claude-opus-4-6".to_string()),
execute_provider: Some("openrouter".to_string()),
execute_model: Some("qwen3.8-max".to_string()),
..Default::default()
};
assert_eq!(
override_for(PlanModeState::PostInitEditing, &agent)
.and_then(|o| o.provider)
.as_deref(),
Some("anthropic")
);
assert_eq!(
override_for(PlanModeState::Active, &agent)
.and_then(|o| o.provider)
.as_deref(),
Some("openrouter")
);
assert_eq!(override_for(PlanModeState::NoPlan, &agent), None);
}
#[test]
fn only_one_half_configured_leaves_the_other_alone() {
let plan_only = planning(Some("anthropic"), None);
assert_eq!(override_for(PlanModeState::Active, &plan_only), None);
let exec_only = executing(Some("openrouter"), None);
assert_eq!(
override_for(PlanModeState::PostInitEditing, &exec_only),
None
);
}
#[test]
fn an_untouched_override_is_recognised_as_still_applied() {
let swap = PlanModeSwap {
original_provider: "modelstudio".to_string(),
original_model: "qwen3.8-max".to_string(),
applied_provider: "anthropic".to_string(),
applied_model: "claude-opus-4-6".to_string(),
};
assert!(swap.still_applied("anthropic", "claude-opus-4-6"));
}
#[test]
fn a_user_switch_mid_plan_is_not_still_applied() {
let swap = PlanModeSwap {
original_provider: "modelstudio".to_string(),
original_model: "qwen3.8-max".to_string(),
applied_provider: "anthropic".to_string(),
applied_model: "claude-opus-4-6".to_string(),
};
assert!(!swap.still_applied("openrouter", "some-other-model"));
assert!(
!swap.still_applied("anthropic", "claude-sonnet-4-6"),
"same provider but a different model is still a deliberate change"
);
}