crates/monetize-ui-server/tests/console_compiles.rs
//! The console must actually compile for the browser.
//!
//! `monetize-ui-web` is built for the browser and `cargo test --workspace`
//! builds it for the HOST. Its pure `fmt` tests do run there — that is measured,
//! not assumed — but a host build says nothing about whether the crate compiles
//! for `wasm32`, which is the only target the console is ever served from. So on
//! 2026-09-05 a change landed with **242 tests green** and a console that did
//! not compile at all: the operator would have got a blank page, and nothing in
//! the suite could have said so.
//!
//! (This paragraph used to claim the workspace run "never builds it" and that
//! the crate "cannot host tests". Both are false — `cargo test --workspace`
//! reports `fmt::tests::…` results from it. The hole is the TARGET, not the
//! crate, and stating it wrongly invites someone to close it in the wrong
//! place.)
//!
//! This guard closes that hole from the one crate that both ships the console
//! (`--ui-dir` serves its bundle) and can host a test.
//!
//! Two deliberate choices, both of which cost something:
//!
//! * It shells out to `cargo`. That is slower than a normal test and it
//! contends on the target directory lock. The alternative is no coverage at
//! all for the half of this product a human actually looks at, which is a
//! worse trade. It uses a *separate* target dir so it cannot deadlock against
//! the run that invoked it — the sibling repo has a flaky guard for exactly
//! the reason this one avoids.
//! * **A missing `wasm32` target FAILS, it does not skip.** A guard that
//! reports `ok` when it could not run is the shape that lets a real defect
//! through wearing a green badge, and this repo has already been bitten by
//! one of those in a sibling (`cli_matrix` reported `ok` whenever its binary
//! was absent). Unmeasured is not a pass. If this fails on your machine,
//! `rustup target add wasm32-unknown-unknown` — that is the fix, not a skip.
use std::path::PathBuf;
use std::process::Command;
fn workspace_root() -> PathBuf {
// CARGO_MANIFEST_DIR is <root>/crates/monetize-ui-server
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.and_then(|p| p.parent())
.expect("the manifest dir must sit two levels under the workspace root")
.to_path_buf()
}
#[test]
fn the_console_compiles_for_the_browser() {
let root = workspace_root();
let installed = Command::new("rustup")
.args(["target", "list", "--installed"])
.output();
match installed {
Ok(out) if String::from_utf8_lossy(&out.stdout).contains("wasm32-unknown-unknown") => {}
Ok(out) => panic!(
"wasm32-unknown-unknown is not installed, so the console was NOT checked. \
UNMEASURED IS NOT A PASS — run `rustup target add wasm32-unknown-unknown`. \
installed targets: {}",
String::from_utf8_lossy(&out.stdout).replace('\n', " ")
),
Err(e) => panic!(
"could not ask rustup which targets are installed ({e}), so the console was NOT \
checked. UNMEASURED IS NOT A PASS."
),
}
let out = Command::new(env!("CARGO"))
.current_dir(&root)
.args([
"check",
"--quiet",
"--target",
"wasm32-unknown-unknown",
"-p",
"monetize-ui-web",
// Its own directory, so this check cannot block on the lock held by
// the very `cargo test` invocation that is running it.
"--target-dir",
"target/console-compile-guard",
])
.output()
.expect("cargo must be runnable");
assert!(
out.status.success(),
"the console does not compile for wasm32, so the operator would be served a page that \
cannot start. `cargo test --workspace` cannot see this on its own — that is why this \
guard exists.\n--- cargo stderr ---\n{}",
String::from_utf8_lossy(&out.stderr)
);
}