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.
795 lines
27 KiB
Rust
795 lines
27 KiB
Rust
//! P2 (affected ATDD до исправления) и R-E: порядок клиентских отказов, immutable-
|
||
//! presence, реальный CAS и наблюдение полного состояния после каждого отказа.
|
||
//! Источники: CORRECTION-PACKAGE P2 (TL F02/F03/F04/F07, QA F-STALE), SPEC v4
|
||
//! D-14/D-16/D-20, TL review run103 R-E. Подмодуль `tests/integration/resources.rs`.
|
||
|
||
use super::helpers::{
|
||
assert_draft_identity, create_draft, created_resource_id, draft_form, draft_metadata,
|
||
draft_updated_at, error_signature, get_card, post_draft_raw, read_content, read_response,
|
||
spawn_authorized, table_row_count,
|
||
};
|
||
use super::{observe_draft_state, put_draft_raw, update_metadata};
|
||
use reqwest::StatusCode;
|
||
use serde_json::{Value, json};
|
||
use serial_test::serial;
|
||
|
||
#[tokio::test(flavor = "multi_thread")]
|
||
#[serial]
|
||
async fn story36_at02_unknown_kind_is_generic_validation_error() {
|
||
let (registry, server, client) = spawn_authorized("story36_unknown_kind").await;
|
||
|
||
// D-20 шаг B: неизвестный kind — отказ формы запроса, а не Resource-специфичный код.
|
||
let meta = draft_metadata(
|
||
"crank://unknown/kind",
|
||
"unknown_kind",
|
||
"video",
|
||
"video/mp4",
|
||
"internal",
|
||
);
|
||
let (status, _, text, body) =
|
||
post_draft_raw(&client, &server, &meta, b"payload", "video/mp4").await;
|
||
assert_eq!(
|
||
status,
|
||
StatusCode::BAD_REQUEST,
|
||
"unknown kind must be a client rejection (D-20 B); observed {} body={text}",
|
||
error_signature(status, &body)
|
||
);
|
||
assert_eq!(
|
||
body["error"]["code"],
|
||
json!("validation_error"),
|
||
"unknown kind belongs to step B and must not get a Resource-specific code (P2); body={text}"
|
||
);
|
||
assert_eq!(table_row_count(registry.pool(), "resources").await, 0);
|
||
}
|
||
|
||
#[tokio::test(flavor = "multi_thread")]
|
||
#[serial]
|
||
async fn story36_at02_unknown_sensitivity_is_client_rejection_not_internal_error() {
|
||
let (registry, server, client) = spawn_authorized("story36_unknown_sensitivity").await;
|
||
|
||
// D-20 шаг E: неизвестная sensitivity — клиентский отказ на своём месте, не storage 500 (P2).
|
||
let meta = draft_metadata(
|
||
"crank://unknown/sensitivity",
|
||
"unknown_sensitivity",
|
||
"text",
|
||
"text/plain",
|
||
"top_secret",
|
||
);
|
||
let (status, text, body) = read_response(
|
||
client
|
||
.post(format!("{server}/resources"))
|
||
.multipart(draft_form(&meta, b"payload", "draft.txt", "text/plain"))
|
||
.send()
|
||
.await
|
||
.expect("draft request must complete"),
|
||
)
|
||
.await;
|
||
assert_eq!(
|
||
status,
|
||
StatusCode::BAD_REQUEST,
|
||
"unknown sensitivity must be a client rejection, not a storage failure (D-20 E); observed {} body={text}",
|
||
error_signature(status, &body)
|
||
);
|
||
assert_ne!(
|
||
body["error"]["code"],
|
||
json!("resource_storage_unavailable"),
|
||
"an unknown user-supplied enum value must never surface as an internal error (P2); body={text}"
|
||
);
|
||
assert_eq!(table_row_count(registry.pool(), "resources").await, 0);
|
||
}
|
||
|
||
#[tokio::test(flavor = "multi_thread")]
|
||
#[serial]
|
||
async fn story36_at02_immutable_fields_present_as_null_or_wrong_type_are_rejected() {
|
||
let (registry, server, client) = spawn_authorized("story36_immutable_presence").await;
|
||
|
||
let mut observations: Vec<String> = Vec::new();
|
||
let mut mismatches: Vec<String> = Vec::new();
|
||
|
||
// D (D-20): присутствие ключа — уже нарушение неизменяемости, независимо от значения.
|
||
// Каждый null-вектор исполняется на **своём** свежем Draft с собственной precondition и
|
||
// собственным полным «до»: принятый `uri: null` иначе изменил бы состояние и сделал бы
|
||
// следующие случаи двухфакторными (R-E, TL run105 F1).
|
||
for field in ["uri", "name", "kind"] {
|
||
let (id, updated_at, before) = case_draft(
|
||
®istry,
|
||
&client,
|
||
&server,
|
||
"presence",
|
||
&format!("null_{field}"),
|
||
)
|
||
.await;
|
||
let mut metadata = update_metadata("", "text/plain", "internal", &updated_at);
|
||
metadata[field] = Value::Null;
|
||
let (status, _text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let after = observe_draft_state(®istry, &client, &server, &id).await;
|
||
record_case(
|
||
&mut observations,
|
||
&mut mismatches,
|
||
&format!("present-but-null-{field}"),
|
||
status,
|
||
&body,
|
||
after == before,
|
||
StatusCode::BAD_REQUEST,
|
||
ExpectedCode::Exact("resource_field_immutable"),
|
||
Some(field),
|
||
);
|
||
}
|
||
|
||
// B (D-20): неверный JSON-тип каждого immutable-ключа — отказ формы запроса с точным
|
||
// generic-кодом и наблюдением неизменного состояния. Изоляция случаев та же (F1).
|
||
for (field, value) in [
|
||
("uri", json!(5)),
|
||
("name", json!([1, 2])),
|
||
("kind", json!({"object": true})),
|
||
] {
|
||
let (id, updated_at, before) = case_draft(
|
||
®istry,
|
||
&client,
|
||
&server,
|
||
"presence",
|
||
&format!("type_{field}"),
|
||
)
|
||
.await;
|
||
let mut metadata = update_metadata("", "text/plain", "internal", &updated_at);
|
||
metadata[field] = value;
|
||
let (status, _text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let after = observe_draft_state(®istry, &client, &server, &id).await;
|
||
record_case(
|
||
&mut observations,
|
||
&mut mismatches,
|
||
&format!("wrong-type-{field}"),
|
||
status,
|
||
&body,
|
||
after == before,
|
||
StatusCode::BAD_REQUEST,
|
||
ExpectedCode::Exact("validation_error"),
|
||
None,
|
||
);
|
||
}
|
||
|
||
assert!(
|
||
mismatches.is_empty(),
|
||
"every null/wrong-type immutable case must be independently observed with its exact code \
|
||
and an unchanged full state; observations: {observations:?}; mismatches: {mismatches:?}"
|
||
);
|
||
}
|
||
|
||
#[tokio::test(flavor = "multi_thread")]
|
||
#[serial]
|
||
async fn story36_at02_update_without_immutable_fields_is_accepted() {
|
||
let (_registry, server, client) = spawn_authorized("story36_immutable_absent").await;
|
||
|
||
// Положительный контроль к негативам выше: отсутствие ключей — валидное обновление.
|
||
let meta = draft_metadata(
|
||
"crank://immutable/absent",
|
||
"immutable_absent",
|
||
"text",
|
||
"text/plain",
|
||
"internal",
|
||
);
|
||
let created = create_draft(
|
||
&client,
|
||
&server,
|
||
&meta,
|
||
b"first body",
|
||
"draft.txt",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let id = created_resource_id(&created);
|
||
let updated_at = draft_updated_at(&get_card(&client, &server, &id).await);
|
||
|
||
let metadata = update_metadata("updated description", "text/plain", "internal", &updated_at);
|
||
let (status, text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
assert_eq!(
|
||
status,
|
||
StatusCode::OK,
|
||
"absent immutable keys must be a valid update (D-16); observed {} body={text}",
|
||
error_signature(status, &body)
|
||
);
|
||
|
||
let card = get_card(&client, &server, &id).await;
|
||
assert_draft_identity(
|
||
&card,
|
||
"crank://immutable/absent",
|
||
"immutable_absent",
|
||
"text",
|
||
);
|
||
assert_eq!(
|
||
card["resource"]["description"],
|
||
json!("updated description")
|
||
);
|
||
assert_eq!(card["version"]["version"], json!(2));
|
||
assert_eq!(
|
||
read_content(&client, &server, &id).await,
|
||
b"second body".to_vec(),
|
||
"the accepted update must switch the served bytes"
|
||
);
|
||
}
|
||
|
||
#[tokio::test(flavor = "multi_thread")]
|
||
#[serial]
|
||
async fn story36_at04_stale_precondition_precedes_content_validation() {
|
||
let (registry, server, client) = spawn_authorized("story36_stale").await;
|
||
|
||
let meta = draft_metadata(
|
||
"crank://stale/draft",
|
||
"stale_draft",
|
||
"text",
|
||
"text/plain",
|
||
"internal",
|
||
);
|
||
let created = create_draft(
|
||
&client,
|
||
&server,
|
||
&meta,
|
||
b"first body",
|
||
"draft.txt",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let id = created_resource_id(&created);
|
||
let first = draft_updated_at(&get_card(&client, &server, &id).await);
|
||
|
||
// Принятое обновление делает `first` настоящим (ранее валидным, теперь stale) precondition.
|
||
let metadata = update_metadata("", "text/plain", "internal", &first);
|
||
let (status, text, _) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
assert_eq!(
|
||
status,
|
||
StatusCode::OK,
|
||
"a fresh precondition must update the Draft; body={text}"
|
||
);
|
||
|
||
// F побеждает G: stale precondition + невалидная кодировка содержимого → 428, не 422.
|
||
let metadata = update_metadata("", "text/plain", "internal", &first);
|
||
let (status, text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
&[0xC3, 0x28],
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
assert_eq!(
|
||
status,
|
||
StatusCode::PRECONDITION_REQUIRED,
|
||
"the stale precondition must be decided before content validation (D-20 F); observed {} body={text}",
|
||
error_signature(status, &body)
|
||
);
|
||
assert_eq!(body["error"]["code"], json!("resource_stale"));
|
||
assert_eq!(
|
||
body["error"]["context"]["field"],
|
||
json!("expected_updated_at")
|
||
);
|
||
assert_eq!(body["error"]["context"]["recovery"], json!("reload"));
|
||
|
||
// ...и с валидным содержимым — тот же 428 (authoritative precondition).
|
||
let metadata = update_metadata("", "text/plain", "internal", &first);
|
||
let (status, text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"third body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
assert_eq!(
|
||
status,
|
||
StatusCode::PRECONDITION_REQUIRED,
|
||
"a stale precondition must be rejected regardless of content validity; observed {} body={text}",
|
||
error_signature(status, &body)
|
||
);
|
||
assert_eq!(body["error"]["code"], json!("resource_stale"));
|
||
|
||
// Отклонённые обновления не оставили принятой версии; прежние bytes читаются.
|
||
assert_eq!(
|
||
table_row_count(registry.pool(), "resource_versions").await,
|
||
2
|
||
);
|
||
assert_eq!(
|
||
read_content(&client, &server, &id).await,
|
||
b"second body".to_vec()
|
||
);
|
||
|
||
// Свежий precondition после отказов продолжает работать.
|
||
let current = draft_updated_at(&get_card(&client, &server, &id).await);
|
||
let metadata = update_metadata("", "text/plain", "internal", ¤t);
|
||
let (status, text, _) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"third body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
assert_eq!(
|
||
status,
|
||
StatusCode::OK,
|
||
"a fresh precondition must still work after stale rejections: {text}"
|
||
);
|
||
assert_eq!(
|
||
read_content(&client, &server, &id).await,
|
||
b"third body".to_vec()
|
||
);
|
||
}
|
||
|
||
#[tokio::test(flavor = "multi_thread")]
|
||
#[serial]
|
||
async fn story36_at04_concurrent_updates_are_a_single_authoritative_cas() {
|
||
let (registry, server, client) = spawn_authorized("story36_cas").await;
|
||
|
||
let meta = draft_metadata(
|
||
"crank://cas/draft",
|
||
"cas_draft",
|
||
"text",
|
||
"text/plain",
|
||
"internal",
|
||
);
|
||
let created = create_draft(
|
||
&client,
|
||
&server,
|
||
&meta,
|
||
b"first body",
|
||
"draft.txt",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let id = created_resource_id(&created);
|
||
let precondition = draft_updated_at(&get_card(&client, &server, &id).await);
|
||
let server_url = format!("{server}");
|
||
|
||
let attempt = |content: &'static [u8]| {
|
||
let client = client.clone();
|
||
let server = server_url.clone();
|
||
let resource_id = id.clone();
|
||
let metadata = update_metadata("", "text/plain", "internal", &precondition);
|
||
async move {
|
||
put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&resource_id,
|
||
&metadata,
|
||
content,
|
||
"text/plain",
|
||
)
|
||
.await
|
||
}
|
||
};
|
||
|
||
// Два одновременных валидных обновления с одним precondition: ровно один принимается.
|
||
let left = attempt(b"left body");
|
||
let right = attempt(b"right body");
|
||
let outcomes = tokio::join!(left, right);
|
||
let outcomes = [outcomes.0, outcomes.1];
|
||
|
||
let accepted = outcomes
|
||
.iter()
|
||
.position(|(status, _, _)| *status == StatusCode::OK);
|
||
let stale = outcomes
|
||
.iter()
|
||
.filter(|(status, _, _)| *status == StatusCode::PRECONDITION_REQUIRED)
|
||
.count();
|
||
let observed = outcomes
|
||
.iter()
|
||
.map(|(status, _, body)| error_signature(*status, body))
|
||
.collect::<Vec<_>>()
|
||
.join(" | ");
|
||
assert!(
|
||
accepted.is_some(),
|
||
"exactly one concurrent update must be accepted: {observed}"
|
||
);
|
||
assert_eq!(
|
||
stale, 1,
|
||
"the loser must observe resource_stale: {observed}"
|
||
);
|
||
// Точный код проигравшей стороны, а не только статус (R-E).
|
||
let stale_outcome = outcomes
|
||
.iter()
|
||
.find(|(status, _, _)| *status == StatusCode::PRECONDITION_REQUIRED)
|
||
.expect("the losing attempt must be a stale rejection");
|
||
assert_eq!(
|
||
stale_outcome.2["error"]["code"],
|
||
json!("resource_stale"),
|
||
"the loser of the CAS must carry the authoritative resource_stale code: {observed}"
|
||
);
|
||
|
||
let winner: &[u8] = if accepted == Some(0) {
|
||
b"left body"
|
||
} else {
|
||
b"right body"
|
||
};
|
||
assert_eq!(
|
||
table_row_count(registry.pool(), "resource_versions").await,
|
||
2,
|
||
"one accepted update must create exactly one new version"
|
||
);
|
||
assert_eq!(
|
||
table_row_count(registry.pool(), "artifact_sources").await,
|
||
2
|
||
);
|
||
assert_eq!(
|
||
get_card(&client, &server, &id).await["version"]["version"],
|
||
json!(2)
|
||
);
|
||
assert_eq!(
|
||
read_content(&client, &server, &id).await,
|
||
winner.to_vec(),
|
||
"the served bytes must be the winner's, with no lost update"
|
||
);
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// P2 remainder (TL review run101 R-E, TL review run103 R-E): неизвестные enum-значения
|
||
// на update, приоритет шагов D-20, immutable-ключи и наблюдение полного состояния
|
||
// после каждого отказа. Helper-ы/типы (`case_draft`, `ExpectedCode`, `CLIENT_CODES`,
|
||
// `record_case`) и лон-векторы F4 живут в private-подмодуле `observations`
|
||
// (health-лимит 1000 строк, R4 TL run113).
|
||
// ---------------------------------------------------------------------------
|
||
|
||
mod observations;
|
||
|
||
use observations::{ExpectedCode, case_draft, record_case};
|
||
|
||
#[tokio::test(flavor = "multi_thread")]
|
||
#[serial]
|
||
async fn story36_at02_update_unknown_enums_and_d20_precedence() {
|
||
let (registry, server, client) = spawn_authorized("story36_update_enums").await;
|
||
|
||
let meta = draft_metadata(
|
||
"crank://update/enums",
|
||
"update_enums",
|
||
"text",
|
||
"text/plain",
|
||
"internal",
|
||
);
|
||
let created = create_draft(
|
||
&client,
|
||
&server,
|
||
&meta,
|
||
b"first body",
|
||
"draft.txt",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let id = created_resource_id(&created);
|
||
let updated_at = draft_updated_at(&get_card(&client, &server, &id).await);
|
||
|
||
// Якорь: наблюдаемое «до» — действительно принятое состояние, отказы которого
|
||
// проверяются ниже (иначе равенство «после == до» ничего не доказывало бы).
|
||
let before = observe_draft_state(®istry, &client, &server, &id).await;
|
||
assert_draft_identity(&before.card, "crank://update/enums", "update_enums", "text");
|
||
assert_eq!(before.card["version"]["version"], json!(1));
|
||
assert_eq!(before.bytes, b"first body".to_vec());
|
||
assert_eq!(before.versions, 1);
|
||
assert_eq!(before.owning_refs, 1);
|
||
|
||
let mut observations: Vec<String> = Vec::new();
|
||
let mut mismatches: Vec<String> = Vec::new();
|
||
|
||
// (B) неизвестный enum-`kind` на update — отказ формы запроса. Принятый D-20 B
|
||
// ставит неизвестный kind раньше C/D/E, поэтому ожидание — generic `validation_error`,
|
||
// а не `resource_field_immutable` (оракул шага D ставится на известный kind ниже).
|
||
let mut metadata = update_metadata("", "text/plain", "internal", &updated_at);
|
||
metadata["kind"] = json!("video");
|
||
let (status, _text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let after = observe_draft_state(®istry, &client, &server, &id).await;
|
||
record_case(
|
||
&mut observations,
|
||
&mut mismatches,
|
||
"unknown-kind-on-update (B)",
|
||
status,
|
||
&body,
|
||
after == before,
|
||
StatusCode::BAD_REQUEST,
|
||
ExpectedCode::Exact("validation_error"),
|
||
None,
|
||
);
|
||
|
||
// (D) immutable `kind` с **известным** значением (json при kind=text) — отказ
|
||
// неизменяемости со своим полем, состояние не меняется.
|
||
let mut metadata = update_metadata("", "text/plain", "internal", &updated_at);
|
||
metadata["kind"] = json!("json");
|
||
let (status, _text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let after = observe_draft_state(®istry, &client, &server, &id).await;
|
||
record_case(
|
||
&mut observations,
|
||
&mut mismatches,
|
||
"immutable-known-kind (D)",
|
||
status,
|
||
&body,
|
||
after == before,
|
||
StatusCode::BAD_REQUEST,
|
||
ExpectedCode::Exact("resource_field_immutable"),
|
||
Some("kind"),
|
||
);
|
||
|
||
// (E) неизвестная sensitivity — клиентский отказ своего шага, не storage 500.
|
||
let metadata = update_metadata("", "text/plain", "top_secret", &updated_at);
|
||
let (status, _text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let after = observe_draft_state(®istry, &client, &server, &id).await;
|
||
record_case(
|
||
&mut observations,
|
||
&mut mismatches,
|
||
"unknown-sensitivity-update (E)",
|
||
status,
|
||
&body,
|
||
after == before,
|
||
StatusCode::BAD_REQUEST,
|
||
ExpectedCode::ClientRejectionExcept(&["resource_storage_unavailable", "internal_error"]),
|
||
None,
|
||
);
|
||
|
||
// (E) MIME, синтаксис которого верен, но которого нет ни в одном allowlist.
|
||
let metadata = update_metadata("", "video/mp4", "internal", &updated_at);
|
||
let (status, _text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"video/mp4",
|
||
)
|
||
.await;
|
||
let after = observe_draft_state(®istry, &client, &server, &id).await;
|
||
record_case(
|
||
&mut observations,
|
||
&mut mismatches,
|
||
"mime-not-allowed (E)",
|
||
status,
|
||
&body,
|
||
after == before,
|
||
StatusCode::BAD_REQUEST,
|
||
ExpectedCode::Exact("resource_mime_not_allowed"),
|
||
Some("mime_type"),
|
||
);
|
||
|
||
// D-20 precedence (D раньше E): immutable-ключ + неизвестная sensitivity в одном payload.
|
||
let mut metadata = update_metadata("", "text/plain", "top_secret", &updated_at);
|
||
metadata["uri"] = json!("crank://update/enums/other");
|
||
let (status, _text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let after = observe_draft_state(®istry, &client, &server, &id).await;
|
||
record_case(
|
||
&mut observations,
|
||
&mut mismatches,
|
||
"precedence-D-over-E",
|
||
status,
|
||
&body,
|
||
after == before,
|
||
StatusCode::BAD_REQUEST,
|
||
ExpectedCode::Exact("resource_field_immutable"),
|
||
Some("uri"),
|
||
);
|
||
|
||
// D-20 precedence (E раньше F): неизвестная sensitivity + stale precondition.
|
||
let mut metadata = update_metadata("", "text/plain", "top_secret", &updated_at);
|
||
metadata["expected_updated_at"] = json!("1970-01-01T00:00:00Z");
|
||
let (status, _text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let after = observe_draft_state(®istry, &client, &server, &id).await;
|
||
record_case(
|
||
&mut observations,
|
||
&mut mismatches,
|
||
"precedence-E-over-F",
|
||
status,
|
||
&body,
|
||
after == before,
|
||
StatusCode::BAD_REQUEST,
|
||
ExpectedCode::ClientRejectionExcept(&["resource_stale"]),
|
||
None,
|
||
);
|
||
|
||
// Положительный контроль: валидное обновление того же Draft проходит и меняет состояние —
|
||
// значит «неизменно» выше было наблюдением, а не неработающим обновлением.
|
||
let metadata = update_metadata("updated description", "text/plain", "public", &updated_at);
|
||
let (status, text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
assert_eq!(
|
||
status,
|
||
StatusCode::OK,
|
||
"a valid update must still succeed after the refusals: {}",
|
||
error_signature(status, &body)
|
||
);
|
||
assert!(
|
||
text.is_empty() || !text.contains("second body"),
|
||
"a successful card response must not echo content bytes: {text}"
|
||
);
|
||
let accepted = observe_draft_state(®istry, &client, &server, &id).await;
|
||
assert_ne!(
|
||
accepted, before,
|
||
"the accepted update must really change the observed state"
|
||
);
|
||
assert_eq!(accepted.card["version"]["version"], json!(2));
|
||
assert_eq!(accepted.bytes, b"second body".to_vec());
|
||
assert_eq!(accepted.versions, 2);
|
||
assert_eq!(accepted.owning_refs, 2);
|
||
assert_eq!(
|
||
accepted.card["resource"]["description"],
|
||
json!("updated description")
|
||
);
|
||
|
||
assert!(
|
||
mismatches.is_empty(),
|
||
"every refusal case must carry its exact stable code and leave the full state unchanged; \
|
||
observations: {observations:?}; mismatches: {mismatches:?}"
|
||
);
|
||
}
|
||
|
||
#[tokio::test(flavor = "multi_thread")]
|
||
#[serial]
|
||
async fn story36_at02_immutable_keys_present_as_strings_are_rejected_per_key() {
|
||
let (registry, server, client) = spawn_authorized("story36_immutable_strings").await;
|
||
|
||
let mut observations: Vec<String> = Vec::new();
|
||
let mut mismatches: Vec<String> = Vec::new();
|
||
|
||
// Каждый immutable-ключ со строковым значением: отказ D-16 со своим `field`,
|
||
// полное состояние наблюдается после каждого случая отдельно (per-case). Каждый случай
|
||
// идёт на своём свежем Draft, чтобы возможное принятие одного ключа не сделало
|
||
// следующий случай двухфакторным (TL run105 F1).
|
||
for (field, value) in [
|
||
("uri", "crank://immutable/presence/strings_other"),
|
||
("name", "immutable_presence_strings_renamed"),
|
||
("kind", "json"),
|
||
] {
|
||
let (id, updated_at, before) = case_draft(
|
||
®istry,
|
||
&client,
|
||
&server,
|
||
"strings",
|
||
&format!("str_{field}"),
|
||
)
|
||
.await;
|
||
let mut metadata = update_metadata("", "text/plain", "internal", &updated_at);
|
||
metadata[field] = json!(value);
|
||
let (status, _text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let after = observe_draft_state(®istry, &client, &server, &id).await;
|
||
record_case(
|
||
&mut observations,
|
||
&mut mismatches,
|
||
&format!("immutable-{field}"),
|
||
status,
|
||
&body,
|
||
after == before,
|
||
StatusCode::BAD_REQUEST,
|
||
ExpectedCode::Exact("resource_field_immutable"),
|
||
Some(field),
|
||
);
|
||
}
|
||
|
||
// Неверный JSON-тип каждого immutable-ключа — отказ формы запроса (шаг B) с точным
|
||
// generic-кодом, а не только статусом; состояние тоже неизменно и изолировано.
|
||
for (field, value) in [
|
||
("uri", json!(5)),
|
||
("name", json!(["nested"])),
|
||
("kind", json!({"object": true})),
|
||
] {
|
||
let (id, updated_at, before) = case_draft(
|
||
®istry,
|
||
&client,
|
||
&server,
|
||
"strings",
|
||
&format!("type_{field}"),
|
||
)
|
||
.await;
|
||
let mut metadata = update_metadata("", "text/plain", "internal", &updated_at);
|
||
metadata[field] = value;
|
||
let (status, _text, body) = put_draft_raw(
|
||
&client,
|
||
&server,
|
||
&id,
|
||
&metadata,
|
||
b"second body",
|
||
"text/plain",
|
||
)
|
||
.await;
|
||
let after = observe_draft_state(®istry, &client, &server, &id).await;
|
||
record_case(
|
||
&mut observations,
|
||
&mut mismatches,
|
||
&format!("wrong-type-{field}"),
|
||
status,
|
||
&body,
|
||
after == before,
|
||
StatusCode::BAD_REQUEST,
|
||
ExpectedCode::Exact("validation_error"),
|
||
None,
|
||
);
|
||
}
|
||
|
||
assert!(
|
||
mismatches.is_empty(),
|
||
"every immutable-key case must carry its exact code/field and leave the full state \
|
||
unchanged; observations: {observations:?}; mismatches: {mismatches:?}"
|
||
);
|
||
}
|