xtask/tests/no_silenced_tests.rs
//! **Tripwire: no `tests/*.rs` anywhere in the nornir workspace may compile to
//! ZERO tests.**
//!
//! A test file whose crate-level inner attribute — `#![cfg(feature = "X")]` —
//! is not satisfied by its crate's `default` feature closure compiles to an
//! EMPTY test binary. `cargo test` then prints `running 0 tests ... ok` and the
//! file is green-by-vacuum: it looks exactly like a passing file, forever.
//! `nornir_testmatrix::audit_repo` resolves every workspace member's `default`
//! closure statically and RED-flags any gated file that is neither
//! default-reachable nor re-invoked by an arm declared in
//! `.nornir/testmatrix-arms.json`.
//!
//! This repo OWNS the engine that finds those files (the guard lives in
//! `../edda/crates/nornir-testmatrix`, and nornir re-exports it). Until now it
//! did not run it on itself.
//!
//! ## What this repo looks like today
//!
//! Measured 2026-08-01 on `oden`, at `origin/main`: **94 test targets scanned ·
//! 64 feature-gated · 5 rescued by declared arms · 0 silenced**.
//!
//! Sixty-four of ninety-four test targets — roughly **two thirds** — carry a
//! crate-level `#![cfg]`. That is the highest gated fraction in the fleet, and
//! it is why nornir is the repo where this check is worth the most. Fifty-nine
//! of those are safe for a dull reason: nornir's `default` set is enormous
//! (server, viz, mcp, net-scan, docs-export, robot, vector, embed-tract,
//! embed-ort, gen-candle, gen-ollama, manual-embed, claude, embed-holger), so a
//! file gated on `viz` alone compiles on a plain `cargo test`. The remaining
//! five are genuinely dark and live only because
//! `.nornir/testmatrix-arms.json` declares two arms for them:
//!
//! ```json
//! { "package": "nornir", "features": ["scip", "testmatrix", "saga", "ra-ingest"] }
//! { "package": "nornir", "features": ["embed-ort-rocm"], "test": "embed_rocm_buckets" }
//! ```
//!
//! That enormous default set is exactly what makes the camouflage work here.
//! The audit named the shape: `all(default-on, default-on, default-OFF)` — a
//! file reads identically to its many running siblings and only the last
//! conjunct is dark. With 59 legitimately-gated-and-running files as cover,
//! a sixtieth that quietly names `scip` or `testmatrix` is invisible to review.
//! Nothing but this check distinguishes them.
//!
//! It has already caught real rot rather than hypothetical rot. When the two
//! arms above were first declared, un-silencing the dark files exposed three
//! bit-rotted tests that nobody had compiled in months:
//! `self_emitters_server.rs` (edition-2024 `set_var` unsafety + a stale struct
//! literal), `viz_utfallsrum_slice.rs` (seeding a spawned server through a
//! `NORNIR_MONITOR` env the server had stopped reading, so it timed out every
//! run), and `ragnars_emb_matrix.rs` — deleted, not rescued, because it drove a
//! `znippy_zoomies::vann::ragnars_emb` module that no longer exists. Declaring
//! a false rescue for an uncompilable file would have been exactly the
//! green-by-vacuum this guard forbids.
//!
//! What this file does NOT prove: that either arm is ever executed, or that the
//! rescued files still pass. It proves the arms exist and still cover every dark
//! file. The `embed_rocm_buckets` arm in particular is COMPILE-verified only —
//! its own note in the arms file says so, and no static audit can upgrade that.
//!
//! ## Why it lives in `xtask`
//!
//! `audit_repo` shells `cargo metadata` at the repo root, so the check is
//! workspace-wide no matter which member hosts it. `xtask` is `publish = false`
//! and its whole dependency set is two tiny edda leaves, so the guard compiles
//! in a blink; hanging it off the root `nornir` package would mean building
//! iceberg, arrow, eframe, wgpu and tantivy before a pure-metadata scan could
//! run, and a guard slow enough to skip gets skipped.
//!
//! The non-vacuity assertion below matters as much as the silence assertion: a
//! repo root that resolves but scans nothing reports "0 silenced" because it
//! looked at nothing. `scanned > 0` is what separates a real green from an empty
//! one — and here it is doing double duty as the check on `ancestors().nth(1)`,
//! since an `xtask`-relative root that drifted would scan xtask alone. (Two
//! repos in this fleet — bifrost and heimdal — genuinely scan zero targets, and
//! for that reason deliberately do NOT carry this file.)
//!
//! Deliberately NOT feature-gated: a guard against silenced tests that is itself
//! silenced is the joke that writes itself — and in a repo where two thirds of
//! the test targets are gated, it is the joke that writes itself twice.
use std::path::{Path, PathBuf};
/// This file lives at `<repo>/xtask/tests/`, so `CARGO_MANIFEST_DIR` is
/// `<repo>/xtask` and the WORKSPACE `Cargo.toml` is one ancestor up:
/// `nth(0)` = `xtask`, **`nth(1)` = the repo root**.
fn repo_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(1)
.unwrap()
.to_path_buf()
}
#[test]
fn this_repo_has_no_silenced_test_files() {
let root = repo_root();
// Cheap, explicit proof that `nth(1)` still points where the doc comment
// says: the WORKSPACE manifest, not xtask's own.
let manifest = root.join("Cargo.toml");
assert!(
manifest.exists(),
"repo_root() resolved to {} which has no Cargo.toml — the ancestors().nth(N) \
in this file is wrong for where it now lives",
root.display()
);
let rep = nornir_testmatrix::audit_repo(&root, "self-audit").unwrap_or_else(|e| {
panic!(
"the silenced-test audit could not RUN at {} — that is a RED, not a skip: {e:#}",
root.display()
)
});
// Non-vacuity (LAW 2: check output, not exit code). A root that resolves but
// scans nothing reports "0 silenced" because it looked at nothing. This also
// catches a root that resolved to `xtask` itself, which has one test target.
assert!(
rep.scanned > 1,
"the audit scanned {} test target(s) under {} — nornir has ~94, so this \
did not look at the workspace and proved nothing",
rep.scanned,
root.display()
);
assert!(
rep.is_green(),
"SILENCED TESTS in `nornir` — {}\n{}",
rep.summary(),
rep.silenced()
.iter()
.map(|f| format!(" · {}", f.message()))
.collect::<Vec<_>>()
.join("\n")
);
}