requirements.test-coverage.run.configuration
Requirements index · View definition
Requirement
The coverage workflow MUST verify that the effective nextest profile and configuration selected for the invocation route every selected test attempt through Habeas’s per-process collector, accounting for profile inheritance and wrapper-rule precedence. If that cannot be established, it MUST fail before executing tests with a diagnostic identifying the conflicting profile or setting, rather than silently collecting incomplete coverage.
Rationale
I judge the two marked tests adequate for requirements.test-coverage.run.configuration.
Obligations derived from the requirement
- Check the effective profile and configuration selected for the invocation, including the profile chosen by CLI flag, environment variable or config file.
- Account for profile inheritance.
- Account for wrapper-rule precedence.
- If routing every attempt through the collector cannot be established, fail before executing tests.
- The failure diagnostic must name the conflicting profile or setting.
Test mapping
The unit test src/execution_coverage/configuration.rs#mod[tests]/fn[native_settings_inheritance_and_precedence] covers inheritance and precedence:
- A valid
ciprofile passes. - A
localprofile that inheritsfast, which inheritsci, passes. - A conflicting
run-wrapper = 'other'rule in the inheritedfastprofile makeslocalfail. The error containsprofile.fast.scripts. - Adding a
habeas-coverageall()rule in the childlocalprofile makes the check pass again, which shows child precedence over the parent. - Three further cases each fail:
- a
test(x)filter with another wrapper; - a platform-restricted collector rule;
- a self-inheriting profile (a cycle).
- a
- Altered wrapper definitions fail: a wrong command, and
overrides-wrapperin place ofwithin-wrapper.
The integration test tests/execution_coverage.rs#fn[invalid_effective_collector_fails_before_any_tests_or_coverage_run] covers the effective profile and configuration selection through the real habeas coverage binary:
- A conflicting rule in the
fastprofile fails the run when the profile is chosen through each of these forms. In every case stderr containsprofile.fast.scripts:--profile fast;--profile=fast;-Pfast;-P fast;- the
NEXTEST_PROFILEenvironment variable; -- --profile fast, which wins overNEXTEST_PROFILE=default.
--profile default --no-runsucceeds even thoughNEXTEST_PROFILE=fastis set. This shows the explicit CLI profile takes precedence over the environment, and that the default profile is still valid.- An alternate
--config-filewith a wrong collector fails, and the diagnostic names that file. - Each unverifiable input flag fails with a diagnostic that names the flag and says “cannot be proven”:
--tool-config-file--archive-file--binaries-metadata--cargo-metadata--target-dir-remap--build-dir-remap
- Failure happens before any test run or coverage output:
target/habeas/coveragedoes not exist after the failures. This is a reasonable proxy for “before executing tests”.
Other tests considered
tests/execution_coverage.rs#fn[missing_unreadable_malformed_or_disabled_collector_is_a_shared_validation_error] is marked for the setup-validation requirements, not this one. It also exercises a default profile with no wrapper rule at all. That path shares check with the run path, so I did not treat its missing mark as a gap.
Gaps
I found none. I looked at the implementations check and verify_configuration only to see how the tests’ inputs reach them. The cases the requirement names are all exercised with assertions on both the failure and the diagnostic text.
Inputs
Implementation
Input 4: outline src/execution_coverage/configuration.rs fn[check]
- File:
src/execution_coverage/configuration.rs - Selector:
fn[check] - Kind:
fn src/execution_coverage/configuration.rs:87–209
// Deliberately prove an unconditional first run-wrapper rule, rather than approximate
// arbitrary nextest filtersets. Unrelated setup/list rules are left to nextest.
// {impl}`requirements.test-coverage.run.configuration`
pub(super) fn check(source: &str, path: &Path, profile: &str) -> io::Result<()> {
let config: toml::Table = source.parse().map_err(|error| invalid(path, error))?;
if !config
.get("experimental")
.and_then(toml::Value::as_array)
.is_some_and(|features| {
features
.iter()
.any(|feature| feature.as_str() == Some("wrapper-scripts"))
})
{
return Err(invalid(path, "experimental must include wrapper-scripts"));
}
let wrapper = config
.get("scripts")
.and_then(|scripts| scripts.get("wrapper"))
.and_then(|wrappers| wrappers.get(WRAPPER))
.and_then(toml::Value::as_table)
.ok_or_else(|| invalid(path, "scripts.wrapper.habeas-coverage is missing"))?;
if !wrapper.get("command").is_some_and(command_is_collector)
|| wrapper.get("target-runner").and_then(toml::Value::as_str) != Some("within-wrapper")
{
return Err(invalid(
path,
"scripts.wrapper.habeas-coverage requires command = [\"habeas\", \"coverage-process\"] and target-runner = \"within-wrapper\"",
));
}
let profiles = config
.get("profile")
.and_then(toml::Value::as_table)
.ok_or_else(|| invalid(path, "profile.default.scripts is missing"))?;
// Validate the entire inheritance chain even if an early wrapper rule is
// unconditional: cycles and an invalid default parent are still malformed.
let mut parent = profile;
let mut chain = BTreeSet::new();
loop {
if !chain.insert(parent) {
return Err(invalid(
path,
format!("profile.{parent}.inherits forms a cycle"),
));
}
let settings = profiles.get(parent).and_then(toml::Value::as_table);
if parent == "default" {
if settings.is_some_and(|settings| settings.contains_key("inherits")) {
return Err(invalid(
path,
"profile.default cannot inherit another profile",
));
}
break;
}
if settings.is_none() && parent != "ci" {
return Err(invalid(path, format!("profile.{parent} is not defined")));
}
parent = match settings.and_then(|settings| settings.get("inherits")) {
Some(value) => value.as_str().ok_or_else(|| {
invalid(path, format!("profile.{parent}.inherits must be a string"))
})?,
None => "default",
};
}
let mut current = profile;
let mut visited = BTreeSet::new();
loop {
if !visited.insert(current) {
return Err(invalid(
path,
format!("profile.{current}.inherits forms a cycle"),
));
}
let settings = profiles.get(current).and_then(toml::Value::as_table);
if current != "default" && settings.is_none() && current != "ci" {
return Err(invalid(path, format!("profile.{current} is not defined")));
}
if let Some(settings) = settings {
if let Some(scripts) = settings.get("scripts") {
let scripts = scripts.as_array().ok_or_else(|| {
invalid(path, format!("profile.{current}.scripts must be an array"))
})?;
for rule in scripts {
let Some(wrapper) = rule.get("run-wrapper") else {
continue;
};
if wrapper.as_str() == Some(WRAPPER)
&& rule.get("filter").and_then(toml::Value::as_str) == Some("all()")
&& rule.get("platform").is_none()
{
return Ok(());
}
return Err(invalid(
path,
format!(
"profile.{current}.scripts: the first run-wrapper rule must unconditionally select {WRAPPER}; its filter/platform or wrapper prevents proving complete coverage"
),
));
}
}
if current == "default" && settings.contains_key("inherits") {
return Err(invalid(
path,
"profile.default cannot inherit another profile",
));
}
}
if current == "default" {
break;
}
current = match settings.and_then(|settings| settings.get("inherits")) {
Some(parent) => parent.as_str().ok_or_else(|| {
invalid(path, format!("profile.{current}.inherits must be a string"))
})?,
None => "default",
};
}
Err(invalid(
path,
format!("profile.{profile}.scripts does not route all attempts through {WRAPPER}"),
))
}
Input 5: outline src/execution_coverage/runner.rs fn[verify_configuration]
- File:
src/execution_coverage/runner.rs - Selector:
fn[verify_configuration] - Kind:
fn src/execution_coverage/runner.rs:282–311
// {impl}`requirements.test-coverage.run.configuration`
fn verify_configuration(root: &Path, args: &[String]) -> io::Result<()> {
for flag in [
"--tool-config-file",
"--archive-file",
"--binaries-metadata",
"--cargo-metadata",
"--target-dir-remap",
"--build-dir-remap",
] {
if option(args, &[flag]).is_some() {
return Err(io::Error::other(format!(
"{flag} cannot be proven to use this instrumented build and collector; use the workspace configuration for `habeas coverage`"
)));
}
}
let profile = option(args, &["--profile", "-P"])
.or_else(|| std::env::var("NEXTEST_PROFILE").ok())
.unwrap_or_else(|| "default".to_owned());
let path = option(args, &["--config-file"])
.map(PathBuf::from)
.unwrap_or_else(|| root.join(".config/nextest.toml"));
configuration::check(
&fs::read_to_string(&path).map_err(|error| {
io::Error::other(format!("{}: {error}; run `habeas setup`", path.display()))
})?,
&path,
&profile,
)
}
Tests
Input 2: outline src/execution_coverage/configuration.rs mod[tests]/fn[native_settings_inheritance_and_precedence]
- File:
src/execution_coverage/configuration.rs - Selector:
mod[tests]/fn[native_settings_inheritance_and_precedence] - Kind:
fn src/execution_coverage/configuration.rs:289–360
// {test}`requirements.test-coverage.setup.configuration`
// {test}`requirements.test-coverage.setup`
// {test}`requirements.test-coverage.setup.validation`
// {test}`requirements.test-coverage.run.configuration`
#[test]
fn native_settings_inheritance_and_precedence() {
let temp = tempfile::tempdir().unwrap();
fs::write(temp.path().join("Cargo.toml"), "[workspace]\n").unwrap();
let (path, source) = configure(temp.path()).unwrap();
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(&path, &source).unwrap();
assert_eq!(configure(temp.path()).unwrap().1, source);
check(&source, &path, "ci").unwrap();
let inherited = format!(
"{source}\n[profile.fast]\ninherits = 'ci'\ntest-threads = 3\n[profile.local]\ninherits = 'fast'\n"
);
check(&inherited, &path, "local").unwrap();
let inherited_conflict = format!(
"{inherited}\n[[profile.fast.scripts]]\nfilter = 'all()'\nrun-wrapper = 'other'\n"
);
assert!(
check(&inherited_conflict, &path, "local")
.unwrap_err()
.to_string()
.contains("profile.fast.scripts")
);
let child_override = format!(
"{inherited_conflict}\n[[profile.local.scripts]]\nfilter = 'all()'\nrun-wrapper = 'habeas-coverage'\n"
);
check(&child_override, &path, "local").unwrap();
for extra in [
"\n[[profile.local.scripts]]\nfilter = 'test(x)'\nrun-wrapper = 'other'\n",
"\n[[profile.local.scripts]]\nfilter = 'all()'\nplatform = 'cfg(unix)'\nrun-wrapper = 'habeas-coverage'\n",
"\n[profile.local]\ninherits = 'local'\n",
] {
assert!(check(&format!("{source}{extra}"), &path, "local").is_err());
}
assert!(
check(
&source.replace("coverage-process", "wrong"),
&path,
"default"
)
.is_err()
);
assert!(
check(
&source.replace("within-wrapper", "overrides-wrapper"),
&path,
"default"
)
.is_err()
);
fs::write(&path, "experimental = ['setup-scripts']\n[profile.default]\nretries = 2\n[[profile.default.scripts]]\nfilter = 'all()'\nsetup = 'prepare'\n").unwrap();
let preserved = configure(temp.path()).unwrap().1;
assert!(
preserved.contains("setup-scripts")
&& preserved.contains("retries = 2")
&& preserved.contains("prepare")
);
fs::write(
&path,
"[[profile.default.scripts]]\nfilter = 'test(x)'\nrun-wrapper = 'custom'\n",
)
.unwrap();
assert!(
configure(temp.path())
.unwrap_err()
.to_string()
.contains("conflict")
);
}
Input 3: outline tests/execution_coverage.rs fn[invalid_effective_collector_fails_before_any_tests_or_coverage_run]
- File:
tests/execution_coverage.rs - Selector:
fn[invalid_effective_collector_fails_before_any_tests_or_coverage_run] - Kind:
fn tests/execution_coverage.rs:1510–1594
// {test}`requirements.test-coverage.run.configuration`
// {test}`requirements.test-coverage.setup.validation`
// {test}`requirements.test-coverage.setup.validation.static`
#[test]
fn invalid_effective_collector_fails_before_any_tests_or_coverage_run() {
let temp = fixture();
let root = temp.path();
habeas::execution_coverage::validate_setup(root).unwrap(); // no completed run required
let path = root.join(".config/nextest.toml");
let mut source = fs::read_to_string(&path).unwrap();
source.push_str("\n[scripts.wrapper.custom]\ncommand = ['false']\ntarget-runner = 'within-wrapper'\n\n[[profile.fast.scripts]]\nfilter = 'test(second)'\nrun-wrapper = 'custom'\n");
fs::write(&path, &source).unwrap();
let failed = coverage(root, &["--profile", "fast"]);
assert!(!failed.status.success());
assert!(String::from_utf8_lossy(&failed.stderr).contains("profile.fast.scripts"));
assert!(!root.join("target/habeas/coverage").exists());
let alternate = root.join("alternate-nextest.toml");
fs::write(
&alternate,
source.replace("coverage-process", "wrong-command"),
)
.unwrap();
let selected = coverage(root, &["--config-file", "alternate-nextest.toml"]);
assert!(!selected.status.success());
assert!(String::from_utf8_lossy(&selected.stderr).contains("alternate-nextest.toml"));
let selected = Command::new(env!("CARGO_BIN_EXE_habeas"))
.arg("coverage")
.current_dir(root)
.env("NEXTEST_PROFILE", "fast")
.output()
.unwrap();
assert!(!selected.status.success());
assert!(String::from_utf8_lossy(&selected.stderr).contains("profile.fast.scripts"));
for args in [vec!["--profile=fast"], vec!["-Pfast"], vec!["-P", "fast"]] {
let selected = coverage(root, &args);
assert!(!selected.status.success());
assert!(String::from_utf8_lossy(&selected.stderr).contains("profile.fast.scripts"));
}
let selected = Command::new(env!("CARGO_BIN_EXE_habeas"))
.args(["coverage", "--", "--profile", "fast"])
.current_dir(root)
.env("NEXTEST_PROFILE", "default")
.output()
.unwrap();
assert!(!selected.status.success());
assert!(String::from_utf8_lossy(&selected.stderr).contains("profile.fast.scripts"));
for flag in [
"--tool-config-file",
"--archive-file",
"--binaries-metadata",
"--cargo-metadata",
"--target-dir-remap",
"--build-dir-remap",
] {
let failed = coverage(root, &[flag, "unverified-input"]);
assert!(!failed.status.success(), "{flag}");
let diagnostic = String::from_utf8_lossy(&failed.stderr);
assert!(
diagnostic.contains(flag) && diagnostic.contains("cannot be proven"),
"{flag}: {diagnostic}"
);
}
assert!(!root.join("target/habeas/coverage").exists());
// The default integration remains valid, while the effective fast profile is not.
habeas::execution_coverage::validate_setup(root).unwrap();
let selected = Command::new(env!("CARGO_BIN_EXE_habeas"))
.args(["coverage", "--", "--profile", "default", "--no-run"])
.current_dir(root)
.env("NEXTEST_PROFILE", "fast")
.env("CARGO_NET_OFFLINE", "true")
.env_remove("CARGO_TARGET_DIR")
.env_remove("CARGO_BUILD_TARGET_DIR")
.env_remove("RUSTC_WORKSPACE_WRAPPER")
.output()
.unwrap();
assert_success(&selected);
assert!(String::from_utf8_lossy(&selected.stderr).contains("Compilation-only run"));
fs::write(&path, source.replace("coverage-process", "wrong-command")).unwrap();
let errors = habeas::validate_repository(root).unwrap().errors.join("\n");
assert!(
errors.contains(".config/nextest.toml")
&& errors.contains("habeas setup")
&& errors.contains("scripts.wrapper.habeas-coverage")
);
}
Other sources
Input 1: requirements selection requirements.test-coverage.run.configuration
requirements.test-coverage.run.configuration:md/requirements/test-coverage.md:40–47
:::{req} run.configuration
The coverage workflow MUST verify that the effective nextest profile and
configuration selected for the invocation route every selected test attempt
through Habeas's per-process collector, accounting for profile inheritance and
wrapper-rule precedence. If that cannot be established, it MUST fail before
executing tests with a diagnostic identifying the conflicting profile or
setting, rather than silently collecting incomplete coverage.
:::
Input 6: outline src/execution_coverage/configuration.rs mod[tests]/fn[setup_conflicts_name_the_setting_and_preserve_existing_native_configuration]
- File:
src/execution_coverage/configuration.rs - Selector:
mod[tests]/fn[setup_conflicts_name_the_setting_and_preserve_existing_native_configuration] - Kind:
fn src/execution_coverage/configuration.rs:362–399
// {test}`requirements.test-coverage.setup.configuration`
#[test]
fn setup_conflicts_name_the_setting_and_preserve_existing_native_configuration() {
let temp = tempfile::tempdir().unwrap();
fs::write(temp.path().join("Cargo.toml"), "[workspace]\n").unwrap();
let (path, valid) = configure(temp.path()).unwrap();
fs::create_dir_all(path.parent().unwrap()).unwrap();
for (source, setting) in [
(
valid.replace("coverage-process", "other-command"),
"scripts.wrapper.habeas-coverage",
),
(
valid.replace("within-wrapper", "overrides-wrapper"),
"scripts.wrapper.habeas-coverage",
),
(
"experimental = 'wrong'\n".to_owned(),
"experimental must be an array",
),
("scripts = 'wrong'\n".to_owned(), "scripts must be a table"),
(
"[profile.default]\nscripts = 'wrong'\n".to_owned(),
"profile.default.scripts must be an array of tables",
),
(
"[[profile.default.scripts]]\nfilter = 'test(x)'\nrun-wrapper = 'custom'\n"
.to_owned(),
"profile.default.scripts",
),
] {
fs::write(&path, &source).unwrap();
let error = configure(temp.path()).unwrap_err().to_string();
assert!(error.contains(setting), "{setting}: {error}");
assert!(error.contains(".config/nextest.toml"), "{error}");
assert_eq!(fs::read_to_string(&path).unwrap(), source);
}
}
Input 7: outline tests/execution_coverage.rs fn[missing_unreadable_malformed_or_disabled_collector_is_a_shared_validation_error]
- File:
tests/execution_coverage.rs - Selector:
fn[missing_unreadable_malformed_or_disabled_collector_is_a_shared_validation_error] - Kind:
fn tests/execution_coverage.rs:1596–1643
// {test}`requirements.test-coverage.setup.validation`
// {test}`requirements.test-coverage.setup.validation.static`
#[test]
fn missing_unreadable_malformed_or_disabled_collector_is_a_shared_validation_error() {
let temp = fixture();
let root = temp.path();
let path = root.join(".config/nextest.toml");
let source = fs::read_to_string(&path).unwrap();
let assert_error = || {
let errors = habeas::validate_repository(root).unwrap().errors.join("\n");
assert!(
errors.contains(".config/nextest.toml") && errors.contains("habeas setup"),
"{errors}"
);
assert!(!root.join("target/habeas/coverage").exists());
};
fs::remove_file(&path).unwrap();
assert_error();
fs::create_dir(&path).unwrap(); // the file cannot be read as text
assert_error();
fs::remove_dir(&path).unwrap();
fs::write(&path, "[invalid").unwrap();
assert_error();
fs::write(
&path,
source
.replace("experimental = ['wrapper-scripts']", "experimental = []")
.replace("experimental = [\"wrapper-scripts\"]", "experimental = []"),
)
.unwrap();
assert_error();
let mut missing_wrapper = source.parse::<toml::Table>().unwrap();
missing_wrapper["scripts"]["wrapper"]
.as_table_mut()
.unwrap()
.remove("habeas-coverage");
fs::write(&path, toml::to_string(&missing_wrapper).unwrap()).unwrap();
assert_error();
let mut missing_rule = source.parse::<toml::Table>().unwrap();
missing_rule["profile"]["default"]
.as_table_mut()
.unwrap()
.remove("scripts");
fs::write(&path, toml::to_string(&missing_rule).unwrap()).unwrap();
assert_error();
fs::write(&path, source).unwrap();
habeas::execution_coverage::validate_setup(root).unwrap();
}
Input 8: outline tests/execution_coverage.rs fn[fixture]
- File:
tests/execution_coverage.rs - Selector:
fn[fixture] - Kind:
fn tests/execution_coverage.rs:11–48
// {cite}`habeas:util`
fn fixture() -> TempDir {
let temp = tempfile::tempdir().unwrap();
let root = temp.path();
for directory in ["src", "tests", "md"] {
fs::create_dir_all(root.join(directory)).unwrap();
}
fs::write(
root.join("Cargo.toml"),
"[package]\nname = 'coverage-fixture'\nversion = '0.1.0'\nedition = '2024'\n[features]\nalpha = []\nbeta = []\n",
)
.unwrap();
fs::write(root.join("book.toml"), "[book]\nsrc = 'md'\n").unwrap();
fs::write(root.join("md/SUMMARY.md"), "# Summary\n").unwrap();
fs::write(
root.join("src/lib.rs"),
concat!(
"pub fn value(flag: bool) -> u32 {\n",
" if flag {\n 10\n } else {\n 20\n }\n}\n",
"#[cfg(test)] #[test] fn same_name() { assert_eq!(value(true), 10); }\n",
"#[cfg(test)] #[test] fn second() { assert_eq!(value(false), 20); }\n",
),
)
.unwrap();
fs::write(root.join("tests/processes.rs"), concat!(
"use std::process::Command;\n",
"#[test] fn same_name() { assert_eq!(coverage_fixture::value(false), 20); }\n",
"#[test] fn child_process() {\n",
" if std::env::var_os(\"COVERAGE_CHILD\").is_some() {\n",
" assert_eq!(coverage_fixture::value(true), 10);\n",
" } else {\n",
" assert!(Command::new(std::env::current_exe().unwrap()).args([\"--exact\", \"child_process\"]).env(\"COVERAGE_CHILD\", \"1\").status().unwrap().success());\n",
" }\n}\n",
"#[test] fn retries() { assert_eq!(std::env::var(\"NEXTEST_ATTEMPT\").unwrap(), \"2\"); }\n",
)).unwrap();
common::coverage_setup(root);
temp
}