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.index.gaps

Requirements index · View definition

evidence Valid

Requirement

The combined coverage overview MUST identify whether the post-suite check of cite requirements.test-coverage.check would pass or fail using the same saved coverage and current exception evidence. Findings that cause the check to fail MUST remain inspectable, including measurement, source discovery, source parsing, and exception-review findings.

Rationale

I read the two marked tests in src/execution_coverage/check.rs. I did not request any implementation source. Together they cover both obligations of requirements.test-coverage.index.gaps.

Obligation 1: the overview says whether the post-suite check would pass or fail, using the same saved coverage and current exception evidence.

mod[tests]/fn[book_verdict_and_gaps_follow_the_native_policy_and_current_reviews] renders the “Coverage gaps” chapter and compares it with the real check’s result. It does this across a sequence of states built from the same saved run and review files:

  • Unreviewed gaps: report(root).passed is false and the page shows “CI would fail” with “2 unresolved gaps”.
  • Review accepted: reviews are set to true, and the page shows “1 unresolved gaps” with a documented accepted exception. The current exception evidence changes the result.
  • Review rejected: reviews are set to false, and the page shows “2 unresolved gaps” and “Review not accepted”.
  • Fully covered: report(root).passed is true and the page shows “CI would pass” with “0 unresolved gaps”. This is the pass case.
  • Measurement removed: the profile.profraw file is deleted. The check fails and the page shows “CI would fail” and “gap counts unavailable”.
  • Below the 80% file target: a file-level obligation for code.rs appears in the overview.

mod[tests]/fn[overview_exposes_parse_and_discovery_findings_and_used_file_exceptions] adds more verdict cases. With accepted file and function exceptions, report(root).passed is true and the page shows “CI would pass”. After a parse failure or a discovery failure, report(root).passed is false and the page shows “CI would fail”.

