use std::sync::Arc;
use super::*;
use crate::app::subagent_host_input::SubagentHostInputBridge;
#[test]
fn parent_selection_updates_are_shared_with_executor_clones() {
let executor = AgentExecutor::new(
Config::default(),
PathBuf::new(),
PathBuf::new(),
crate::app::agent_concurrency::AgentConcurrency::from_config(1),
SubagentHostInputBridge::new(),
crate::app::subagent_messaging::SubagentNoticeBridge::new(),
);
let cloned = executor.clone();
executor.update_selection(
"openai-codex",
"gpt-5.6-luna",
rho_sdk::ReasoningLevel::Low,
"codex",
);
let config = cloned.config.read().expect("delegated config lock");
let chosen = config.expect_conversation_model();
assert_eq!(
(&*chosen.provider, &*chosen.model, &*chosen.auth),
("openai-codex", "gpt-5.6-luna", "codex")
);
assert_eq!(config.reasoning, rho_sdk::ReasoningLevel::Low);
drop(config);
executor.update_permission_mode(crate::permission::PermissionMode::Plan);
assert_eq!(
cloned.launch_permission_mode(),
crate::permission::PermissionMode::Plan
);
cloned.update_permission_mode(crate::permission::PermissionMode::Supervised);
assert_eq!(
executor.launch_permission_mode(),
crate::permission::PermissionMode::Supervised
);
}
#[test]
fn update_selection_does_not_alter_bound_claude_runtime() {
use crate::agent::{AgentDefinition, AgentId, AgentRuntimeSpec, PromptPolicy};
use crate::app::agent_binding::{AgentBinder, AgentInvocation, AgentRole, BoundRuntime};
let executor = AgentExecutor::new(
Config {
permission_mode: crate::permission::PermissionMode::Plan,
..Config::with_model("openai-codex", "gpt-parent-before", "codex")
},
PathBuf::new(),
PathBuf::new(),
crate::app::agent_concurrency::AgentConcurrency::from_config(1),
SubagentHostInputBridge::new(),
crate::app::subagent_messaging::SubagentNoticeBridge::new(),
);
let definition = Arc::new(AgentDefinition {
id: AgentId::new("claude-bound").unwrap(),
description: "claude".into(),
prompt: PromptPolicy::Replace("plan".into()),
runtime: AgentRuntimeSpec::ClaudeCli(crate::agent::ClaudeAgentConfig {
tools: crate::agent::ClaudeToolPolicy::Allow(vec!["Read".into()]),
inherit_claude_config: false,
model: Some("opus".into()),
reasoning: None,
}),
});
let host_before = executor
.config
.read()
.expect("delegated config lock")
.clone();
let bound_before = AgentBinder::bind(
Arc::clone(&definition),
AgentInvocation {
role: AgentRole::Delegated,
available_tools: crate::agent::AgentCapabilities::default(),
},
&host_before,
)
.unwrap();
executor.update_selection(
"moonshot-kimi",
"kimi-parent-after",
rho_sdk::ReasoningLevel::High,
"kimi-oauth",
);
let host_after = executor
.config
.read()
.expect("delegated config lock")
.clone();
assert_eq!(
host_after.expect_conversation_model().provider,
"moonshot-kimi"
);
assert_eq!(
host_after.expect_conversation_model().model,
"kimi-parent-after"
);
match bound_before.runtime() {
BoundRuntime::ClaudeCli {
model,
tools,
inherit_claude_config,
permission_mode,
..
} => {
assert_eq!(model.as_deref(), Some("opus"));
assert_eq!(tools.as_slice(), ["Read".to_string()].as_slice());
assert!(!*inherit_claude_config);
assert_eq!(*permission_mode, crate::permission::PermissionMode::Plan);
}
BoundRuntime::Rho { .. } | BoundRuntime::Antigravity { .. } => {
panic!("expected Claude bound runtime")
}
}
assert!(bound_before.rho_config().is_none());
let bound_after = AgentBinder::bind(
definition,
AgentInvocation {
role: AgentRole::Delegated,
available_tools: crate::agent::AgentCapabilities::default(),
},
&host_after,
)
.unwrap();
match bound_after.runtime() {
BoundRuntime::ClaudeCli {
model,
permission_mode,
..
} => {
assert_eq!(model.as_deref(), Some("opus"));
assert_eq!(*permission_mode, crate::permission::PermissionMode::Plan);
}
BoundRuntime::Rho { .. } | BoundRuntime::Antigravity { .. } => {
panic!("expected Claude bound runtime")
}
}
assert_ne!(host_after.expect_conversation_model().model, "opus");
assert_ne!(
host_after.expect_conversation_model().provider,
"claude-code"
);
}