#![allow(clippy::unwrap_used, clippy::expect_used)]
use agentgear::{
AgentBackend, BackendState, Capabilities, CheckStatus, Desired, DoctorCheck, DoctorReport, Error, Outcome, Plugin, Result, Scope,
Source,
};
struct FakeAgent;
impl AgentBackend for FakeAgent {
fn id(&self) -> &'static str {
"fake"
}
fn detect(&self) -> bool {
true
}
fn capabilities(&self) -> Capabilities {
Capabilities {
plugins: false,
mcp: true,
hooks: false,
commands: false,
agents: false,
skills: false,
instructions: false,
scopes: &["user"],
}
}
fn probe(&self, _plugin: &Plugin, _scope: &Scope, _source: &Source) -> Result<BackendState> {
Ok(BackendState::Healthy)
}
fn reconcile(&self, _plugin: &Plugin, _desired: &Desired, _scope: &Scope) -> Result<Outcome> {
Err(Error::Backend { agent: "fake".into(), detail: "config write refused".into() })
}
fn remove(&self, _plugin: &Plugin, _scope: &Scope, _source: &Source) -> Result<Outcome> {
Ok(Outcome::Removed)
}
fn report(&self, _plugin: &Plugin, _source: &Source) -> DoctorReport {
DoctorReport::from_checks(vec![DoctorCheck {
name: "fake backend reachable",
status: CheckStatus::Ok("constructed out of crate".into()),
}])
}
}
#[test]
fn external_backend_constructs_report_and_error() {
let fake = FakeAgent;
assert_eq!(fake.id(), "fake");
assert!(fake.capabilities().mcp);
let boxed: Box<dyn AgentBackend> = Box::new(FakeAgent);
assert!(boxed.detect());
}
#[test]
fn from_error_collapses_to_a_failed_check() {
let report = DoctorReport::from_error(Error::Backend { agent: "fake".into(), detail: "boom".into() });
assert!(!report.is_healthy());
let rendered = report.to_string();
assert!(rendered.contains("fake: boom"), "rendered: {rendered}");
}
#[test]
fn backend_error_renders_agent_and_detail() {
let err = Error::Backend { agent: "fake".into(), detail: "config write refused".into() };
assert_eq!(err.to_string(), "fake: config write refused");
}