Obligation 2: findings that cause the check to fail remain inspectable.

  • Measurement: after the profile is deleted, the test asserts “missing or unreadable coverage” and the “gap counts unavailable” wording. It also asserts that a false “0 unresolved gaps” is not shown, and that no stale “zero execution” rows appear.
  • Source parsing: a file containing fn broken( is added. The test asserts “cannot parse rust source”, “Coverage-check findings”, the file name driver.rs, and “Gap counts incomplete” on the src and src/nested directory summaries. It also asserts that the independent threshold finding “src/nested/driver.rs: below 80%” is still reported.
  • Source discovery: a corrupt .git/index is created. The test asserts “cannot discover reference sources”, “Gap counts incomplete” or “gap counts unavailable”, and no false “0 unresolved gaps”.
  • Exception review: the test covers “Review missing”, “Review not accepted”, “determination is false”, and “No tracked justification is present.” The rejected case also asserts the <details class="gap-footer"><summary>Coverage-check findings section.

Weakness, not a gap. Some finding messages are asserted with whole-page contains rather than within a specific section. A finding that appeared anywhere on the page would still pass these assertions. Given the paired report(root) comparisons and the footer assertion in the rejected-review case, I do not treat this as a gap.

Every clause of the requirement therefore has a test that exercises it and asserts the outcome, and the tests carry {test} markings for the subject. There is no acknowledgment to account for.

Inputs

Tests

Input 3: outline src/execution_coverage/check.rs mod[tests]/fn[book_verdict_and_gaps_follow_the_native_policy_and_current_reviews]
    // {test}`requirements.test-coverage.index.gaps`
    // {test}`requirements.test-coverage.index.gaps.summary`
    // {test}`requirements.test-coverage.index.gaps.details`
    // {test}`requirements.test-coverage.index.gaps.details.initial`
    // {test}`requirements.test-coverage.index.gaps.explanations`
    // {test}`requirements.test-coverage.index.gaps.accepted`
    // {test}`requirements.test-coverage.index.file_map.combined`
    // {test}`requirements.test-coverage.index.file_map.combined.measurement`
    // {test}`requirements.test-coverage.index.file_map.minimum`
    // {test}`requirements.test-coverage.index.file_map.combined.details`
    #[test]
    fn book_verdict_and_gaps_follow_the_native_policy_and_current_reviews() {
        use mdbook_preprocessor::book::{Book, Chapter};
        let source = "fn a() {}\n\n/// Invariant fallback, unreachable through the public API.\n// {cite}`habeas:coverage`\nfn b() {}\n";
        let temp = fixture(source);
        let root = temp.path();
        let mut p = process(root, &[(1, 1), (2, 1), (3, 1), (4, 1), (5, 0)], 0);
        p.functions.as_mut().unwrap()[0].count = 0;
        let path = record(root, "both", 1, "same", vec![p]);
        let render = || {
            let mut book = Book::new();
            book.push_item(Chapter::new(
                "Requirements index",
                "# Requirements index\n".into(),
                "requirements-index.md",
                vec![],
            ));
            book::populate_in(
                &mut book,
                root,
                Some(root.join("target")),
                Path::new("requirements-index.md"),
            )
            .unwrap();
            book.chapters()
                .find(|chapter| chapter.name == "Coverage gaps")
                .unwrap()
                .content
                .clone()
        };
        let missing = render();
        exercise_file_click(&missing);
        let permitted_details = regex::Regex::new(r#"<details class="([^"]+)""#).unwrap();
        let assert_details = |html: &str| {
            for tag in permitted_details.captures_iter(html) {
                assert!(
                    matches!(
                        &tag[1],
                        "gap-directory" | "gap-explanation" | "gap-accepted-group" | "gap-footer"
                    ),
                    "unexpected expandable section: {}",
                    &tag[1]
                );
            }
            assert!(!html.contains("Test runs and provenance"));
            assert!(!html.contains("habeas-coverage-test"));
        };
        assert_details(&missing);
        let unresolved_rows = missing
            .split("class=\"gap-obligation-table\"")
            .nth(1)
            .unwrap()
            .split("</tbody></table>")
            .next()
            .unwrap();
        for row in [
            "<code>fn[a]</code><br><span class=\"gap-meta\">code.rs:1</span></td><td>zero execution</td>",
            "<code>fn[b]</code><br><span class=\"gap-meta\">code.rs:5</span></td><td>zero execution</td>",
        ] {
            assert!(unresolved_rows.contains(row));
        }

        assert!(!report(root).passed);
        assert!(missing.contains("CI would fail"));
        assert!(missing.contains("2 unresolved gaps"));
        assert!(missing.contains("0 file obligations · 2 function obligations"));
        assert!(missing.contains("Missing habeas:coverage proposal"));
        assert!(missing.contains("Review missing"));
        assert!(missing.contains("Invariant fallback, unreachable through the public API."));
        assert!(missing.contains("aria-expanded=\"false\""));
        assert!(missing.contains("class=\"gap-detail-row\" id=\"habeas-gap-file-0\" hidden"));
        assert!(missing.contains("code.rs:1"));
        assert!(missing.contains("code.rs:5"));
        reviews(root, json!(true));
        let accepted = render();
        assert_details(&accepted);
        assert!(accepted.contains("1 unresolved gaps"));
        assert!(accepted.contains("Documented gaps — 1 accepted exceptions"));
        assert!(!accepted.contains("class=\"gap-accepted-group\" open"));
        assert!(accepted.contains("fn[b]"));
        assert!(accepted.contains("current and accepted"));
        let documented = accepted
            .split("class=\"gap-accepted-group\"")
            .nth(1)
            .unwrap()
            .split("class=\"gap-footer\"")
            .next()
            .unwrap();
        for field in [
            "fn[b]",
            "code.rs:5",
            "zero execution",
            "Invariant fallback, unreachable through the public API.",
            "current and accepted",
            "Current workspace source notes",
            "coverage-reports/files/",
        ] {
            assert!(
                documented.contains(field),
                "missing documented field: {field}"
            );
        }
        assert!(accepted.contains("80.0%")); // Accepted exceptions add no execution.
        reviews(root, json!(false));
        let rejected = render();
        assert_details(&rejected);
        assert!(
            rejected.contains("<details class=\"gap-footer\"><summary>Coverage-check findings")
        );
        assert!(rejected.contains("2 unresolved gaps"));
        assert!(rejected.contains("Review not accepted"));
        assert!(rejected.contains("determination is false"));
        assert!(rejected.contains("Documented gaps — 0 accepted exceptions"));
        reviews(root, json!(true));
        let mut attempt: Attempt = load(&path.join("attempt.json")).unwrap();
        for entry in attempt.processes[0].functions.as_mut().unwrap() {
            entry.count = 1;
        }
        save(&path.join("attempt.json"), &attempt).unwrap();
        let covered = render();
        assert!(report(root).passed);
        assert!(covered.contains("CI would pass"));
        assert!(covered.contains("0 unresolved gaps"));
        assert!(!covered.contains("data-file=\"code.rs\""));
        assert!(covered.contains("Documented gaps — 0 accepted exceptions"));
        fs::remove_file(path.join("profile.profraw")).unwrap();
        let unavailable = render();
        assert!(!report(root).passed);
        assert!(unavailable.contains("CI would fail"));
        assert!(unavailable.contains("gap counts unavailable"));
        assert!(!unavailable.contains("0 unresolved gaps"));
        assert!(
            !unavailable
                .split("</section>")
                .next()
                .unwrap()
                .contains("zero execution")
        );
        assert!(unavailable.contains("missing or unreadable coverage"));
        fs::write(
            root.join("code.rs"),
            "fn a() {}\n// {cite}`habeas:coverage`\nfn b() {}\n",
        )
        .unwrap();
        record(
            root,
            "both",
            2,
            "same",
            vec![process(root, &[(1, 1), (2, 1), (3, 1)], 0)],
        );
        let no_justification = render();
        assert!(no_justification.contains("No tracked justification is present."));
        // File-level and function-level obligations share the same file control
        // and must both expose their source, measurement and explanation.
        record(
            root,
            "both",
            3,
            "same",
            vec![process(root, &[(1, 1), (2, 0), (3, 0)], 0)],
        );
        let below_target = render();
        exercise_file_click(&below_target);
        let rows = below_target
            .split("class=\"gap-obligation-table\"")
            .nth(1)
            .unwrap()
            .split("</tbody></table>")
            .next()
            .unwrap();
        assert!(
            rows.contains("<code>File root</code><br><span class=\"gap-meta\">code.rs:1</span>")
        );
        assert!(rows.contains("1/3 (33.3%); 80% target; uncovered lines: 2-3"));
        assert!(rows.contains("Missing habeas:coverage proposal"));
        assert!(rows.contains("<code>fn[a]</code>"));
        assert!(rows.contains("<code>fn[b]</code>"));
        assert_details(&below_target);
    }
Input 4: outline src/execution_coverage/check.rs mod[tests]/fn[overview_exposes_parse_and_discovery_findings_and_used_file_exceptions]
    // {test}`requirements.test-coverage.index.gaps`
    // {test}`requirements.test-coverage.index.gaps.summary`
    // {test}`requirements.test-coverage.index.file_map.combined`
    // {test}`requirements.test-coverage.index.gaps.accepted`
    #[test]
    fn overview_exposes_parse_and_discovery_findings_and_used_file_exceptions() {
        use mdbook_preprocessor::book::{Book, Chapter};
        let source = "//! :::{cite} habeas:coverage\n//! This platform adapter is unreachable from the public interface.\n//! :::\n\n/// Same invariant protects entry to this adapter.\n// {cite}`habeas:coverage`\nfn adapter() {}\n";
        let temp = fixture(source);
        let root = temp.path();
        let render = || {
            let mut book = Book::new();
            book.push_item(Chapter::new(
                "Requirements index",
                "# Requirements index\n".into(),
                "requirements-index.md",
                vec![],
            ));
            book::populate_in(
                &mut book,
                root,
                Some(root.join("target")),
                Path::new("requirements-index.md"),
            )
            .unwrap();
            book.chapters()
                .find(|chapter| chapter.name == "Coverage gaps")
                .unwrap()
                .content
                .clone()
        };
        reviews(root, json!(true));
        record(
            root,
            "adapter",
            1,
            "same",
            vec![process(root, &[(7, 0)], 0)],
        );
        let accepted = render();
        assert!(report(root).passed);
        assert!(accepted.contains("CI would pass"));
        assert!(accepted.contains("Documented gaps — 2 accepted exceptions"));
        assert!(!accepted.contains("data-file=\"code.rs\""));
        let documented = accepted
            .split("class=\"gap-accepted-group\"")
            .nth(1)
            .unwrap()
            .split("<p class=\"gap-footer")
            .next()
            .unwrap();
        for text in [
            "File root",
            "code.rs:1",
            "code.rs:7",
            "fn[adapter]",
            "zero execution",
            "0/1 (0.0%)",
            "This platform adapter is unreachable",
            "Same invariant",
            "current and accepted",
            "Current workspace source notes",
            "coverage-reports/files/",
        ] {
            assert!(
                documented.contains(text),
                "missing documented field: {text}"
            );
        }
        // Measurement still succeeds when a discovered source cannot be parsed.
        fs::create_dir_all(root.join("src/nested")).unwrap();
        fs::write(root.join("src/nested/driver.rs"), "fn broken(").unwrap();
        let mut p = process(root, &[(7, 0)], 0);
        p.lines
            .insert("src/nested/driver.rs".into(), BTreeMap::from([(1, 0)]));
        let attempt = record(root, "adapter", 2, "same", vec![p]);
        let run_path = attempt.parent().unwrap().parent().unwrap().join("run.json");
        let mut run: Run = super::super::load(&run_path).unwrap();
        run.sources
            .insert("src/nested/driver.rs".into(), "fn broken(".into());
        save(&run_path, &run).unwrap();
        let broken = render();
        assert!(!report(root).passed);
        assert!(broken.contains("CI would fail"));
        assert!(broken.contains("Gap counts incomplete"));
        assert!(broken.to_lowercase().contains("cannot parse rust source"));
        assert!(broken.contains("Coverage-check findings"));
        assert!(!broken.contains("0 unresolved gaps"));
        assert!(broken.contains("driver.rs"));
        for directory in ["src", "src/nested"] {
            let summary = broken
                .split(&format!("data-directory=\"{directory}\""))
                .nth(1)
                .unwrap()
                .split("</summary>")
                .next()
                .unwrap();
            assert!(
                summary.contains("Gap counts incomplete: 1 established uncovered obligations"),
                "{summary}"
            );
        }
        assert!(
            report(root)
                .text
                .contains("src/nested/driver.rs: below 80%"),
            "independent measured file threshold must still run after parse failure"
        );
        fs::remove_file(root.join("src/nested/driver.rs")).unwrap();
        git2::Repository::init(root).unwrap();
        fs::write(root.join(".git/index"), "not a valid index").unwrap();
        let discovery = render();
        assert!(!report(root).passed);
        assert!(discovery.contains("CI would fail"));
        assert!(discovery.contains("cannot discover reference sources"));
        assert!(
            discovery.contains("Gap counts incomplete")
                || discovery.contains("gap counts unavailable")
        );
        assert!(!discovery.contains("0 unresolved gaps"));
    }

Referenced definitions

Input 2: requirements selection requirements.test-coverage.check
:::{req} check
`habeas coverage-check` MUST check saved execution coverage against
{cite}`requirements.test-coverage.check.threshold` and
{cite}`requirements.test-coverage.check.functions`, returning success only when
every applicable obligation is satisfied or has accepted exception evidence
under {cite}`requirements.test-coverage.check.exceptions`. The command MUST NOT
build the project, execute tests, collect coverage, or invoke an assessment model.
:::

Other sources

Input 1: requirements selection requirements.test-coverage.index.gaps
:::{req} index.gaps
The combined coverage overview MUST identify whether the post-suite check of
{cite}`requirements.test-coverage.check` would pass or fail using the same
saved coverage and current exception evidence. Findings that cause the check
to fail MUST remain inspectable, including measurement, source discovery,
source parsing, and exception-review findings.
:::