requirements.test-coverage.index.file_map.combined
Requirements index · View definition
Requirement
The coverage index MUST present a gaps-focused file coverage map representing all current first-party Rust files under
as its primary overview. Its primary file rows MUST list only files with unsatisfied coverage obligations under
or
. A file meeting its line target MUST still be listed when it contains an unsatisfied function obligation.
Its coverage counts MUST use only records eligible for the combined view under
and
, following
.
Rationale
I judge the tests adequate for requirements.test-coverage.index.file_map.combined. I did not request implementation source.
Obligations derived from the subject
- The gaps-focused map covers all current first-party Rust files, so a file with unsatisfied obligations must appear whatever its measurement state.
- Primary file rows list only files with an unsatisfied threshold or function obligation. Files that are satisfied or have no executable obligations are omitted.
- A file that meets its line target is still listed when it has a zero-execution function.
- Counts use only records eligible under
requirements.test-coverage.index.selectionandrequirements.test-coverage.index.freshness. Stale, unavailable or incompatible records are excluded and are not shown as 0% or “not measured”.
Mapping to tests
- Obligations 2 and 3:
book.rs#mod[tests]/fn[combined_directory_minimum_includes_hidden_passing_files]is the main test.src/gap.rsis at 95.0%, above the line target, but has a zero-count function. It is asserted listed withdata-file="src/gap.rs"and “95.0%”.src/nested/deep/gap.rsis listed because of its function obligation.src/nested/passing.rsis exactly at 80% with a positive function count. It is asserted absent from the map and from the file notes.assert_eq!(map.matches("data-file=").count(), 3)shows no other rows are present.- The test also asserts the “1 file obligations · 3 function obligations” summary.
- Obligation 1, file states:
book.rs#mod[tests]/fn[gaps_union_process_locations_and_omit_per_test_reports]covers four cases.code.rsis listed at 2/3 (66.7%), with process and child locations unioned.zero.rsis listed at 0.0%.executable.rs, which has no recorded lines, is listed as “not measured” with no percentage and no bar.unmeasured.rs, which has no executable code, is omitted. The test asserts exactly 3 file rows.
- Obligation 4, incomplete, stale and unreadable records:
book.rs#mod[tests]/fn[maps_distinguish_no_runs_zero_hits_stale_and_incomplete_coverage]andbook.rs#mod[tests]/fn[incomplete_attempts_do_not_label_their_files_as_unmeasured_in_a_partial_map]check these cases.- They cover no runs, empty runs, diagnostics, a missing source, an empty or missing profile, stale source, unreadable
attempt.json, and a stale selected attempt. - Each case shows “Coverage unavailable” with no
data-file, no “not measured”, no directory controls and no minimum. - A good plus a bad attempt does not produce a partial map.
- They cover no runs, empty runs, diagnostics, a missing source, an empty or missing profile, stale source, unreadable
- Obligations 2 and 3, accepted exceptions and threshold:
check.rs#mod[tests]/fn[book_verdict_and_gaps_follow_the_native_policy_and_current_reviews]checks the following.- Function gaps are listed with zero execution.
- Accepted exceptions move out of the unresolved rows.
- A covered file is not listed (
!covered.contains("data-file=\"code.rs\"")). - Unavailable coverage gives “gap counts unavailable”.
- A below-target file is listed as “1/3 (33.3%); 80% target; uncovered lines: 2-3”.
- Re-recording the same test with a newer start replaces the older attempt in the rendered overview.
- Obligation 4, parse and discovery failures:
check.rs#mod[tests]/fn[overview_exposes_parse_and_discovery_findings_and_used_file_exceptions]checks the following.- Accepted file and function exceptions are omitted from the primary rows.
- A parse failure or discovery failure is reported as incomplete or unavailable and is not shown as “0 unresolved gaps”.
- Obligation 4, selection and freshness: the selection and freshness rules are tested directly in
selection_distinguishes_binaries_and_selects_latest_attempts_within_the_active_buildandfiltered_runs_union_latest_attempts_and_invalidate_with_saved_source.- They cover latest-per-test by attempt start, filtered-run union, failed or interrupted newest attempts, stale source, and exclusion of other build configurations.
- The gaps map reads the same selection. The subject’s own tests also show that stale, unavailable and superseded attempts change the map.
Gaps
I found none. A map-specific test that unions a filtered run across different tests would be a nice addition. The selection, freshness and union behaviour it would exercise is already covered by the tests above, so I do not count its absence as a gap. I also did not treat these tests as unmarked: the other selection and freshness tests carry their own {test} references.
Inputs
Tests
Input 8: outline src/execution_coverage/book.rs mod[tests]/fn[combined_directory_minimum_includes_hidden_passing_files]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[combined_directory_minimum_includes_hidden_passing_files] - Kind:
fn src/execution_coverage/book.rs:1030–1114
// {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 9: outline src/execution_coverage/book.rs mod[tests]/fn[gaps_union_process_locations_and_omit_per_test_reports]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[gaps_union_process_locations_and_omit_per_test_reports] - Kind:
fn src/execution_coverage/book.rs:1116–1205
// {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.summary`
// {test}`requirements.test-coverage.index.file_map.combined.details`
// {test}`requirements.test-coverage.index.file_map.notes`
// {test}`requirements.test-coverage.index.details`
#[test]
fn gaps_union_process_locations_and_omit_per_test_reports() {
let (temp, mut book) = fixture();
let root = temp.path();
fs::write(
root.join("code.rs"),
"fn one() {}\nfn two() {}\nfn three() {}\n// not instrumented\n",
)
.unwrap();
fs::write(root.join("zero.rs"), "fn zero() {}\n").unwrap();
fs::write(root.join("unmeasured.rs"), "// no instrumentation\n").unwrap();
fs::write(root.join("executable.rs"), "fn unmeasured() {}\n").unwrap();
let path = record(root, "one", 1, "a", &[(1, 2), (2, 0)]);
let run_path = path.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&run_path).unwrap();
for file in ["zero.rs", "unmeasured.rs", "executable.rs"] {
run.sources
.insert(file.into(), fs::read_to_string(root.join(file)).unwrap());
}
save(&run_path, &run).unwrap();
let mut attempt: Attempt = load(&path.join("attempt.json")).unwrap();
attempt.processes[0]
.lines
.insert("zero.rs".into(), BTreeMap::from([(1, 0)]));
fs::write(path.join("2-child.profraw"), "child profile fixture").unwrap();
attempt.processes.push(Process {
functions: Some(vec![]),
pid: 2,
profiles: vec!["2-child.profraw".into()],
diagnostic: None,
lines: BTreeMap::from([("code.rs".into(), BTreeMap::from([(1, 0), (3, u64::MAX)]))]),
});
save(&path.join("attempt.json"), &attempt).unwrap();
populate(&mut book, root).unwrap();
let index = &book.chapters().next().unwrap().content;
assert!(index.contains("Line coverage: **2/4 (50.0%)**"));
let map = map_html(index);
assert!(file_card(map, "code.rs").contains("2/3 instrumented lines covered"));
assert!(file_card(map, "code.rs").contains("66.7%"));
assert!(file_card(map, "code.rs").contains("--gap-covered: 66.666667%"));
let notes_path = super::super::notes::path(Path::new("reports/coverage.md"), "code.rs");
let href = crate::chapter_href(Path::new("reports/coverage.md"), ¬es_path, None);
assert!(file_card(map, "code.rs").contains(&format!("href=\"{href}\"")));
let notes = book
.chapters()
.find(|chapter| chapter.path.as_ref() == Some(¬es_path))
.unwrap();
assert!(notes.content.contains("File: <code>code.rs</code>"));
assert!(file_card(map, "zero.rs").contains("0.0%"));
assert!(file_card(map, "zero.rs").contains("--gap-covered: 0.000000%"));
assert!(
!map.contains("data-file=\"unmeasured.rs\""),
"a non-executable file has no gap"
);
let unmeasured = file_card(map, "executable.rs")
.split("</tr>")
.next()
.unwrap();
assert!(unmeasured.contains("not measured"));
assert!(!unmeasured.contains('%'));
assert!(!unmeasured.contains("gap-coverage-bar"));
assert!(map.contains("<th>File</th><th>Coverage</th>"));
assert_eq!(
map.matches("class=\"gap-file-row habeas-coverage-file\"")
.count(),
3
);
let mut html = String::new();
pulldown_cmark::html::push_html(
&mut html,
pulldown_cmark::Parser::new_ext(index, pulldown_cmark::Options::all()),
);
assert!(html.contains("Unresolved coverage gaps"));
assert!(!html.contains("habeas-coverage-test"));
assert!(!html.contains("Test runs and provenance"));
assert!(!html.contains("binary / one"));
assert!(
book.chapters()
.skip(1)
.all(|chapter| chapter.name.starts_with("File notes:"))
);
}
Input 10: 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 11: 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 12: 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);
}
Input 13: outline src/execution_coverage/check.rs mod[tests]/fn[overview_exposes_parse_and_discovery_findings_and_used_file_exceptions]
- File:
src/execution_coverage/check.rs - Selector:
mod[tests]/fn[overview_exposes_parse_and_discovery_findings_and_used_file_exceptions] - Kind:
fn src/execution_coverage/check.rs:948–1068
// {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.references.rust_item_coverage
requirements.references.rust_item_coverage:md/requirements/references.md:224–226
:::{req} rust_item_coverage
During repository validation, Habeas MUST parse every first-party Rust source file: every `.rs` file among the sources reference discovery considers under {cite}`requirements.references.discovery`, except those under the project-root `vendor` directory. Each explicitly declared function or method, including trait methods and test helpers, and each struct, enum, and union is an item that can be covered. An item is covered when it has a valid `{impl}`, `{cite}`, or `{test}` reference to a defined requirement or named example, or a valid citation of the built-in `habeas:util` under {cite}`requirements.references.util`, in a Rust comment attached to it or within its body; or when its outline node, or an outline node containing it, is recorded with its current hash as an outline input of an evidence record, a citation review, or a site review. Outline inputs recorded from selected search snippets under {cite}`requirements.authoring.finish_search.inputs` MUST count alongside mandatory inputs and additional reads. Comments belong to items under {cite}`requirements.references.outline_comments`; a comment before a field, variant, or attribute inside an item belongs to that item. A named example MUST reference a requirement under {cite}`requirements.examples.definition`. A reference in a string literal, on an enclosing module or impl block, or only in an evidence input MUST NOT count for the items it encloses. Habeas MUST report a Rust parse failure instead of silently skipping the file. Only {cite}`requirements.references.coverage.tests` and {cite}`requirements.references.coverage.examples` make an uncovered item a validation error; other items without recent coverage are warned about under {cite}`requirements.references.coverage.report`.
:::
Input 3: requirements selection requirements.test-coverage.check.threshold
requirements.test-coverage.check.threshold:md/requirements/test-coverage.md:582–603
:::{req} check.threshold
Each first-party Rust file under
{cite}`requirements.references.rust_item_coverage` MUST have at least 80%
execution coverage of its instrumented lines, or current accepted exception
evidence explaining why the file falls below that target under
{cite}`requirements.test-coverage.check.exceptions`. Counts MUST use the
file-and-line union rule of {cite}`requirements.test-coverage.index.summary`;
a line counts as executed when any eligible test process or its associated
child processes has a positive execution count for it.
The check MUST use the combined selection and freshness rules of
{cite}`requirements.test-coverage.index.selection` and
{cite}`requirements.test-coverage.index.freshness`, restricted to the active
build configuration. It MUST compare exact counts rather than rounded displayed
percentages, average file percentages, or impose an 80% target within each
function. A file whose executable code is not measured MUST require exception
evidence rather than pass with a fabricated percentage. A file established to
contain no executable coverage obligations MUST be reported as such and MUST
NOT require a threshold exception.
Absence of recorded instrumented lines alone MUST NOT establish that a file
contains no executable coverage obligations.
:::
Input 4: requirements selection requirements.test-coverage.check.functions
requirements.test-coverage.check.functions:md/requirements/test-coverage.md:605–616
:::{req} check.functions
Every function under {cite}`requirements.test-coverage.check.scope` without
recorded execution attributable to it MUST have current accepted exception
evidence under {cite}`requirements.test-coverage.check.exceptions`, even when
its containing file meets the target of
{cite}`requirements.test-coverage.check.threshold`.
Execution attributable only to another function, including a nested function
or closure, MUST NOT establish coverage of the enclosing function merely
because their source locations overlap. Having no recorded lines alone MUST
NOT establish that a function has no executable coverage obligations.
:::
Input 5: requirements selection requirements.test-coverage.index.selection
requirements.test-coverage.index.selection:md/requirements/test-coverage.md:178–194
:::{req} index.selection
The coverage index MUST combine the most recent recorded test attempt for each
nextest binary and test name among the retained runs. "Most recent" MUST refer
to when the attempt started, including failed or interrupted attempts. A newer
filtered run MUST update only the tests it executes, leaving other compatible
test records available to the combined view. A newer attempt with missing or
unreadable coverage MUST be shown as unavailable rather than replaced with an
older successful attempt. Results from incompatible instrumented build
configurations MUST NOT be combined under
{cite}`requirements.test-coverage.storage.configuration`.
The main combined view MUST use the instrumented build configuration of the
most recently started recorded test attempt. Latest-per-test selection MUST
occur within that configuration. Records from other configurations MUST be
identified as excluded historical coverage. Configuration selection MUST use
recorded metadata without building or executing tests.
:::
Input 6: requirements selection requirements.test-coverage.index.freshness
requirements.test-coverage.index.freshness:md/requirements/test-coverage.md:196–204
:::{req} index.freshness
Only records whose captured source inputs match the current project source and
whose build configurations are compatible MAY contribute execution counts to
the combined view of {cite}`requirements.test-coverage.index.selection`.
Records invalidated by a source change, or whose compatibility cannot be
established, MUST be identified as stale or unavailable and excluded from the
combined coverage totals. Their per-process reports and matching captured source
MUST remain retained in the build artifacts until those artifacts are removed.
:::
Input 7: requirements selection requirements.test-coverage.index.file_map
requirements.test-coverage.index.file_map:md/requirements/test-coverage.md:227–241
:::{req} index.file_map
A file coverage map MUST identify each file by its workspace-relative path and
show its covered and instrumented line counts and percentage. These counts MUST
use the union rule of {cite}`requirements.test-coverage.index.summary`,
restricted to the file and the records represented by that map, including
associated child processes. The map MUST visually distinguish coverage levels
while also displaying percentages as text. The percentage MUST describe the
map's recorded instrumented lines, rather than all physical source lines.
A listed file with instrumented lines but no positive execution counts MUST
show 0%. A listed file with no recorded instrumented lines in otherwise usable
coverage MUST show "not measured" without a percentage. Coverage whose
completeness cannot be established MUST be identified as unavailable rather
than as 0% or "not measured".
:::
Other sources
Input 1: requirements selection requirements.test-coverage.index.file_map.combined
requirements.test-coverage.index.file_map.combined:md/requirements/test-coverage.md:368–381
:::{req} index.file_map.combined
The coverage index MUST present a gaps-focused file coverage map representing
all current first-party Rust files under
{cite}`requirements.references.rust_item_coverage` as its primary overview.
Its primary file rows MUST list only files with unsatisfied coverage
obligations under {cite}`requirements.test-coverage.check.threshold` or
{cite}`requirements.test-coverage.check.functions`. A file meeting its line
target MUST still be listed when it contains an unsatisfied function obligation.
Its coverage counts MUST use only records eligible for the combined view under
{cite}`requirements.test-coverage.index.selection` and
{cite}`requirements.test-coverage.index.freshness`, following
{cite}`requirements.test-coverage.index.file_map`.
:::
Input 14: 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 15: outline src/execution_coverage/book.rs mod[tests]/fn[selection_distinguishes_binaries_and_selects_latest_attempts_within_the_active_build]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[selection_distinguishes_binaries_and_selects_latest_attempts_within_the_active_build] - Kind:
fn src/execution_coverage/book.rs:1779–1855
// {test}`requirements.test-coverage.index.selection`
#[test]
fn selection_distinguishes_binaries_and_selects_latest_attempts_within_the_active_build() {
let (temp, mut book) = fixture();
for (binary, started, counts) in [
("first", 1, [(1, 1), (2, 0)]),
("second", 2, [(1, 0), (2, 1)]),
] {
let dir = record(temp.path(), "same", started, "build-a", &counts);
let path = dir.join("attempt.json");
let mut attempt: Attempt = load(&path).unwrap();
attempt.binary = binary.into();
save(&path, &attempt).unwrap();
}
populate(&mut book, temp.path()).unwrap();
let index = &book.chapters().next().unwrap().content;
assert!(index.contains("2/2 (100.0%)"));
let saved = load_saved(temp.path(), Some(temp.path().join("target")));
assert_eq!(saved.selected.len(), 2);
let binaries = saved
.selected
.iter()
.map(|&i| saved.records[i].attempt.binary.as_str())
.collect::<BTreeSet<_>>();
assert_eq!(binaries, BTreeSet::from(["first", "second"]));
let (temp, mut book) = fixture();
// Write newest first; run-start and UUID ordering deliberately disagree
// with attempt-start ordering.
for (test, start, config, counts) in [
("two", 40, "build-a", [(2, 1)]),
("one", 30, "build-a", [(1, 1)]),
("one", 35, "build-b", [(1, 0)]),
("two", 10, "build-a", [(2, 0)]),
] {
let attempt = record(temp.path(), test, start, config, &counts);
let dir = attempt.parent().unwrap().parent().unwrap();
let path = dir.join("run.json");
let mut run: Run = load(&path).unwrap();
run.started = if config == "build-b" { 1000 } else { start };
run.id = uuid::Uuid::from_u128(100 - start).to_string();
save(&path, &run).unwrap();
fs::rename(dir, dir.parent().unwrap().join(&run.id)).unwrap();
}
populate(&mut book, temp.path()).unwrap();
let index = &book.chapters().next().unwrap().content;
assert!(index.contains("2/2 (100.0%)"));
assert!(index.contains("1 attempts from a historical build configuration"));
let saved = load_saved(temp.path(), Some(temp.path().join("target")));
let tests = saved
.selected
.iter()
.map(|&i| saved.records[i].attempt.test.as_str())
.collect::<BTreeSet<_>>();
assert_eq!(tests, BTreeSet::from(["one", "two"]));
// A retry in the same run must also use attempt-start ordering.
let (temp, mut book) = fixture();
let newest = record(temp.path(), "one", 20, "build-a", &[(1, 1)]);
let mut older: Attempt = load(&newest.join("attempt.json")).unwrap();
older.started = 10;
older.id = uuid::Uuid::from_u128(u128::MAX).to_string();
older.attempt = "older".into();
older.processes[0].lines = BTreeMap::from([("code.rs".into(), BTreeMap::from([(1, 0)]))]);
let older_dir = newest.parent().unwrap().join(&older.id);
fs::create_dir(&older_dir).unwrap();
fs::copy(newest.join("1-1.profraw"), older_dir.join("1-1.profraw")).unwrap();
save(&older_dir.join("attempt.json"), &older).unwrap();
populate(&mut book, temp.path()).unwrap();
assert!(
book.chapters()
.next()
.unwrap()
.content
.contains("1/1 (100.0%)")
);
}