#[path = "support/workspace_root.rs"]
#[allow(dead_code)]
mod workspace_root;
use std::{collections::BTreeSet, path::Path};
fn read_rel(rel: &str) -> String {
std::fs::read_to_string(Path::new(env!("CARGO_MANIFEST_DIR")).join(rel))
.unwrap_or_else(|e| panic!("read {rel}: {e}"))
}
fn manifest() -> String {
read_rel("Cargo.toml")
}
fn skip_notice(rel: &str) -> String {
format!("feature_map: skipped — {rel} is not in this source tree (a published tarball?)")
}
fn repo_file(root: Option<&Path>, rel: &str) -> Option<String> {
let Some(root) = root else {
eprintln!("{}", skip_notice(rel));
return None;
};
let path = root.join(rel);
Some(std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("read {}: {e}", path.display())))
}
fn parity_manifest() -> Option<String> {
repo_file(
workspace_root::try_workspace_root().as_deref(),
"coremlit-parity/Cargo.toml",
)
}
fn ci_yml() -> Option<String> {
repo_file(
workspace_root::try_workspace_root().as_deref(),
".github/workflows/ci.yml",
)
}
fn expected_features() -> Vec<(&'static str, Vec<&'static str>)> {
vec![
("default", vec![]),
("serde", vec!["dep:serde", "windit?/serde"]),
("tracing", vec!["dep:tracing"]),
(
"whisper",
vec![
"dep:libc",
"dep:mach2",
"dep:rand",
"dep:serde_json",
"dep:tokenizers",
"dep:unicode_categories",
],
),
(
"nl-recognizer",
vec!["whisper", "dep:objc2-natural-language"],
),
(
"align",
vec![
"dep:asry",
"dep:humantime",
"dep:serde_json",
"dep:serde",
"dep:tokenizers",
],
),
("align-oracle", vec!["align", "asry/alignment"]),
("speaker", vec!["dep:diaric"]),
("vad", vec!["dep:zuoer"]),
(
"clap",
vec![
"dep:rustfft",
"dep:tokenizers",
"dep:windit",
"dep:serde_json",
],
),
(
"granite",
vec![
"dep:tokenizers",
"dep:windit",
"windit/text",
"dep:sha2",
"dep:serde_json",
],
),
(
"ced",
vec!["dep:rustfft", "dep:soundevents-dataset", "dep:windit"],
),
("lid", vec!["dep:rustfft", "dep:windit"]),
("identity", vec!["dep:rustfft"]),
(
"siglip",
vec!["dep:tokenizers", "dep:pixon", "dep:sha2", "dep:serde_json"],
),
("face", vec!["dep:sha2"]),
("commercial-face-arcface", vec!["face"]),
]
}
fn expected_parity_features() -> Vec<(&'static str, Vec<&'static str>)> {
vec![
("default", vec![]),
(
"speaker-oracle",
vec![
"coremlit/speaker",
"dep:dia",
"dep:diaric",
"dia/ort",
"dia/bundled-segmentation",
],
),
("clap-oracle", vec!["coremlit/clap", "dep:textclap"]),
(
"vad-bundled",
vec!["coremlit/vad", "dep:silero", "silero/bundled"],
),
]
}
const BARE_CRATE_MAP: &[(&str, &str)] = &[
("whisperkit", "whisper"),
("alignkit", "align"),
("speakerkit", "speaker"),
("vadkit", "vad"),
("clapkit", "clap"),
];
const INTENDED_CI_COMBOS: &[&str] = &[
"", "whisper",
"align",
"speaker",
"speaker,serde",
"vad",
"whisper,vad",
"align-oracle",
"clap",
"granite",
"siglip",
"ced",
"lid",
"identity",
"identity,speaker",
"face",
"commercial-face-arcface",
"whisper,align,speaker,vad,clap,granite,siglip,ced,lid,identity,face,serde,tracing,nl-recognizer",
"whisper,align-oracle,speaker,vad,clap,granite,siglip,ced,lid,identity,face,serde,tracing,nl-recognizer",
];
const INTENDED_PARITY_CI_COMBOS: &[&str] = &[
"speaker-oracle",
"clap-oracle",
"vad-bundled",
"speaker-oracle,clap-oracle,vad-bundled",
];
fn features_block(manifest: &str) -> String {
let mut out = String::new();
let mut in_features = false;
for line in manifest.lines() {
if line.starts_with('[') {
in_features = line.trim() == "[features]";
continue;
}
if in_features {
out.push_str(line);
out.push('\n');
}
}
out
}
fn feature_names(block: &str) -> BTreeSet<String> {
let mut names = BTreeSet::new();
for line in block.lines() {
if line.starts_with(char::is_whitespace) {
continue;
}
let trimmed = line.trim_start();
if trimmed.is_empty() || trimmed.starts_with('#') {
continue;
}
if let Some((key, _)) = line.split_once('=') {
let key = key.trim();
if !key.is_empty() && !key.contains(char::is_whitespace) {
names.insert(key.to_string());
}
}
}
names
}
fn feature_deps(block: &str, feature: &str) -> BTreeSet<String> {
let mut collecting = false;
let mut buf = String::new();
for line in block.lines() {
if collecting {
buf.push('\n');
buf.push_str(line);
if line.contains(']') {
break;
}
continue;
}
if line.starts_with(char::is_whitespace) {
continue;
}
let Some((key, rest)) = line.split_once('=') else {
continue;
};
if key.trim() != feature {
continue;
}
collecting = true;
buf.push_str(rest);
if rest.contains(']') {
break;
}
}
buf
.split('"')
.skip(1)
.step_by(2)
.map(str::to_string)
.collect()
}
const JOB_INDENT: usize = 2;
fn ci_feature_combos(yaml: &str, job: &str) -> BTreeSet<String> {
let job_key = format!("{job}:");
let mut combos = BTreeSet::new();
let mut in_job = false;
let mut seen_matrix = false;
let mut key_indent: Option<usize> = None;
for line in yaml.lines() {
let indent = line.len() - line.trim_start().len();
let trimmed = line.trim_start();
if trimmed.is_empty() || trimmed.starts_with('#') {
continue;
}
if !in_job {
in_job = indent == JOB_INDENT && trimmed == job_key;
continue;
}
if indent <= JOB_INDENT {
break;
}
let Some(ki) = key_indent else {
if trimmed == "matrix:" {
seen_matrix = true;
} else if seen_matrix && trimmed == "features:" {
key_indent = Some(indent);
}
continue;
};
if indent <= ki {
break;
}
if let Some(inner) = trimmed.strip_prefix("- ").and_then(quoted_inner) {
combos.insert(inner);
}
}
combos
}
fn quoted_inner(s: &str) -> Option<String> {
let start = s.find('"')?;
let rest = &s[start + 1..];
let end = rest.find('"')?;
Some(rest[..end].to_string())
}
fn owned(combos: &[&str]) -> BTreeSet<String> {
combos.iter().map(|s| (*s).to_string()).collect()
}
fn intended_ci_combos() -> BTreeSet<String> {
owned(INTENDED_CI_COMBOS)
}
struct IntendedClippy {
job: &'static str,
package: &'static str,
empty_arm: bool,
}
const FEATURES_CLIPPY: IntendedClippy = IntendedClippy {
job: "features",
package: "coremlit",
empty_arm: true,
};
const PARITY_CLIPPY: IntendedClippy = IntendedClippy {
job: "parity",
package: "coremlit-parity",
empty_arm: false,
};
const CLIPPY_STEP_CONDITION: &str = "${{ !cancelled() }}";
const MATRIX_FEATURES_ARG: &str = r#"--features "${{ matrix.features }}""#;
type CiEntry = (String, Vec<String>);
fn without_comment(line: &str) -> &str {
line
.split_once(" #")
.map_or(line, |(code, _)| code)
.trim_end()
}
fn ci_job_lines<'a>(yaml: &'a str, job: &str) -> Vec<(usize, &'a str)> {
let job_key = format!("{job}:");
let mut lines = Vec::new();
let mut in_job = false;
for line in yaml.lines() {
let trimmed = line.trim_start();
if trimmed.is_empty() || trimmed.starts_with('#') {
continue;
}
let indent = line.len() - trimmed.len();
let text = without_comment(trimmed);
if !in_job {
in_job = indent == JOB_INDENT && text == job_key;
continue;
}
if indent <= JOB_INDENT {
break;
}
lines.push((indent, text));
}
lines
}
fn ci_entry(text: &str) -> CiEntry {
let (key, value) = text.split_once(':').unwrap_or((text, ""));
let value = value.trim();
let body = if value.is_empty() || value.starts_with(['|', '>']) {
Vec::new()
} else {
vec![value.to_string()]
};
(key.trim().to_string(), body)
}
fn ci_steps(job: &[(usize, &str)]) -> Vec<Vec<CiEntry>> {
let Some(at) = job.iter().position(|&(_, text)| text == "steps:") else {
return Vec::new();
};
let steps_indent = job[at].0;
let mut steps: Vec<Vec<CiEntry>> = Vec::new();
let mut first_indent = None;
for &(indent, text) in &job[at + 1..] {
if indent <= steps_indent {
break;
}
let item_indent = *first_indent.get_or_insert(indent);
let opens_step = indent == item_indent && text.starts_with("- ");
if opens_step {
steps.push(Vec::new());
}
let Some(step) = steps.last_mut() else {
return Vec::new();
};
if opens_step || indent == item_indent + 2 {
step.push(ci_entry(if opens_step { &text[2..] } else { text }));
} else if let Some((_, body)) = step.last_mut() {
body.push(text.to_string());
}
}
steps
}
fn ci_body<'a>(step: &'a [CiEntry], key: &str) -> &'a [String] {
step
.iter()
.find(|(name, _)| name == key)
.map_or(&[][..], |(_, body)| body.as_slice())
}
fn ci_commands(step: &[CiEntry]) -> Vec<String> {
let mut commands: Vec<String> = Vec::new();
let mut joining = false;
for line in ci_body(step, "run") {
let (text, continues) = line
.strip_suffix('\\')
.map_or((line.as_str(), false), |head| (head.trim_end(), true));
match commands.last_mut() {
Some(last) if joining => {
last.push(' ');
last.push_str(text);
}
_ => commands.push(text.to_string()),
}
joining = continues;
}
commands
}
fn runs_cargo(command: &str, subcommand: &str) -> bool {
let tokens: Vec<&str> = command.split_whitespace().collect();
tokens.windows(2).any(|pair| pair == ["cargo", subcommand])
}
fn runs_clippy(command: &str) -> bool {
runs_cargo(command, "clippy")
}
fn installs_component(steps: &[Vec<CiEntry>], component: &str) -> bool {
steps.iter().any(|step| {
ci_body(step, "with").iter().any(|line| {
line.strip_prefix("components:").is_some_and(|list| {
list
.split(',')
.any(|installed| installed.trim().trim_matches(['"', '\'']) == component)
})
})
})
}
fn clippy_step_drift(yaml: &str, want: &IntendedClippy) -> Result<(), String> {
let job = want.job;
let steps = ci_steps(&ci_job_lines(yaml, job));
let clippy: Vec<usize> = steps
.iter()
.enumerate()
.filter(|(_, step)| ci_commands(step).iter().any(|command| runs_clippy(command)))
.map(|(at, _)| at)
.collect();
let [at] = clippy[..] else {
return Err(format!(
"ci.yml `{job}` job: expected exactly one step running `cargo clippy`, found {} among {} \
parsed step(s) — the clippy step was dropped, duplicated or commented out, or the job's \
`steps:` list changed shape",
clippy.len(),
steps.len()
));
};
let step = &steps[at];
let condition = ci_body(step, "if");
if condition.first().map(String::as_str) != Some(CLIPPY_STEP_CONDITION) {
return Err(format!(
"ci.yml `{job}` job: the clippy step must carry `if: {CLIPPY_STEP_CONDITION}` so a red \
test step above cannot hide its verdict, found {condition:?}"
));
}
if !installs_component(&steps[..at], "clippy") {
return Err(format!(
"ci.yml `{job}` job: no step ahead of the clippy step installs `components: clippy`"
));
}
let commands: Vec<String> = ci_commands(step)
.into_iter()
.filter(|command| runs_clippy(command))
.collect();
let on_matrix = |command: &str| command.contains(MATRIX_FEATURES_ARG);
if !commands.iter().any(|command| on_matrix(command)) {
return Err(format!(
"ci.yml `{job}` job: no clippy command in the step carries `{MATRIX_FEATURES_ARG}`, so \
the matrix row's features are never linted"
));
}
if want.empty_arm && commands.iter().all(|command| on_matrix(command)) {
return Err(format!(
"ci.yml `{job}` job: no clippy command in the step runs without `--features`, so the \
bare-core row (`\"\"`) has nothing to lint it"
));
}
for command in &commands {
let arm = if on_matrix(command) {
"the `--features` arm"
} else {
"the empty-features arm"
};
let tokens: Vec<&str> = command.split_whitespace().collect();
let separator = tokens.iter().position(|token| *token == "--");
let (cargo_args, lint_args) = tokens.split_at(separator.unwrap_or(tokens.len()));
let package_args = format!("cargo clippy -p {}", want.package);
let needs = [
(
package_args.as_str(),
cargo_args
.windows(4)
.any(|run| run == ["cargo", "clippy", "-p", want.package]),
),
("--no-deps", cargo_args.contains(&"--no-deps")),
("--all-targets", cargo_args.contains(&"--all-targets")),
(
"-- -D warnings",
lint_args.windows(2).any(|pair| pair == ["-D", "warnings"]),
),
];
if let Some((need, _)) = needs.iter().find(|(_, present)| !present) {
return Err(format!(
"ci.yml `{job}` job: {arm} of the clippy step must carry `{need}`, found: {command}"
));
}
}
Ok(())
}
fn assert_clippy_step(yaml: &str, want: &IntendedClippy) {
if let Err(drift) = clippy_step_drift(yaml, want) {
panic!("{drift}");
}
}
const CHECK_JOB: &str = "check";
fn check_job_step_at(steps: &[Vec<CiEntry>], subcommand: &str) -> Result<usize, String> {
let found: Vec<usize> = steps
.iter()
.enumerate()
.filter(|(_, step)| {
ci_commands(step)
.iter()
.any(|command| runs_cargo(command, subcommand))
})
.map(|(at, _)| at)
.collect();
let [at] = found[..] else {
return Err(format!(
"ci.yml `{CHECK_JOB}` job: expected exactly one step running `cargo {subcommand}`, found {} \
among {} parsed step(s) — the step was dropped, duplicated or commented out, or the job's \
`steps:` list changed shape",
found.len(),
steps.len()
));
};
Ok(at)
}
fn check_job_step(yaml: &str, subcommand: &str) -> Result<Vec<CiEntry>, String> {
let steps = ci_steps(&ci_job_lines(yaml, CHECK_JOB));
let at = check_job_step_at(&steps, subcommand)?;
Ok(steps.into_iter().nth(at).expect("`at` indexes `steps`"))
}
fn names_a_package(arg: &str) -> bool {
matches!(arg, "-p" | "--package") || arg.starts_with("--package=")
}
fn check_fmt_drift(yaml: &str) -> Result<(), String> {
let step = check_job_step(yaml, "fmt")?;
for command in ci_commands(&step)
.into_iter()
.filter(|command| runs_cargo(command, "fmt"))
{
let tokens: Vec<&str> = command.split_whitespace().collect();
let separator = tokens.iter().position(|token| *token == "--");
let (cargo_args, _) = tokens.split_at(separator.unwrap_or(tokens.len()));
let needs = [
("--all", cargo_args.contains(&"--all")),
("--check", tokens.contains(&"--check")),
];
if let Some((need, _)) = needs.iter().find(|(_, present)| !present) {
return Err(format!(
"ci.yml `{CHECK_JOB}` job: the fmt step must carry `{need}`, found: {command}"
));
}
}
Ok(())
}
fn check_clippy_drift(yaml: &str) -> Result<(), String> {
let step = check_job_step(yaml, "clippy")?;
for command in ci_commands(&step)
.into_iter()
.filter(|command| runs_clippy(command))
{
let tokens: Vec<&str> = command.split_whitespace().collect();
let separator = tokens.iter().position(|token| *token == "--");
let (cargo_args, lint_args) = tokens.split_at(separator.unwrap_or(tokens.len()));
if cargo_args.iter().any(|arg| names_a_package(arg)) {
return Err(format!(
"ci.yml `{CHECK_JOB}` job: the clippy step must lint the whole workspace, but it names a \
package, so `--all-features` no longer reaches `coremlit-parity`'s oracle features, \
found: {command}"
));
}
let needs = [
("--all-targets", cargo_args.contains(&"--all-targets")),
("--all-features", cargo_args.contains(&"--all-features")),
(
"-- -D warnings",
lint_args.windows(2).any(|pair| pair == ["-D", "warnings"]),
),
];
if let Some((need, _)) = needs.iter().find(|(_, present)| !present) {
return Err(format!(
"ci.yml `{CHECK_JOB}` job: the clippy step must carry `{need}`, found: {command}"
));
}
}
Ok(())
}
fn denies_warnings(flags: &str) -> bool {
let tokens: Vec<&str> = flags
.trim()
.trim_matches(['"', '\''])
.split_whitespace()
.collect();
tokens.contains(&"-Dwarnings") || tokens.windows(2).any(|pair| pair == ["-D", "warnings"])
}
fn check_doc_drift(yaml: &str) -> Result<(), String> {
let step = check_job_step(yaml, "doc")?;
for command in ci_commands(&step)
.into_iter()
.filter(|command| runs_cargo(command, "doc"))
{
let tokens: Vec<&str> = command.split_whitespace().collect();
for need in ["--no-deps", "--all-features"] {
if !tokens.contains(&need) {
return Err(format!(
"ci.yml `{CHECK_JOB}` job: the doc step must carry `{need}`, found: {command}"
));
}
}
}
let flags = ci_body(&step, "env")
.iter()
.find_map(|line| line.strip_prefix("RUSTDOCFLAGS:"));
if !flags.is_some_and(denies_warnings) {
return Err(format!(
"ci.yml `{CHECK_JOB}` job: the doc step's `env:` must set `RUSTDOCFLAGS: -D warnings`, so \
a broken intra-doc link fails the job instead of passing it, found: {flags:?}"
));
}
Ok(())
}
fn check_components_drift(yaml: &str) -> Result<(), String> {
let steps = ci_steps(&ci_job_lines(yaml, CHECK_JOB));
for (subcommand, component) in [("fmt", "rustfmt"), ("clippy", "clippy")] {
let at = check_job_step_at(&steps, subcommand)?;
if !installs_component(&steps[..at], component) {
return Err(format!(
"ci.yml `{CHECK_JOB}` job: no step ahead of the `cargo {subcommand}` step installs \
`components: {component}`, so the job relies on the runner image for it"
));
}
}
Ok(())
}
const MODEL_TESTS_JOB: &str = "model-tests";
const GATE_CONDITION: &str = "${{ !cancelled() && steps.download.outcome != 'failure' }}";
const LEDGER_CONDITION: &str = "${{ !cancelled() }}";
const MODEL_TESTS_CHECKS: [&str; 5] = [
"Verify staged overlay ordering",
"Verify staged artifact checksums",
"fp16 graph sweep",
"fp16 sweep inventory",
"Model gates",
];
fn step_label(step: &[CiEntry]) -> String {
["name", "uses", "run"]
.iter()
.find_map(|key| ci_body(step, key).first())
.cloned()
.unwrap_or_else(|| "(an unnamed step)".to_string())
}
fn model_tests_guard_drift(yaml: &str) -> Result<(), String> {
let job = MODEL_TESTS_JOB;
let steps = ci_steps(&ci_job_lines(yaml, job));
let Some(staged) = steps
.iter()
.position(|step| ci_body(step, "id").first().map(String::as_str) == Some("download"))
else {
return Err(format!(
"ci.yml `{job}` job: no step has `id: download` among {} parsed step(s) — every guard \
reads the staging outcome through that id, and without it nothing short-circuits; the \
staging step was renamed, dropped or commented out, or the job's `steps:` list changed \
shape",
steps.len()
));
};
let Some((ledger, checks)) = steps[staged + 1..].split_last() else {
return Err(format!(
"ci.yml `{job}` job: no step follows the staging step, so there is no `Gate ledger` and \
no check to guard"
));
};
let is_the_ledger = ci_body(ledger, "name")
.first()
.is_some_and(|name| name.starts_with("Gate ledger"));
if !is_the_ledger {
return Err(format!(
"ci.yml `{job}` job: the last step must be the `Gate ledger`, which is what reports a \
check that never ran, found `{}`",
step_label(ledger)
));
}
let condition = ci_body(ledger, "if");
if condition.first().map(String::as_str) != Some(LEDGER_CONDITION) {
return Err(format!(
"ci.yml `{job}` job: the `Gate ledger` step must carry `if: {LEDGER_CONDITION}` alone, so \
it reports even when the download died and took every check with it, found {condition:?}"
));
}
let runs_a_kit_test = checks.iter().any(|step| {
ci_commands(step)
.iter()
.any(|command| runs_cargo(command, "test"))
});
if !runs_a_kit_test {
return Err(format!(
"ci.yml `{job}` job: no step between the staging step and the `Gate ledger` runs `cargo \
test`, so the guards pin nothing about the kit's tests — they were dropped or commented \
out, or the job's `steps:` list changed shape"
));
}
for step in checks {
let condition = ci_body(step, "if");
if condition.first().map(String::as_str) != Some(GATE_CONDITION) {
return Err(format!(
"ci.yml `{job}` job: the step `{}` must carry `if: {GATE_CONDITION}` — GitHub's default \
condition is `success()`, so without it one red step above marks this check `skipped`, \
and `skipped` is silent — found {condition:?}",
step_label(step)
));
}
}
let ledger_lines: Vec<&String> = ledger.iter().flat_map(|(_, body)| body).collect();
for step in checks {
let Some(id) = ci_body(step, "id").first() else {
return Err(format!(
"ci.yml `{job}` job: the step `{}` has no `id:`, so the `Gate ledger` step cannot report \
whether it ran",
step_label(step)
));
};
let entry = format!("=${{{{ steps.{id}.outcome }}}}");
if !ledger_lines.iter().any(|line| line.contains(&entry)) {
return Err(format!(
"ci.yml `{job}` job: the `Gate ledger` step never reads step `{id}` (`{entry}`), so the \
check `{}` could be skipped without the shard saying so",
step_label(step)
));
}
}
for name in MODEL_TESTS_CHECKS {
let present = checks.iter().any(|step| {
ci_body(step, "name")
.first()
.is_some_and(|label| label.starts_with(name))
});
if !present {
return Err(format!(
"ci.yml `{job}` job: no step between the staging step and the `Gate ledger` is named \
`{name}`, which every shard runs — it was removed, renamed or commented out, or the \
job's `steps:` list changed shape"
));
}
}
Ok(())
}
#[track_caller]
fn assert_no_drift(drift: Result<(), String>) {
if let Err(drift) = drift {
panic!("{drift}");
}
}
fn rename_table_rows(doc: &str) -> Vec<Vec<String>> {
let mut rows = Vec::new();
let mut in_table = false;
for line in doc.lines() {
if let Some(heading) = line.strip_prefix("## ") {
in_table = heading.contains("Rename table");
continue;
}
if !in_table {
continue;
}
let line = line.trim();
if !line.starts_with('|') {
continue;
}
let cells: Vec<String> = line
.trim_matches('|')
.split('|')
.map(|c| c.trim().to_string())
.collect();
if cells.iter().any(|c| c == "Old crate") {
continue;
}
if cells
.iter()
.all(|c| !c.is_empty() && c.chars().all(|ch| ch == '-'))
{
continue;
}
rows.push(cells);
}
rows
}
fn unbacktick(cell: &str) -> &str {
cell.trim_matches('`')
}
#[test]
fn feature_names_match_the_pinned_set() {
let actual = feature_names(&features_block(&manifest()));
let expected: BTreeSet<String> = expected_features()
.iter()
.map(|(name, _)| (*name).to_string())
.collect();
assert_eq!(
actual, expected,
"Cargo.toml [features] names drifted from the pinned flat feature set (FEATURE_MAP.md)"
);
}
#[test]
fn oracle_features_are_not_this_crates() {
let names = feature_names(&features_block(&manifest()));
for moved in ["speaker-oracle", "clap-oracle", "vad-bundled"] {
assert!(
!names.contains(moved),
"`{moved}` is declared on coremlit again — it belongs to coremlit-parity, whose \
oracle deps (`dia`, `textclap`) are unpublished git sources cargo publish rejects"
);
}
assert!(
names.contains("align-oracle"),
"`align-oracle` must STAY on coremlit: it only enables a feature of `asry`, a dependency \
this crate has either way, so moving it would relocate code without removing a git dep"
);
}
#[test]
fn parity_feature_names_match_the_pinned_set() {
let Some(parity) = parity_manifest() else {
return;
};
let actual = feature_names(&features_block(&parity));
let expected: BTreeSet<String> = expected_parity_features()
.iter()
.map(|(name, _)| (*name).to_string())
.collect();
assert_eq!(
actual, expected,
"coremlit-parity [features] names drifted from the pinned oracle feature set"
);
}
#[test]
fn parity_feature_deps_are_pinned_with_no_cross_oracle_leakage() {
let Some(parity) = parity_manifest() else {
return;
};
let block = features_block(&parity);
for (name, deps) in expected_parity_features() {
let actual = feature_deps(&block, name);
let expected: BTreeSet<String> = deps.iter().map(|d| (*d).to_string()).collect();
assert_eq!(
actual, expected,
"coremlit-parity feature `{name}` dependency set drifted"
);
}
}
#[test]
fn parity_crate_is_never_published() {
let Some(parity) = parity_manifest() else {
return;
};
assert!(
parity.lines().any(|l| l.trim() == "publish = false"),
"coremlit-parity must declare `publish = false` — it depends on unpublished git sources"
);
}
#[test]
fn old_per_crate_feature_names_are_gone() {
let names = feature_names(&features_block(&manifest()));
for old in ["dia", "dia-oracle", "parity-oracle", "vadkit", "bundled"] {
assert!(
!names.contains(old),
"old per-crate feature `{old}` is still declared — the rename table maps it away"
);
}
}
#[test]
fn feature_deps_are_pinned_with_no_cross_kit_leakage() {
let block = features_block(&manifest());
for (name, deps) in expected_features() {
let actual = feature_deps(&block, name);
let expected: BTreeSet<String> = deps.iter().map(|d| (*d).to_string()).collect();
assert_eq!(
actual, expected,
"feature `{name}` dependency set drifted (cross-kit leakage or a dropped/added dep)"
);
}
}
#[test]
fn rename_table_pins_every_bare_crate_row() {
let rows = rename_table_rows(&read_rel("FEATURE_MAP.md"));
assert!(
rows.len() >= BARE_CRATE_MAP.len(),
"rename-table parse found only {} row(s) — the parser or the table shape broke",
rows.len()
);
for (kit, feature) in BARE_CRATE_MAP {
let found = rows
.iter()
.any(|r| r.len() >= 3 && r[0] == *kit && r[1] == "(crate)" && unbacktick(&r[2]) == *feature);
assert!(
found,
"FEATURE_MAP.md rename table must map bare crate `{kit}` | (crate) | `{feature}` \
(a removed or altered bare-crate row)"
);
}
}
fn assert_combo_sets_eq(actual: &BTreeSet<String>, expected: &BTreeSet<String>, what: &str) {
let missing: Vec<&String> = expected.difference(actual).collect();
let unexpected: Vec<&String> = actual.difference(expected).collect();
assert!(
missing.is_empty() && unexpected.is_empty(),
"{what} drifted from the pinned curated set — missing (pinned but not in the \
active matrix): {missing:?}; unexpected (in the active matrix but not pinned): {unexpected:?}"
);
}
#[test]
fn ci_pins_the_curated_feature_combos() {
let Some(ci) = ci_yml() else {
return;
};
assert_combo_sets_eq(
&ci_feature_combos(&ci, "features"),
&intended_ci_combos(),
"ci.yml `features` job matrix",
);
}
#[test]
fn ci_pins_the_curated_parity_combos() {
let Some(ci) = ci_yml() else {
return;
};
assert_combo_sets_eq(
&ci_feature_combos(&ci, "parity"),
&owned(INTENDED_PARITY_CI_COMBOS),
"ci.yml `parity` job matrix",
);
}
#[test]
fn ci_pins_the_features_job_clippy_step() {
let Some(ci) = ci_yml() else {
return;
};
assert_clippy_step(&ci, &FEATURES_CLIPPY);
}
#[test]
fn ci_pins_the_parity_job_clippy_step() {
let Some(ci) = ci_yml() else {
return;
};
assert_clippy_step(&ci, &PARITY_CLIPPY);
}
#[test]
fn ci_pins_the_check_job_clippy_step() {
let Some(ci) = ci_yml() else {
return;
};
assert_no_drift(check_clippy_drift(&ci));
}
#[test]
fn ci_pins_the_check_job_fmt_step() {
let Some(ci) = ci_yml() else {
return;
};
assert_no_drift(check_fmt_drift(&ci));
}
#[test]
fn ci_pins_the_check_job_doc_step() {
let Some(ci) = ci_yml() else {
return;
};
assert_no_drift(check_doc_drift(&ci));
}
#[test]
fn ci_pins_the_check_job_components() {
let Some(ci) = ci_yml() else {
return;
};
assert_no_drift(check_components_drift(&ci));
}
#[test]
fn ci_pins_the_model_tests_step_guards() {
let Some(ci) = ci_yml() else {
return;
};
assert_no_drift(model_tests_guard_drift(&ci));
}
#[test]
fn a_repo_file_is_skipped_by_name_outside_the_source_tree() {
assert_eq!(repo_file(None, ".github/workflows/ci.yml"), None);
assert_eq!(
skip_notice(".github/workflows/ci.yml"),
"feature_map: skipped — .github/workflows/ci.yml is not in this source tree (a published \
tarball?)"
);
}
#[test]
fn a_repo_file_is_read_from_the_root_it_is_given() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let text = repo_file(Some(root), "Cargo.toml").expect("a root yields the file");
assert!(text.contains("[package]"), "read the wrong file: {text}");
}
#[test]
#[should_panic(expected = "no-such-file.yml")]
fn a_repo_file_missing_inside_the_source_tree_is_a_failure() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let _ = repo_file(Some(root), "no-such-file.yml");
}
const DOCTORED_MATRIX: &str = r#"
jobs:
check:
runs-on: macos-15
steps:
- run: cargo build --features whisper --examples
features:
runs-on: macos-15
strategy:
fail-fast: false
matrix:
features:
- ""
- "whisper"
- "align"
- "speaker"
- "speaker,serde"
- "vad"
- "whisper,vad"
- "align-oracle"
- "clap"
- "granite"
- "siglip"
- "ced"
- "lid"
- "identity"
- "identity,speaker"
- "face"
- "commercial-face-arcface"
- "whisper,align,speaker,vad,clap,granite,siglip,ced,lid,identity,face,serde,tracing,nl-recognizer"
- "whisper,align-oracle,speaker,vad,clap,granite,siglip,ced,lid,identity,face,serde,tracing,nl-recognizer"
steps:
- uses: actions/checkout@v7
parity:
runs-on: macos-15
strategy:
fail-fast: false
matrix:
features:
- "speaker-oracle"
- "clap-oracle"
- "vad-bundled"
- "speaker-oracle,clap-oracle,vad-bundled"
steps:
- uses: actions/checkout@v7
"#;
#[test]
fn ci_combo_parser_reads_the_wellformed_matrix() {
assert_combo_sets_eq(
&ci_feature_combos(DOCTORED_MATRIX, "features"),
&intended_ci_combos(),
"well-formed doctored matrix",
);
}
#[test]
fn ci_combo_parser_scopes_each_job_separately() {
let features = ci_feature_combos(DOCTORED_MATRIX, "features");
let parity = ci_feature_combos(DOCTORED_MATRIX, "parity");
assert_combo_sets_eq(
&parity,
&owned(INTENDED_PARITY_CI_COMBOS),
"well-formed doctored parity matrix",
);
assert!(
features.is_disjoint(&parity),
"the two jobs' parsed combo sets bled into each other: {features:?} vs {parity:?}"
);
}
#[test]
fn ci_combo_parser_returns_empty_for_an_absent_job() {
assert!(
ci_feature_combos(DOCTORED_MATRIX, "no-such-job").is_empty(),
"an absent job must parse to no combos at all"
);
}
#[test]
fn ci_combo_check_reds_when_bare_core_is_deleted() {
let doctored = DOCTORED_MATRIX.replace(" - \"\"\n", "");
assert_ne!(
ci_feature_combos(&doctored, "features"),
intended_ci_combos(),
"deleting the bare-core `- \"\"` entry must make the parsed set differ from the pinned set"
);
}
#[test]
fn ci_combo_check_reds_when_bare_core_is_commented_out() {
let doctored = DOCTORED_MATRIX.replace(" - \"\"\n", " # - \"\"\n");
assert_ne!(
ci_feature_combos(&doctored, "features"),
intended_ci_combos(),
"commenting out the bare-core `- \"\"` entry must make the parsed set differ from the pinned set"
);
}
#[test]
fn ci_combo_check_reds_when_a_combo_is_dropped() {
let doctored = DOCTORED_MATRIX.replace(" - \"whisper,vad\"\n", "");
assert_ne!(
ci_feature_combos(&doctored, "features"),
intended_ci_combos(),
"dropping the `whisper,vad` combo must make the parsed set differ from the pinned set"
);
}
const DOCTORED_CLIPPY_JOBS: &str = r#"
jobs:
check:
runs-on: macos-15
steps:
- uses: actions/checkout@v7
- run: cargo clippy --all-targets --all-features -- -D warnings
features:
runs-on: macos-15
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: "cargo test -p coremlit (features: ${{ matrix.features }})"
run: |
if [ -z "${{ matrix.features }}" ]; then
cargo test -p coremlit
else
cargo test -p coremlit --features "${{ matrix.features }}"
fi
- name: "cargo clippy -p coremlit --all-targets (features: ${{ matrix.features }})"
if: ${{ !cancelled() }}
run: |
if [ -z "${{ matrix.features }}" ]; then
cargo clippy -p coremlit --no-deps --all-targets -- -D warnings
else
cargo clippy -p coremlit --no-deps --all-targets --features "${{ matrix.features }}" -- -D warnings
fi
parity:
runs-on: macos-15
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: "cargo test -p coremlit-parity (features: ${{ matrix.features }})"
run: cargo test -p coremlit-parity --features "${{ matrix.features }}"
- name: "cargo clippy -p coremlit-parity --all-targets (features: ${{ matrix.features }})"
if: ${{ !cancelled() }}
run: cargo clippy -p coremlit-parity --no-deps --all-targets --features "${{ matrix.features }}" -- -D warnings
"#;
#[test]
fn ci_clippy_check_reads_the_wellformed_steps() {
assert_clippy_step(DOCTORED_CLIPPY_JOBS, &FEATURES_CLIPPY);
assert_clippy_step(DOCTORED_CLIPPY_JOBS, &PARITY_CLIPPY);
}
#[test]
fn ci_clippy_check_reds_on_each_dropped_piece() {
struct Mutation {
what: &'static str,
from: &'static str,
to: &'static str,
pin: &'static IntendedClippy,
names: &'static [&'static str],
}
let mutations = [
Mutation {
what: "the empty arm drops --all-targets",
from: "cargo clippy -p coremlit --no-deps --all-targets -- -D warnings",
to: "cargo clippy -p coremlit --no-deps -- -D warnings",
pin: &FEATURES_CLIPPY,
names: &["`features`", "the empty-features arm", "`--all-targets`"],
},
Mutation {
what: "the features arm drops --all-targets",
from: "cargo clippy -p coremlit --no-deps --all-targets --features",
to: "cargo clippy -p coremlit --no-deps --features",
pin: &FEATURES_CLIPPY,
names: &["`features`", "the `--features` arm", "`--all-targets`"],
},
Mutation {
what: "the features arm drops -D warnings",
from: "--all-targets --features \"${{ matrix.features }}\" -- -D warnings",
to: "--all-targets --features \"${{ matrix.features }}\"",
pin: &FEATURES_CLIPPY,
names: &["`features`", "the `--features` arm", "`-- -D warnings`"],
},
Mutation {
what: "the empty arm drops --no-deps",
from: "cargo clippy -p coremlit --no-deps --all-targets -- -D warnings",
to: "cargo clippy -p coremlit --all-targets -- -D warnings",
pin: &FEATURES_CLIPPY,
names: &["`features`", "the empty-features arm", "`--no-deps`"],
},
Mutation {
what: "a trailing comment stands in for --all-targets",
from: "cargo clippy -p coremlit --no-deps --all-targets -- -D warnings",
to: "cargo clippy -p coremlit --no-deps -- -D warnings # --all-targets",
pin: &FEATURES_CLIPPY,
names: &["`features`", "`--all-targets`"],
},
Mutation {
what: "the features arm stops reading the matrix row",
from: "--all-targets --features \"${{ matrix.features }}\" -- -D warnings",
to: "--all-targets -- -D warnings",
pin: &FEATURES_CLIPPY,
names: &["`features`", "--features \"${{ matrix.features }}\""],
},
Mutation {
what: "the empty arm is gone",
from: " cargo clippy -p coremlit --no-deps --all-targets -- -D warnings\n",
to: "",
pin: &FEATURES_CLIPPY,
names: &["`features`", "without `--features`"],
},
Mutation {
what: "the parity step drops --all-targets",
from: "-p coremlit-parity --no-deps --all-targets",
to: "-p coremlit-parity --no-deps",
pin: &PARITY_CLIPPY,
names: &["`parity`", "`--all-targets`"],
},
Mutation {
what: "the parity step lints the wrong package",
from: "run: cargo clippy -p coremlit-parity",
to: "run: cargo clippy -p coremlit",
pin: &PARITY_CLIPPY,
names: &["`parity`", "`cargo clippy -p coremlit-parity`"],
},
Mutation {
what: "the features step loses its condition",
from: " if: ${{ !cancelled() }}\n",
to: "",
pin: &FEATURES_CLIPPY,
names: &["`features`", "`if: ${{ !cancelled() }}`"],
},
Mutation {
what: "the parity step's condition becomes always()",
from: " if: ${{ !cancelled() }}\n run: cargo clippy",
to: " if: ${{ always() }}\n run: cargo clippy",
pin: &PARITY_CLIPPY,
names: &["`parity`", "`if: ${{ !cancelled() }}`"],
},
Mutation {
what: "the features job stops installing clippy",
from: "components: clippy",
to: "components: rustfmt",
pin: &FEATURES_CLIPPY,
names: &["`features`", "`components: clippy`"],
},
];
for case in mutations {
let doctored = DOCTORED_CLIPPY_JOBS.replacen(case.from, case.to, 1);
assert_ne!(
doctored, DOCTORED_CLIPPY_JOBS,
"{}: the case matched nothing in the fixture",
case.what
);
let Err(drift) = clippy_step_drift(&doctored, case.pin) else {
panic!(
"{}: the pin still reads the doctored ci.yml as intended",
case.what
);
};
for name in case.names {
assert!(
drift.contains(name),
"{}: the message must name {name}, got: {drift}",
case.what
);
}
}
}
#[test]
fn ci_clippy_check_reds_when_a_job_loses_its_step() {
let (head, tail) = DOCTORED_CLIPPY_JOBS
.split_once(" - name: \"cargo clippy -p coremlit --all-targets")
.expect("the fixture's `features` clippy step");
let (_, parity) = tail
.split_once(" parity:")
.expect("the fixture's `parity` job");
let doctored = format!("{head} parity:{parity}");
let Err(drift) = clippy_step_drift(&doctored, &FEATURES_CLIPPY) else {
panic!("a `features` job without a clippy step still passed its pin");
};
assert!(
drift.contains("`features`") && drift.contains("exactly one step running `cargo clippy`"),
"the message must name the job and the missing step, got: {drift}"
);
assert_clippy_step(&doctored, &PARITY_CLIPPY);
}
#[test]
fn ci_clippy_check_reds_when_the_commands_are_commented_out() {
let doctored = DOCTORED_CLIPPY_JOBS
.lines()
.map(|line| {
if line.contains("cargo clippy -p coremlit --no-deps") {
format!("# {line}")
} else {
line.to_string()
}
})
.collect::<Vec<_>>()
.join("\n");
assert_ne!(doctored, DOCTORED_CLIPPY_JOBS);
let Err(drift) = clippy_step_drift(&doctored, &FEATURES_CLIPPY) else {
panic!("a `features` job with its clippy commands commented out still passed its pin");
};
assert!(
drift.contains("`features`") && drift.contains("exactly one step running `cargo clippy`"),
"the message must name the job and the missing step, got: {drift}"
);
}
#[test]
fn ci_clippy_check_reads_a_rewrapped_command() {
let doctored = DOCTORED_CLIPPY_JOBS.replacen(
"--no-deps --all-targets --features \"${{ matrix.features }}\" -- -D warnings",
"--no-deps --all-targets \\\n --features \"${{ matrix.features }}\" -- -D warnings",
1,
);
assert_ne!(doctored, DOCTORED_CLIPPY_JOBS);
assert_clippy_step(&doctored, &FEATURES_CLIPPY);
}
fn doctored_in(fixture: &str, job: &str, from: &str, to: &str) -> String {
let key = format!("\n {job}:\n");
let at = fixture
.find(&key)
.unwrap_or_else(|| panic!("the fixture has no `{job}` job"));
let (head, tail) = fixture.split_at(at);
format!("{head}{}", tail.replacen(from, to, 1))
}
struct Doctored {
what: &'static str,
yaml: String,
names: &'static [&'static str],
}
fn assert_each_drift_reds(fixture: &str, cases: &[Doctored], pin: fn(&str) -> Result<(), String>) {
for case in cases {
assert_ne!(
case.yaml, fixture,
"{}: the case matched nothing in the fixture",
case.what
);
let Err(drift) = pin(&case.yaml) else {
panic!(
"{}: the pin still reads the doctored ci.yml as intended",
case.what
);
};
for name in case.names {
assert!(
drift.contains(name),
"{}: the message must name {name}, got: {drift}",
case.what
);
}
}
}
const DOCTORED_CHECK_JOBS: &str = r#"
jobs:
docs:
runs-on: macos-15
steps:
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- run: cargo fmt --all --check
- run: cargo clippy --all-targets --all-features -- -D warnings
- run: cargo doc --no-deps --all-features
env:
RUSTDOCFLAGS: -D warnings
check:
runs-on: macos-15
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- run: cargo fmt --all --check
- run: cargo clippy --all-targets --all-features -- -D warnings
- run: cargo doc --no-deps --all-features
env:
RUSTDOCFLAGS: -D warnings
- run: cargo build --features whisper --examples
features:
runs-on: macos-15
steps:
- run: cargo clippy --all-targets --all-features -- -D warnings
"#;
const CHECK_FMT_STEP: &str = " - run: cargo fmt --all --check\n";
const CHECK_CLIPPY_STEP: &str =
" - run: cargo clippy --all-targets --all-features -- -D warnings\n";
const CHECK_DOC_STEP: &str = " - run: cargo doc --no-deps --all-features\n env:\n RUSTDOCFLAGS: -D warnings\n";
#[test]
fn ci_check_job_pins_read_the_wellformed_steps() {
assert_no_drift(check_fmt_drift(DOCTORED_CHECK_JOBS));
assert_no_drift(check_clippy_drift(DOCTORED_CHECK_JOBS));
assert_no_drift(check_doc_drift(DOCTORED_CHECK_JOBS));
assert_no_drift(check_components_drift(DOCTORED_CHECK_JOBS));
}
#[test]
fn ci_check_fmt_pin_reds_on_each_dropped_piece() {
let in_check = |from: &str, to: &str| doctored_in(DOCTORED_CHECK_JOBS, "check", from, to);
let cases = [
Doctored {
what: "the fmt step is gone",
yaml: in_check(CHECK_FMT_STEP, ""),
names: &["`check`", "exactly one step running `cargo fmt`"],
},
Doctored {
what: "the fmt step is commented out",
yaml: in_check(CHECK_FMT_STEP, " # - run: cargo fmt --all --check\n"),
names: &["`check`", "exactly one step running `cargo fmt`"],
},
Doctored {
what: "a second fmt step is added",
yaml: in_check(
" - run: cargo build",
&format!("{CHECK_FMT_STEP} - run: cargo build"),
),
names: &["`check`", "exactly one step running `cargo fmt`", "found 2"],
},
Doctored {
what: "the step drops --check",
yaml: in_check("cargo fmt --all --check", "cargo fmt --all"),
names: &["`check`", "`--check`"],
},
Doctored {
what: "the step drops --all",
yaml: in_check("cargo fmt --all --check", "cargo fmt --check"),
names: &["`check`", "`--all`"],
},
Doctored {
what: "--all rides after the separator, where rustfmt rejects it",
yaml: in_check("cargo fmt --all --check", "cargo fmt -- --all --check"),
names: &["`check`", "`--all`"],
},
Doctored {
what: "a trailing comment stands in for --check",
yaml: in_check("cargo fmt --all --check", "cargo fmt --all # --check"),
names: &["`check`", "`--check`"],
},
Doctored {
what: "the step's name spells the flag its run line dropped",
yaml: in_check(
CHECK_FMT_STEP,
" - name: cargo fmt --all --check\n run: cargo fmt --all\n",
),
names: &["`check`", "`--check`"],
},
];
assert_each_drift_reds(DOCTORED_CHECK_JOBS, &cases, check_fmt_drift);
}
#[test]
fn ci_check_fmt_pin_reads_a_respelled_command() {
for spelling in [
" - run: cargo fmt --all -- --check\n",
" - run: cargo fmt --check --all\n",
" - run: |\n cargo fmt --all \\\n --check\n",
] {
let doctored = doctored_in(DOCTORED_CHECK_JOBS, "check", CHECK_FMT_STEP, spelling);
assert_ne!(doctored, DOCTORED_CHECK_JOBS);
assert_no_drift(check_fmt_drift(&doctored));
}
}
#[test]
fn ci_check_clippy_pin_reds_on_each_dropped_piece() {
let in_check = |from: &str, to: &str| doctored_in(DOCTORED_CHECK_JOBS, "check", from, to);
let cases = [
Doctored {
what: "the clippy step is gone",
yaml: in_check(CHECK_CLIPPY_STEP, ""),
names: &["`check`", "exactly one step running `cargo clippy`"],
},
Doctored {
what: "the clippy step is commented out",
yaml: in_check(
CHECK_CLIPPY_STEP,
" # - run: cargo clippy --all-targets --all-features -- -D warnings\n",
),
names: &["`check`", "exactly one step running `cargo clippy`"],
},
Doctored {
what: "a second clippy step is added",
yaml: in_check(
" - run: cargo build",
" - run: cargo clippy --all-targets --all-features -- -D warnings\n - run: cargo build",
),
names: &[
"`check`",
"exactly one step running `cargo clippy`",
"found 2",
],
},
Doctored {
what: "the step drops --all-targets",
yaml: in_check(
"cargo clippy --all-targets --all-features",
"cargo clippy --all-features",
),
names: &["`check`", "`--all-targets`"],
},
Doctored {
what: "the step drops --all-features",
yaml: in_check(
"cargo clippy --all-targets --all-features",
"cargo clippy --all-targets",
),
names: &["`check`", "`--all-features`"],
},
Doctored {
what: "the step drops -D warnings",
yaml: in_check("--all-features -- -D warnings", "--all-features"),
names: &["`check`", "`-- -D warnings`"],
},
Doctored {
what: "the step narrows to one package",
yaml: in_check(
"cargo clippy --all-targets",
"cargo clippy -p coremlit --all-targets",
),
names: &["`check`", "the whole workspace", "names a package"],
},
Doctored {
what: "a trailing comment stands in for --all-features",
yaml: in_check(
"cargo clippy --all-targets --all-features -- -D warnings",
"cargo clippy --all-targets -- -D warnings # --all-features",
),
names: &["`check`", "`--all-features`"],
},
Doctored {
what: "the step's name spells the flag its run line dropped",
yaml: in_check(
CHECK_CLIPPY_STEP,
" - name: cargo clippy --all-targets --all-features -- -D warnings\n run: cargo clippy --all-targets -- -D warnings\n",
),
names: &["`check`", "`--all-features`"],
},
];
assert_each_drift_reds(DOCTORED_CHECK_JOBS, &cases, check_clippy_drift);
}
#[test]
fn ci_check_doc_pin_reds_on_each_dropped_piece() {
let in_check = |from: &str, to: &str| doctored_in(DOCTORED_CHECK_JOBS, "check", from, to);
let cases = [
Doctored {
what: "the doc step is gone",
yaml: in_check(CHECK_DOC_STEP, ""),
names: &["`check`", "exactly one step running `cargo doc`"],
},
Doctored {
what: "the doc step is commented out",
yaml: in_check(
" - run: cargo doc --no-deps --all-features\n",
" # - run: cargo doc --no-deps --all-features\n",
),
names: &["`check`", "exactly one step running `cargo doc`"],
},
Doctored {
what: "a second doc step is added",
yaml: in_check(
" - run: cargo build",
&format!("{CHECK_DOC_STEP} - run: cargo build"),
),
names: &["`check`", "exactly one step running `cargo doc`", "found 2"],
},
Doctored {
what: "the step drops --no-deps",
yaml: in_check(
"cargo doc --no-deps --all-features",
"cargo doc --all-features",
),
names: &["`check`", "`--no-deps`"],
},
Doctored {
what: "the step drops --all-features",
yaml: in_check("cargo doc --no-deps --all-features", "cargo doc --no-deps"),
names: &["`check`", "`--all-features`"],
},
Doctored {
what: "RUSTDOCFLAGS is gone",
yaml: in_check(" env:\n RUSTDOCFLAGS: -D warnings\n", ""),
names: &["`check`", "`RUSTDOCFLAGS: -D warnings`"],
},
Doctored {
what: "RUSTDOCFLAGS stops denying warnings",
yaml: in_check("RUSTDOCFLAGS: -D warnings", "RUSTDOCFLAGS: --cfg docsrs"),
names: &["`check`", "`RUSTDOCFLAGS: -D warnings`"],
},
Doctored {
what: "a trailing comment stands in for -D warnings",
yaml: in_check(
"RUSTDOCFLAGS: -D warnings",
"RUSTDOCFLAGS: --cfg docsrs # -D warnings",
),
names: &["`check`", "`RUSTDOCFLAGS: -D warnings`"],
},
];
assert_each_drift_reds(DOCTORED_CHECK_JOBS, &cases, check_doc_drift);
}
#[test]
fn ci_check_doc_pin_reads_a_respelled_flag() {
let doctored = doctored_in(
DOCTORED_CHECK_JOBS,
"check",
"RUSTDOCFLAGS: -D warnings",
"RUSTDOCFLAGS: \"--cfg docsrs -Dwarnings\"",
);
assert_ne!(doctored, DOCTORED_CHECK_JOBS);
assert_no_drift(check_doc_drift(&doctored));
}
const CHECK_TOOLCHAIN_STEP: &str = " - uses: dtolnay/rust-toolchain@stable\n with:\n components: clippy, rustfmt\n";
#[test]
fn ci_check_components_pin_reds_on_each_dropped_piece() {
let in_check = |from: &str, to: &str| doctored_in(DOCTORED_CHECK_JOBS, "check", from, to);
let cases = [
Doctored {
what: "the toolchain step asks for no components",
yaml: in_check(" with:\n components: clippy, rustfmt\n", ""),
names: &["`check`", "`cargo fmt`", "`components: rustfmt`"],
},
Doctored {
what: "the toolchain step stops asking for rustfmt",
yaml: in_check("components: clippy, rustfmt", "components: clippy"),
names: &["`check`", "`cargo fmt`", "`components: rustfmt`"],
},
Doctored {
what: "the toolchain step stops asking for clippy",
yaml: in_check("components: clippy, rustfmt", "components: rustfmt"),
names: &["`check`", "`cargo clippy`", "`components: clippy`"],
},
Doctored {
what: "the components line is only a comment",
yaml: in_check(
" components: clippy, rustfmt\n",
" # components: clippy, rustfmt\n",
),
names: &["`check`", "`components: rustfmt`"],
},
Doctored {
what: "a trailing comment stands in for a component",
yaml: in_check(
"components: clippy, rustfmt",
"components: clippy # rustfmt",
),
names: &["`check`", "`components: rustfmt`"],
},
Doctored {
what: "another input names the component",
yaml: in_check(
"components: clippy, rustfmt",
"toolchain: rustfmt\n components: clippy",
),
names: &["`check`", "`components: rustfmt`"],
},
Doctored {
what: "the toolchain step comes after the steps that need it",
yaml: in_check(
&format!("{CHECK_TOOLCHAIN_STEP} - run: cargo fmt --all --check\n"),
&format!(" - run: cargo fmt --all --check\n{CHECK_TOOLCHAIN_STEP}"),
),
names: &["`check`", "no step ahead of", "`components: rustfmt`"],
},
Doctored {
what: "the toolchain step is commented out",
yaml: in_check(
CHECK_TOOLCHAIN_STEP,
" # - uses: dtolnay/rust-toolchain@stable\n # with:\n # components: clippy, rustfmt\n",
),
names: &["`check`", "`components: rustfmt`"],
},
Doctored {
what: "the fmt step is gone",
yaml: in_check(" - run: cargo fmt --all --check\n", ""),
names: &["`check`", "exactly one step running `cargo fmt`"],
},
Doctored {
what: "the clippy step is gone",
yaml: in_check(CHECK_CLIPPY_STEP, ""),
names: &["`check`", "exactly one step running `cargo clippy`"],
},
];
assert_each_drift_reds(DOCTORED_CHECK_JOBS, &cases, check_components_drift);
}
#[test]
fn ci_check_components_pin_reads_a_respelled_list() {
for list in [
"rustfmt, clippy",
"clippy,rustfmt",
"\"clippy, rustfmt\"",
"'clippy', 'rustfmt'",
] {
let doctored = doctored_in(
DOCTORED_CHECK_JOBS,
"check",
"components: clippy, rustfmt",
&format!("components: {list}"),
);
assert_ne!(doctored, DOCTORED_CHECK_JOBS);
assert_no_drift(check_components_drift(&doctored));
}
}
const DOCTORED_MODEL_TESTS_JOBS: &str = r#"
jobs:
staging:
runs-on: macos-15
steps:
- name: Stage this kit's models
id: download
uses: ./.github/actions/stage-models
- name: Model gates
id: gates
if: ${{ !cancelled() && steps.download.outcome != 'failure' }}
run: cargo test -p coremlit -- --ignored
- name: Gate ledger (a gate that never ran proves nothing)
if: ${{ !cancelled() }}
run: echo ledger
model-tests:
name: model-tests (${{ matrix.kit }})
runs-on: macos-15
strategy:
fail-fast: false
matrix:
include:
- kit: whisper
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
- name: Stage this kit's models
id: download
uses: ./.github/actions/stage-models
with:
kit: ${{ matrix.kit }}
- name: Verify staged overlay ordering
id: overlay
if: ${{ !cancelled() && steps.download.outcome != 'failure' }}
run: ./check-overlay.sh
- name: Verify staged artifact checksums
id: checksums
if: ${{ !cancelled() && steps.download.outcome != 'failure' }}
run: |
set -euo pipefail
shasum -a 256 -c CHECKSUMS.sha256
- name: fp16 graph sweep
id: fp16_guards
if: ${{ !cancelled() && steps.download.outcome != 'failure' }}
run: cargo test -p coremlit --test fp16_guards
- name: fp16 sweep inventory
id: fp16_inventory
if: ${{ !cancelled() && steps.download.outcome != 'failure' }}
run: tests/fp16_sweep_inventory.sh
- name: Model gates
id: gates
if: ${{ !cancelled() && steps.download.outcome != 'failure' }}
env:
KIT: ${{ matrix.kit }}
run: |
set -euo pipefail
cargo test -p coremlit --features "$features" -- --ignored
- name: Gate ledger (a gate that never ran proves nothing)
if: ${{ !cancelled() }}
env:
LEDGER: |
overlay-ordering=${{ steps.overlay.outcome }}
artifact-checksums=${{ steps.checksums.outcome }}
fp16-graph-sweep=${{ steps.fp16_guards.outcome }}
fp16-sweep-inventory=${{ steps.fp16_inventory.outcome }}
model-gates=${{ steps.gates.outcome }}
run: |
set -euo pipefail
printf '%s\n' "$LEDGER"
parity:
runs-on: macos-15
steps:
- run: cargo test -p coremlit-parity
"#;
const MODEL_TESTS_GUARD_LINE: &str =
" if: ${{ !cancelled() && steps.download.outcome != 'failure' }}\n";
#[test]
fn ci_model_tests_pin_reads_the_wellformed_job() {
assert_no_drift(model_tests_guard_drift(DOCTORED_MODEL_TESTS_JOBS));
}
#[test]
fn ci_model_tests_pin_reds_on_each_dropped_piece() {
let in_job =
|from: &str, to: &str| doctored_in(DOCTORED_MODEL_TESTS_JOBS, "model-tests", from, to);
let guarded = |id: &str| format!(" id: {id}\n{MODEL_TESTS_GUARD_LINE}");
let without_tests = doctored_in(
&in_job(
"run: cargo test -p coremlit --test fp16_guards",
"run: echo fp16",
),
"model-tests",
" cargo test -p coremlit --features \"$features\" -- --ignored\n",
" echo gates\n",
);
let inventory = format!(
" - name: fp16 sweep inventory\n id: fp16_inventory\n{MODEL_TESTS_GUARD_LINE} \
run: tests/fp16_sweep_inventory.sh\n"
);
let ledger_entry = " model-gates=${{ steps.gates.outcome }}\n";
let cases = [
Doctored {
what: "the staging step's id is renamed",
yaml: in_job("id: download", "id: staged"),
names: &["`model-tests`", "`id: download`"],
},
Doctored {
what: "a check loses its condition",
yaml: in_job(&guarded("gates"), " id: gates\n"),
names: &[
"`model-tests`",
"`Model gates`",
"steps.download.outcome != 'failure'",
],
},
Doctored {
what: "a check's condition loses the staging clause",
yaml: in_job(
&guarded("fp16_guards"),
" id: fp16_guards\n if: ${{ !cancelled() }}\n",
),
names: &["`model-tests`", "`fp16 graph sweep`"],
},
Doctored {
what: "a check's condition becomes always()",
yaml: in_job(
&guarded("checksums"),
" id: checksums\n if: ${{ always() && steps.download.outcome != 'failure' }}\n",
),
names: &["`model-tests`", "`Verify staged artifact checksums`"],
},
Doctored {
what: "a check's condition is only a comment",
yaml: in_job(
&guarded("gates"),
" id: gates\n # if: ${{ !cancelled() && steps.download.outcome != 'failure' }}\n",
),
names: &["`model-tests`", "`Model gates`"],
},
Doctored {
what: "a check is added without a condition",
yaml: in_job(
" - name: Model gates\n",
" - run: cargo test -p coremlit --test newcheck\n - name: Model gates\n",
),
names: &["`model-tests`", "`cargo test -p coremlit --test newcheck`"],
},
Doctored {
what: "the ledger loses its condition",
yaml: in_job(
" - name: Gate ledger (a gate that never ran proves nothing)\n if: ${{ !cancelled() }}\n",
" - name: Gate ledger (a gate that never ran proves nothing)\n",
),
names: &["`model-tests`", "`Gate ledger`", "alone"],
},
Doctored {
what: "the ledger waits on the download",
yaml: in_job(
" if: ${{ !cancelled() }}\n env:\n LEDGER",
" if: ${{ !cancelled() && steps.download.outcome != 'failure' }}\n env:\n LEDGER",
),
names: &["`model-tests`", "`Gate ledger`", "alone"],
},
Doctored {
what: "a step is added after the ledger",
yaml: in_job(
" parity:\n",
" - run: cargo test -p coremlit --test late\n parity:\n",
),
names: &["`model-tests`", "the last step", "`Gate ledger`"],
},
Doctored {
what: "the ledger is no longer the Gate ledger",
yaml: in_job(
"Gate ledger (a gate that never ran proves nothing)",
"Verdict summary",
),
names: &["`model-tests`", "the last step", "`Gate ledger`"],
},
Doctored {
what: "no kit test is left between staging and the ledger",
yaml: without_tests,
names: &["`model-tests`", "`cargo test`"],
},
Doctored {
what: "a check loses its id",
yaml: in_job(
" - name: Model gates\n id: gates\n",
" - name: Model gates\n",
),
names: &["`model-tests`", "`Model gates`", "`id:`"],
},
Doctored {
what: "the ledger no longer reads a check",
yaml: in_job(ledger_entry, ""),
names: &["`model-tests`", "`Gate ledger`", "`gates`", "`Model gates`"],
},
Doctored {
what: "the ledger's entry for a check is only a comment",
yaml: in_job(
ledger_entry,
" # model-gates=${{ steps.gates.outcome }}\n",
),
names: &["`model-tests`", "`Gate ledger`", "`gates`"],
},
Doctored {
what: "the ledger reads the check under another id",
yaml: in_job(
ledger_entry,
" model-gates=${{ steps.gate.outcome }}\n",
),
names: &["`model-tests`", "`Gate ledger`", "`gates`"],
},
Doctored {
what: "a check is dropped",
yaml: in_job(&inventory, ""),
names: &[
"`model-tests`",
"`fp16 sweep inventory`",
"every shard runs",
],
},
Doctored {
what: "a check is renamed",
yaml: in_job("name: fp16 sweep inventory", "name: fp16 inventory sweep"),
names: &["`model-tests`", "`fp16 sweep inventory`"],
},
Doctored {
what: "a check is commented out",
yaml: in_job(
&inventory,
" # - name: fp16 sweep inventory\n # id: fp16_inventory\n # if: ${{ !cancelled() && steps.download.outcome != 'failure' }}\n # run: tests/fp16_sweep_inventory.sh\n",
),
names: &["`model-tests`", "`fp16 sweep inventory`"],
},
];
assert_each_drift_reds(DOCTORED_MODEL_TESTS_JOBS, &cases, model_tests_guard_drift);
}
#[test]
fn ci_model_tests_pin_reds_when_the_job_is_absent() {
let renamed = DOCTORED_MODEL_TESTS_JOBS.replacen(" model-tests:\n", " model-shards:\n", 1);
assert_ne!(renamed, DOCTORED_MODEL_TESTS_JOBS);
let Err(drift) = model_tests_guard_drift(&renamed) else {
panic!("a ci.yml with no `model-tests` job still passed its pin");
};
assert!(
drift.contains("`model-tests`") && drift.contains("`id: download`"),
"the message must name the job and the missing staging step, got: {drift}"
);
}