feat(epic3): deliver the accepted Epic 3 scope through Story 3.17
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

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.
This commit is contained in:
bsodfather committed 2026-10-25 09:08:22 +00:00
1 parent 1b6db09bd1
commit 54ce770682
357 files changed
+117394 -5115

No files matched your search

@@ -0,0 +1,195 @@
//! BUILD-ONLY: in-crate проверки per-revision адаптера Story 3.6 (AT-3.6-06, таргет V).
//!
//! Статус на стадии Dev ATDD: **не зарегистрирован**. BUILD объявляет файл из production-модуля:
//! ```text
//! // crates/crank-community-mcp/src/resource_wire.rs
//! #[cfg(test)] #[path = "resource_wire/tests.rs"] mod tests;
//! ```
//! Сегодня `src/resource_wire.rs` не существует, поэтому файл не компилируется и не исполняется;
//! нулевая коллекция — не PASS. Внешний таргет `tests/unit.rs` этой крейты для приватного модуля
//! невидим и намеренно не трогается (D-19).
//!
//! Минимальный будущий интерфейс (SPEC v4 §5, D-17): чистые per-revision функции
//! `resource_wire::{resource_contents_2026_07_28, resource_contents_2025_11_25}` (без регистрации
//! MCP-методов и без рекламы capability) вида
//! `(uri: &str, kind: crank_core::resource::ResourceKind, mime_type: &str, bytes: &[u8]) -> Value`:
//! ветка `contents[]` выбирается **typed kind**, а не разбором байтов (никакого content sniffing):
//! для `ResourceKind::Binary` — `{uri, mimeType, blob: base64}` всегда, даже если байты
//! декодируются как UTF-8; для text/JSON — `{uri, mimeType, text}`. Форма одинакова для обеих
//! ревизий (`2026-07-28`, `2025-11-25`) со своими правилами ревизии.
//! Регистрация `CAPABILITY_DESCRIPTORS`/`METHOD_DESCRIPTORS` не меняется, и `resources/read`
//! сохраняет существующий ответ (existing GREEN, проверяется отдельной строкой).
//!
//! Запуск после BUILD: `cargo test -p crank-community-mcp --lib story36_ -- --test-threads=1`.
use super::{resource_contents_2025_11_25, resource_contents_2026_07_28};
use crate::protocol::{CAPABILITY_DESCRIPTORS, METHOD_DESCRIPTORS};
use crank_core::resource::ResourceKind;
use serde_json::{Value, json};
const TEXT: &[u8] = "Заголовок\n".as_bytes();
const JSON_DOCUMENT: &[u8] = "{\"b\":1,\"a\":[1,2,3],\"дубликат\":1,\"дубликат\":2}".as_bytes();
const BINARY_BYTES: &[u8] = &[0x00, 0xFF, 0x80, 0xC3, 0x28];
/// Байты, которые **корректно** декодируются как UTF-8, но принадлежат kind=binary:
/// выбор ветки не может зависеть от декодируемости (D-5/D-17).
const BINARY_UTF8_MARKUP: &[u8] =
b"<html><body><script>window.__c36='active'</script></body></html>";
struct Case {
label: &'static str,
uri: &'static str,
kind: ResourceKind,
mime: &'static str,
bytes: &'static [u8],
}
/// Один набор кейсов на обе ревизии: правила выбора ветки общие, форма `contents[]`
/// отличается только правилами конкретной ревизии.
fn cases() -> Vec<Case> {
let mut cases = vec![
Case {
label: "text/plain",
uri: "crank://adapter/text",
kind: ResourceKind::Text,
mime: "text/plain",
bytes: TEXT,
},
Case {
label: "json/application-json",
uri: "crank://adapter/payload",
kind: ResourceKind::Json,
mime: "application/json",
bytes: JSON_DOCUMENT,
},
];
for (label, mime, bytes) in [
(
"binary/octet-stream",
"application/octet-stream",
BINARY_UTF8_MARKUP,
),
("binary/image-png", "image/png", BINARY_BYTES),
("binary/image-jpeg", "image/jpeg", BINARY_BYTES),
("binary/image-gif", "image/gif", BINARY_BYTES),
("binary/image-webp", "image/webp", BINARY_BYTES),
("binary/image-svg", "image/svg+xml", BINARY_UTF8_MARKUP),
("binary/text-html", "text/html", BINARY_UTF8_MARKUP),
("binary/application-pdf", "application/pdf", BINARY_BYTES),
] {
cases.push(Case {
label,
uri: "crank://adapter/asset",
kind: ResourceKind::Binary,
mime,
bytes,
});
}
cases
}
fn assert_case(revision: &str, build: fn(&str, ResourceKind, &str, &[u8]) -> Value, case: &Case) {
let label = format!("{revision}/{}", case.label);
let contents = build(case.uri, case.kind, case.mime, case.bytes);
assert_eq!(
contents["uri"],
json!(case.uri),
"{label}: uri must be preserved"
);
assert_eq!(
contents["mimeType"],
json!(case.mime),
"{label}: adapter must report the declared MIME"
);
match case.kind {
ResourceKind::Binary => {
assert!(
contents.get("text").is_none(),
"{label}: kind=binary must never carry a text branch, even for UTF-8-decodable bytes"
);
let blob = contents["blob"]
.as_str()
.unwrap_or_else(|| panic!("{label}: kind=binary must carry base64 `blob`"));
assert_eq!(
base64_decode(blob),
case.bytes,
"{label}: base64 must decode to the exact stored bytes"
);
}
ResourceKind::Text | ResourceKind::Json => {
assert!(
contents.get("blob").is_none(),
"{label}: text/JSON contents must not carry a blob branch"
);
assert_eq!(
contents["text"],
json!(std::str::from_utf8(case.bytes).expect("text/JSON fixtures must be UTF-8")),
"{label}: text contents must be the exact stored bytes"
);
}
}
}
#[test]
fn story36_at06_negotiated_binary_adapter_both_revisions() {
for case in cases() {
assert_case("2026-07-28", resource_contents_2026_07_28, &case);
assert_case("2025-11-25", resource_contents_2025_11_25, &case);
}
}
#[test]
fn story36_at06_unknown_or_unsupported_mime_is_a_safe_finding() {
let finding = super::resource_mime_finding("application/zip");
assert_eq!(finding.code(), "resource_mime_not_allowed");
// finding не содержит bytes содержимого
let serialized = serde_json::to_string(&finding).expect("finding must serialize");
assert!(!serialized.contains("blob"));
assert!(!serialized.contains("text"));
}
#[test]
fn story38_resources_capability_is_registered_and_advertised() {
// D-17 regression successor: 3.6 deliberately registered no Resources while the handler did not
// exist; Story 3.8 implements `resources/list` + `resources/read`, so advertisement and dispatch
// now carry the capability for both supported revisions.
let capability_names: Vec<String> = CAPABILITY_DESCRIPTORS
.iter()
.map(|descriptor| format!("{:?}", descriptor.id).to_ascii_lowercase())
.collect();
assert!(
capability_names
.iter()
.any(|name| name.contains("resource")),
"CAPABILITY_DESCRIPTORS must carry the implemented Resources capability: {capability_names:?}"
);
let advertised_keys: Vec<String> = CAPABILITY_DESCRIPTORS
.iter()
.filter_map(|descriptor| descriptor.advertised.map(|(key, _)| key.to_owned()))
.collect();
assert!(
advertised_keys.iter().any(|key| key == "resources"),
"the implemented Resources capability must be advertised: {advertised_keys:?}"
);
let method_names: Vec<String> = METHOD_DESCRIPTORS
.iter()
.map(|descriptor| descriptor.name.to_owned())
.collect();
for method in ["resources/list", "resources/read"] {
assert!(
method_names.iter().any(|name| name == method),
"{method} must be registered now that it is served: {method_names:?}"
);
}
}
/// Независимый декодер: ожидание не берётся из адаптера.
fn base64_decode(encoded: &str) -> Vec<u8> {
use base64::Engine as _;
base64::engine::general_purpose::STANDARD
.decode(encoded)
.expect("adapter must emit standard base64")
}