use std::time::Duration;
use meerkat_core::ShellDefaults;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ToolTimeoutPolicy {
default_timeout: Duration,
}
impl ToolTimeoutPolicy {
pub const fn new(default_timeout: Duration) -> Self {
Self { default_timeout }
}
pub const fn default_timeout(self) -> Duration {
self.default_timeout
}
pub const fn default_timeout_secs(self) -> u64 {
self.default_timeout.as_secs()
}
}
impl Default for ToolTimeoutPolicy {
fn default() -> Self {
Self {
default_timeout: Duration::from_secs(ShellDefaults::default().timeout_secs),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn single_policy_value_flows_to_both_call_sites() {
let policy = ToolTimeoutPolicy::default();
assert_eq!(
Duration::from_secs(policy.default_timeout_secs()),
policy.default_timeout(),
"shell-seconds view and dispatcher Duration view must agree"
);
assert_eq!(
policy.default_timeout_secs(),
ShellDefaults::default().timeout_secs,
"policy default must equal the canonical config-layer default"
);
let custom = ToolTimeoutPolicy::new(Duration::from_secs(123));
assert_eq!(custom.default_timeout(), Duration::from_secs(123));
assert_eq!(custom.default_timeout_secs(), 123);
assert_ne!(
custom.default_timeout(),
ToolTimeoutPolicy::default().default_timeout(),
"a changed policy must differ from the default in the dispatcher view"
);
assert_ne!(
custom.default_timeout_secs(),
ToolTimeoutPolicy::default().default_timeout_secs(),
"a changed policy must differ from the default in the shell view"
);
}
}