D: D3 peer wording, peers://status and peer-aware prompts
Server instructions and the eight tool descriptions mention peers and the untrusted-data rule only while a registry is configured. peers://status returns the list_peers JSON and is advertised only then. diagnose_unit and container_health_report take an optional validated peer argument.
This commit is contained in:
1 parent
ae09f0530c
commit
5237e772d4
5 files changed
+466
-162
No files matched your search
+112
-1
@@ -95,6 +95,10 @@ impl Harness {
|
||||
}
|
||||
|
||||
async fn open(&self) -> String {
|
||||
self.init().await.0
|
||||
}
|
||||
|
||||
async fn init(&self) -> (String, serde_json::Value) {
|
||||
let (status, head, body) = self.post(init_body(), None).await;
|
||||
assert_eq!(status, 200, "{head}\n{body}");
|
||||
let sid = head
|
||||
@@ -110,7 +114,7 @@ impl Harness {
|
||||
)
|
||||
.await;
|
||||
assert_eq!(status, 202);
|
||||
sid
|
||||
(sid, rpc(&body))
|
||||
}
|
||||
|
||||
async fn rpc(&self, sid: &str, body: &str) -> serde_json::Value {
|
||||
@@ -350,3 +354,110 @@ async fn peer_argument_without_configuration_is_a_tool_error() {
|
||||
assert_eq!(v["result"]["isError"], true, "{v}");
|
||||
assert!(result_text(&v).contains("peer beta: unknown peer"), "{v}");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn instructions_and_prompts_mention_peers_only_when_enabled() {
|
||||
let fake = FakeTransport::new();
|
||||
let h = start(peers_state(&fake)).await;
|
||||
let (sid, init) = h.init().await;
|
||||
let instructions = init["result"]["instructions"].as_str().unwrap();
|
||||
assert!(instructions.contains("list_peers"), "{instructions}");
|
||||
assert!(instructions.contains("untrusted data"), "{instructions}");
|
||||
|
||||
let v = h
|
||||
.rpc(&sid, r#"{"jsonrpc":"2.0","id":2,"method":"prompts/list"}"#)
|
||||
.await;
|
||||
for prompt in v["result"]["prompts"].as_array().unwrap() {
|
||||
let args = prompt["arguments"].as_array().cloned().unwrap_or_default();
|
||||
let peer = args.iter().find(|a| a["name"] == "peer");
|
||||
assert!(
|
||||
peer.is_some(),
|
||||
"{} must advertise the peer argument: {prompt}",
|
||||
prompt["name"]
|
||||
);
|
||||
assert_ne!(peer.unwrap()["required"], true);
|
||||
}
|
||||
let v = h
|
||||
.rpc(
|
||||
&sid,
|
||||
r#"{"jsonrpc":"2.0","id":3,"method":"prompts/get","params":{"name":"diagnose_unit","arguments":{"name":"nginx.service","peer":"beta"}}}"#,
|
||||
)
|
||||
.await;
|
||||
let text = v["result"]["messages"][0]["content"]["text"]
|
||||
.as_str()
|
||||
.unwrap();
|
||||
assert!(text.contains("peer `beta`"), "{text}");
|
||||
assert!(text.contains("untrusted data"), "{text}");
|
||||
|
||||
// Peers off: no peer arguments, no peer wording.
|
||||
let h = start(local_state()).await;
|
||||
let (sid, init) = h.init().await;
|
||||
let instructions = init["result"]["instructions"].as_str().unwrap();
|
||||
assert!(
|
||||
!instructions.to_ascii_lowercase().contains("peer"),
|
||||
"{instructions}"
|
||||
);
|
||||
let v = h
|
||||
.rpc(&sid, r#"{"jsonrpc":"2.0","id":2,"method":"prompts/list"}"#)
|
||||
.await;
|
||||
for prompt in v["result"]["prompts"].as_array().unwrap() {
|
||||
for arg in prompt["arguments"].as_array().cloned().unwrap_or_default() {
|
||||
assert_ne!(arg["name"], "peer", "{}", prompt["name"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn peers_status_resource() {
|
||||
let fake = FakeTransport::new();
|
||||
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 v = h
|
||||
.rpc(
|
||||
&sid,
|
||||
r#"{"jsonrpc":"2.0","id":3,"method":"resources/read","params":{"uri":"peers://status"}}"#,
|
||||
)
|
||||
.await;
|
||||
let text = v["result"]["contents"][0]["text"].as_str().unwrap();
|
||||
let status: serde_json::Value = serde_json::from_str(text).unwrap();
|
||||
assert_eq!(status["peers"].as_array().unwrap().len(), 2, "{status}");
|
||||
|
||||
// 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 v = h
|
||||
.rpc(
|
||||
&sid,
|
||||
r#"{"jsonrpc":"2.0","id":3,"method":"resources/read","params":{"uri":"peers://status"}}"#,
|
||||
)
|
||||
.await;
|
||||
assert!(v["error"].is_object(), "{v}");
|
||||
}
|
||||
Reference in new issue
Block a user