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.file_map.directories.data

Requirements index · View definition

evidence Valid

Requirement

Expanding or collapsing a directory group under cite requirements.test-coverage.index.file_map.directories MUST NOT change the files, coverage counts, or measurement statuses represented by the map.

Rationale

Obligation. Expanding or collapsing a directory group must not change the files, coverage counts, or measurement statuses the map represents.

How the map is built. GapDirectory::render in src/execution_coverage/book.rs emits each group as a native <details class="gap-directory" data-directory=… open>. The group’s summary and its file rows are always in the markup. My search found no script, toggle handler, or event listener, so expanding or collapsing is only the browser changing the open attribute. A realistic violation would be markup that differs between open and closed forms. Examples are dropping file rows, changing counts, or relabeling statuses when a group is closed.

Test coverage. directory_minima_use_exact_fractions_and_count_unmeasured_descendants is marked {test} for directories.data. It simulates a collapse by removing open from the src/nested group’s opening tag in the rendered map. It then asserts the following.

  • The map really changed (assert_ne!).
  • The sibling src group stays open.
  • The inner content of the src/nested group is identical to the open version, which covers its summary, counts, statuses, and descendant rows.
  • file_card is identical for src/a.rs, src/nested/b.rs and src/nested/c.rs.
  • Re-applying open reproduces the original map exactly.

A later scenario with nested, sibling, and prefix-similar directories (src-other) closes src/nested. It asserts that every directory’s summary content is unchanged, including the not-measured counts, percentages, and “No measured files” statuses. These scenarios cover files, counts, and statuses across several states: measured, zero-covered, and not measured.

combined_directory_minimum_includes_hidden_passing_files is also marked. It checks that all groups render open by default, with their files and counts intact. That is the baseline the collapse test compares against.

Assessment. No scripted state exists, so the attribute-only comparison is the strongest check available without a browser. It would catch any markup-level difference between open and closed forms. I found no unaddressed obligation or untested scenario.

Inputs

Tests

Input 3: outline src/execution_coverage/book.rs mod[tests]/fn[combined_directory_minimum_includes_hidden_passing_files]
    // {test}`requirements.test-coverage.index.file_map.combined`
    // {test}`requirements.test-coverage.index.file_map.directories.initial`
    // {test}`requirements.test-coverage.index.file_map.directories.data`
    // {test}`requirements.test-coverage.index.file_map.minimum`
    // {test}`requirements.test-coverage.index.gaps.summary`
    // {test}`requirements.test-coverage.index.file_map.directories`
    #[test]
    fn combined_directory_minimum_includes_hidden_passing_files() {
        let (temp, mut book) = fixture();
        let root = temp.path();
        fs::create_dir_all(root.join("src/nested/deep")).unwrap();
        fs::write(
            root.join("src/gap.rs"),
            format!("fn gap() {{\n{}}}\n", " let value = 1;\n".repeat(18)),
        )
        .unwrap();
        fs::write(
            root.join("src/nested/passing.rs"),
            "fn passing() {\n let a = 1;\n let b = 2;\n let c = 3;\n}\n",
        )
        .unwrap();
        fs::write(root.join("src/nested/deep/gap.rs"), "fn nested_gap() {}\n").unwrap();
        let path = record(root, "all", 1, "same", &[(1, 0), (2, 1)]);
        let run_path = path.parent().unwrap().parent().unwrap().join("run.json");
        let mut run: Run = load(&run_path).unwrap();
        let mut attempt: Attempt = load(&path.join("attempt.json")).unwrap();
        for (file, total, covered, count) in [
            ("src/gap.rs", 20, 19, 0),
            ("src/nested/passing.rs", 5, 4, 1),
            ("src/nested/deep/gap.rs", 1, 1, 0),
        ] {
            run.sources
                .insert(file.into(), fs::read_to_string(root.join(file)).unwrap());
            attempt.processes[0].lines.insert(
                file.into(),
                (1..=total)
                    .map(|line| (line, u64::from(line <= covered)))
                    .collect(),
            );
            attempt.processes[0].functions.as_mut().unwrap().push(
                super::super::FunctionExecution {
                    file: file.into(),
                    line: 1,
                    column: 1,
                    count,
                },
            );
        }
        save(&run_path, &run).unwrap();
        save(&path.join("attempt.json"), &attempt).unwrap();
        populate(&mut book, root).unwrap();
        let overview = &book.chapters().next().unwrap().content;
        let map = map_html(overview);
        assert!(map.contains("data-directory=\"src\" open"));
        assert!(map.contains("data-min-covered=\"4\" data-min-instrumented=\"5\">80.0%"));
        assert!(map.contains("2 uncovered obligations"));
        for (directory, expected) in [("src", 2), ("src/nested", 1), ("src/nested/deep", 1)] {
            let summary = directory_summary(map, directory);
            assert!(summary.contains(&format!("{expected} uncovered obligations")));
            assert!(summary.contains("Minimum measured file coverage:"));
        }
        assert_directory_contents(map, "src", &["src/nested"], &["src/gap.rs"]);
        assert_directory_contents(map, "src/nested", &["src/nested/deep"], &[]);
        assert_directory_contents(map, "src/nested/deep", &[], &["src/nested/deep/gap.rs"]);
        for directory in ["src", "src/nested", "src/nested/deep"] {
            assert!(map.contains(&format!("data-directory=\"{directory}\" open")));
        }
        assert!(map.contains("data-file=\"code.rs\""));
        assert!(
            map.find("data-file=\"code.rs\"").unwrap()
                < map.find("<details class=\"gap-directory\"").unwrap(),
            "root file rows are outside directory controls"
        );
        assert_eq!(map.matches("data-file=").count(), 3);
        assert!(map.contains("data-file=\"src/gap.rs\""));
        assert!(map.contains("95.0%"));
        assert!(file_card(map, "src/gap.rs").contains("<code>src/gap.rs</code>"));
        assert!(map.contains("zero execution"));
        assert!(!map.contains("data-file=\"src/nested/passing.rs\""));
        assert!(
            book.chapters()
                .all(|chapter| chapter.name != "File notes: src/nested/passing.rs")
        );
        assert!(overview.contains("1 file obligations · 3 function obligations"));
    }
