test(axum): prove response delivery boundary

Decode emitted effect bytes, assert dispatch rejection status and diagnostics, and verify the shared embedded runtime body through public IntoResponse paths.

req: axum_integration/003

req: axum_integration/005

req: failure/005

req: wire/007
This commit is contained in:
slhx agent
2026-07-17 00:21:42 +02:00
parent b0a8275b03
commit 0fe2376874
2 changed files with 61 additions and 3 deletions
+60 -2
View File
@@ -829,8 +829,59 @@ fn interactions_reject_unknown_handle_ids() {
);
}
#[test]
fn runtime_js_response_serves_embedded_runtime() {
#[tokio::test]
async fn effect_and_dispatch_responses_preserve_status_wire_and_diagnostics() {
let batch = Slot::<String>::new(3)
.text("saved")
.into_batch(BuildFingerprint(77));
let response = EffectResponse {
batch: batch.clone(),
}
.into_response();
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(response.headers()[header::CONTENT_TYPE], HEMX_CONTENT_TYPE);
assert_eq!(response.headers()[HEMX_FINGERPRINT_HEADER], "77");
let body = to_bytes(response.into_body(), 4096).await.unwrap();
assert_eq!(hemx_core::EffectBatch::from_wire(&body), Ok(batch.clone()));
for (rejection, status, message) in [
(
DispatchRejection::UnknownHandle(9),
StatusCode::NOT_FOUND,
"unknown hemx handle id 9",
),
(
DispatchRejection::InvalidForm {
handle_id: 9,
message: "missing title".into(),
},
StatusCode::BAD_REQUEST,
"invalid hemx form for handle id 9: missing title",
),
(
DispatchRejection::HandlerError(HandlerFailure::Response {
status: StatusCode::CONFLICT,
message: "stale".into(),
}),
StatusCode::CONFLICT,
"stale",
),
] {
let response = rejection.into_response();
assert_eq!(response.status(), status);
assert_eq!(
to_bytes(response.into_body(), 4096).await.unwrap().as_ref(),
message.as_bytes()
);
}
let response = DispatchRejection::HandlerError(HandlerFailure::Effects(batch)).into_response();
assert_eq!(response.headers()[header::CONTENT_TYPE], HEMX_CONTENT_TYPE);
// test req: axum_integration/003 req: failure/005 req: wire/007
}
#[tokio::test]
async fn runtime_js_response_serves_embedded_runtime() {
let response = runtime_js().into_response();
assert_eq!(
@@ -849,6 +900,13 @@ fn runtime_js_response_serves_embedded_runtime() {
response.headers()[header::CONTENT_LENGTH],
runtime_js_source().len().to_string()
);
assert_eq!(
to_bytes(response.into_body(), runtime_js_source().len() + 1)
.await
.unwrap()
.as_ref(),
runtime_js_source().as_bytes()
);
}
// req: axum_integration/005