crates/gunnar-ui-server/tests/mcp_feature.rs
//! **The SLIM RULE for the MCP connector, held to the dependency graph**
//! (TASKS-13, owner 2026-10-25): `gunnar-mcp` is in this crate's tree ONLY
//! under the `mcp` feature. The default build does not contain it at all; the
//! routes' half of the rule is `anonymous::mcp`.
//!
//! 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_mcp_connector() {
let t = tree(&[]);
assert!(t.contains("gunnar-ui-server"), "{t}");
assert!(
!t.contains("gunnar-mcp"),
"the default build links the MCP connector:\n{t}"
);
}
#[test]
fn the_metered_build_does_not_contain_it_either() {
assert!(!tree(&["metered"]).contains("gunnar-mcp"));
}
#[test]
fn the_mcp_build_does() {
assert!(tree(&["mcp"]).contains("gunnar-mcp"));
}
#[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("mcp"), "{default}");
assert!(manifest.contains("mcp = [\"dep:gunnar-mcp\", \"dep:nordisk-console-switch\"]"));
}