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,361 @@
//! AC03 / AT-3.7-03: immutable Published Resource Version.
//!
//! Публикация создаёт неизменяемую версию; последующее редактирование Draft создаёт новый
//! Draft, но не меняет опубликованные bytes/metadata (TL interface decisions 2–3, risk E3-R3:
//! «concurrent edit/archive/publish ... cannot mutate a published snapshot»). Точное значение
//! версии читается через `GET .../resources/{id}/versions/{version}` и `.../versions/{v}/content`;
//! зависший precondition повторной публикации остаётся 428 `resource_stale`/`recovery=reload`
//! и не создаёт duplicate/partial writes.
use super::super::helpers::{
assert_download_policy, draft_metadata, draft_updated_at, error_signature, get_card,
header_value, read_content, sha256_hex, spawn_authorized, table_row_count,
};
use super::{
assert_immutable_metadata, assert_version_not_published, create_and_publish, publish,
publish_raw, published_metadata, read_version, read_version_content, resource_card_id,
update_draft_expect_success, version_metadata,
};
use crank_registry::PostgresRegistry;
use reqwest::StatusCode;
use serde_json::json;
use serial_test::serial;
/// Итоги существующих реестровых отношений: нужны как наблюдение «duplicate/partial writes
/// не появилось». Схема публикации ещё не выбрана (TL decision 5), поэтому тест не опирается на
/// новые отношения — только на уже принятые.
async fn relation_counts(registry: &PostgresRegistry) -> (i64, i64, i64, i64) {
(
table_row_count(registry.pool(), "resources").await,
table_row_count(registry.pool(), "resource_versions").await,
table_row_count(registry.pool(), "artifact_sources").await,
table_row_count(registry.pool(), "artifact_blobs").await,
)
}
#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn story37_at03_publish_creates_immutable_version_readable_exactly() {
let (_registry, server, client) = spawn_authorized("story37_at03_immutable").await;
let bytes = "опубликованное содержимое\nвторая строка\n".as_bytes();
let mut meta = draft_metadata(
"crank://story37/published",
"published_doc",
"text",
"text/plain",
"internal",
);
meta["description"] = json!("опубликованное описание");
let raw_upload_filename = "story37-published-raw.bin";
let published = create_and_publish(
&client,
&server,
&meta,
bytes,
raw_upload_filename,
"text/plain",
)
.await;
let id = published.draft.resource_id.clone();
let snapshot = published.published_version.clone();
// Тело успешного ответа несёт и карточку Resource, и immutable metadata (TL decision 2).
assert_eq!(
resource_card_id(&published.body).as_deref(),
Some(id.as_str()),
"a successful publish must answer the Resource card too: {}",
published.body
);
// Точные поля Published Version: независимый оракул digest считается тестом.
assert_eq!(snapshot["version"], json!(1));
assert_eq!(snapshot["uri"], json!("crank://story37/published"));
assert_eq!(snapshot["name"], json!("published_doc"));
assert_eq!(snapshot["description"], json!("опубликованное описание"));
assert_eq!(snapshot["kind"], json!("text"));
assert_eq!(snapshot["mime_type"], json!("text/plain"));
assert_eq!(snapshot["size_bytes"], json!(bytes.len()));
assert_eq!(snapshot["digest"], json!(sha256_hex(bytes)));
assert_eq!(snapshot["sensitivity"], json!("internal"));
// GET .../versions/{version} возвращает тот же immutable object.
let (status, text, body) = read_version(&client, &server, &id, 1).await;
assert_eq!(
status,
StatusCode::OK,
"the exact Published Version metadata must be readable (TL decision 3); observed {} body={text}",
error_signature(status, &body)
);
let observed = version_metadata(&body);
assert_eq!(
observed, snapshot,
"GET versions/1 must return the same immutable metadata object that publish returned"
);
assert_immutable_metadata(&observed, raw_upload_filename);
// GET .../versions/{version}/content отдаёт точные опубликованные bytes и остаётся инертным.
let response = read_version_content(&client, &server, &id, 1).await;
assert_eq!(response.status(), StatusCode::OK);
assert_download_policy(response.headers());
let disposition = header_value(response.headers(), "content-disposition");
assert!(
!disposition.contains(raw_upload_filename),
"the raw upload filename must not reach the published download header: {disposition}"
);
assert_eq!(
response
.bytes()
.await
.expect("published content must be readable")
.to_vec(),
bytes.to_vec(),
"GET versions/1/content must return the exact published bytes"
);
}
#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn story37_at03_draft_edit_does_not_change_published_bytes_or_metadata() {
let (_registry, server, client) = spawn_authorized("story37_at03_pinned").await;
let first_bytes = "published body v1\n".as_bytes();
let mut meta = draft_metadata(
"crank://story37/pinned",
"pinned_doc",
"text",
"text/plain",
"internal",
);
meta["description"] = json!("опубликованное описание");
let published = create_and_publish(
&client,
&server,
&meta,
first_bytes,
"story37-pinned-raw.bin",
"text/plain",
)
.await;
let id = published.draft.resource_id.clone();
let snapshot = published.published_version.clone();
let card_before_edit = get_card(&client, &server, &id).await;
let second_bytes = "draft body v2\n".as_bytes();
let updated = update_draft_expect_success(
&client,
&server,
&id,
&json!({
"description": "изменённое описание черновика",
"mime_type": "text/plain",
"sensitivity": "public",
"expected_updated_at": draft_updated_at(&card_before_edit),
}),
second_bytes,
"story37-pinned-raw.bin",
"text/plain",
)
.await;
assert_eq!(
updated["version"]["version"],
json!(2),
"editing after publication must create a new Draft version (AT-3.7-03)"
);
// Черновик изменился по всем наблюдаемым полям.
let card = get_card(&client, &server, &id).await;
assert_eq!(card["version"]["version"], json!(2));
assert_eq!(card["version"]["digest"], json!(sha256_hex(second_bytes)));
assert_eq!(card["version"]["sensitivity"], json!("public"));
assert_eq!(
card["resource"]["description"],
json!("изменённое описание черновика")
);
assert_eq!(
read_content(&client, &server, &id).await,
second_bytes.to_vec(),
"the current Draft content must be the edited bytes"
);
// Опубликованный snapshot не изменился ни в metadata, ни в bytes.
let (status, text, body) = read_version(&client, &server, &id, 1).await;
assert_eq!(
status,
StatusCode::OK,
"the published snapshot must stay readable after a Draft edit; observed {} body={text}",
error_signature(status, &body)
);
let observed = version_metadata(&body);
assert_eq!(
observed, snapshot,
"a Draft edit must not change the Published Version metadata (AT-3.7-03)"
);
assert_eq!(
observed["description"],
json!("опубликованное описание"),
"the published description must stay pinned"
);
assert_eq!(
observed["sensitivity"],
json!("internal"),
"the published sensitivity must stay pinned even when the Draft raises it"
);
let response = read_version_content(&client, &server, &id, 1).await;
assert_eq!(response.status(), StatusCode::OK);
assert_download_policy(response.headers());
assert_eq!(
response
.bytes()
.await
.expect("published content must be readable")
.to_vec(),
first_bytes.to_vec(),
"the published bytes must stay pinned after a Draft edit"
);
}
#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn story37_at03_stale_and_repeated_publish_never_mutate_published_snapshot() {
let (registry, server, client) = spawn_authorized("story37_at03_stale").await;
let first_bytes = "published v1 bytes\n".as_bytes();
let mut meta = draft_metadata(
"crank://story37/stale",
"stale_doc",
"text",
"text/plain",
"internal",
);
meta["description"] = json!("опубликованное описание v1");
let published = create_and_publish(
&client,
&server,
&meta,
first_bytes,
"story37-stale-v1.txt",
"text/plain",
)
.await;
let id = published.draft.resource_id.clone();
let snapshot = published.published_version.clone();
let counts_after_publish = relation_counts(&registry).await;
// Повтор той же публикации: precondition прежней карточки уже stale (TL decision 2/3).
let (status, text, body) = publish(&client, &server, &id, &published.draft.updated_at).await;
assert_eq!(
status,
StatusCode::PRECONDITION_REQUIRED,
"repeating the same publish must be 428; observed {} body={text}",
error_signature(status, &body)
);
assert_eq!(body["error"]["code"], json!("resource_stale"));
assert_eq!(body["error"]["context"]["recovery"], json!("reload"));
// Отсутствующий precondition — тот же 428 без публикации.
let (status, text, body) = publish_raw(&client, &server, &id, &json!({})).await;
assert_eq!(
status,
StatusCode::PRECONDITION_REQUIRED,
"a publish without precondition must be 428 (TL decision 2); observed {} body={text}",
error_signature(status, &body)
);
assert_eq!(body["error"]["code"], json!("resource_stale"));
// Ни duplicate publication, ни partial writes: отношения и снапшот не изменились.
assert_eq!(
relation_counts(&registry).await,
counts_after_publish,
"a stale/repeated publish must not write any row"
);
let (status, text, body) = read_version(&client, &server, &id, 1).await;
assert_eq!(
status,
StatusCode::OK,
"the published snapshot must stay readable; observed {} body={text}",
error_signature(status, &body)
);
assert_eq!(
version_metadata(&body),
snapshot,
"a stale publish must not mutate the published snapshot"
);
// Редактирование Draft: publish с прежним (теперь stale) precondition снова 428.
let card = get_card(&client, &server, &id).await;
let second_bytes = "draft v2 bytes\n".as_bytes();
update_draft_expect_success(
&client,
&server,
&id,
&json!({
"description": "черновик v2",
"mime_type": "text/plain",
"sensitivity": "public",
"expected_updated_at": draft_updated_at(&card),
}),
second_bytes,
"story37-stale-v2.txt",
"text/plain",
)
.await;
let (status, text, body) = publish(&client, &server, &id, &published.draft.updated_at).await;
assert_eq!(
status,
StatusCode::PRECONDITION_REQUIRED,
"a publish racing a Draft edit must be 428; observed {} body={text}",
error_signature(status, &body)
);
assert_eq!(body["error"]["code"], json!("resource_stale"));
assert_version_not_published(&client, &server, &id, 2, "AT-3.7-03 stale publish").await;
let (status, text, body) = read_version(&client, &server, &id, 1).await;
assert_eq!(
status,
StatusCode::OK,
"the published snapshot must survive the racing publish; observed {} body={text}",
error_signature(status, &body)
);
assert_eq!(version_metadata(&body), snapshot);
// Публикация актуального Draft создаёт новую Published Version, прежняя остаётся точной.
let card = get_card(&client, &server, &id).await;
let (status, text, body) = publish(&client, &server, &id, &draft_updated_at(&card)).await;
assert_eq!(
status,
StatusCode::OK,
"the current Draft must be publishable with a fresh precondition; observed {} body={text}",
error_signature(status, &body)
);
let second_published = published_metadata(&body);
assert_immutable_metadata(&second_published, "story37-stale-v2.txt");
assert_eq!(second_published["version"], json!(2));
assert_eq!(second_published["digest"], json!(sha256_hex(second_bytes)));
assert_eq!(second_published["sensitivity"], json!("public"));
let (status, text, body) = read_version(&client, &server, &id, 1).await;
assert_eq!(
status,
StatusCode::OK,
"the earlier Published Version must stay readable; observed {} body={text}",
error_signature(status, &body)
);
assert_eq!(
version_metadata(&body),
snapshot,
"publishing a newer version must not rewrite the earlier Published Version"
);
let response = read_version_content(&client, &server, &id, 1).await;
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response
.bytes()
.await
.expect("published content must be readable")
.to_vec(),
first_bytes.to_vec(),
"the earlier Published Version bytes must stay exact"
);
}