D: share tool-name fixture and dedupe MCP peer tests
This commit is contained in:
1 parent
d1bec4a3d8
commit
e2c553dbe4
3 files changed
+32
-42
No files matched your search
+17
-41
@@ -130,6 +130,18 @@ impl Harness {
|
||||
self.rpc(sid, &body).await
|
||||
}
|
||||
|
||||
async fn resource_uris(&self, sid: &str) -> Vec<String> {
|
||||
let v = self
|
||||
.rpc(sid, r#"{"jsonrpc":"2.0","id":2,"method":"resources/list"}"#)
|
||||
.await;
|
||||
v["result"]["resources"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|r| r["uri"].as_str().unwrap().to_owned())
|
||||
.collect()
|
||||
}
|
||||
|
||||
async fn tools(&self, sid: &str) -> Vec<serde_json::Value> {
|
||||
let v = self
|
||||
.rpc(sid, r#"{"jsonrpc":"2.0","id":9,"method":"tools/list"}"#)
|
||||
@@ -179,21 +191,7 @@ async fn tool_list_is_ten_with_peers_and_eight_without() {
|
||||
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"
|
||||
]
|
||||
);
|
||||
assert_eq!(names, skyg_linux_tracker::mcp::peers::tool_names());
|
||||
let units = tool(&tools, "list_systemd_units");
|
||||
assert!(
|
||||
units["inputSchema"]["properties"]["peer"].is_object(),
|
||||
@@ -413,19 +411,8 @@ async fn peers_status_resource() {
|
||||
let h = start(peers_state(&fake)).await;
|
||||
let sid = h.open().await;
|
||||
|
||||
let v = h
|
||||
.rpc(
|
||||
&sid,
|
||||
r#"{"jsonrpc":"2.0","id":2,"method":"resources/list"}"#,
|
||||
)
|
||||
.await;
|
||||
let uris: Vec<&str> = v["result"]["resources"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|r| r["uri"].as_str().unwrap())
|
||||
.collect();
|
||||
assert!(uris.contains(&"peers://status"), "{uris:?}");
|
||||
let uris = h.resource_uris(&sid).await;
|
||||
assert!(uris.iter().any(|u| u == "peers://status"), "{uris:?}");
|
||||
|
||||
let v = h
|
||||
.rpc(
|
||||
@@ -440,19 +427,8 @@ async fn peers_status_resource() {
|
||||
// Absent entirely when peers are off: not listed, not readable.
|
||||
let h = start(local_state()).await;
|
||||
let sid = h.open().await;
|
||||
let v = h
|
||||
.rpc(
|
||||
&sid,
|
||||
r#"{"jsonrpc":"2.0","id":2,"method":"resources/list"}"#,
|
||||
)
|
||||
.await;
|
||||
let uris: Vec<&str> = v["result"]["resources"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|r| r["uri"].as_str().unwrap())
|
||||
.collect();
|
||||
assert!(!uris.contains(&"peers://status"), "{uris:?}");
|
||||
let uris = h.resource_uris(&sid).await;
|
||||
assert!(!uris.iter().any(|u| u == "peers://status"), "{uris:?}");
|
||||
let v = h
|
||||
.rpc(
|
||||
&sid,
|
||||
|
||||
Reference in new issue
Block a user