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.explanations

Requirements index · View definition

evidence Valid

Requirement

Each unsatisfied obligation under cite requirements.test-coverage.index.gaps.summary MUST distinguish a missing habeas:coverage proposal from a present proposal whose review is missing or is not current and accepted. When a present proposal contains no tracked justification, the view MUST say so.

Present justification text and review validation findings MUST remain inspectable following cite requirements.test-coverage.index.file_map.notes.justifications and cite requirements.test-coverage.index.file_map.notes.reviews.

Rationale

The only test marked for this requirement is src/execution_coverage/check.rs#mod[tests]/fn[book_verdict_and_gaps_follow_the_native_policy_and_current_reviews]. It renders the real “Coverage gaps” chapter through book::populate_in and checks the output against each obligation.

Obligations and the scenarios that cover them

  • Missing proposal versus present proposal with a missing review. Function a has no habeas:coverage citation. Function b has a citation and a doc comment, but no review has been recorded yet.
    • The test asserts the page contains “Missing habeas:coverage proposal” and “Review missing”.
    • The justification text “Invariant fallback, unreachable through the public API.” is also asserted.
    • src/execution_coverage/book.rs#fn[explanation_html] shows these are two separate branches.
  • Present proposal whose review is not accepted. After reviews(root, json!(false)), the test asserts “Review not accepted” and “determination is false”, so the validation finding is inspectable. It also asserts “Documented gaps — 0 accepted exceptions”, which checks the rejected exception is not presented as accepted.
  • Present proposal with a current and accepted review. The test asserts “current and accepted”, plus the justification text, source location and the other documented fields, inside the documented-gaps group. This is the positive counterpart that the other states are distinguished from.
  • No tracked justification. The test rewrites code.rs so b carries a bare citation with no doc comment or commentary. It asserts “No tracked justification is present.”
  • Justification text and findings stay inspectable.
    • The details sections are collapsible, and the test asserts that only the permitted <details> classes appear. That includes gap-explanation.
    • The justification text and the rejection finding are asserted present in the rendered HTML.
  • Both file-level and function-level obligations. The final scenario checks the “File root” row and the function rows. It asserts “Missing habeas:coverage proposal” for the below-target file obligation.

Residual observations (not gaps)

  • The assertions are mostly page-wide contains checks, not per-row associations.
  • A stale review is not asserted separately. In the “no justification” step the earlier review is likely stale, but only the justification message is checked there.
  • explanation_html has only three states: accepted, review missing, and a generic not-accepted branch that also lists findings. The requirement’s “missing or not current and accepted” wording is therefore covered by the missing and rejected cases, because stale, invalid and rejected reviews share that branch.

No obligation of this requirement lacks a test that exercises it and asserts its outcome.

Inputs

Implementation

Input 6: outline src/execution_coverage/book.rs fn[explanation_html]
// {impl}`requirements.test-coverage.index.gaps.explanations`
fn explanation_html(gap: &super::check::Obligation) -> String {
    let Some(exception) = &gap.exception else {
        return "<span class=\"gap-unresolved\">Missing habeas:coverage proposal</span>".into();
    };
    let state = if exception.accepted {
        "Current and accepted"
    } else if exception.review_missing {
        "Review missing"
    } else {
        "Review not accepted"
    };
    let mut html = format!("<details class=\"gap-explanation\"><summary>{state}</summary>");
    if exception.justification.trim().is_empty() {
        html.push_str("<p>No tracked justification is present.</p>");
    } else {
        html.push_str(&format!(
            "<pre>{}</pre>",
            escaped(&crate::redaction::redact_text(&exception.justification))
        ));
    }
    for finding in &exception.findings {
        html.push_str(&format!("<p>{}</p>", escaped(finding)));
    }
    html.push_str("</details>");
    html
}

Tests

Input 5: 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);
    }

Referenced definitions

Input 2: requirements selection requirements.test-coverage.index.gaps.summary
:::{req} index.gaps.summary
The combined coverage overview MUST identify the numbers of unsatisfied file
and function obligations and group those obligations by source file.
Each directory summary MUST identify the number of unsatisfied obligations
within that directory and its descendants, regardless of which groups are
expanded.

When measurement or source discovery or parsing prevents establishing those
counts, the affected counts MUST be identified as unavailable or incomplete
rather than presented as complete counts. An empty list of established
unsatisfied obligations MUST NOT imply that the check passes when
{cite}`requirements.test-coverage.index.gaps` reports other failures.
:::
Input 3: requirements selection requirements.test-coverage.index.file_map.notes.justifications
:::{req} index.file_map.notes.justifications
The view of {cite}`requirements.test-coverage.index.file_map.notes` MUST show
each `habeas:coverage` citation attached to the file root or an explicitly
declared function or method. Each entry MUST identify its source item and
source location and show the fenced citation commentary and Rust doc comments
supplying its tracked justification under
{cite}`requirements.test-coverage.check.exceptions.anchor`.
When no tracked justification is present, the entry MUST say so.

File-root citations MUST be labelled as file-threshold exception proposals;
function and method citations MUST be labelled as function exception proposals,
following {cite}`requirements.test-coverage.check.exceptions.anchor`.
:::
Input 4: requirements selection requirements.test-coverage.index.file_map.notes.reviews
:::{req} index.file_map.notes.reviews
Each citation entry under
{cite}`requirements.test-coverage.index.file_map.notes.justifications` MUST
show whether its source item's citation review is current and accepted under
{cite}`requirements.test-coverage.check.exceptions.reviews`.

Missing, unreadable, stale, invalid, or rejected reviews MUST NOT be presented
as accepted. The view MUST distinguish a missing review from a present review
that is not accepted and expose the validation findings explaining
non-acceptance.
:::

Other sources

Input 1: requirements selection requirements.test-coverage.index.gaps.explanations
:::{req} index.gaps.explanations
Each unsatisfied obligation under
{cite}`requirements.test-coverage.index.gaps.summary` MUST distinguish a
missing `habeas:coverage` proposal from a present proposal whose review is
missing or is not current and accepted. When a present proposal contains no
tracked justification, the view MUST say so.

Present justification text and review validation findings MUST remain
inspectable following
{cite}`requirements.test-coverage.index.file_map.notes.justifications` and
{cite}`requirements.test-coverage.index.file_map.notes.reviews`.
:::