mod oneshot;
pub mod start;
pub mod status;
pub mod steer;
pub mod collect;
pub mod resume;
pub use oneshot::SubagentTool;
pub use start::SubagentStartTool;
pub use status::SubagentStatusTool;
pub use steer::SubagentSteerTool;
pub use collect::SubagentCollectTool;
pub use resume::SubagentResumeTool;
pub(crate) fn apply_subagent_runtime_policy(
runtime: &mut crate::Runtime,
config: &crate::config::SynapsConfig,
) {
runtime.apply_auth_config(config);
runtime.set_cache_ttl(crate::core::config::CacheTtl::FiveMinutes);
}
#[cfg(test)]
mod cache_ttl_policy_tests {
use super::apply_subagent_runtime_policy;
use crate::core::config::CacheTtl;
#[tokio::test]
async fn subagent_policy_forces_five_minutes_even_when_parent_is_one_hour() {
let mut parent_config = crate::config::SynapsConfig::default();
parent_config.cache_ttl = CacheTtl::OneHour;
let mut runtime = crate::Runtime::new().await
.expect("Runtime::new() must succeed in test environment");
runtime.set_cache_ttl(CacheTtl::OneHour);
assert_eq!(
runtime.cache_ttl(),
CacheTtl::OneHour,
"pre-condition: runtime must be at OneHour before applying subagent policy"
);
apply_subagent_runtime_policy(&mut runtime, &parent_config);
assert_eq!(
runtime.cache_ttl(),
CacheTtl::FiveMinutes,
"subagent spawn must always use 5m TTL, even when parent config is 1h \
(paying 1h write premium on short-lived one-shots is unrecoverable waste)"
);
}
#[tokio::test]
async fn subagent_policy_forces_five_minutes_even_when_parent_is_hybrid() {
let mut parent_config = crate::config::SynapsConfig::default();
parent_config.cache_ttl = CacheTtl::Hybrid;
let mut runtime = crate::Runtime::new().await
.expect("Runtime::new() must succeed in test environment");
runtime.set_cache_ttl(CacheTtl::Hybrid);
assert_eq!(runtime.cache_ttl(), CacheTtl::Hybrid, "pre-condition: must be Hybrid");
apply_subagent_runtime_policy(&mut runtime, &parent_config);
assert_eq!(
runtime.cache_ttl(),
CacheTtl::FiveMinutes,
"subagent spawn must always use 5m TTL, even when parent config is hybrid"
);
}
#[tokio::test]
async fn subagent_policy_is_idempotent_when_parent_already_five_minutes() {
let parent_config = crate::config::SynapsConfig::default();
let mut runtime = crate::Runtime::new().await
.expect("Runtime::new() must succeed in test environment");
assert_eq!(runtime.cache_ttl(), CacheTtl::FiveMinutes, "pre-condition: Runtime::new() must default to 5m");
apply_subagent_runtime_policy(&mut runtime, &parent_config);
assert_eq!(
runtime.cache_ttl(),
CacheTtl::FiveMinutes,
"subagent spawn must stay 5m when parent is already 5m (idempotent)"
);
}
}