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
@@ -9,7 +9,7 @@ Part of [Phase 5: Consolidator](README.md). Contracts: [contracts.md](contracts.
|
|||||||
| Depends on | B (and C2 client call shared, not duplicated). In practice: A0 for compiling; `PeerRegistry::get` from A0 (unhardened forwarder) until C2 lands; develop against `FakeTransport` + `registry_with` |
|
| Depends on | B (and C2 client call shared, not duplicated). In practice: A0 for compiling; `PeerRegistry::get` from A0 (unhardened forwarder) until C2 lands; develop against `FakeTransport` + `registry_with` |
|
||||||
| Blocks | F |
|
| Blocks | F |
|
||||||
| Can start when | A0 is merged (the rmcp conditional-tools spike can start on day one, it needs nothing from peers) |
|
| Can start when | A0 is merged (the rmcp conditional-tools spike can start on day one, it needs nothing from peers) |
|
||||||
| Owned files | `src/mcp/mod.rs`, `src/mcp/prompts.rs`, `src/mcp/resources.rs`, tool-list snapshot test (in `src/mcp/mod.rs`), a new `src/mcp/peers.rs` if the code is easier to keep apart (WS-D may add it) |
|
| Owned files | `src/mcp/mod.rs`, `src/mcp/prompts.rs`, `src/mcp/resources.rs`, tool-list snapshot test (in `src/mcp/mod.rs`), a new `src/mcp/peers.rs` if the code is easier to keep apart (WS-D may add it), new `tests/mcp_peers.rs` |
|
||||||
| Do not touch | `src/api/**` (C, B), `src/peers/**` (A, B, C), `src/state.rs`, `src/server.rs`, `src/telemetry/**`, `src/error.rs`, `docs/api.md`, `README.md`, `AGENTS.md` (F4 edits the tool-count line), `nix/**`, `Cargo.toml` |
|
| Do not touch | `src/api/**` (C, B), `src/peers/**` (A, B, C), `src/state.rs`, `src/server.rs`, `src/telemetry/**`, `src/error.rs`, `docs/api.md`, `README.md`, `AGENTS.md` (F4 edits the tool-count line), `nix/**`, `Cargo.toml` |
|
||||||
|
|
||||||
Shared-file seams: WS-D is the only editor of `src/mcp/**`. It reads `AppState.peers` (A0) and calls `PeerRegistry::get` / `snapshot` / `status`; it never builds URLs or headers itself. The MCP `service()` function must keep working unchanged when `state.peers` is `None`.
|
Shared-file seams: WS-D is the only editor of `src/mcp/**`. It reads `AppState.peers` (A0) and calls `PeerRegistry::get` / `snapshot` / `status`; it never builds URLs or headers itself. The MCP `service()` function must keep working unchanged when `state.peers` is `None`.
|
||||||
|
|||||||
@@ -43,6 +43,20 @@ const PEER_AWARE: [&str; 8] = [
|
|||||||
/// Tools that only exist while peers are configured.
|
/// Tools that only exist while peers are configured.
|
||||||
const PEER_TOOLS: [&str; 2] = ["get_peer", "list_peers"];
|
const PEER_TOOLS: [&str; 2] = ["get_peer", "list_peers"];
|
||||||
|
|
||||||
|
/// Every tool visible while peers are configured, sorted by name.
|
||||||
|
///
|
||||||
|
/// Shared with the integration snapshot so the expected list is not copied
|
||||||
|
/// into the test.
|
||||||
|
pub fn tool_names() -> Vec<&'static str> {
|
||||||
|
let mut names: Vec<&'static str> = PEER_AWARE
|
||||||
|
.iter()
|
||||||
|
.chain(PEER_TOOLS.iter())
|
||||||
|
.copied()
|
||||||
|
.collect();
|
||||||
|
names.sort_unstable();
|
||||||
|
names
|
||||||
|
}
|
||||||
|
|
||||||
/// The two list tools took no parameters before the peer argument existed, so
|
/// The two list tools took no parameters before the peer argument existed, so
|
||||||
/// their schema carried no `$schema` key; `schemars` adds one to derived
|
/// their schema carried no `$schema` key; `schemars` adds one to derived
|
||||||
/// parameters. Dropping it keeps the peers-off schema byte-identical.
|
/// parameters. Dropping it keeps the peers-off schema byte-identical.
|
||||||
|
|||||||
+17
-41
@@ -130,6 +130,18 @@ impl Harness {
|
|||||||
self.rpc(sid, &body).await
|
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> {
|
async fn tools(&self, sid: &str) -> Vec<serde_json::Value> {
|
||||||
let v = self
|
let v = self
|
||||||
.rpc(sid, r#"{"jsonrpc":"2.0","id":9,"method":"tools/list"}"#)
|
.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 tools = h.tools(&sid).await;
|
||||||
let mut names: Vec<&str> = tools.iter().map(|t| t["name"].as_str().unwrap()).collect();
|
let mut names: Vec<&str> = tools.iter().map(|t| t["name"].as_str().unwrap()).collect();
|
||||||
names.sort();
|
names.sort();
|
||||||
assert_eq!(
|
assert_eq!(names, skyg_linux_tracker::mcp::peers::tool_names());
|
||||||
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");
|
let units = tool(&tools, "list_systemd_units");
|
||||||
assert!(
|
assert!(
|
||||||
units["inputSchema"]["properties"]["peer"].is_object(),
|
units["inputSchema"]["properties"]["peer"].is_object(),
|
||||||
@@ -413,19 +411,8 @@ async fn peers_status_resource() {
|
|||||||
let h = start(peers_state(&fake)).await;
|
let h = start(peers_state(&fake)).await;
|
||||||
let sid = h.open().await;
|
let sid = h.open().await;
|
||||||
|
|
||||||
let v = h
|
let uris = h.resource_uris(&sid).await;
|
||||||
.rpc(
|
assert!(uris.iter().any(|u| u == "peers://status"), "{uris:?}");
|
||||||
&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 v = h
|
let v = h
|
||||||
.rpc(
|
.rpc(
|
||||||
@@ -440,19 +427,8 @@ async fn peers_status_resource() {
|
|||||||
// Absent entirely when peers are off: not listed, not readable.
|
// Absent entirely when peers are off: not listed, not readable.
|
||||||
let h = start(local_state()).await;
|
let h = start(local_state()).await;
|
||||||
let sid = h.open().await;
|
let sid = h.open().await;
|
||||||
let v = h
|
let uris = h.resource_uris(&sid).await;
|
||||||
.rpc(
|
assert!(!uris.iter().any(|u| u == "peers://status"), "{uris:?}");
|
||||||
&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 v = h
|
let v = h
|
||||||
.rpc(
|
.rpc(
|
||||||
&sid,
|
&sid,
|
||||||
|
|||||||
Reference in new issue
Block a user