Files
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

214 lines
7.7 KiB
Rust

//! Story 3.8 AC02 / AT-3.8-02: `resources/read` returns the exact published text/JSON/binary content
//! and MIME in the negotiated shape, with Request ID/Trace ID preserved and no content capture in
//! telemetry.
use serde_json::Value;
use super::fixtures::*;
#[allow(clippy::too_many_arguments)]
fn check_content(
checks: &mut RevisionChecks,
body: &Value,
revision: &str,
uri: &str,
expected_text: Option<&str>,
expected_blob: Option<&str>,
mime: &str,
) {
let Some(result) = checks.result(body, revision, "resources/read") else {
return;
};
if revision != LEGACY_REVISION {
// The pinned 2026-07-28 schema: `ReadResourceResult extends CacheableResult`.
checks.require(result["resultType"].as_str() == Some("complete"), || {
format!("a modern read result must carry Result.resultType=\"complete\" on {revision}: {body}")
});
checks.require(
result.get("ttlMs").and_then(Value::as_u64).is_some(),
|| {
format!(
"a modern read result must carry CacheableResult.ttlMs on {revision}: {body}"
)
},
);
checks.require(
matches!(result.get("cacheScope").and_then(Value::as_str), Some("public" | "private")),
|| format!("a modern read result must carry CacheableResult.cacheScope on {revision}: {body}"),
);
}
let Some(contents) = result["contents"].as_array() else {
checks.require(false, || {
format!("resources/read must return contents[] on {revision}: {body}")
});
return;
};
checks.require(contents.len() == 1, || {
format!("an exact published static version must yield exactly one content entry on {revision}: {body}")
});
let Some(content) = contents.first() else {
return;
};
checks.require(content["uri"].as_str() == Some(uri), || {
format!("the read content must address the requested published URI on {revision}: {body}")
});
checks.require(content["mimeType"].as_str() == Some(mime), || {
format!("the read must return the published MIME type {mime} on {revision}: {body}")
});
if let Some(expected_text) = expected_text {
checks.require(content["text"].as_str() == Some(expected_text), || {
format!("the read must return the exact published text bytes on {revision}: {body}")
});
checks.require(content.get("blob").is_none(), || {
format!(
"a text/JSON Resource must not be converted to a base64 blob on {revision}: {body}"
)
});
}
if let Some(expected_blob) = expected_blob {
checks.require(content["blob"].as_str() == Some(expected_blob), || {
format!(
"a binary Resource must be returned as the exact base64 blob on {revision}: {body}"
)
});
checks.require(content.get("text").is_none(), || {
format!(
"binary bytes that happen to be valid UTF-8 must still be a blob (no sniffing) on {revision}: {body}"
)
});
}
}
#[tokio::test]
async fn read_serves_the_exact_published_text_for_every_supported_revision() {
let endpoint = standard_endpoint("read_text").await;
let expected = String::from_utf8(endpoint.text.bytes.clone()).expect("text fixture is UTF-8");
let mut checks = RevisionChecks::default();
for revision in supported_revisions() {
let body =
json_body(read_resource(&endpoint, &revision, &endpoint.text.uri, None).await).await;
check_content(
&mut checks,
&body,
&revision,
&endpoint.text.uri,
Some(&expected),
None,
"text/plain",
);
}
checks.finish();
}
/// The typed kind decides the wire conversion: text/JSON => `text`, binary => `blob` base64, with no
/// content sniffing (the binary fixture bytes are valid UTF-8 on purpose).
#[tokio::test]
async fn read_converts_json_to_text_and_binary_to_base64_without_sniffing() {
let endpoint = standard_endpoint("read_kinds").await;
let json_text = String::from_utf8(endpoint.json.bytes.clone()).expect("JSON fixture is UTF-8");
let json_blob = base64_of(&endpoint.json.bytes);
let binary_blob = base64_of(&endpoint.binary.bytes);
assert_ne!(
json_blob, binary_blob,
"the two fixtures must differ so a wrong content cannot pass"
);
let mut checks = RevisionChecks::default();
for revision in supported_revisions() {
let json_wire =
json_body(read_resource(&endpoint, &revision, &endpoint.json.uri, None).await).await;
check_content(
&mut checks,
&json_wire,
&revision,
&endpoint.json.uri,
Some(&json_text),
None,
"application/json",
);
let binary_body =
json_body(read_resource(&endpoint, &revision, &endpoint.binary.uri, None).await).await;
check_content(
&mut checks,
&binary_body,
&revision,
&endpoint.binary.uri,
None,
Some(&binary_blob),
"image/png",
);
}
checks.finish();
}
/// Request/Trace identity is preserved and the Resource content is never captured into telemetry.
#[tokio::test]
async fn read_preserves_request_identity_without_capturing_content_in_telemetry() {
let endpoint = standard_endpoint("read_telemetry").await;
let canary = String::from_utf8(endpoint.text.bytes.clone()).expect("text fixture is UTF-8");
assert!(
!canary.trim().is_empty(),
"the content canary must be non-empty"
);
let logs = CapturedLogs::default();
let (body, request_id, trace_id) = {
let _capture = logs.install();
let response = read_resource(
&endpoint,
MODERN_REVISION,
&endpoint.text.uri,
Some("story38-read-corr"),
)
.await;
let request_id = response.headers()["x-request-id"]
.to_str()
.expect("x-request-id header")
.to_owned();
let trace_id = response.headers()["x-trace-id"]
.to_str()
.expect("x-trace-id header")
.to_owned();
(json_body(response).await, request_id, trace_id)
};
let mut checks = RevisionChecks::default();
check_content(
&mut checks,
&body,
MODERN_REVISION,
&endpoint.text.uri,
Some(&canary),
None,
"text/plain",
);
checks.require(request_id == "story38-read-corr", || {
format!("the read response must preserve the request id, got {request_id}")
});
checks.require(!trace_id.is_empty(), || {
"the read response must carry a trace id, got an empty header".to_owned()
});
let captured = logs.output();
checks.require(captured.contains("story38-read-corr"), || {
format!("the read telemetry must keep the Request ID, captured logs: {captured}")
});
checks.require(captured.contains("resource read outcome"), || {
format!("the read telemetry must record the read outcome event, captured logs: {captured}")
});
checks.require(
captured.contains("outcome=\"ok\"") && captured.contains("content_bytes="),
|| {
format!(
"the read telemetry must record a successful read outcome without content, captured logs: {captured}"
)
},
);
checks.require(!captured.contains(canary.trim()), || {
format!("the read telemetry must not capture Resource content, captured logs: {captured}")
});
checks.finish();
}