Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/edda

xtask/tests/spawn_reasons.rs

//! ★ **Every raw spawn in edda's runtime crates says why it is not a jera job** (A32-14; RA4-11
//! for estate-front, whose spawns moved here from gunnar in A32-11 step 2).
//!
//! The matcher is the shared one (RA4-7): `nornir_xtask_support::spawn_guard`, the same call-shape
//! guard gunnar, monetize and holger run, so a `.spawn(` on any receiver, a detached
//! `spawn_blocking(` and a process constructor are all seen, not only a list of receiver names.

use std::path::Path;

use nornir_xtask_support::spawn_guard::{message, Guard};

/// The trees edda's guard reads: EVERY crate of edda but the [`TOOLING`] and the [`MACHINERY`]
/// (RA5-35: it read estate-front only, so the runtime crates a box runs went unread: wg-appliance-core's
/// HubRelay, estate-clock, nornir-git, guest-host, admit, appliance-grow). estate-front serves every
/// product's :80/:443; [`every_crate_that_runs_in_a_box_is_guarded`] keeps a new crate from going unread.
const GUARD: Guard<'static> = Guard {
    trees: &[
        "crates/admit/src",
        "crates/app-heartbeat/src",
        "crates/appliance-grow/src",
        "crates/appliance-pid1/src",
        "crates/autonom/src",
        "crates/cloud-media-bootproof/src",
        "crates/disk-snapshot/src",
        "crates/dwarves-runa/src",
        "crates/edda-build-thing/src",
        "crates/eid-app/src",
        "crates/eid-core/src",
        "crates/estate-clock/src",
        "crates/estate-front/src",
        "crates/guest-host/src",
        "crates/gunnar-bitmap/src",
        "crates/gunnar-delta/src",
        "crates/gunnar-pack/src",
        "crates/gunnar-pktline/src",
        "crates/gunnar-sendpack/src",
        "crates/gunnar-stage/src",
        "crates/nordisk-alloc/src",
        "crates/nordisk-console-switch/src",
        "crates/nornir-appshell/src",
        "crates/nornir-auth-apikey/src",
        "crates/nornir-auth-bearer/src",
        "crates/nornir-auth-client/src",
        "crates/nornir-auth-mtls/src",
        "crates/nornir-auth-oauth2/src",
        "crates/nornir-auth-oidc/src",
        "crates/nornir-auth-policy/src",
        "crates/nornir-auth-saml/src",
        "crates/nornir-auth-sshsig/src",
        "crates/nornir-auth-webauthn/src",
        "crates/nornir-claude/src",
        "crates/nornir-cli-outcome/src",
        "crates/nornir-config/src",
        "crates/nornir-crashlog/src",
        "crates/nornir-docbook/src",
        "crates/nornir-docgen/src",
        "crates/nornir-escape/src",
        "crates/nornir-feature-graph/src",
        "crates/nornir-flight/src",
        "crates/nornir-gate/src",
        "crates/nornir-git/src",
        "crates/nornir-graph/src",
        "crates/nornir-hash/src",
        "crates/nornir-humanize/src",
        "crates/nornir-identity/src",
        "crates/nornir-identity-directory/src",
        "crates/nornir-identity-session/src",
        "crates/nornir-identity-sso/src",
        "crates/nornir-identity-web/src",
        "crates/nornir-knowledge-view/src",
        "crates/nornir-parquet-delta/src",
        "crates/nornir-poll-cadence/src",
        "crates/nornir-purgatory/src",
        "crates/nornir-release-ledger/src",
        "crates/nornir-service/src",
        "crates/nornir-tpm/src",
        "crates/nornir-trace/src",
        "crates/nornir-vault/src",
        "crates/nornir-warehouse-trait/src",
        "crates/nornir-wire/src",
        "crates/nornir-workspace/src",
        "crates/nornir-zone/src",
        "crates/step-board/src",
        "crates/storage-git-gix/src",
        "crates/upcloud-api/src",
        "crates/wg-appliance-core/src",
    ],
    machinery: &[],
};

#[test]
fn every_raw_spawn_in_eddas_runtime_crates_says_why_it_is_not_a_jera_job() {
    let root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().expect("xtask sits in the repository root");
    let bad = GUARD.unreasoned_in(root);
    assert!(bad.is_empty(), "{}", message(&bad, "jera::jobs"));
}

/// RA5-35: the crates that run on a build or test host and never in a box: their processes and
/// threads are the tool's own work (cargo, git, a browser, a benchmark), not a server's.
const TOOLING: &[&str] = &[
    "nornir-bench", "nornir-build-info-flight", "nornir-build-thing", "nornir-codegen-judge", "nornir-coverage",
    "nornir-depgraph", "nornir-fleet", "nornir-pages", "nornir-release", "nornir-release-core", "nornir-robotui",
    "nornir-saga", "nornir-testmatrix", "nornir-xtask-support", "web-journey",
];
/// The job machinery: jera's spawns ARE the jobs (the ledger's runner, its process and VM boot).
const MACHINERY: &[&str] = &["jera"];

/// RA5-35: every crate of edda whose code runs in a box is read. A crate under `crates/` is in the
/// guard's trees, or named as tooling or machinery above, so a new crate cannot go unread.
#[test]
fn every_crate_that_runs_in_a_box_is_guarded() {
    let root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().expect("xtask sits in the repository root");
    let mut unread = Vec::new();
    for e in std::fs::read_dir(root.join("crates")).expect("crates/").flatten() {
        let name = e.file_name().to_string_lossy().into_owned();
        let tree = format!("crates/{name}/src");
        let named = TOOLING.contains(&name.as_str()) || MACHINERY.contains(&name.as_str());
        if root.join(&tree).is_dir() && !named && !GUARD.trees.contains(&tree.as_str()) {
            unread.push(name);
        }
    }
    unread.sort();
    assert!(unread.is_empty(), "crates the spawn guard does not read (add them to GUARD, or say why they are TOOLING): {unread:?}");
    for name in TOOLING.iter().chain(MACHINERY) {
        assert!(root.join("crates").join(name).join("src").is_dir(), "{name} is named but is no crate here");
        assert!(!GUARD.trees.contains(&format!("crates/{name}/src").as_str()), "{name} is both guarded and left out");
    }
}