requirements.test-coverage.setup.validation.static
Requirements index · View definition
Requirement
The setup validation of
MUST NOT run tests, collect coverage, or require an existing completed coverage run. It MUST work during the first instrumented test run, before that run’s profiles and reports have been written.
Rationale
I found no test-adequacy gap for requirements.test-coverage.setup.validation.static.
The requirement has four obligations:
- Setup validation must not run tests.
- It must not collect coverage.
- It must not need an existing completed coverage run.
- It must work during the first instrumented run, before that run’s profiles and reports exist.
Mapping to tests
- No completed run needed, and works before any profiles or reports exist.
tests/execution_coverage.rs#fn[invalid_effective_collector_fails_before_any_tests_or_coverage_run]callshabeas::execution_coverage::validate_setup(root).unwrap()on a freshfixture(). The inline comment says “no completed run required”.- The fixture contains only sources and
.config/nextest.toml. It has notargetdirectory, profiles or reports, so the successful validation models the state before the first instrumented run’s output is written. - The same test calls
validate_setupagain after the failedcoverageinvocations. It still succeeds, and the effective-profile failure is still caught when it should be. - It also checks that
habeas::validate_repositoryreports the broken setup without any prior run.
- Does not run tests or collect coverage.
src/execution_coverage/configuration.rs#mod[tests]/fn[workspace_member_uses_the_native_config_at_the_workspace_root]runsvalidate_setup(&member). It then asserts thatmember/.configis absent and that the workspace root has notargetdirectory. Running tests or building would have createdtarget.tests/execution_coverage.rs#fn[missing_unreadable_malformed_or_disabled_collector_is_a_shared_validation_error]runsvalidate_repositorythrough five failure cases: missing file, unreadable file, malformed TOML, wrapper scripts disabled, and a missing wrapper or rule. Each case asserts thattarget/habeas/coveragedoes not exist.- In the invalid-collector test, the failing
coverageinvocations (an invalid profile, an alternate config file,NEXTEST_PROFILE, and the unverifiable flags) each fail before any coverage output appears. The test asserts thattarget/habeas/coverageis absent.
- The same validation works across layouts. The workspace-member test validates both a workspace-root config and an excluded-member config. This shows validation is static across layouts.
Assessment
- The three tests are all marked
{test}for the subject. - The assertions check outcomes, not just execution. These are success without a prior run, an absent coverage or target directory, and diagnostics that name the file.
- The remaining obligations of
requirements.test-coverage.setup.validation(naming the file, thehabeas setupdirection, and inspecting collector settings) belong to the parent requirement, so I did not assess them here.
Inputs
Tests
Input 3: outline src/execution_coverage/configuration.rs mod[tests]/fn[workspace_member_uses_the_native_config_at_the_workspace_root]
- File:
src/execution_coverage/configuration.rs - Selector:
mod[tests]/fn[workspace_member_uses_the_native_config_at_the_workspace_root] - Kind:
fn src/execution_coverage/configuration.rs:401–435
// {test}`requirements.test-coverage.setup.configuration`
// {test}`requirements.test-coverage.setup.validation.static`
#[test]
fn workspace_member_uses_the_native_config_at_the_workspace_root() {
let temp = tempfile::tempdir().unwrap();
fs::write(
temp.path().join("Cargo.toml"),
"[workspace]\nmembers = ['member']\n",
)
.unwrap();
let member = temp.path().join("member");
fs::create_dir(&member).unwrap();
fs::write(
member.join("Cargo.toml"),
"[package]\nname = 'member'\nversion = '0.1.0'\n",
)
.unwrap();
let (path, source) = configure(&member).unwrap();
assert_eq!(path, temp.path().join(".config/nextest.toml"));
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(path, source).unwrap();
validate_setup(&member).unwrap();
assert!(!member.join(".config").exists());
assert!(!temp.path().join("target").exists());
fs::write(
temp.path().join("Cargo.toml"),
"[workspace]\nmembers = []\nexclude = ['mem*']\n",
)
.unwrap();
let (excluded_path, source) = configure(&member).unwrap();
assert_eq!(excluded_path, member.join(".config/nextest.toml"));
fs::create_dir_all(excluded_path.parent().unwrap()).unwrap();
fs::write(excluded_path, source).unwrap();
validate_setup(&member).unwrap();
}
Input 4: 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")
);
}
Input 5: 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();
}
Referenced definitions
Input 2: requirements selection requirements.test-coverage.setup.validation
requirements.test-coverage.setup.validation:md/requirements/test-coverage.md:524–535
:::{req} setup.validation
Repository validation, including the test calling `habeas::validate()` under
{cite}`requirements.integration.validate`, MUST check that the saved nextest
integration required by
{cite}`requirements.test-coverage.setup.configuration` is present and valid
for the coverage workflow's default profile, accounting for profile inheritance
and wrapper-rule precedence. A missing, unreadable, malformed, or incompatible
integration MUST be a validation error naming the affected file or setting and
directing the agent to repair it with `habeas setup`. The check MUST inspect the
collector settings and selection rules rather than only the file's existence.
Nextest's unrelated settings MUST retain their native meaning.
:::
Other sources
Input 1: requirements selection requirements.test-coverage.setup.validation.static
requirements.test-coverage.setup.validation.static:md/requirements/test-coverage.md:537–542
:::{req} setup.validation.static
The setup validation of {cite}`requirements.test-coverage.setup.validation`
MUST NOT run tests, collect coverage, or require an existing completed coverage
run. It MUST work during the first instrumented test run, before that run's
profiles and reports have been written.
:::
Input 6: 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
}