Files
moli/moli-core/tests/web_apis/request_stream.rs
T
ldm0 e0ea2537bc fix(fetch): preserve and clone Request stream bodies
Retain ReadableStream BodyInit values instead of extracting empty bytes.
Validate stream construction options, tee cloned bodies with independent
chunks, and proxy inherited stream-only bodies while immediately marking
the original disturbed. Use native stream operations for cancellation and
error propagation even when public stream methods are overridden.

Cover consumption, clone isolation, validation, errors, and cancellation in
window, child-frame, and worker realms. The 37-case Fetch WPT comparison
adds four passing cases and six passing subtests without regressions;
public stream tee still passes all 52 subtests.

Validation: cargo fmt --all; cargo clippy --workspace --all-targets
--all-features -- -D warnings; cargo nextest run --no-fail-fast
(17,943 passed, 13 skipped); 9/9 CLI regression probes.
2026-11-02 06:02:17 +08:00

43 lines
1.4 KiB
Rust

use super::*;
async fn assert_request_stream_body(scenario: &str) -> Result<()> {
let server = FixtureServer::spawn().await?;
let browser = Browser::new(AppConfig::default())?;
let source = format!(
"{}\nrunRequestStreamBodyProbe({}, {}).then(finish, error => finish({{error: String(error)}}));",
include_str!("../fixtures/runtime/request_stream_body.js"),
serde_json::to_string(scenario)?,
serde_json::to_string(&server.url("/net/echo"))?,
);
for target in ["window", "child", "worker"] {
let observed = tokio::time::timeout(
Duration::from_secs(20),
super::event_dispatch::run_probe(&browser, &server, target, &source),
)
.await??;
assert_eq!(
observed,
serde_json::json!({"errors": []}),
"{scenario}/{target}"
);
}
server.shutdown().await;
Ok(())
}
#[tokio::test(flavor = "multi_thread")]
async fn request_stream_inputs_preserve_identity_bytes_and_consumption_state() -> Result<()> {
assert_request_stream_body("input").await
}
#[tokio::test(flavor = "multi_thread")]
async fn request_stream_clones_tee_bytes_and_forward_cancellation_and_errors() -> Result<()> {
assert_request_stream_body("clone").await
}
#[tokio::test(flavor = "multi_thread")]
async fn request_stream_construction_proxies_inherited_bodies_and_respects_overrides() -> Result<()>
{
assert_request_stream_body("inherit").await
}