Gunnar

mikronova/funnel-core

tests/no_silenced_tests.rs

//! **Tripwire: no `tests/*.rs` in this repo 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`.
//!
//! ## What this repo looks like today
//!
//! Measured 2026-08-01 on `oden`: **1 test target scanned · 0 feature-gated ·
//! 0 silenced · 0 declared arms**. funnel-core is a pure workflow-DAG core with
//! an EMPTY `[features]` table — there is no feature anything could hide behind,
//! so `tests/public_api.rs` is unconditionally compiled and the repo is GREEN by
//! construction rather than by declaration. That is precisely why adopting the
//! guard here costs nothing and is worth doing: it is a **tripwire for the
//! future**. The day someone adds a `[features]` table and gates a test file on
//! a non-default arm, this test goes red on that commit instead of eleven days
//! and 122 hidden `#[test]` fns later — which is what the fleet-wide sweep found
//! had already happened elsewhere.
//!
//! 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. (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.

use std::path::{Path, PathBuf};

/// This file lives at `<repo>/tests/`, and funnel-core's package root IS the
/// repo root (a standalone, workspace-less crate), so `CARGO_MANIFEST_DIR` is
/// already the directory holding the `Cargo.toml` the audit must run against.
fn repo_root() -> PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR"))
        .ancestors()
        .nth(0)
        .unwrap()
        .to_path_buf()
}

#[test]
fn this_repo_has_no_silenced_test_files() {
    let root = repo_root();
    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.
    assert!(
        rep.scanned > 0,
        "the audit scanned ZERO test targets under {} — it proved nothing",
        root.display()
    );
    assert!(
        rep.is_green(),
        "SILENCED TESTS in `funnel-core` — {}\n{}",
        rep.summary(),
        rep.silenced()
            .iter()
            .map(|f| format!("  · {}", f.message()))
            .collect::<Vec<_>>()
            .join("\n")
    );
}