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

nordisk/gunnar

xtask/tests/detached_same_as_root.rs

//! **The detached front and guest build as they did inside the root workspace**
//! (2026-10-22).
//!
//! `crates/gunnar-front` and `crates/gunnar-monetize-guest` left the root workspace
//! so that a lone clone can load it (`xtask/tests/lone_clone.rs`). A detached
//! workspace takes its profiles and its `[patch]` from its OWN manifest, so the
//! root's were copied into each; this fails the day the copies drift, which would
//! silently build the front with another profile than the server.

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

const DETACHED: &[&str] = &["crates/gunnar-front", "crates/gunnar-monetize-guest"];

fn root() -> PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR"))
        .parent()
        .expect("xtask has a parent")
        .to_path_buf()
}

/// Pure: the `[profile.*]` tables of a manifest, comments and blank lines dropped.
fn profiles(manifest: &str) -> Vec<String> {
    let mut out = Vec::new();
    let mut on = false;
    for line in manifest.lines().map(str::trim) {
        if line.starts_with('[') {
            on = line.starts_with("[profile.");
        }
        if on && !line.is_empty() && !line.starts_with('#') {
            out.push(line.to_string());
        }
    }
    out
}

#[test]
fn profiles_reads_only_profile_tables() {
    let m = "[package]\nname = \"x\"\n[profile.release]\n# c\nlto = \"thin\"\n\n[workspace]\n[profile.test]\ndebug = 1\n";
    assert_eq!(
        profiles(m),
        [
            "[profile.release]",
            "lto = \"thin\"",
            "[profile.test]",
            "debug = 1"
        ]
    );
}

#[test]
fn each_detached_crate_has_the_roots_profiles_and_vendored_patch() {
    let root = root();
    let root_text = std::fs::read_to_string(root.join("Cargo.toml")).expect("root Cargo.toml");
    let want = profiles(&root_text);
    assert!(want.len() > 10, "the root's profiles were not found");
    for d in DETACHED {
        let text =
            std::fs::read_to_string(root.join(d).join("Cargo.toml")).expect("detached manifest");
        assert!(
            text.lines().any(|l| l.trim() == "[workspace]"),
            "{d} is not its own workspace"
        );
        assert_eq!(
            profiles(&text),
            want,
            "{d}'s profiles drifted from the root's"
        );
        assert!(
            text.contains("gix-parallel = { path = \"../../vendor/gix-parallel\" }"),
            "{d} lost the vendored gix-parallel patch the root applies"
        );
        assert!(
            root_text.lines().any(|l| l.trim() == format!("\"{d}\",")),
            "the root workspace does not exclude {d}"
        );
    }
}