Files
crank/apps/mcp-server/tests/integration/mcp_prompts/get.rs
T
bsodfather 54ce770682
CI / Rust Checks (pull_request) Failing after 13m41s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped
Community Release / release (push) Failing after 13m33s
feat(epic3): deliver the accepted Epic 3 scope through Story 3.17
Recovery delivery of the accumulated, TL-accepted Epic 3 work that had never been
committed to Git (stories 3.6-3.17, see the crank board). Story 3.18 is not accepted
yet and is deliberately excluded: its logging surface, its capability registration,
its oracle projections and its tests are not part of this tree.

Accepted scope
- 3.6 typed static Resource Drafts; 3.7 publication and exact binding of static
  Resource Versions; 3.8 MCP discovery/read and revocation of static Resources;
- 3.9 Resource import/export in API and UI plus TLS dependency maintenance;
  3.10 REST-backed Resource templates; 3.11 shared REST read runtime and the MCP
  revision/capability foundation;
- 3.12 parameterised Prompt Drafts with preview; 3.13 Prompt publication and exact
  version binding to Agents; 3.14 MCP prompts; 3.15 Prompt import/export;
- 3.16 composite Prompts with published Resources (dependency content scan plus
  dynamic read through the accepted 3.11 runtime, admin preview and MCP prompts/get);
- 3.17 bounded MCP completion suggestions from typed published schemas and the
  resources/list admission fix for bound template publications.

Accepted evidence being reused (unchanged code paths)
- 3.16 candidate: core 7, admin-api 22, registry 4, mcp-server 4, UI 6; one final
  `just verify` run 1651 passed / 0 failed / 2 ignored.
- 3.17 candidate: full run 1672 passed / 0 failed / 2 ignored, QA targeted reruns and
  a real MCP Inspector 2.12.0 client smoke.

Delivery engineering in this commit
- CI: one event per change (feature branches are gated by their pull request, push
  runs only on main), story events run the changed packages, the full workspace suite
  stays the feature/release gate; no cache/sharding without a measured runner check.
- Release: the packaged archives, checksums and SBOM are now uploaded to the Gitea
  release entry of the tag instead of dying with the runner workspace.

Not included on purpose: Story 3.18 work, build caches, runtime databases, local
credentials and scratch evidence.

Refs: crank kanban t_e39d7263; baseline 1b6db09bd1.
2026-10-25 09:08:22 +00:00

349 lines
12 KiB
Rust

