Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

test(scripts): synchronize async chunk fixture on execution

ldm0bfb22b2cd5e5
diff --git a/moli-core/tests/fixtures/runtime/parse_time_async_classic_chunked.html b/moli-core/tests/fixtures/runtime/parse_time_async_classic_chunked.html
index a0e70a524..06dc851ef 100644
--- a/moli-core/tests/fixtures/runtime/parse_time_async_classic_chunked.html
+++ b/moli-core/tests/fixtures/runtime/parse_time_async_classic_chunked.html
@@ -7,7 +7,7 @@
window.parseTimeDclFired = true;
});
</script>
- <script async src="/assets/parse_time_async.js"></script>
+ <script async src="/assets/parse_time_async_chunked.js"></script>
</head>
<body>
<!--
diff --git a/moli-core/tests/fixtures/runtime/parse_time_async_classic_chunked.js b/moli-core/tests/fixtures/runtime/parse_time_async_classic_chunked.js
new file mode 100644
index 000000000..2b7172b27
--- /dev/null
+++ b/moli-core/tests/fixtures/runtime/parse_time_async_classic_chunked.js
@@ -0,0 +1,4 @@
+window.parseTimeAsyncSawTail = !!document.getElementById("late");
+window.parseTimeAsyncSawDcl = window.parseTimeDclFired === true;
+// Release the response tail only after observing the parser's partial DOM.
+void fetch("/compat/parse-time-async-classic-chunked-executed");
diff --git a/moli-test-support/src/lib.rs b/moli-test-support/src/lib.rs
index 6cb26618a..c05112a3b 100644
--- a/moli-test-support/src/lib.rs
+++ b/moli-test-support/src/lib.rs
@@ -650,6 +650,8 @@ const PARSE_TIME_ASYNC_CLASSIC_HTML: &str =
include_str!("../../moli-core/tests/fixtures/runtime/parse_time_async_classic.html");
const PARSE_TIME_ASYNC_CLASSIC_CHUNKED_HTML: &str =
include_str!("../../moli-core/tests/fixtures/runtime/parse_time_async_classic_chunked.html");
+const PARSE_TIME_ASYNC_CLASSIC_CHUNKED_JS: &str =
+ include_str!("../../moli-core/tests/fixtures/runtime/parse_time_async_classic_chunked.js");
const PARSE_TIME_ASYNC_CLASSIC_SLOW_CHUNKED_TAIL_HTML: &str = include_str!(
"../../moli-core/tests/fixtures/runtime/parse_time_async_classic_slow_chunked_tail.html"
);
diff --git a/moli-test-support/src/routes_core.rs b/moli-test-support/src/routes_core.rs
index 480e045c3..0b0bd1695 100644
--- a/moli-test-support/src/routes_core.rs
+++ b/moli-test-support/src/routes_core.rs
@@ -2096,8 +2096,11 @@ pub(super) async fn parse_time_async_classic_chunked_page(headers: HeaderMap) ->
{
return;
}
- let _ = tokio::time::timeout(Duration::from_millis(500), tail_gate.notified()).await;
- sleep(Duration::from_millis(20)).await;
+ // A request for the asset does not imply that its body has arrived or
+ // executed. Its dedicated script acknowledges execution before tail
+ // delivery. The timeout is only a bounded failure escape: the test's
+ // before-tail assertions still fail if the parser cannot make progress.
+ let _ = tokio::time::timeout(Duration::from_secs(5), tail_gate.notified()).await;
let _ = tx
.send(Ok::<Bytes, std::convert::Infallible>(Bytes::from(tail)))
.await;
@@ -2114,6 +2117,13 @@ pub(super) async fn parse_time_async_classic_chunked_page(headers: HeaderMap) ->
.expect("chunked async classic response should build")
}
+pub(super) async fn parse_time_async_classic_chunked_executed(headers: HeaderMap) -> StatusCode {
+ if let Some(host_key) = request_host_key(&headers) {
+ notify_parse_time_async_chunked_tail_gate_if_present(&host_key);
+ }
+ StatusCode::NO_CONTENT
+}
+
pub(super) async fn parse_time_async_classic_slow_chunked_tail_page() -> Response {
let split_marker = "<script defer";
let split_index = PARSE_TIME_ASYNC_CLASSIC_SLOW_CHUNKED_TAIL_HTML
@@ -4362,13 +4372,14 @@ pub(super) async fn asset_parse_time_defer_script() -> Response {
javascript_response(PARSE_TIME_DEFER_JS)
}
-pub(super) async fn asset_parse_time_async_script(headers: HeaderMap) -> Response {
- if let Some(host_key) = request_host_key(&headers) {
- notify_parse_time_async_chunked_tail_gate_if_present(&host_key);
- }
+pub(super) async fn asset_parse_time_async_script() -> Response {
javascript_response(PARSE_TIME_ASYNC_JS)
}
+pub(super) async fn asset_parse_time_async_chunked_script() -> Response {
+ javascript_response(PARSE_TIME_ASYNC_CLASSIC_CHUNKED_JS)
+}
+
pub(super) async fn asset_parse_time_async_load_order_script() -> Response {
javascript_response(PARSE_TIME_ASYNC_LOAD_ORDER_JS)
}
diff --git a/moli-test-support/src/server_routes.rs b/moli-test-support/src/server_routes.rs
index 46959608b..7a6c387c7 100644
--- a/moli-test-support/src/server_routes.rs
+++ b/moli-test-support/src/server_routes.rs
@@ -1129,6 +1129,10 @@ pub(super) fn build_router() -> Router {
"/compat/parse-time-async-classic-chunked",
get(parse_time_async_classic_chunked_page),
)
+ .route(
+ "/compat/parse-time-async-classic-chunked-executed",
+ get(parse_time_async_classic_chunked_executed),
+ )
.route(
"/compat/parse-time-async-classic-slow-chunked-tail",
get(parse_time_async_classic_slow_chunked_tail_page),
@@ -2138,6 +2142,10 @@ pub(super) fn build_router() -> Router {
"/assets/parse_time_async.js",
get(asset_parse_time_async_script),
)
+ .route(
+ "/assets/parse_time_async_chunked.js",
+ get(asset_parse_time_async_chunked_script),
+ )
.route(
"/assets/parse_time_async_load_order.js",
get(asset_parse_time_async_load_order_script),