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.
261 lines
11 KiB
Rust
261 lines
11 KiB
Rust
//! Story 3.7 / AC03 registry-level: immutable publication ownership, CAS и отказ
|
|
//! без partial writes.
|
|
//!
|
|
//! Проверяется на реальном PostgreSQL:
|
|
//! - публикация создаёт отдельную owning-ссылку на тот же immutable blob;
|
|
//! - Draft edit после публикации не отсоединяет publication source и не меняет snapshot;
|
|
//! - повторный/stale publish и отказ по несовпавшему snapshot не пишут строк и не
|
|
//! сдвигают ревизию карточки.
|
|
|
|
use super::*;
|
|
|
|
use crank_core::resource::ResourceError;
|
|
use crank_registry::model::resource::{PublishResourceVersionRequest, ResourcePublicationRecord};
|
|
|
|
async fn publish_current(sandbox: &Sandbox, resource_id: &ResourceId) -> ResourcePublicationRecord {
|
|
let current = sandbox
|
|
.registry
|
|
.get_resource_draft(WORKSPACE_ID, resource_id)
|
|
.await
|
|
.expect("draft must be readable");
|
|
sandbox
|
|
.registry
|
|
.publish_resource_version(PublishResourceVersionRequest {
|
|
workspace_id: WorkspaceId::new(WORKSPACE_ID),
|
|
resource_id: resource_id.clone(),
|
|
expected_updated_at: current.resource.updated_at,
|
|
expected_version: current.version.version,
|
|
expected_digest: current.version.digest.clone(),
|
|
expected_size_bytes: current.version.size_bytes,
|
|
artifact: registered(sandbox, b"registry payload"),
|
|
published_at: OffsetDateTime::now_utc(),
|
|
})
|
|
.await
|
|
.expect("a valid current draft must publish")
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn story37_at03_publication_owns_blob_independently_of_draft_edit() {
|
|
let sandbox = sandbox("at37_publication_owning").await;
|
|
let resource_id = seeded_draft(&sandbox).await;
|
|
let publication = publish_current(&sandbox, &resource_id).await;
|
|
|
|
assert_eq!(publication.version, 1);
|
|
assert_eq!(publication.uri, "crank://registry/draft");
|
|
assert_eq!(publication.kind, "text");
|
|
assert_eq!(publication.mime_type, "text/plain");
|
|
assert_eq!(publication.sensitivity, "internal");
|
|
assert_eq!(publication.size_bytes, 16);
|
|
assert_eq!(publication.digest, sha256_hex(b"registry payload"));
|
|
|
|
let status: String = sqlx::query_scalar("select status from resources where resource_id = $1")
|
|
.bind(resource_id.as_str())
|
|
.fetch_one(sandbox.registry.pool())
|
|
.await
|
|
.expect("resources must be queryable");
|
|
assert_eq!(
|
|
status, "published",
|
|
"publish must switch the card to published"
|
|
);
|
|
|
|
let draft_source: String = sqlx::query_scalar(
|
|
"select artifact_source_id from resource_versions where resource_id = $1 and superseded_at is null",
|
|
)
|
|
.bind(resource_id.as_str())
|
|
.fetch_one(sandbox.registry.pool())
|
|
.await
|
|
.expect("draft source must be queryable");
|
|
let publication_source: String = sqlx::query_scalar(
|
|
"select artifact_source_id from resource_publications where resource_id = $1 and version = 1",
|
|
)
|
|
.bind(resource_id.as_str())
|
|
.fetch_one(sandbox.registry.pool())
|
|
.await
|
|
.expect("publication source must be queryable");
|
|
assert_ne!(
|
|
draft_source, publication_source,
|
|
"publication must own a dedicated source, not the mutable draft owning ref"
|
|
);
|
|
|
|
// Draft edit: новая версия, новая draft-ссылка, карточка снова Draft.
|
|
let current = sandbox
|
|
.registry
|
|
.get_resource_draft(WORKSPACE_ID, &resource_id)
|
|
.await
|
|
.expect("draft must be readable");
|
|
sandbox
|
|
.registry
|
|
.update_resource_draft(UpdateResourceDraftRequest {
|
|
workspace_id: WorkspaceId::new(WORKSPACE_ID),
|
|
resource_id: resource_id.clone(),
|
|
description: "edited after publication".to_owned(),
|
|
mime_type: "text/plain".to_owned(),
|
|
sensitivity: "public".to_owned(),
|
|
expected_updated_at: current.resource.updated_at,
|
|
artifact: registered(&sandbox, b"edited payload"),
|
|
})
|
|
.await
|
|
.expect("draft edit after publication must succeed");
|
|
|
|
let status: String = sqlx::query_scalar("select status from resources where resource_id = $1")
|
|
.bind(resource_id.as_str())
|
|
.fetch_one(sandbox.registry.pool())
|
|
.await
|
|
.expect("resources must be queryable");
|
|
assert_eq!(
|
|
status, "draft",
|
|
"a Draft edit must return the card to draft"
|
|
);
|
|
|
|
let publication_lifecycle: String = sqlx::query_scalar(
|
|
"select lifecycle from artifact_sources where workspace_id = $1 and source_id = $2",
|
|
)
|
|
.bind(WORKSPACE_ID)
|
|
.bind(&publication_source)
|
|
.fetch_one(sandbox.registry.pool())
|
|
.await
|
|
.expect("publication source must still exist");
|
|
assert_eq!(
|
|
publication_lifecycle, "active",
|
|
"a Draft edit must not detach the publication owning source"
|
|
);
|
|
|
|
// Snapshot остаётся exact и читается через publication owning source.
|
|
let resolved = sandbox
|
|
.registry
|
|
.resolve_resource_publication(WORKSPACE_ID, &resource_id, 1)
|
|
.await
|
|
.expect("published version must stay resolvable after the edit");
|
|
assert_eq!(resolved.publication, publication);
|
|
let bytes = sandbox
|
|
.store
|
|
.read(&resolved.artifact_ref)
|
|
.expect("published bytes must stay readable");
|
|
assert_eq!(bytes, b"registry payload");
|
|
}
|
|
|
|
async fn totals(sandbox: &Sandbox) -> (i64, i64, i64, i64, i64) {
|
|
(
|
|
count(sandbox, "select count(*) from resources").await,
|
|
count(sandbox, "select count(*) from resource_versions").await,
|
|
count(sandbox, "select count(*) from artifact_sources").await,
|
|
count(sandbox, "select count(*) from artifact_blobs").await,
|
|
count(sandbox, "select count(*) from resource_publications").await,
|
|
)
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn story37_at03_stale_repeat_and_refusal_never_write_rows() {
|
|
let sandbox = sandbox("at37_publication_stale").await;
|
|
let resource_id = seeded_draft(&sandbox).await;
|
|
let card_before = sandbox
|
|
.registry
|
|
.get_resource_draft(WORKSPACE_ID, &resource_id)
|
|
.await
|
|
.expect("card must be readable");
|
|
|
|
// Отказ по несовпавшему snapshot (TOCTOU) — stale и без записей, ещё до публикации.
|
|
let initial = totals(&sandbox).await;
|
|
let mismatched = sandbox
|
|
.registry
|
|
.publish_resource_version(PublishResourceVersionRequest {
|
|
workspace_id: WorkspaceId::new(WORKSPACE_ID),
|
|
resource_id: resource_id.clone(),
|
|
expected_updated_at: card_before.resource.updated_at,
|
|
expected_version: card_before.version.version,
|
|
expected_digest: sha256_hex(b"not the stored payload"),
|
|
expected_size_bytes: card_before.version.size_bytes,
|
|
artifact: registered(&sandbox, b"registry payload"),
|
|
published_at: OffsetDateTime::now_utc(),
|
|
})
|
|
.await
|
|
.expect_err("a snapshot mismatch must be refused");
|
|
assert!(matches!(mismatched, ResourceError::Stale));
|
|
assert_eq!(
|
|
totals(&sandbox).await,
|
|
initial,
|
|
"a refused snapshot must not write rows"
|
|
);
|
|
|
|
let publication = sandbox
|
|
.registry
|
|
.publish_resource_version(PublishResourceVersionRequest {
|
|
workspace_id: WorkspaceId::new(WORKSPACE_ID),
|
|
resource_id: resource_id.clone(),
|
|
expected_updated_at: card_before.resource.updated_at,
|
|
expected_version: card_before.version.version,
|
|
expected_digest: card_before.version.digest.clone(),
|
|
expected_size_bytes: card_before.version.size_bytes,
|
|
artifact: registered(&sandbox, b"registry payload"),
|
|
published_at: OffsetDateTime::now_utc(),
|
|
})
|
|
.await
|
|
.expect("a valid current draft must publish");
|
|
assert_eq!(publication.version, 1);
|
|
let after_publish = totals(&sandbox).await;
|
|
let published_card = sandbox
|
|
.registry
|
|
.get_resource_draft(WORKSPACE_ID, &resource_id)
|
|
.await
|
|
.expect("card must be readable");
|
|
assert!(
|
|
published_card.resource.updated_at > card_before.resource.updated_at,
|
|
"a successful publish must advance the CAS revision monotonically"
|
|
);
|
|
|
|
// Повтор той же публикации с прежней карточкой: CAS уже сдвинут.
|
|
let repeated = sandbox
|
|
.registry
|
|
.publish_resource_version(PublishResourceVersionRequest {
|
|
workspace_id: WorkspaceId::new(WORKSPACE_ID),
|
|
resource_id: resource_id.clone(),
|
|
expected_updated_at: card_before.resource.updated_at,
|
|
expected_version: 1,
|
|
expected_digest: card_before.version.digest.clone(),
|
|
expected_size_bytes: card_before.version.size_bytes,
|
|
artifact: registered(&sandbox, b"registry payload"),
|
|
published_at: OffsetDateTime::now_utc(),
|
|
})
|
|
.await
|
|
.expect_err("repeating the same publish must be stale");
|
|
assert!(matches!(repeated, ResourceError::Stale));
|
|
|
|
// Повтор со свежей карточкой без правки Draft: версия уже опубликована (no duplicate).
|
|
let duplicate = sandbox
|
|
.registry
|
|
.publish_resource_version(PublishResourceVersionRequest {
|
|
workspace_id: WorkspaceId::new(WORKSPACE_ID),
|
|
resource_id: resource_id.clone(),
|
|
expected_updated_at: published_card.resource.updated_at,
|
|
expected_version: published_card.version.version,
|
|
expected_digest: published_card.version.digest.clone(),
|
|
expected_size_bytes: published_card.version.size_bytes,
|
|
artifact: registered(&sandbox, b"registry payload"),
|
|
published_at: OffsetDateTime::now_utc(),
|
|
})
|
|
.await
|
|
.expect_err("re-publishing an unchanged published draft must be stale");
|
|
assert!(matches!(duplicate, ResourceError::Stale));
|
|
|
|
assert_eq!(
|
|
totals(&sandbox).await,
|
|
after_publish,
|
|
"stale/refused publications must not write rows"
|
|
);
|
|
let card_after = sandbox
|
|
.registry
|
|
.get_resource_draft(WORKSPACE_ID, &resource_id)
|
|
.await
|
|
.expect("card must be readable");
|
|
assert_eq!(
|
|
card_after.resource.updated_at, published_card.resource.updated_at,
|
|
"a refused publish must not advance the CAS revision"
|
|
);
|
|
let resolved = sandbox
|
|
.registry
|
|
.resolve_resource_publication(WORKSPACE_ID, &resource_id, 1)
|
|
.await
|
|
.expect("published version must stay readable");
|
|
assert_eq!(resolved.publication, publication);
|
|
}
|