//! AT-3.14-02 / AT-3.14-03 / AT-3.14-04: `prompts/get` renders one exact bound Published Prompt
//! Version deterministically, rejects every invalid argument before rendering, keeps an archived
//! bound version readable, and never serves another Agent's snapshot. Every case runs on both
//! supported protocol revisions: the legacy era resolves workspace and Agent from the initialized
//! session, so its snapshot selection is proven separately below.
use crank_core::prompt::MAX_TEXT_BYTES;
use crank_registry::RegistryError;
use crank_registry::model::AgentPromptBinding;
use serde_json::{Value, json};
use super::fixtures::*;
fn messages(body: &Value) -> &Vec<Value> {
body["result"]["messages"]
.as_array()
.unwrap_or_else(|| panic!("prompts/get must carry messages: {body}"))
}
fn greeting_messages() -> Vec<Value> {
vec![
json!({"role": "system", "content": {"type": "text", "text": "Be brief."}}),
json!({"role": "user", "content": {"type": "text", "text": "Hello Ada"}}),
]
}
#[tokio::test]
async fn get_renders_typed_arguments_deterministically_on_both_revisions() {
let endpoint = prompt_endpoint().await;
for revision in [MODERN_REVISION, LEGACY_REVISION] {
let body = endpoint
.on_revision(
revision,
"prompts/get",
json!({"name": "greeting", "arguments": {"name": "Ada"}}),
Some("greeting"),
)
.await;
assert_eq!(
body["result"]["description"],
json!("Greets the customer"),
"the bound description is served on {revision}: {body}"
);
assert_eq!(
messages(&body),
&greeting_messages(),
"the typed renderer output is served unchanged on {revision}: {body}"
);
let repeated = endpoint
.on_revision(
revision,
"prompts/get",
json!({"name": "greeting", "arguments": {"name": "Ada"}}),
Some("greeting"),
)
.await;
assert_eq!(
body, repeated,
"rendering is deterministic on {revision}: {repeated}"
);
// The rendered enum/default argument path is accepted too.
let with_tone = endpoint
.on_revision(
revision,
"prompts/get",
json!({"name": "greeting", "arguments": {"name": "Ada", "tone": "dry"}}),
Some("greeting"),
)
.await;
assert_eq!(
messages(&with_tone)[1]["content"],
json!({"type": "text", "text": "Hello Ada"}),
"an explicit enum value still renders the bound template on {revision}: {with_tone}"
);
}
}
#[tokio::test]
async fn get_rejects_each_invalid_argument_before_rendering_without_disclosure() {
let endpoint = prompt_endpoint().await;
let oversized = "x".repeat(MAX_TEXT_BYTES + 1);
for revision in [MODERN_REVISION, LEGACY_REVISION] {
for (arguments, reason, argument) in [
(json!({}), "missing_argument", "name"),
(
json!({"name": "Ada", "extra": "x"}),
"unknown_argument",
"extra",
),
(json!({"name": 5}), "argument_invalid", "name"),
(
json!({"name": "Ada", "tone": "loud"}),
"argument_invalid",
"tone",
),
(json!({"name": oversized}), "argument_too_large", "name"),
] {
let body = endpoint
.on_revision(
revision,
"prompts/get",
json!({"name": "greeting", "arguments": arguments}),
Some("greeting"),
)
.await;
assert_eq!(
body["error"]["code"],
json!(-32602),
"{reason} on {revision}: a typed argument rejection is invalid params: {body}"
);
assert_eq!(
body["error"]["data"]["reason"],
json!(reason),
"{reason} on {revision}: {body}"
);
assert_eq!(
body["error"]["data"]["argument"],
json!(argument),
"{reason} on {revision}: {body}"
);
// No partial rendering and no foreign metadata: neither bound content nor any prompt
// message may appear anywhere in the error envelope.
let serialized = body.to_string();
for leaked in [
"Be brief.",
"Hello ",
"Archived but bound.",
"Draft content.",
] {
assert!(
!serialized.contains(leaked),
"{reason} on {revision}: the rejection must not disclose {leaked:?}: {serialized}"
);
}
assert!(
body.get("result").is_none(),
"{reason} on {revision}: a rejected request carries no result: {body}"
);
}
}
}
#[tokio::test]
async fn get_serves_the_archived_bound_version_and_archive_blocks_new_bindings() {
let endpoint = prompt_endpoint().await;
// AT-3.14-03: the immutable snapshot behaviour survives the archive, on every revision.
for revision in [MODERN_REVISION, LEGACY_REVISION] {
let serving = endpoint
.on_revision(
revision,
"prompts/get",
json!({"name": "archived-prompt"}),
Some("archived-prompt"),
)
.await;
assert_eq!(
messages(&serving),
&vec![
json!({"role": "user", "content": {"type": "text", "text": "Archived but bound."}})
],
"an archived Prompt Version bound before the archive keeps serving on {revision}: {serving}"
);
}
// Archive forbids new bindings: the exact version may not be attached to another Agent.
let other_agent = crank_core::AgentId::new(format!("agent_{OTHER_AGENT_SLUG}"));
let rebind = bind_prompts(
&endpoint.registry,
&other_agent,
&[AgentPromptBinding {
prompt_id: endpoint.archived_id.clone(),
prompt_version: 1,
}],
)
.await;
assert!(
matches!(rebind, Err(RegistryError::PromptArchived { .. })),
"archive must refuse new bindings, got {rebind:?}"
);
// Archive forbids new publications of the same Prompt (archived is terminal lifecycle).
let publication = endpoint
.registry
.publish_prompt_draft(crank_registry::model::PublishPromptRequest {
workspace_id: crank_core::WorkspaceId::new("ws_default"),
prompt_id: endpoint.archived_id.clone(),
expected_updated_at: endpoint.archived_updated_at,
published_at: time::OffsetDateTime::now_utc(),
})
.await;
assert!(
matches!(publication, Err(RegistryError::PromptNotDraft { .. })),
"archive must refuse new publications, got {publication:?}"
);
}
#[tokio::test]
async fn get_of_an_unknown_unbound_or_foreign_prompt_is_indistinguishable() {
let endpoint = prompt_endpoint().await;
for revision in [MODERN_REVISION, LEGACY_REVISION] {
for name in [
"draft-prompt",
"other-agent-prompt",
"prm_a_greeting",
"never-existed",
] {
let body = endpoint
.on_revision(revision, "prompts/get", json!({"name": name}), Some(name))
.await;
assert_eq!(
body["error"]["code"],
json!(-32602),
"{name} on {revision}: an unaddressable Prompt is invalid params: {body}"
);
assert_eq!(
body["error"]["message"],
json!("the requested prompt is not available"),
"Draft, unbound, foreign and unknown names share one safe answer on {revision}: {body}"
);
let serialized = body.to_string();
for leaked in ["Other agent secret.", "Draft content.", "Be brief."] {
assert!(
!serialized.contains(leaked),
"{name} on {revision}: leaked {leaked:?}: {serialized}"
);
}
}
}
}
#[tokio::test]
async fn get_serves_the_exact_bound_version_after_a_draft_edit() {
let endpoint = prompt_endpoint().await;
edit_greeting_draft(&endpoint).await;
for revision in [MODERN_REVISION, LEGACY_REVISION] {
let body = endpoint
.on_revision(
revision,
"prompts/get",
json!({"name": "greeting", "arguments": {"name": "Ada"}}),
Some("greeting"),
)
.await;
assert_eq!(
messages(&body)[1]["content"],
json!({"type": "text", "text": "Hello Ada"}),
"the bound v1 snapshot stays immutable after a Draft edit on {revision}: {body}"
);
let listed = endpoint
.on_revision(revision, "prompts/list", json!({}), None)
.await;
assert_eq!(
listed["result"]["prompts"][0]["description"],
json!("Greets the customer"),
"discovery still describes the bound version, not the new Draft, on {revision}: {listed}"
);
}
}
/// The legacy era takes workspace and Agent from the *initialized session*, not from the request
/// body. A session of the other Agent therefore serves that Agent's snapshot, and a Prompt bound to
/// the sales Agent is indistinguishable from an unknown name on it.
#[tokio::test]
async fn legacy_session_serves_only_its_own_agent_snapshot() {
let endpoint = prompt_endpoint().await;
let other_key = endpoint.other_agent_key().await;
let session = endpoint
.legacy_session_for(OTHER_AGENT_SLUG, &other_key)
.await;
let own = endpoint
.legacy_for(
OTHER_AGENT_SLUG,
&other_key,
&session,
"prompts/get",
json!({"name": "other-agent-prompt"}),
)
.await;
assert_eq!(
messages(&own),
&vec![json!({"role": "user", "content": {"type": "text", "text": "Other agent secret."}})],
"the session's own bound snapshot is served: {own}"
);
let listed = endpoint
.legacy_for(
OTHER_AGENT_SLUG,
&other_key,
&session,
"prompts/list",
json!({}),
)
.await;
assert_eq!(
listed["result"]["prompts"]
.as_array()
.expect("the session lists its own prompts")
.iter()
.map(|prompt| prompt["name"].as_str().unwrap_or_default().to_owned())
.collect::<Vec<String>>(),
vec!["other-agent-prompt"],
"the legacy session lists only its own bound Prompt: {listed}"
);
// Every Prompt bound to the sales Agent is foreign to this session.
for name in ["greeting", "review", "archived-prompt"] {
let body = endpoint
.legacy_for(
OTHER_AGENT_SLUG,
&other_key,
&session,
"prompts/get",
json!({"name": name}),
)
.await;
assert_eq!(
body["error"]["code"],
json!(-32602),
"{name}: a foreign bound Prompt is invalid params on the legacy era: {body}"
);
assert_eq!(
body["error"]["message"],
json!("the requested prompt is not available"),
"{name}: a foreign bound Prompt shares the safe answer: {body}"
);
assert!(
body.get("result").is_none(),
"{name}: a foreign bound Prompt carries no result: {body}"
);
let serialized = body.to_string();
for leaked in ["Be brief.", "Hello ", "Archived but bound."] {
assert!(
!serialized.contains(leaked),
"{name}: the foreign rejection must not disclose {leaked:?}: {serialized}"
);
}
}
}