Craft Anything: understand how any software works, and craft your own.
Rust
Testing a coding agent says it only checked the program's version (#49)
BFlat34adf21094c8
diff --git a/crates/ai/src/lib.rs b/crates/ai/src/lib.rsindex eec439af..4bcfa08d 100644--- a/crates/ai/src/lib.rs+++ b/crates/ai/src/lib.rs@@ -211,6 +211,10 @@ pub struct TestReport {pub model: String,pub latency_ms: u64,pub reply: String,+ /// Only the coding agent's `--version` ran (`reply` is its first line): it's installed, but+ /// whether it's signed in, has a model and quota shows only when it gets a message (#48).+ #[serde(default)]+ pub version_only: bool,}/// Text kept in the journal for a user message (bounded).@@ -565,7 +569,8 @@ impl AiHub {}}- /// Send a tiny request and time it. Blocking (bounded); run it off the UI thread.+ /// Send a tiny request and time it; a coding agent only runs `--version`, so its report says+ /// `version_only`. Blocking (bounded); run it off the UI thread.pub fn test_backend(&self, name: &str) -> Result<TestReport, ToolError> {let e = self.entry(name)?;let start = Instant::now();@@ -581,6 +586,7 @@ impl AiHub {model: e.config.model.clone(),latency_ms: start.elapsed().as_millis() as u64,reply: out.stdout_text().lines().next().unwrap_or_default().trim().to_string(),+ version_only: true,});}let mut slot = self.build_model(&e)?;@@ -602,6 +608,7 @@ impl AiHub {model: if r.model.is_empty() { model } else { r.model },latency_ms: start.elapsed().as_millis() as u64,reply: r.message.text().trim().to_string(),+ version_only: false,})}diff --git a/crates/ai/src/tests.rs b/crates/ai/src/tests.rsindex 49444f23..afaabe9a 100644--- a/crates/ai/src/tests.rs+++ b/crates/ai/src/tests.rs@@ -84,6 +84,19 @@ pub(crate) fn serve(status: &'static str, body: &'static str) -> String {base}+/// #48: a coding agent's test only runs `--version`, and its report says so.+#[test]+fn a_coding_agent_test_says_it_only_checked_the_version() {+ let (h, _d) = hub();+ let config = BackendConfig { name: "Agent".into(), kind: BackendKind::AgentCli, model: "opencode".into(), base_url: None, ssh_host: None, enabled: true };+ // cargo stands in for the agent's program: it's there wherever these tests run.+ let options = BackendOptions { command: Some("cargo".into()), ..Default::default() };+ h.add_backend_with(BackendEntry { config, options }, None).unwrap();+ let r = h.test_backend("Agent").unwrap();+ assert!(r.version_only && r.reply.starts_with("cargo "), "{r:?}");+ assert_eq!(serde_json::to_value(&r).unwrap()["version_only"], true, "the CLI's ai test prints it");+}+/// #37: doctor asks a local server for its models instead of trusting an open port.#[test]fn a_local_server_is_reachable_only_when_it_lists_models() {@@ -345,7 +358,7 @@ fn hub_config_keys_and_test_backend() {assert_eq!(h.backends().len(), 2);assert!(h.has_key("Claude") && h.has_key("Local"));let r = h.test_backend("Claude").unwrap();- assert_eq!(r.reply, "ready");+ assert_eq!((r.reply.as_str(), r.version_only), ("ready", false));assert_eq!(r.model, "claude-haiku-5-5");assert_eq!(seen.lock().unwrap()[0].body["output_config"]["effort"], "high");assert_eq!(h.list_models("Claude").unwrap(), vec!["claude-opus-5-5", "claude-haiku-5-5"]);