D: D2 list_peers and get_peer behind peers.enabled

The two status tools and the optional peer argument exist only when a
registry is configured. rmcp's disable_route hides the tools; the eight
shared schemas lose the optional peer property, and the two list tools also
lose the derived $schema key, so the peers-off list and schemas match a
build without the feature byte for byte. Both snapshot variants and the
wire-level tool list are asserted.
This commit is contained in:
ari committed 2026-10-19 22:59:49 -04:00
1 parent d3285a994b
commit ae09f0530c
3 files changed
+357 -12

No files matched your search

+122 -3
View File
@@ -113,13 +113,24 @@ impl Harness {
sid
}
async fn rpc(&self, sid: &str, body: &str) -> serde_json::Value {
let (status, head, text) = self.post(body, Some(sid)).await;
assert_eq!(status, 200, "{head}\n{text}");
rpc(&text)
}
async fn call(&self, sid: &str, id: u32, tool: &str, arguments: &str) -> serde_json::Value {
let body = format!(
r#"{{"jsonrpc":"2.0","id":{id},"method":"tools/call","params":{{"name":"{tool}","arguments":{arguments}}}}}"#
);
let (status, head, text) = self.post(&body, Some(sid)).await;
assert_eq!(status, 200, "{head}\n{text}");
rpc(&text)
self.rpc(sid, &body).await
}
async fn tools(&self, sid: &str) -> Vec<serde_json::Value> {
let v = self
.rpc(sid, r#"{"jsonrpc":"2.0","id":9,"method":"tools/list"}"#)
.await;
v["result"]["tools"].as_array().expect("tools").clone()
}
}
@@ -149,6 +160,114 @@ fn result_text(v: &serde_json::Value) -> String {
.to_owned()
}
fn tool<'a>(tools: &'a [serde_json::Value], name: &str) -> &'a serde_json::Value {
tools
.iter()
.find(|t| t["name"] == name)
.unwrap_or_else(|| panic!("tool {name} missing from {tools:?}"))
}
#[tokio::test]
async fn tool_list_is_ten_with_peers_and_eight_without() {
let fake = FakeTransport::new();
let h = start(peers_state(&fake)).await;
let sid = h.open().await;
let tools = h.tools(&sid).await;
let mut names: Vec<&str> = tools.iter().map(|t| t["name"].as_str().unwrap()).collect();
names.sort();
assert_eq!(
names,
[
"get_container",
"get_container_logs",
"get_journal_logs",
"get_peer",
"get_systemd_unit",
"list_containers",
"list_peers",
"list_systemd_timers",
"list_systemd_units",
"tail_journal"
]
);
let units = tool(&tools, "list_systemd_units");
assert!(
units["inputSchema"]["properties"]["peer"].is_object(),
"{units}"
);
assert!(
units["inputSchema"]["required"]
.as_array()
.is_none_or(|r| r.is_empty()),
"peer and state are optional: {units}"
);
let h = start(local_state()).await;
let sid = h.open().await;
let tools = h.tools(&sid).await;
let mut names: Vec<&str> = tools.iter().map(|t| t["name"].as_str().unwrap()).collect();
names.sort();
assert_eq!(names.len(), 8, "{names:?}");
assert!(!names.contains(&"list_peers"));
assert!(!names.contains(&"get_peer"));
for t in &tools {
let props = &t["inputSchema"]["properties"];
assert!(
props.get("peer").is_none(),
"{} must not advertise peer when peers are off: {t}",
t["name"]
);
assert!(
!t["description"].as_str().unwrap_or("").contains("peer"),
"{}",
t["name"]
);
}
}
#[tokio::test]
async fn list_peers_and_get_peer_tools() {
let fake = FakeTransport::new();
let h = start(peers_state(&fake)).await;
let sid = h.open().await;
let v = h.call(&sid, 2, "list_peers", "{}").await;
assert_eq!(v["result"]["isError"], false, "{v}");
let body: serde_json::Value = serde_json::from_str(&result_text(&v)).unwrap();
let mut names: Vec<&str> = body["peers"]
.as_array()
.unwrap()
.iter()
.map(|p| p["name"].as_str().unwrap())
.collect();
names.sort();
assert_eq!(names, ["beta", "gamma"]);
assert!(body["peers"][0].get("server").is_some());
let v = h.call(&sid, 3, "get_peer", r#"{"name":"beta"}"#).await;
assert_eq!(v["result"]["isError"], false, "{v}");
let v = h.call(&sid, 4, "get_peer", r#"{"name":"nope"}"#).await;
assert_eq!(v["result"]["isError"], true, "{v}");
assert!(result_text(&v).contains("not_found"), "{v}");
}
#[tokio::test]
async fn peer_tools_are_absent_without_configuration() {
let h = start(local_state()).await;
let sid = h.open().await;
let v = h.call(&sid, 2, "list_peers", "{}").await;
let error = &v["error"];
assert!(error.is_object(), "{v}");
assert!(
error["message"]
.as_str()
.unwrap_or("")
.contains("tool not found"),
"{v}"
);
}
#[tokio::test]
async fn peer_argument_reads_through_the_consolidator() {
let fake = FakeTransport::new();