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

Requirements index · View definition

evidence Valid

Requirement

In the combined gaps overview, clicking a listed file MUST expand or collapse its uncovered obligations in place. Each expanded file MUST show each obligation’s source item and source location, measurement, and explanation status.

Rationale

The subject has three obligations. Clicking a listed file expands and collapses its uncovered obligations in place. Each expanded file shows each obligation’s source item and source location. Each also shows its measurement and explanation status. The marked test src/execution_coverage/check.rs#mod[tests]/fn[book_verdict_and_gaps_follow_the_native_policy_and_current_reviews] covers all three.

  • Expand and collapse in place: The test calls the helper exercise_file_click on the rendered HTML, both for the missing-review case and the below-target case. The helper takes the real onclick, aria-controls and row ids from the HTML. It runs the handler in Node with stubbed DOM objects. It asserts that the first click un-hides the generated detail row, sets aria-expanded to true and changes the chevron to ▾. It asserts that the second click re-hides the row, sets aria-expanded back to false and restores ▸. The test also checks that the detail rows start hidden and that the button has aria-expanded="false". The rows are in the same page, so the expansion is in place.

  • Source item and location: The unresolved-gaps table rows are asserted to contain <code>fn[a]</code> with code.rs:1, and <code>fn[b]</code> with code.rs:5. In the below-target scenario, the file-level obligation is asserted as <code>File root</code> with code.rs:1, and the fn[a] and fn[b] rows are also present. The documented/accepted section is asserted to contain fn[b] and code.rs:5.

  • Measurement: The tests assert “zero execution” in the function rows. They assert “1/3 (33.3%); 80% target; uncovered lines: 2-3” in the file-level row.

  • Explanation status: The tests assert these statuses:

    • “Missing habeas:coverage proposal”
    • “Review missing”
    • “Review not accepted” with “determination is false”
    • “current and accepted” together with the explanation text
    • “No tracked justification is present.”

    They also assert the details structure: only the permitted <details> classes appear, and there is no provenance block.

Only one file is expanded per scenario. Handling several files would be the same per-row handler logic, and the text does not distinguish that case. I found no gap.

Inputs

Tests

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

Other sources

Input 1: requirements selection requirements.test-coverage.index.gaps.details
:::{req} index.gaps.details
In the combined gaps overview, clicking a listed file MUST expand or collapse
its uncovered obligations in place. Each expanded file MUST show each
obligation's source item and source location, measurement, and explanation
status.
:::
Input 3: outline src/execution_coverage/check.rs mod[tests]/fn[exercise_file_click]
    // Execute the handler emitted by the renderer, using its actual controls
    // and row IDs. Node is already part of this repository's CI tooling.
    // {cite}`habeas:util`
    fn exercise_file_click(html: &str) {
        let button = html
            .split("class=\"gap-file-button\"")
            .nth(1)
            .unwrap()
            .split('>')
            .next()
            .unwrap();
        let attribute = |name: &str| {
            button
                .split(&format!("{name}=\""))
                .nth(1)
                .unwrap()
                .split('"')
                .next()
                .unwrap()
                .to_owned()
        };
        let ids = html
            .split("class=\"gap-detail-row\" id=\"")
            .skip(1)
            .map(|part| part.split('"').next().unwrap().to_owned())
            .collect::<Vec<_>>();
        let data = json!({"handler": attribute("onclick"), "controls": attribute("aria-controls"), "ids": ids});
        let output = std::process::Command::new("node").arg("-e").arg(r#"
            const assert = require('node:assert/strict');
            const vm = require('node:vm');
            const data = JSON.parse(process.argv[1]);
            const rows = new Map(data.ids.map(id => [id, {hidden: true}]));
            const attributes = {'aria-controls': data.controls, 'aria-expanded': 'false'};
            const chevron = {textContent: '▸'};
            const button = {getAttribute: name => attributes[name],
                setAttribute: (name, value) => {attributes[name] = value},
                querySelector: name => {assert.equal(name, '.gap-chevron'); return chevron}};
            const document = {getElementById: id => rows.get(id)};
            const click = () => vm.runInNewContext('(function(){' + data.handler + '}).call(button)', {button, document});
            assert.ok(rows.has(data.controls), 'controls must identify a generated row');
            click();
            assert.equal(rows.get(data.controls).hidden, false);
            assert.equal(attributes['aria-expanded'], 'true');
            assert.equal(chevron.textContent, '▾');
            click();
            assert.equal(rows.get(data.controls).hidden, true);
            assert.equal(attributes['aria-expanded'], 'false');
            assert.equal(chevron.textContent, '▸');
        "#).arg(data.to_string()).output().expect("Node is required for coverage UI tests");
        assert!(
            output.status.success(),
            "{}",
            String::from_utf8_lossy(&output.stderr)
        );
    }