crates/gunnar-ui-server/tests/public_site_feature.rs
//! **The owner's SLIM RULE, held to the dependency graph** (TASKS-12,
//! 2026-10-25): `gunnar-public-site` is in this crate's tree ONLY under the
//! `public-site` feature. The default build does not contain it at all; the
//! routes' half of the rule is `anonymous::public_site`.
//!
//! Asked of cargo itself (`cargo tree`, offline, against this lock), because
//! the claim is about what cargo would compile, and only cargo can say that.
use std::process::Command;
fn tree(features: &[&str]) -> String {
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned());
let manifest = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
let mut cmd = Command::new(cargo);
cmd.args(["tree", "--offline", "--locked", "--manifest-path", manifest, "-p", "gunnar-ui-server", "-e", "normal", "--prefix", "none"]);
if !features.is_empty() {
cmd.args(["--features", &features.join(",")]);
}
let out = cmd.output().expect("cargo tree runs");
assert!(out.status.success(), "cargo tree failed: {}", String::from_utf8_lossy(&out.stderr));
String::from_utf8_lossy(&out.stdout).into_owned()
}
#[test]
fn the_default_build_does_not_contain_the_public_site() {
let t = tree(&[]);
assert!(t.contains("gunnar-ui-server"), "{t}");
assert!(!t.contains("gunnar-public-site"), "the default build links the public site:\n{t}");
}
#[test]
fn the_metered_build_does_not_contain_it_either() {
assert!(!tree(&["metered"]).contains("gunnar-public-site"));
}
#[test]
fn the_public_site_build_does() {
assert!(tree(&["public-site"]).contains("gunnar-public-site"));
}
#[test]
fn the_feature_is_off_by_default_in_the_manifest() {
let manifest = std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml")).unwrap();
let default = manifest.lines().find(|l| l.starts_with("default = ")).expect("a default line");
assert!(!default.contains("public-site"), "{default}");
assert!(manifest.contains("public-site = [\"dep:gunnar-public-site\", \"dep:ureq\", \"dep:nordisk-console-switch\"]"));
}