mod embeds;
use std::path::{Path, PathBuf};
fn packaged() -> Vec<String> {
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned());
let mut cmd = crate::spawn::command(&cargo);
cmd.current_dir(root())
.args(["package", "--list", "--offline", "--allow-dirty"]);
let out = crate::spawn::output(&mut cmd).expect("cargo runs");
assert!(
out.status.success(),
"cargo package --list did not answer: {}",
String::from_utf8_lossy(&out.stderr)
);
String::from_utf8_lossy(&out.stdout)
.lines()
.map(str::to_owned)
.collect()
}
fn root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
}
fn is_ruled_in(path: &str) -> bool {
let named = matches!(
path,
"Cargo.toml"
| "Cargo.lock"
| "Cargo.toml.orig"
| ".cargo_vcs_info.json"
| "PROTOCOL"
| "build.rs"
| "README.md"
| "LICENSE"
| "docs/tools.example.json"
);
named
|| path
.strip_prefix("src/")
.is_some_and(|rest| Path::new(rest).extension().is_some_and(|ext| ext == "rs"))
}
#[test]
fn no_commentary_or_apparatus_ships() {
let strays: Vec<String> = packaged().into_iter().filter(|p| !is_ruled_in(p)).collect();
assert!(
strays.is_empty(),
"paths `cargo publish` would upload that no class rules in. A yanked \
version stays downloadable, so widen `include` in Cargo.toml only with \
a reason, and add the class beside it here:\n{}",
strays.join("\n")
);
}
#[test]
fn the_files_a_registry_needs_ship() {
let list = packaged();
for needed in [
"Cargo.toml",
"Cargo.lock",
"PROTOCOL",
"build.rs",
"README.md",
"LICENSE",
"src/lib.rs",
"src/main.rs",
"docs/tools.example.json",
] {
assert!(
list.iter().any(|p| p == needed),
"{needed} is not in the packaged list — `include` dropped a file the \
registry or the build needs"
);
}
}
#[test]
fn the_list_is_not_vacuous() {
let list = packaged();
let sources = list.iter().filter(|p| p.starts_with("src/")).count();
assert!(
sources > 30,
"the packaged list carries {sources} src paths over {} entries — the \
spawn is broken, not the tree",
list.len()
);
}
#[test]
fn the_allowlist_sees_its_own_violations() {
for stray in [
"docs/DESIGN.md",
"AGENTS.md",
"CLAUDE.md",
"Makefile",
"Containerfile",
"deny.toml",
"clippy.toml",
"tarpaulin.toml",
"rules/no-bare-command.yml",
"rules/fixtures/violations.rs",
".githooks/pre-commit",
".github/workflows/release-plz.yml",
"scripts/leak-scan.sh",
"scripts/leak-fixtures/README.md",
"scripts/leak-fixtures/private-key.txt",
] {
assert!(!is_ruled_in(stray), "{stray} must not be ruled in");
}
for shipped in [
"src/main.rs",
"src/channel/tls.rs",
"LICENSE",
"docs/tools.example.json",
] {
assert!(is_ruled_in(shipped), "{shipped} must be ruled in");
}
}
#[test]
fn the_readme_names_the_install_route_for_the_published_crate() {
let readme = std::fs::read_to_string(root().join("README.md")).expect("the README");
assert!(
readme.contains("cargo install thrall --locked"),
"the README no longer names the crate route. It is the file crates.io \
renders, so it is the one page a stranger who found this crate reads, \
and `cargo install` is what they came for"
);
}