requirements.test-coverage.index.file_map.combined.measurement
Requirements index · View definition
Requirement
The combined gaps overview MUST visibly identify coverage excluded because it is stale, missing, or unreadable. Measurement failures under
MUST be reported separately from uncovered file and function obligations. They MUST NOT be presented as zero execution or as absence of individual function measurement in otherwise usable coverage.
When the coverage check reports a measurement failure under
, the combined overview MUST show coverage as unavailable and omit file rows and directory groups. Measurement findings MUST remain inspectable under
. When no usable selected coverage exists, the overview MUST retain the collection guidance of
. Numerical coverage MUST NOT be fabricated from missing or incomplete data.
Rationale
The marked tests adequately check requirements.test-coverage.index.file_map.combined.measurement. The cited requirements are treated as context only.
Obligations and the tests that cover them
-
Visibly identify coverage excluded as stale, missing, or unreadable.
book.rs#mod[tests]/fn[maps_distinguish_no_runs_zero_hits_stale_and_incomplete_coverage]covers these cases. Each one asserts “Coverage unavailable” plus a reason string:- no processes;
- an attempt diagnostic;
- a process diagnostic;
- a missing source;
- an empty profile;
- an incomplete child process, with “missing or unreadable coverage”;
- a stale attempt, with “1 stale test attempts”;
- an unreadable attempt, with “1 unavailable test attempts”;
- corrupt
attempt.json, with “Coverage history is incomplete”.
book.rs#mod[tests]/fn[filtered_runs_union_latest_attempts_and_invalidate_with_saved_source]covers failed and interrupted newest attempts, which show “missing or unreadable coverage”. It also covers stale source, which shows “stale coverage; recollect”.book.rs#mod[tests]/fn[unreadable_history_cannot_reintroduce_an_older_success]covers missing captured sources, a schema mismatch, a missing raw profile, and unreadable newest metadata.
-
Show coverage as unavailable and omit file rows and directory groups.
maps_distinguish_no_runs_zero_hits_stale_and_incomplete_coverageasserts thatdata-file=is absent in every failure case.book.rs#mod[tests]/fn[incomplete_attempts_do_not_label_their_files_as_unmeasured_in_a_partial_map]uses a good attempt alongside an unavailable or stale one. It asserts there is nodata-file=, nogap-directory, nodata-min-covered=, no coverage bar, and no “not measured” label. Together these show that a usable file’s data is not rendered.
-
Report measurement failures separately from uncovered obligations, and never as zero execution.
check.rs#mod[tests]/fn[book_verdict_and_gaps_follow_the_native_policy_and_current_reviews]removes a profile after a passing state. It asserts “CI would fail”, “gap counts unavailable”, and the absence of “0 unresolved gaps”. It also asserts that “zero execution” does not appear in the summary section, and that “missing or unreadable coverage” does appear.maps_distinguish_no_runs_zero_hits_stale_and_incomplete_coverageseparately shows that genuinely zero-hit coverage renders “0.0%” in a file card. That is the contrast case.
-
Keep findings inspectable under
requirements.test-coverage.index.gaps. Thecheck.rstest asserts that the “Coverage gaps” chapter carries the measurement finding. The tests inbook.rsassert the reasons and diagnostics, such as “A retained raw profile is missing” and “Matching captured source is missing”. -
Retain the
requirements.test-coverage.index.unavailablecollection guidance when no usable coverage exists.- The no-runs case asserts “Run
habeas coverage”. - The empty-run case asserts “No usable instrumented lines”.
- The stale case asserts “stale coverage; recollect”.
- The no-runs case asserts “Run
-
Do not fabricate numerical coverage.
- The empty run asserts there is no “Line coverage:” and no “NaN”.
- The unreadable-newest case asserts the older “1/1 (100.0%)” does not reappear.
- The failed-newest and partial cases assert “gap counts unavailable”. The implementation (
fn[populate_in]) gates “Line coverage:” onpolicy.measured, which is also the branch that produces “Gap counts incomplete”. The “Coverage unavailable · gap counts unavailable” text comes from the opposite branch offn[gaps_map]. Asserting that text therefore rules out a numeric summary in the same states.
I found no unacknowledged gap. All the relevant tests carry {test} references to the subject.
Inputs
Implementation
Input 10: outline src/execution_coverage/book.rs fn[gaps_map]
- File:
src/execution_coverage/book.rs - Selector:
fn[gaps_map] - Kind:
fn src/execution_coverage/book.rs:213–302
// {impl}`requirements.test-coverage.index.file_map.combined`
// {impl}`requirements.test-coverage.index.file_map.combined.measurement`
// {impl}`requirements.test-coverage.index.file_map.table`
// {impl}`requirements.test-coverage.index.file_map.directories`
// {impl}`requirements.test-coverage.index.file_map.directories.initial`
// {impl}`requirements.test-coverage.index.file_map.directories.data`
// {impl}`requirements.test-coverage.index.file_map.minimum`
// {impl}`requirements.test-coverage.index.file_map.minimum.statuses`
// {impl}`requirements.test-coverage.index.gaps`
// {impl}`requirements.test-coverage.index.gaps.summary`
// {impl}`requirements.test-coverage.index.gaps.details`
// {impl}`requirements.test-coverage.index.gaps.details.initial`
// {impl}`requirements.test-coverage.index.gaps.accepted`
// {impl}`requirements.test-coverage.index.file_map.notes`
fn gaps_map(policy: &super::check::PolicyReport, index: &Path, attempts: usize) -> String {
let mut html = format!(
"<style>{}</style>\n<section class=\"habeas-coverage-map habeas-coverage-gaps\" aria-label=\"Coverage gaps\">\n<p class=\"gap-meta\">Combined coverage · {attempts} selected test attempts</p><p class=\"gap-policy gap-meta\">File target: 80% of instrumented lines. Every function needs execution or an accepted explanation.</p>\n",
include_str!("../../assets/coverage-gaps.css")
);
let unresolved: Vec<_> = policy
.files
.iter()
.flat_map(|file| &file.obligations)
.filter(|gap| !gap.accepted())
.collect();
let files = unresolved
.iter()
.filter(|gap| gap.selector.is_empty())
.count();
let functions = unresolved.len() - files;
html.push_str(&format!(
"<div class=\"gap-verdict\" role=\"status\"><strong>CI would {}</strong>",
if policy.report.passed { "pass" } else { "fail" }
));
if policy.counts_complete {
html.push_str(&format!("<span>{} unresolved gaps</span><span class=\"gap-meta\">{files} file obligations · {functions} function obligations</span>", unresolved.len()));
} else if policy.measured {
html.push_str(&format!(
"<span>Gap counts incomplete: {} established unresolved gaps</span>",
unresolved.len()
));
} else {
html.push_str("<span>Coverage unavailable · gap counts unavailable</span>");
}
html.push_str("</div><p class=\"gap-section-label\">Unresolved coverage gaps</p>\n");
let mut directory = GapDirectory::default();
for file in &policy.files {
if !file.obligations.iter().any(|gap| !gap.accepted()) {
continue;
}
let mut dir = &mut directory;
if let Some((folder, _)) = file.file.rsplit_once('/') {
for part in folder.split('/') {
dir = dir.directories.entry(part.into()).or_default();
}
}
dir.files.push(file);
}
directory.render(&mut html, "", policy, index, &mut 0);
if unresolved.is_empty() && policy.counts_complete {
html.push_str("<p>No unsatisfied file or function obligations.</p>\n");
}
let accepted = policy
.files
.iter()
.flat_map(|file| {
file.obligations
.iter()
.filter(|gap| gap.accepted())
.map(move |gap| (file, gap))
})
.collect::<Vec<_>>();
html.push_str(&format!("<details class=\"gap-accepted-group\"><summary>Documented gaps — {} accepted exceptions</summary><p class=\"gap-meta\">Current workspace source notes. Accepted exceptions do not increase measured percentages.</p>\n", accepted.len()));
for (file, gap) in accepted {
let notes = crate::chapter_href(index, &super::notes::path(index, &file.file), None);
html.push_str(&format!("<div class=\"gap-accepted-item\"><p><a href=\"{}\"><code>{}:{} #{}</code></a> · {} · <span class=\"gap-accepted-state\">current and accepted</span></p>{}</div>\n", escaped(¬es), escaped(&file.file), gap.line, escaped(if gap.selector.is_empty() { "File root" } else { &gap.selector }), escaped(&gap.measurement), explanation_html(gap)));
}
html.push_str("</details>\n");
if !policy.findings.is_empty() {
html.push_str(
"<details class=\"gap-footer\"><summary>Coverage-check findings</summary><ul>",
);
for finding in &policy.findings {
html.push_str(&format!("<li>{}</li>", escaped(finding)));
}
html.push_str("</ul></details>\n");
}
html.push_str("<p class=\"gap-footer gap-meta\">Coverage uses the latest compatible attempt for each test, including filtered runs. This does not establish that all current tests were measured. Saved measurements and current exception reviews determine the CI verdict.</p>\n</section>\n\n");
html
}
Tests
Input 5: outline src/execution_coverage/book.rs mod[tests]/fn[maps_distinguish_no_runs_zero_hits_stale_and_incomplete_coverage]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[maps_distinguish_no_runs_zero_hits_stale_and_incomplete_coverage] - Kind:
fn src/execution_coverage/book.rs:1207–1326
// {test}`requirements.test-coverage.index.file_map`
// {test}`requirements.test-coverage.index.file_map.table`
// {test}`requirements.test-coverage.index.file_map.combined`
// {test}`requirements.test-coverage.index.file_map.test`
// {test}`requirements.test-coverage.index.file_map.combined.measurement`
// {test}`requirements.test-coverage.index.summary`
#[test]
fn maps_distinguish_no_runs_zero_hits_stale_and_incomplete_coverage() {
let (temp, book) = fixture();
let root = temp.path();
let mut no_runs = book.clone();
populate(&mut no_runs, root).unwrap();
let index = &no_runs.chapters().next().unwrap().content;
assert!(index.contains("Coverage unavailable"));
assert!(index.contains("gap counts unavailable"));
assert!(!map_html(index).contains("data-file="));
assert!(index.contains("Run `habeas coverage`"));
let empty_path = record(root, "empty", 0, "empty", &[]);
let mut empty = book.clone();
populate(&mut empty, root).unwrap();
let empty_index = &empty.chapters().next().unwrap().content;
assert!(empty_index.contains("Coverage unavailable"));
assert!(!empty_index.contains("Line coverage:"));
assert!(!empty_index.contains("NaN"));
assert!(!map_html(empty_index).contains("data-file="));
assert!(empty_index.contains("No usable instrumented lines"));
fs::remove_dir_all(empty_path.parent().unwrap().parent().unwrap()).unwrap();
let path = record(root, "zero", 1, "a", &[(1, 0), (2, 0)]);
let mut zero = book.clone();
populate(&mut zero, root).unwrap();
assert!(
file_card(
map_html(&zero.chapters().next().unwrap().content),
"code.rs"
)
.contains("0.0%")
);
let mut attempt: Attempt = load(&path.join("attempt.json")).unwrap();
attempt.processes[0]
.lines
.get_mut("code.rs")
.unwrap()
.insert(1, 1);
for failure in [
"no processes",
"attempt diagnostic",
"process diagnostic",
"missing source",
"empty profile",
] {
let mut missing = attempt.clone();
match failure {
"no processes" => missing.processes.clear(),
"attempt diagnostic" => missing.diagnostics.push("export incomplete".into()),
"process diagnostic" => {
missing.processes[0].diagnostic = Some("unreadable profile".into());
}
"missing source" => {
missing.processes[0]
.lines
.insert("uncaptured.rs".into(), BTreeMap::from([(1, 1)]));
}
"empty profile" => fs::write(path.join("1-1.profraw"), "").unwrap(),
_ => unreachable!(),
}
save(&path.join("attempt.json"), &missing).unwrap();
let mut unavailable = book.clone();
populate(&mut unavailable, root).unwrap();
let index = &unavailable.chapters().next().unwrap().content;
assert!(index.contains("Coverage unavailable"), "{failure}");
assert!(!map_html(index).contains("data-file="), "{failure}");
assert!(
index.contains("missing or unreadable coverage"),
"{failure}"
);
fs::write(path.join("1-1.profraw"), "retained profile fixture").unwrap();
}
save(&path.join("attempt.json"), &attempt).unwrap();
fs::write(root.join("code.rs"), "changed source\n").unwrap();
fs::write(root.join("new.rs"), "fn newly_added() {}\n").unwrap();
let mut stale = book.clone();
populate(&mut stale, root).unwrap();
let index = &stale.chapters().next().unwrap().content;
assert!(index.contains("Coverage unavailable"));
assert!(!map_html(index).contains("data-file="));
assert!(index.contains("1 stale test attempts"));
attempt.processes.push(Process {
functions: Some(vec![]),
pid: 2,
profiles: vec!["missing-child.profraw".into()],
diagnostic: None,
lines: BTreeMap::from([("code.rs".into(), BTreeMap::from([(2, 1)]))]),
});
save(&path.join("attempt.json"), &attempt).unwrap();
let mut incomplete = book.clone();
populate(&mut incomplete, root).unwrap();
let index = &incomplete.chapters().next().unwrap().content;
assert!(index.contains("Coverage unavailable"));
assert!(!map_html(index).contains("data-file="));
assert!(index.contains("missing or unreadable coverage"));
fs::write(root.join("code.rs"), "fn one() {}\nfn two() {}\n").unwrap();
fs::remove_file(root.join("new.rs")).unwrap();
let mut unreadable = book.clone();
populate(&mut unreadable, root).unwrap();
let index = &unreadable.chapters().next().unwrap().content;
assert!(index.contains("1 unavailable test attempts"));
assert!(index.contains("Coverage unavailable"));
assert!(!map_html(index).contains("data-file="));
// Unreadable metadata cannot establish latest-per-test selection.
fs::write(path.join("attempt.json"), "not JSON").unwrap();
let mut uncertain = book;
populate(&mut uncertain, root).unwrap();
let index = &uncertain.chapters().next().unwrap().content;
assert!(index.contains("Coverage history is incomplete"));
assert!(index.contains("gap counts unavailable"));
assert!(!map_html(index).contains("data-file="));
}
Input 6: outline src/execution_coverage/book.rs mod[tests]/fn[incomplete_attempts_do_not_label_their_files_as_unmeasured_in_a_partial_map]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[incomplete_attempts_do_not_label_their_files_as_unmeasured_in_a_partial_map] - Kind:
fn src/execution_coverage/book.rs:1328–1380
// {test}`requirements.test-coverage.index.file_map`
// {test}`requirements.test-coverage.index.file_map.table`
// {test}`requirements.test-coverage.index.file_map.combined`
// {test}`requirements.test-coverage.index.file_map.combined.measurement`
// {test}`requirements.test-coverage.index.freshness`
// {test}`requirements.test-coverage.index.file_map.minimum`
// {test}`requirements.test-coverage.index.file_map.minimum.statuses`
#[test]
fn incomplete_attempts_do_not_label_their_files_as_unmeasured_in_a_partial_map() {
let (temp, book) = fixture();
let root = temp.path();
fs::create_dir_all(root.join("src/nested")).unwrap();
fs::write(root.join("src/nested/other.rs"), "fn other() {}\n").unwrap();
let good = record(root, "good", 1, "a", &[(1, 1)]);
let bad = record(root, "bad", 2, "a", &[]);
let mut attempt: Attempt = load(&bad.join("attempt.json")).unwrap();
attempt.processes[0].lines =
BTreeMap::from([("src/nested/other.rs".into(), BTreeMap::from([(1, 1)]))]);
save(&bad.join("attempt.json"), &attempt).unwrap();
for path in [&good, &bad] {
let run_path = path.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&run_path).unwrap();
run.sources
.insert("src/nested/other.rs".into(), "fn other() {}\n".into());
save(&run_path, &run).unwrap();
}
fs::remove_file(bad.join("1-1.profraw")).unwrap();
let mut partial = book.clone();
populate(&mut partial, root).unwrap();
let index = &partial.chapters().next().unwrap().content;
assert!(index.contains("Coverage unavailable"));
assert!(!map_html(index).contains("data-file="));
assert!(!map_html(index).contains("not measured"));
assert!(!map_html(index).contains("class=\"gap-directory\""));
assert!(!map_html(index).contains("data-min-covered="));
assert!(!map_html(index).contains("gap-coverage-bar\""));
assert!(index.contains("1 unavailable test attempts"));
// A stale selected attempt leaves the same unknown per-file state.
let run_path = bad.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&run_path).unwrap();
run.inputs
.insert("missing-build-input".into(), "old-hash".into());
save(&run_path, &run).unwrap();
let mut stale = book;
populate(&mut stale, root).unwrap();
let index = &stale.chapters().next().unwrap().content;
assert!(index.contains("Coverage unavailable"));
assert!(!map_html(index).contains("data-file="));
assert!(!map_html(index).contains("class=\"gap-directory\""));
assert!(!map_html(index).contains("data-min-covered="));
assert!(!map_html(index).contains("not measured"));
assert!(index.contains("1 stale test attempts"));
}
Input 7: outline src/execution_coverage/book.rs mod[tests]/fn[filtered_runs_union_latest_attempts_and_invalidate_with_saved_source]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[filtered_runs_union_latest_attempts_and_invalidate_with_saved_source] - Kind:
fn src/execution_coverage/book.rs:1857–1985
// {test}`requirements.test-coverage.index`
// {test}`requirements.test-coverage.processes.reports`
// {test}`requirements.test-coverage.storage.configuration`
// {test}`requirements.test-coverage.index.selection`
// {test}`requirements.test-coverage.index.summary`
// {test}`requirements.test-coverage.index.details`
// {test}`requirements.test-coverage.index.freshness`
// {test}`requirements.test-coverage.index.render_only`
// {test}`requirements.test-coverage.index.file_map.combined.measurement`
#[test]
fn filtered_runs_union_latest_attempts_and_invalidate_with_saved_source() {
let (temp, book) = fixture();
let root = temp.path();
record(root, "one", 1, "build-a", &[(1, 1), (2, 0)]);
record(root, "two", 2, "build-a", &[(1, 0), (2, 1)]);
let mut combined = book.clone();
populate(&mut combined, root).unwrap();
assert!(
combined
.chapters()
.next()
.unwrap()
.content
.contains("2/2 (100.0%)")
);
assert!(
combined
.chapters()
.next()
.unwrap()
.content
.contains("2 selected test attempts")
);
assert!(
!combined
.chapters()
.next()
.unwrap()
.content
.contains("{coverage-index}")
);
// A failing newest attempt replaces the earlier success, even with no data.
let newest = record(root, "one", 3, "build-a", &[]);
let mut attempt: Attempt = load(&newest.join("attempt.json")).unwrap();
attempt.diagnostics.push("profile missing".into());
for outcome in ["failed", "interrupted"] {
attempt.outcome = outcome.into();
save(&newest.join("attempt.json"), &attempt).unwrap();
let mut combined = book.clone();
populate(&mut combined, root).unwrap();
assert!(
combined
.chapters()
.next()
.unwrap()
.content
.contains("gap counts unavailable")
);
assert!(
combined
.chapters()
.next()
.unwrap()
.content
.contains("missing or unreadable coverage")
);
assert!(
combined
.chapters()
.next()
.unwrap()
.content
.contains("2 selected test attempts")
);
}
fs::write(root.join("code.rs"), "changed source\n").unwrap();
let mut stale = book.clone();
populate(&mut stale, root).unwrap();
assert!(
stale
.chapters()
.next()
.unwrap()
.content
.contains("gap counts unavailable")
);
assert!(
stale
.chapters()
.next()
.unwrap()
.content
.contains("stale coverage; recollect")
);
let saved = load_saved(root, Some(root.join("target")));
assert!(
saved
.records
.iter()
.all(|record| record.run.sources["code.rs"].contains("fn one() {}"))
);
record(root, "one", 4, "build-b", &[(1, 1)]);
let mut other = book;
populate(&mut other, root).unwrap();
assert!(
other
.chapters()
.next()
.unwrap()
.content
.contains("historical build configuration")
);
assert!(
other
.chapters()
.next()
.unwrap()
.content
.contains("1/1 (100.0%)")
);
assert!(
other
.chapters()
.next()
.unwrap()
.content
.contains("1 selected test attempts")
);
}
Input 8: outline src/execution_coverage/book.rs mod[tests]/fn[unreadable_history_cannot_reintroduce_an_older_success]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[unreadable_history_cannot_reintroduce_an_older_success] - Kind:
fn src/execution_coverage/book.rs:2188–2262
// {test}`requirements.test-coverage.index.selection`
// {test}`requirements.test-coverage.index.unavailable`
// {test}`requirements.test-coverage.index.freshness`
// {test}`requirements.test-coverage.storage.outcomes`
// {test}`requirements.test-coverage.index.file_map.combined.measurement`
#[test]
fn unreadable_history_cannot_reintroduce_an_older_success() {
let (temp, mut book) = fixture();
record(temp.path(), "one", 1, "a", &[(1, 1)]);
let newest = record(temp.path(), "one", 2, "a", &[(1, 0)]);
fs::write(newest.join("attempt.json"), "not JSON").unwrap();
populate(&mut book, temp.path()).unwrap();
let index = &book.chapters().next().unwrap().content;
assert!(index.contains("cannot establish latest-per-test selection"));
assert!(index.contains("gap counts unavailable"));
assert!(!index.contains("1/1 (100.0%)"));
let (temp, mut book) = fixture();
let newest = record(temp.path(), "one", 1, "a", &[(1, 1)]);
let path = newest.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&path).unwrap();
run.sources.clear();
save(&path, &run).unwrap();
populate(&mut book, temp.path()).unwrap();
assert!(
book.chapters()
.next()
.unwrap()
.content
.contains("missing or unreadable coverage")
);
assert!(
book.chapters()
.next()
.unwrap()
.content
.contains("Matching captured source is missing")
);
// Unsupported metadata cannot establish compatibility for combined totals.
let (temp, mut book) = fixture();
let attempt = record(temp.path(), "one", 1, "a", &[(1, 1)]);
let path = attempt.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&path).unwrap();
run.schema = 99;
save(&path, &run).unwrap();
populate(&mut book, temp.path()).unwrap();
let index = &book.chapters().next().unwrap().content;
assert!(index.contains("Coverage history is incomplete"));
assert!(index.contains("gap counts unavailable"));
// A retained result with an unreadable/missing raw profile is unavailable.
let (temp, mut book) = fixture();
let attempt = record(temp.path(), "one", 1, "a", &[(1, 1)]);
fs::remove_file(attempt.join("1-1.profraw")).unwrap();
populate(&mut book, temp.path()).unwrap();
assert!(
book.chapters()
.next()
.unwrap()
.content
.contains("missing or unreadable coverage")
);
assert!(
book.chapters()
.next()
.unwrap()
.content
.contains("gap counts unavailable")
);
assert!(
book.chapters()
.next()
.unwrap()
.content
.contains("A retained raw profile is missing")
);
}
Input 9: outline src/execution_coverage/check.rs mod[tests]/fn[book_verdict_and_gaps_follow_the_native_policy_and_current_reviews]
- File:
src/execution_coverage/check.rs - Selector:
mod[tests]/fn[book_verdict_and_gaps_follow_the_native_policy_and_current_reviews] - Kind:
fn src/execution_coverage/check.rs:757–946
// {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.check.measurement
requirements.test-coverage.check.measurement:md/requirements/test-coverage.md:618–633
:::{req} check.measurement
The coverage check MUST fail when no usable coverage has been collected, or when
a selected latest attempt has missing, unreadable, or stale coverage. It MUST
distinguish these measurement failures from measured lines with zero execution
and from individual functions absent from otherwise usable coverage. Exception
evidence MUST NOT excuse measurement failures or permit substitution of an
older attempt. Excluded historical runs and incompatible configurations MUST
NOT by themselves cause failure.
Coverage whose format does not support the function attribution required by
{cite}`requirements.test-coverage.check.functions` MUST be rejected with guidance
to recollect coverage. When missing or corrupt metadata prevents establishing
the latest-per-test selection or active configuration, the check MUST fail
rather than silently use remaining records. Historical data MAY be disregarded
without failure only when its exclusion can be established.
:::
Input 3: requirements selection requirements.test-coverage.index.gaps
requirements.test-coverage.index.gaps:md/requirements/test-coverage.md:407–413
:::{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.
:::
Input 4: requirements selection requirements.test-coverage.index.unavailable
requirements.test-coverage.index.unavailable:md/requirements/test-coverage.md:488–493
:::{req} index.unavailable
When no coverage run has been recorded, the coverage index MUST show a readable
message explaining how to collect one. Missing, unreadable, or incomplete run
data MUST produce a visible diagnostic in the index
without preventing the rest of the book from rendering.
:::
Other sources
Input 1: requirements selection requirements.test-coverage.index.file_map.combined.measurement
requirements.test-coverage.index.file_map.combined.measurement:md/requirements/test-coverage.md:383–399
:::{req} index.file_map.combined.measurement
The combined gaps overview MUST visibly identify coverage excluded because it
is stale, missing, or unreadable. Measurement failures under
{cite}`requirements.test-coverage.check.measurement` MUST be reported separately
from uncovered file and function obligations. They MUST NOT be presented as
zero execution or as absence of individual function measurement in otherwise
usable coverage.
When the coverage check reports a measurement failure under
{cite}`requirements.test-coverage.check.measurement`, the combined overview
MUST show coverage as unavailable and omit file rows and directory groups.
Measurement findings MUST remain inspectable under
{cite}`requirements.test-coverage.index.gaps`. When no usable selected coverage
exists, the overview MUST retain the collection guidance of
{cite}`requirements.test-coverage.index.unavailable`. Numerical coverage MUST
NOT be fabricated from missing or incomplete data.
:::
Input 11: outline src/execution_coverage/book.rs fn[populate_in]
- File:
src/execution_coverage/book.rs - Selector:
fn[populate_in] - Kind:
fn src/execution_coverage/book.rs:526–691
// {impl}`requirements.test-coverage.index.navigation`
// {impl}`requirements.test-coverage.index.source`
// {impl}`requirements.test-coverage.index.guidance`
// {impl}`requirements.test-coverage.index.summary`
// {impl}`requirements.test-coverage.index.details`
// {impl}`requirements.test-coverage.index.file_map.test`
// {impl}`requirements.test-coverage.index.file_map.combined.details`
pub(super) fn populate_in(
book: &mut Book,
project: &Path,
target: Option<PathBuf>,
parent: &Path,
) -> io::Result<()> {
let index_path = parent.with_extension("").join("coverage.md");
let saved = load_saved(project, target);
let root = workspace_root(project).unwrap_or_else(|_| project.to_path_buf());
let policy = super::check::check_saved(&root, &saved)?;
let SavedCoverage {
records,
selected,
diagnostics,
uncertain_history,
current_files,
discovery_failed: _,
} = saved;
let note_files = if policy.measured {
policy
.files
.iter()
.filter(|file| !file.obligations.is_empty())
.map(|file| file.file.clone())
.collect()
} else {
current_files
};
let mut summary = String::from("# Coverage gaps\n\n");
summary.push_str(&gaps_map(&policy, &index_path, selected.len()));
if policy.measured {
let totals = union(selected.iter().map(|&index| &records[index]));
let covered = totals.values().filter(|&&count| count > 0).count();
summary.push_str(&format!("Line coverage: **{covered}/{} ({:.1}%)** from the union of instrumented file-and-line locations.\n\n", totals.len(), 100.0 * covered as f64 / totals.len() as f64));
}
if uncertain_history {
summary.push_str("Coverage history is incomplete: cannot establish latest-per-test selection. Combined totals are unavailable until the affected build artifacts are repaired or removed.\n\n");
}
if records.is_empty() {
summary.push_str("No test coverage is available. Run `habeas coverage` (or `cargo habeas coverage` in this repository), then rebuild the book.\n\n");
}
let stale = selected
.iter()
.filter(|&&index| !records[index].fresh)
.count();
let incomplete = selected
.iter()
.filter(|&&index| records[index].fresh && !readable(&records[index]))
.count();
let historical = records.last().map_or(0, |latest| {
records
.iter()
.filter(|record| record.run.configuration != latest.run.configuration)
.count()
});
if stale > 0 || incomplete > 0 || historical > 0 {
summary.push_str(&format!(
"**Excluded coverage:** {stale} stale test attempts; {incomplete} unavailable test attempts; {historical} attempts from a historical build configuration.\n\n"
));
}
for diagnostic in diagnostics {
summary.push_str(&format!(
"**Coverage diagnostic:** {}\n\n",
escaped(&diagnostic)
));
}
let existing: BTreeSet<_> = book
.chapters()
.filter_map(|chapter| chapter.path.clone())
.collect();
let mut generated = BTreeSet::from([index_path.clone()]);
if existing.contains(&index_path) {
return Err(io::Error::other(format!(
"coverage index path conflicts with an existing chapter: {}",
index_path.display()
)));
}
let mut details = Vec::new();
let notes_root = workspace_root(project).unwrap_or_else(|_| project.to_path_buf());
for chapter in super::notes::pages(¬es_root, ¬e_files, &index_path) {
let path = chapter
.path
.as_ref()
.expect("file notes have a render path");
if existing.contains(path) || !generated.insert(path.clone()) {
return Err(io::Error::other(format!(
"coverage report path conflicts with an existing chapter: {}",
path.display()
)));
}
details.push(BookItem::Chapter(chapter));
}
summary.push_str("## Collect coverage and check CI policy\n\n");
summary.push_str(super::GUIDANCE);
summary.push('\n');
let mut coverage = Some(Chapter::new("Coverage gaps", summary, &index_path, vec![]));
let mut found = false;
book.for_each_chapter_mut(|chapter| {
if chapter.path.as_deref() == Some(parent) {
found = true;
chapter.content.push_str(&format!(
"\n\n[Coverage gaps]({}) — uncovered obligations and their explanations.\n",
crate::chapter_href(parent, &index_path, None)
));
let mut page = coverage.take().expect("requirements index occurs once");
page.source_path = None;
page.parent_names = chapter.parent_names.clone();
page.parent_names.push(chapter.name.clone());
page.number = chapter.number.as_ref().map(|number| {
let mut parts = number.to_vec();
parts.push(1);
SectionNumber::new(parts)
});
for (offset, item) in details.iter_mut().enumerate() {
let BookItem::Chapter(child) = item else {
unreachable!()
};
child.parent_names = page.parent_names.clone();
child.parent_names.push(page.name.clone());
child.number = page.number.as_ref().map(|number| {
let mut parts = number.to_vec();
parts.push(offset as u32 + 1);
SectionNumber::new(parts)
});
}
page.sub_items.append(&mut details);
fn renumber(chapter: &mut Chapter, number: Vec<u32>) {
chapter.number = Some(SectionNumber::new(number.clone()));
let mut next = 1;
for item in &mut chapter.sub_items {
if let BookItem::Chapter(child) = item {
let mut parts = number.clone();
parts.push(next);
renumber(child, parts);
next += 1;
}
}
}
if let Some(number) = &chapter.number {
let mut next = 2;
for item in &mut chapter.sub_items {
if let BookItem::Chapter(child) = item {
let mut parts = number.to_vec();
parts.push(next);
renumber(child, parts);
next += 1;
}
}
}
chapter.sub_items.insert(0, BookItem::Chapter(page));
}
});
if !found {
return Err(io::Error::other(
"requirements index chapter disappeared before coverage generation",
));
}
Ok(())
}