Input 4: outline src/execution_coverage/book.rs mod[tests]/fn[directory_minima_use_exact_fractions_and_count_unmeasured_descendants]
    // {test}`requirements.test-coverage.index.file_map.minimum`
    // {test}`requirements.test-coverage.index.file_map.minimum.statuses`
    // {test}`requirements.test-coverage.index.file_map.minimum.descendants`
    // {test}`requirements.test-coverage.index.file_map.directories`
    // {test}`requirements.test-coverage.index.file_map.directories.data`
    #[test]
    fn directory_minima_use_exact_fractions_and_count_unmeasured_descendants() {
        let render = |files: &[(&str, usize, usize)]| {
            let mut policy = super::super::check::PolicyReport {
                report: super::super::check::CheckReport {
                    passed: false,
                    text: String::new(),
                },
                files: files
                    .iter()
                    .map(|&(file, covered, total)| super::super::check::FilePolicy {
                        file: file.into(),
                        covered,
                        total,
                        obligations: vec![super::super::check::Obligation {
                            selector: String::new(),
                            line: 1,
                            measurement: "below target".into(),
                            exception: None,
                        }],
                    })
                    .collect(),
                counts_complete: true,
                measured: true,
                findings: vec![],
            };
            // Unlisted files with no obligations or accepted exceptions must
            // not inflate the directory's not-measured count.
            for (file, accepted) in [
                ("src/nested/hidden-empty.rs", false),
                ("src/nested/hidden-accepted.rs", true),
            ] {
                policy.files.push(super::super::check::FilePolicy {
                    file: file.into(),
                    covered: 0,
                    total: 0,
                    obligations: if accepted {
                        vec![super::super::check::Obligation {
                            selector: String::new(),
                            line: 1,
                            measurement: "not measured".into(),
                            exception: Some(super::super::check::Exception {
                                accepted: true,
                                review_missing: false,
                                justification: "No instrumented obligations.".into(),
                                findings: vec![],
                            }),
                        }]
                    } else {
                        vec![]
                    },
                });
            }
            gaps_map(&policy, Path::new("coverage.md"), 1)
        };
        let map = render(&[("src/higher.rs", 501, 1000), ("src/lower.rs", 1001, 2000)]);
        assert!(
            directory_summary(&map, "src")
                .contains("data-min-covered=\"1001\" data-min-instrumented=\"2000\"")
        );
        let map = render(&[
            ("src/a.rs", 1, 2),
            ("src/nested/b.rs", 1, 4),
            ("src/nested/c.rs", 0, 0),
        ]);
        for directory in ["src", "src/nested"] {
            let summary = directory_summary(&map, directory);
            assert!(summary.contains("Minimum measured file coverage:"));
            assert!(summary.contains("25.0%"));
            assert!(summary.contains("1 not measured"));
            assert!(!summary.contains("0 unavailable"));
            assert!(!summary.contains("2 not measured"));
        }
        assert_directory_contents(&map, "src", &["src/nested"], &["src/a.rs"]);
        assert_directory_contents(
            &map,
            "src/nested",
            &[],
            &["src/nested/b.rs", "src/nested/c.rs"],
        );
        // Changing one native details control only changes its open attribute;
        // all file identities, measurements, summaries and sibling state remain.
        let opening = "<details class=\"gap-directory\" data-directory=\"src/nested\" open>";
        let closed_opening = opening.replace(" open>", ">");
        let closed = map.replace(opening, &closed_opening);
        assert_ne!(closed, map);
        assert!(closed.contains("data-directory=\"src\" open>"));
        assert!(closed.contains("data-directory=\"src/nested\">"));
        assert_eq!(
            directory_group(&closed, "src/nested")
                .split_once('>')
                .unwrap()
                .1,
            directory_group(&map, "src/nested")
                .split_once('>')
                .unwrap()
                .1
        );
        for file in ["src/a.rs", "src/nested/b.rs", "src/nested/c.rs"] {
            assert_eq!(file_card(&map, file), file_card(&closed, file));
        }
        assert_eq!(closed.replace(&closed_opening, opening), map);
        let map = render(&[("src/unknown.rs", 0, 0)]);
        let summary = directory_summary(&map, "src");
        assert!(summary.contains("No measured files"));
        assert!(summary.contains("1 not measured"));
        assert!(!summary.contains('%'));
        let map = render(&[
            ("src/measured-zero.rs", 0, 4),
            ("src/nested/unmeasured.rs", 0, 0),
        ]);
        let summary = directory_summary(&map, "src");
        assert!(summary.contains("Minimum measured file coverage:"));
        assert!(summary.contains("0.0%"));
        assert!(summary.contains("1 not measured"));
        assert!(!summary.contains("2 not measured"));
        let zero = file_card(&map, "src/measured-zero.rs");
        assert!(zero.contains("data-status=\"measured\""));
        assert!(zero.contains("0.0%"));
        assert!(zero.contains("0/4 instrumented lines covered"));
        assert!(!zero.contains("not measured"));
        let nested = directory_summary(&map, "src/nested");
        assert!(nested.contains("No measured files"));
        assert!(nested.contains("1 not measured"));
        assert!(!nested.contains('%'));
        let map = render(&[
            ("src/direct.rs", 0, 0),
            ("src/nested/a.rs", 0, 0),
            ("src/nested/deep/b.rs", 0, 0),
            ("src/nested/deep/c.rs", 0, 0),
            ("src/sibling/d.rs", 0, 0),
            ("src/measured-zero.rs", 0, 4),
            ("src/positive.rs", 1, 4),
            ("src-other/outside.rs", 0, 0),
        ]);
        for (directory, count) in [
            ("src", 5),
            ("src/nested", 3),
            ("src/nested/deep", 2),
            ("src/sibling", 1),
            ("src-other", 1),
        ] {
            let summary = directory_summary(&map, directory);
            assert!(
                summary.contains(&format!(" · {count} not measured")),
                "{summary}"
            );
        }
        assert!(directory_summary(&map, "src").contains("0.0%"));
        let closed = map.replace(
            "<details class=\"gap-directory\" data-directory=\"src/nested\" open>",
            "<details class=\"gap-directory\" data-directory=\"src/nested\">",
        );
        for directory in [
            "src",
            "src/nested",
            "src/nested/deep",
            "src/sibling",
            "src-other",
        ] {
            assert_eq!(
                directory_summary(&closed, directory)
                    .split_once('>')
                    .unwrap()
                    .1,
                directory_summary(&map, directory)
                    .split_once('>')
                    .unwrap()
                    .1
            );
        }
    }

