Files
Hermes DevOps 75fe5a123c [skip ci] wip: preserve Hermes crank development checkpoint
Owner-authorized recovery of accumulated source changes.
Includes accepted work and in-progress changes; NOT a release or acceptance.
Parent baseline 1b6db09bd1. Runtime data, build caches and local credentials excluded.
2026-10-25 10:00:22 +00:00

171 lines
5.9 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! AT-3.6-06: содержимое не попадает в тела отказов (RED + зафиксированный GAP по sink-ам).
//!
//! Источник: SPEC v4 §2 (AT-3.6-06), §6 (секреты/логи), §7 (захват logs/errors/telemetry и
//! положительные контроли sink-а); QA test-design run77:117–119.
//!
//! Проверяется наблюдаемое на реальном HTTP: ни одна отказная ветвь не возвращает байты
//! содержимого, отказ несёт `x-trace-id` (то есть событие отказа атрибутируется), а валидный
//! follow-up той же сессии проходит. Захват writer/span/metric sink-ов здесь **не** ставится:
//! глобальный tracing-подписчик процесса уже назначается модулем
//! `integration::openapi_source::telemetry` через `set_global_default(...).expect(...)`;
//! второй глобальный default в том же тестовом бинаре конфликтует и ломает существующий тест,
//! поэтому coverage логов/span-ов/метрик — отчётный GAP/NOT_PROVEN, а не доказательство.
use super::helpers::{
create_draft, created_resource_id, draft_metadata, error_signature, post_draft_raw,
read_preview, read_response, spawn_authorized,
};
use reqwest::StatusCode;
use serde_json::json;
use serial_test::serial;
#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn story36_at06_content_never_enters_logs_errors_or_telemetry() {
const CANARY: &str = "C36-CONTENT-CANARY";
let (_registry, server, client) = spawn_authorized("story36_canary").await;
// (1) malformed JSON: canary внутри отклоняемого содержимого
let malformed = format!("{{\"leak\":\"{CANARY}\"");
let meta = draft_metadata(
"crank://canary/json",
"canary_json",
"json",
"application/json",
"internal",
);
let (status, traceable, text, body) = post_draft_raw(
&client,
&server,
&meta,
malformed.as_bytes(),
"application/json",
)
.await;
assert!(
traceable,
"(1) a refusal must carry `x-trace-id` so the rejection is attributable (SPEC §7)"
);
assert!(
!text.contains(CANARY),
"(1) refusal must not echo content bytes: {text}"
);
assert_eq!(
status,
StatusCode::UNPROCESSABLE_ENTITY,
"(1) expected resource_content_invalid_json; observed {} body={text}",
error_signature(status, &body)
);
assert_eq!(
body["error"]["code"],
json!("resource_content_invalid_json")
);
// (2) invalid UTF-8: canary + повреждённая последовательность
let invalid_utf8 = [CANARY.as_bytes(), &[0xC3, 0x28]].concat();
let meta = draft_metadata(
"crank://canary/utf8",
"canary_utf8",
"text",
"text/plain",
"internal",
);
let (status, traceable, text, body) =
post_draft_raw(&client, &server, &meta, &invalid_utf8, "text/plain").await;
assert!(traceable, "(2) a refusal must carry `x-trace-id`");
assert!(
!text.contains(CANARY),
"(2) refusal must not echo content bytes: {text}"
);
assert_eq!(
status,
StatusCode::UNPROCESSABLE_ENTITY,
"(2) expected resource_content_invalid_utf8; observed {} body={text}",
error_signature(status, &body)
);
assert_eq!(
body["error"]["code"],
json!("resource_content_invalid_utf8")
);
// (3) duplicate uri: принятый Draft + повторный create с canary в содержимом
let meta = draft_metadata(
"crank://canary/dup",
"canary_dup",
"text",
"text/plain",
"internal",
);
create_draft(
&client,
&server,
&meta,
b"safe payload",
"draft.txt",
"text/plain",
)
.await;
let (status, _traceable, text, body) =
post_draft_raw(&client, &server, &meta, CANARY.as_bytes(), "text/plain").await;
assert!(
!text.contains(CANARY),
"(3) refusal must not echo content bytes: {text}"
);
assert_eq!(
status,
StatusCode::CONFLICT,
"(3) expected resource_uri_duplicate; observed {} body={text}",
error_signature(status, &body)
);
// (4) отсутствующий Resource: отказ не раскрывает metadata
let (status, text, body) = read_response(
client
.get(format!("{server}/resources/res_story36_canary_missing"))
.send()
.await
.expect("missing resource request must complete"),
)
.await;
assert!(
!text.contains(CANARY),
"(4) refusal must not echo content bytes: {text}"
);
assert_eq!(
status,
StatusCode::NOT_FOUND,
"(4) expected resource_not_found; observed {} body={text}",
error_signature(status, &body)
);
// (5) positive control: валидный create + preview той же сессии
let safe = draft_metadata(
"crank://canary/ok",
"canary_ok",
"text",
"text/plain",
"internal",
);
let created = create_draft(
&client,
&server,
&safe,
b"safe payload",
"draft.txt",
"text/plain",
)
.await;
let id = created_resource_id(&created);
let (status, text, body) = read_preview(&client, &server, &id).await;
assert_eq!(
status,
StatusCode::OK,
"(5) valid follow-up preview must succeed: {text}"
);
assert!(
!body.to_string().contains(CANARY),
"(5) the canary must never surface in a successful read of another Draft"
);
}