fn declared_targets() -> Vec<String> {
let src = std::fs::read_to_string(
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fuzz/Cargo.toml"),
)
.expect("read fuzz/Cargo.toml");
let mut out = Vec::new();
let mut in_bin = false;
for line in src.lines() {
let t = line.trim();
if t == "[[bin]]" {
in_bin = true;
continue;
}
if t.starts_with('[') {
in_bin = false;
continue;
}
if in_bin && let Some(rest) = t.strip_prefix("name = ") {
out.push(rest.trim().trim_matches('"').to_string());
in_bin = false;
}
}
out.sort();
out
}
fn matrix_targets(workflow: &str) -> Vec<String> {
let src = std::fs::read_to_string(
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(".github/workflows").join(workflow),
)
.unwrap_or_else(|e| panic!("read {workflow}: {e}"));
let line = src
.lines()
.map(str::trim)
.find(|l| l.starts_with("target: ["))
.unwrap_or_else(|| panic!("{workflow} declares no `target: [...]` matrix"));
let inner = line
.trim_start_matches("target: [")
.trim_end_matches(']');
let mut out: Vec<String> =
inner.split(',').map(|s| s.trim().to_string()).filter(|s| !s.is_empty()).collect();
out.sort();
out
}
fn nightly_targets() -> Vec<String> {
let mut out = matrix_targets("fuzz.yml");
out.push("parse".to_string());
out.sort();
out
}
#[test]
fn every_fuzz_target_is_wired_into_the_nightly() {
let declared = declared_targets();
assert!(declared.len() >= 8, "only {} targets found — the Cargo.toml parse is wrong", declared.len());
assert_eq!(
declared,
nightly_targets(),
"fuzz/Cargo.toml and the nightly disagree. A target missing from the nightly never explores, \
so its corpus never grows and the per-push replay has nothing to replay."
);
}
#[test]
fn every_fuzz_target_is_wired_into_the_per_push_replay() {
let declared = declared_targets();
assert_eq!(
declared,
matrix_targets("fuzz-replay.yml"),
"fuzz/Cargo.toml and the per-push replay disagree. A target missing from the replay still \
finds bugs overnight, but a regression in it stays invisible until the next morning — \
which is the whole reason the replay exists."
);
}