test(xtask): assert html examples avoid reloads

Wrap html_examples browser smoke interactions with a no-navigation guard so dynamic paths fail if native form fallback or full-page reload occurs.

req: test/014

req: test/006
This commit is contained in:
slhx agent
2026-06-25 18:37:27 +02:00
parent da8fb70168
commit 1a67d0c5a4
3 changed files with 31 additions and 5 deletions
+27 -4
View File
@@ -103,7 +103,10 @@ fn run_html_examples_smoke() -> ExitCode {
if let Err(code) = cdp_wait_for_html_examples() {
return code;
}
if let Err(code) = cdp_assert("revealed fallback without IntersectionObserver", REVEALED_FALLBACK_SMOKE) {
if let Err(code) = cdp_assert(
"revealed fallback without IntersectionObserver",
REVEALED_FALLBACK_SMOKE,
) {
return code;
}
println!("html_examples smoke ok: revealed fallback without IntersectionObserver");
@@ -124,7 +127,10 @@ fn pick_unused_port() -> Result<u16, ExitCode> {
fn start_html_examples_server(addr: &str) -> Result<HtmlExamplesServer, ExitCode> {
let mut child = Command::new("cargo")
.args(["run", "-p", "hemx-html-examples"])
.env("HEMX_HTML_EXAMPLES_PORT", addr.rsplit(':').next().unwrap_or("3029"))
.env(
"HEMX_HTML_EXAMPLES_PORT",
addr.rsplit(':').next().unwrap_or("3029"),
)
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
@@ -206,7 +212,9 @@ fn cdp_wait_for_html_examples() -> Result<(), ExitCode> {
ExitCode::FAILURE
})?;
if output.status.success()
&& String::from_utf8_lossy(&output.stdout).trim().ends_with("true")
&& String::from_utf8_lossy(&output.stdout)
.trim()
.ends_with("true")
{
return Ok(());
}
@@ -217,8 +225,23 @@ fn cdp_wait_for_html_examples() -> Result<(), ExitCode> {
}
fn cdp_assert(name: &str, script: &str) -> Result<(), ExitCode> {
// Each interaction must be handled by hemx without full-page navigation or
// reload; failures here catch native form fallback sneaking into the smoke. req: test/014
let guarded_script = format!(
r#"(async()=>{{
const __hemxSmokeUrl = location.href;
const __hemxSmokeMarker = String(Date.now()) + Math.random();
const __hemxSmokeNavCount = performance.getEntriesByType("navigation").length;
window.__hemxSmokeNoReload = __hemxSmokeMarker;
const __hemxSmokeResult = await ({script});
if (location.href !== __hemxSmokeUrl) throw new Error("page navigated during smoke interaction");
if (window.__hemxSmokeNoReload !== __hemxSmokeMarker) throw new Error("page reloaded during smoke interaction");
if (performance.getEntriesByType("navigation").length !== __hemxSmokeNavCount) throw new Error("navigation entry changed during smoke interaction");
return __hemxSmokeResult;
}})()"#
);
let output = Command::new("cdp-browser")
.args(["js", script])
.args(["js", &guarded_script])
.output()
.map_err(|err| {
eprintln!("failed to run browser smoke `{name}`: {err}");