Referenced definitions

Input 2: requirements selection requirements.test-coverage.index.file_map.directories
:::{req} index.file_map.directories
The table of {cite}`requirements.test-coverage.index.file_map.table` MUST group
its listed files by their directory hierarchy. Each non-root directory
containing a listed file, directly or through descendants, MUST have a group.
Each group MUST be independently expandable and collapsible.

A collapsed group MUST show its workspace-relative path and the summaries
required by {cite}`requirements.test-coverage.index.file_map.minimum` and
{cite}`requirements.test-coverage.index.file_map.minimum.statuses`, while
hiding its file rows and descendant groups.
:::

Other sources

Input 1: requirements selection requirements.test-coverage.index.file_map.directories.data
:::{req} index.file_map.directories.data
Expanding or collapsing a directory group under
{cite}`requirements.test-coverage.index.file_map.directories` MUST NOT change
the files, coverage counts, or measurement statuses represented by the map.
:::
Input 5: outline src/execution_coverage/book.rs impl[GapDirectory<'_>]/fn[render]
    fn render(
        &self,
        html: &mut String,
        folder: &str,
        policy: &super::check::PolicyReport,
        index: &Path,
        next: &mut usize,
    ) {
        if !self.files.is_empty() {
            html.push_str("<table class=\"gap-file-table\"><colgroup><col><col><col><col></colgroup><thead><tr><th>File</th><th>Coverage</th><th>Uncovered obligations</th><th>Explanation</th></tr></thead><tbody>\n");
            for file in &self.files {
                let id = format!("habeas-gap-file-{}", *next);
                *next += 1;
                let gaps: Vec<_> = file
                    .obligations
                    .iter()
                    .filter(|gap| !gap.accepted())
                    .collect();
                let threshold = gaps.iter().any(|gap| gap.selector.is_empty());
                let functions = gaps.len() - usize::from(threshold);
                let undocumented = gaps.iter().filter(|gap| gap.exception.is_none()).count();
                let description = match (threshold, functions) {
                    (true, 0) => "file below target".to_owned(),
                    (true, n) => format!("file + {n} functions"),
                    (false, 1) => "1 function".to_owned(),
                    (false, n) => format!("{n} functions"),
                };
                let explanation = if undocumented == gaps.len() {
                    "Missing"
                } else {
                    "Review needed"
                };
                let percentage = if file.total == 0 {
                    "not measured".to_owned()
                } else {
                    percentage_label(file.covered, file.total)
                };
                let indicator = if file.total == 0 {
                    String::new()
                } else {
                    format!(
                        "<span class=\"gap-coverage-bar\" aria-hidden=\"true\" style=\"--gap-covered: {:.6}%\"></span>",
                        100.0 * file.covered as f64 / file.total as f64
                    )
                };
                html.push_str(&format!("<tr class=\"gap-file-row habeas-coverage-file\" data-file=\"{}\" data-status=\"{}\"><td><button class=\"gap-file-button\" aria-expanded=\"false\" aria-controls=\"{id}\" onclick=\"const row=document.getElementById(this.getAttribute('aria-controls'));row.hidden=!row.hidden;this.setAttribute('aria-expanded',String(!row.hidden));this.querySelector('.gap-chevron').textContent=row.hidden?'▸':'▾'\"><span class=\"gap-chevron\" aria-hidden=\"true\">▸</span><code>{}</code></button></td><td class=\"gap-percentage\">{percentage}{indicator}</td><td>{description}</td><td class=\"gap-unresolved\">{explanation}</td></tr>\n", escaped(&file.file), if file.total == 0 { "not measured" } else { "measured" }, escaped(&file.file)));
                let notes =
                    crate::chapter_href(index, &super::notes::path(index, &file.file), None);
                html.push_str(&format!("<tr class=\"gap-detail-row\" id=\"{id}\" hidden><td colspan=\"4\"><p class=\"gap-detail-title\"><code>{}</code> · {}/{} instrumented lines covered · <a href=\"{}\">Current source notes</a></p><table class=\"gap-obligation-table\"><thead><tr><th>Source item</th><th>Measurement</th><th>Explanation</th></tr></thead><tbody>", escaped(&file.file), file.covered, file.total, escaped(&notes)));
                for gap in gaps {
                    html.push_str(&format!("<tr><td><code>{}</code><br><span class=\"gap-meta\">{}:{}</span></td><td>{}</td><td>{}</td></tr>\n", escaped(if gap.selector.is_empty() { "File root" } else { &gap.selector }), escaped(&file.file), gap.line, escaped(&gap.measurement), explanation_html(gap)));
                }
                html.push_str("</tbody></table></td></tr>\n");
            }
            html.push_str("</tbody></table>\n");
        }
        for (name, directory) in &self.directories {
            let path = if folder.is_empty() {
                name.clone()
            } else {
                format!("{folder}/{name}")
            };
            let prefix = format!("{path}/");
            let minimum = policy
                .files
                .iter()
                .filter(|file| file.file.starts_with(&prefix) && file.total > 0)
                .min_by(|a, b| {
                    ((a.covered as u128) * (b.total as u128))
                        .cmp(&((b.covered as u128) * (a.total as u128)))
                });
            let min = minimum.map_or_else(|| "No measured files".to_owned(), |file| format!("Minimum measured file coverage: <strong data-min-covered=\"{}\" data-min-instrumented=\"{}\">{}</strong>", file.covered, file.total, percentage_label(file.covered, file.total)));
            let not_measured = policy
                .files
                .iter()
                .filter(|file| {
                    file.file.starts_with(&prefix)
                        && file.total == 0
                        && file.obligations.iter().any(|gap| !gap.accepted())
                })
                .count();
            let counts = if policy.counts_complete {
                format!("{} uncovered obligations", directory.count())
            } else if policy.measured {
                format!(
                    "Gap counts incomplete: {} established uncovered obligations",
                    directory.count()
                )
            } else {
                "Gap counts unavailable".to_owned()
            };
            html.push_str(&format!("<details class=\"gap-directory\" data-directory=\"{}\" open><summary><code>{}/</code><span class=\"gap-meta\">{min} · {counts}{} </span></summary>\n", escaped(&path), escaped(&path), if not_measured > 0 { format!(" · {not_measured} not measured") } else { String::new() }));
            directory.render(html, &path, policy, index, next);
            html.push_str("</details>\n");
        }
    }