//! AT-3.14-01 / AT-3.14-04: `prompts/list` serves exactly the bound Published Prompt Versions with //! revision-scoped pagination and typed argument metadata; Draft, unbound and foreign Prompts of //! another Agent are never disclosed. Every case runs on both supported protocol revisions, because //! AC-4 requires the behaviour to be proven per revision and the legacy era resolves workspace and //! Agent from the initialized session instead of the request body. use serde_json::{Value, json}; use super::fixtures::*; fn names(page: &Value) -> Vec { page["result"]["prompts"] .as_array() .unwrap_or_else(|| panic!("prompts/list must carry a prompts array: {page}")) .iter() .map(|prompt| prompt["name"].as_str().unwrap_or_default().to_owned()) .collect() } #[tokio::test] async fn list_serves_only_bound_published_prompts_with_typed_arguments() { let endpoint = prompt_endpoint().await; for revision in [MODERN_REVISION, LEGACY_REVISION] { let body = endpoint .on_revision(revision, "prompts/list", json!({}), None) .await; assert!( body.get("error").is_none(), "prompts/list must succeed on {revision}: {body}" ); let listed = names(&body); assert_eq!( listed, BOUND_PROMPT_NAMES, "only the bound Published Prompt Versions may be listed on {revision}: {body}" ); for excluded in ["draft-prompt", "other-agent-prompt"] { assert!( !listed.contains(&excluded.to_owned()), "{excluded} must not be discoverable on {revision}: {body}" ); } let greeting = body["result"]["prompts"] .as_array() .unwrap() .iter() .find(|prompt| prompt["name"] == json!("greeting")) .expect("the bound greeting is listed"); assert_eq!(greeting["description"], json!("Greets the customer")); let arguments = greeting["arguments"] .as_array() .expect("the listed Prompt must carry argument metadata"); assert_eq!( arguments.len(), 2, "both arguments are advertised on {revision}: {greeting}" ); assert_eq!(arguments[0]["name"], json!("name")); assert_eq!(arguments[0]["required"], json!(true)); assert_eq!(arguments[0]["schema"]["type"], json!("string")); assert_eq!(arguments[1]["name"], json!("tone")); assert_eq!(arguments[1]["required"], json!(false)); assert_eq!(arguments[1]["schema"]["enum"], json!(["warm", "dry"])); assert_eq!(arguments[1]["default"], json!("warm")); assert!( greeting.get("messages").is_none(), "discovery must not disclose message content on {revision}: {greeting}" ); } } #[tokio::test] async fn list_paginates_deterministically_and_binds_the_cursor_to_the_revision() { let endpoint = prompt_endpoint().await; for revision in [MODERN_REVISION, LEGACY_REVISION] { let first = endpoint .on_revision(revision, "prompts/list", json!({"limit": 2}), None) .await; let cursor = first["result"]["nextCursor"] .as_str() .unwrap_or_else(|| { panic!("a bounded first page must carry a continuation on {revision}: {first}") }) .to_owned(); assert_eq!( names(&first), vec!["greeting", "review"], "the first page is deterministic on {revision}: {first}" ); let second = endpoint .on_revision( revision, "prompts/list", json!({"cursor": cursor.clone(), "limit": 2}), None, ) .await; assert_eq!( names(&second), vec!["archived-prompt"], "the continuation serves the next bound slice and nothing else on {revision}: {second}" ); assert!( second["result"].get("nextCursor").is_none(), "the last page carries no continuation on {revision}: {second}" ); // A page is never mixed across protocol revisions: the other era refuses this cursor. let other_revision = match revision { MODERN_REVISION => LEGACY_REVISION, _ => MODERN_REVISION, }; let cross_revision = endpoint .on_revision( other_revision, "prompts/list", json!({"cursor": cursor.clone()}), None, ) .await; assert_eq!( cross_revision["error"]["code"], json!(-32602), "a {revision} cursor must be refused as invalid params on {other_revision}: {cross_revision}" ); // A malformed token is invalid params, never the first page. let malformed = endpoint .on_revision( revision, "prompts/list", json!({"cursor": "not-a-cursor"}), None, ) .await; assert_eq!( malformed["error"]["code"], json!(-32602), "a malformed cursor is invalid params on {revision}: {malformed}" ); } } #[tokio::test] async fn list_of_an_agent_shows_only_its_own_bound_snapshot() { let endpoint = prompt_endpoint().await; // The other Agent binds exactly one Prompt; it must not see the sales Agent's snapshot. let other_key = endpoint.other_agent_key().await; for revision in [MODERN_REVISION, LEGACY_REVISION] { let body = endpoint .on_revision_for( OTHER_AGENT_SLUG, &other_key, revision, "prompts/list", json!({}), None, ) .await; assert_eq!( names(&body), vec!["other-agent-prompt"], "an Agent sees only its own bound snapshot on {revision}: {body}" ); } }