Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

requirements.test-coverage.setup.validation

Requirements index · View definition

evidence Valid

Requirement

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.

Rationale

The reviewed tests cover each obligation in requirements.test-coverage.setup.validation. I did not read the implementation source. I judged only from the supplied test text.

Missing, unreadable, malformed or incompatible integration is a validation error naming the file and directing to habeas setup.

  • tests/execution_coverage.rs#fn[missing_unreadable_malformed_or_disabled_collector_is_a_shared_validation_error] calls habeas::validate_repository after each of these changes:
    • the file is removed (missing);
    • the path becomes a directory (unreadable);
    • the content is [invalid (malformed);
    • experimental no longer lists wrapper-scripts (incompatible);
    • scripts.wrapper.habeas-coverage is removed (incompatible);
    • the default profile’s scripts rule is removed (incompatible).
  • Each case asserts that the joined errors contain both .config/nextest.toml and habeas setup.
  • It also asserts that no coverage output directory was created, and that the restored file passes validate_setup.

The check inspects collector settings and selection rules, not just whether the file exists.

  • The test above shows that removing the wrapper definition or the default profile’s rule causes failure even though the file is present.
  • tests/execution_coverage.rs#fn[invalid_effective_collector_fails_before_any_tests_or_coverage_run] replaces the collector command (coverage-process becomes wrong-command). It asserts that validate_repository reports .config/nextest.toml, habeas setup and scripts.wrapper.habeas-coverage.
  • The unit test also changes within-wrapper to overrides-wrapper. That change is rejected.

Profile inheritance and wrapper-rule precedence.

  • src/execution_coverage/configuration.rs#mod[tests]/fn[native_settings_inheritance_and_precedence] exercises check with these cases:
    • The valid default configuration passes.
    • A profile inheriting through a chain (local inherits fast, which inherits ci) passes.
    • A conflicting rule in the inherited fast profile fails, and the error names profile.fast.scripts.
    • A child-profile all() rule that restores the habeas wrapper takes precedence and passes.
    • A competing test(x) rule, a platform-qualified rule and a self-inheriting profile are all rejected.
  • The integration test asserts that the invalid fast profile is rejected and that the default profile still validates.
  • Profile selection routes are also tested: --profile, -P, the NEXTEST_PROFILE environment variable and --config-file.

Unrelated nextest settings keep their native meaning.

  • test-threads = 3 on an inheriting profile still validates.
  • configure preserves experimental = ['setup-scripts'], retries = 2 and an unrelated setup script.
  • Valid unrelated configuration is therefore not rejected or altered.

I found no scenario the requirement names that is untested. Several tests carry the {test} marker for the subject.

Inputs

Tests

Input 4: outline src/execution_coverage/configuration.rs mod[tests]/fn[native_settings_inheritance_and_precedence]
    // {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 5: outline tests/execution_coverage.rs fn[invalid_effective_collector_fails_before_any_tests_or_coverage_run]
// {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 6: outline tests/execution_coverage.rs fn[missing_unreadable_malformed_or_disabled_collector_is_a_shared_validation_error]
// {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.integration.validate
:::{req} validate
`habeas::validate()` MUST check the current Cargo and mdBook project and make its Cargo test fail with all validation errors when any requirement evidence is invalid.
Its failure message MUST instruct the agent to run `habeas author --all`, address
the reported gaps, and rerun tests. Validation MUST remain deterministic and MUST
NOT invoke authoring itself. {cite}`requirements.authoring.batch`
{cite}`requirements.authoring.deterministic_validation`
:::
Input 3: requirements selection requirements.test-coverage.setup.configuration
:::{req} setup.configuration
`habeas setup` MUST configure native nextest settings in
`.config/nextest.toml` at the Cargo workspace root so the coverage workflow of
{cite}`requirements.test-coverage.run` routes each executed test attempt through
the per-process collector of {cite}`requirements.test-coverage.processes`.
Those settings MUST use nextest's own configuration format.
Repeating setup MUST avoid duplicate configuration, preserve unrelated nextest
settings, and report conflicting settings for review rather than overwrite them.
:::

Other sources

Input 1: requirements selection requirements.test-coverage.setup.validation
:::{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.
:::