requirements.test-coverage.index.details
Requirements index · View definition
Requirement
habeas mdbookMUST NOT generate per-test coverage subchapters or captured-source pages under the execution-coverage chapter of. File-notes pages supporting coverage gap explanations under
MUST remain available.
Rationale
The subject has two obligations. The first is that habeas mdbook MUST NOT generate per-test coverage subchapters or captured-source pages under the execution-coverage chapter. The second is that file-notes pages MUST remain available. The marked tests cover both.
No per-test or captured-source pages
src/execution_coverage/book.rs#mod[tests]/fn[gaps_omit_test_data_and_preserve_saved_profiles_and_sources]records two tests and adds a child process. Afterpopulate, it loops over every chapter in the book, which includes nested subchapters.- It asserts that no chapter content contains “Test process coverage”, “Captured source”, “habeas-coverage-test”, “Test runs and provenance”, “binary / one”, “binary / two”, or the captured source text.
- It asserts that no chapter name starts with “binary /”.
- It asserts that no chapter path ends in “-source.md”.
- It asserts that every chapter is either “Coverage gaps” or a “File notes:” page.
- A per-test subchapter or a captured-source page would break at least one of these assertions.
- It also asserts that the saved attempt and run data and the profile files are unchanged.
gaps_union_process_locations_and_omit_per_test_reportsasserts that every chapter after the index has a name starting with “File notes:”. It also asserts that the rendered index lacks “habeas-coverage-test”, “Test runs and provenance”, and “binary / one”.generated_reports_inherit_the_requirements_index_hierarchyis also marked for this requirement. It iterates overcoverage.sub_itemsand checks each page’s parent names, section numbers, and link back to../coverage.html. Those pages are the notes pages.
File-notes pages remain available
gaps_union_process_locations_and_omit_per_test_reportscomputes the notes path forcode.rs. It asserts that the file card links to that path. It then finds the chapter at that path and asserts that its content contains “File:code.rs”.- The same test shows that a non-executable file gets no card, so the notes pages are produced for the listed files.
gaps_omit_test_data_and_preserve_saved_profiles_and_sourcesasserts that no “File notes: passing.rs” page exists for a fully passing file, and that the remaining chapters are “Coverage gaps” or “File notes:” pages.
Not assessed here
- Whether each notes page identifies its workspace-relative path belongs to
requirements.test-coverage.index.file_map.notes. That is a cited requirement and is not reassessed. filtered_runs_union_latest_attempts_and_invalidate_with_saved_sourcecarries the reference but adds no extra assertions for this subject.
The negative obligation is checked on name, path, and content across all chapters. The positive obligation is checked by an existence and content assertion. I found no gap.
Inputs
Tests
Input 4: outline src/execution_coverage/book.rs mod[tests]/fn[generated_reports_inherit_the_requirements_index_hierarchy]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[generated_reports_inherit_the_requirements_index_hierarchy] - Kind:
fn src/execution_coverage/book.rs:870–970
// {test}`requirements.test-coverage.index`
// {test}`requirements.test-coverage.index.navigation`
// {test}`requirements.test-coverage.index.source`
// {test}`requirements.test-coverage.index.guidance`
// {test}`requirements.test-coverage.check.guidance`
// {test}`requirements.test-coverage.check.exceptions.setup`
// {test}`requirements.test-coverage.index.details`
#[test]
fn generated_reports_inherit_the_requirements_index_hierarchy() {
for number in [Some(SectionNumber::new(vec![3, 2])), None] {
let (temp, mut book) = fixture();
let BookItem::Chapter(parent) = &mut book.items[0] else {
unreachable!()
};
parent.path = Some("reports.md".into());
parent.name = "Requirements index".into();
parent.content = "# Requirements index\n".into();
parent.parent_names = vec!["Reports".into()];
parent.number = number.clone();
parent.sub_items.push(BookItem::Chapter(Chapter::new(
"Guide",
"# Guide\n".into(),
"reports/guide.md",
vec![],
)));
record(temp.path(), "one", 1, "a", &[(1, 1)]);
// Build fixture configuration before invoking the production path.
fs::create_dir(temp.path().join("md")).unwrap();
fs::write(temp.path().join("book.toml"), "[book]\nsrc='md'\n").unwrap();
fs::write(temp.path().join("md/SUMMARY.md"), "# Summary\n").unwrap();
super::populate_in(
&mut book,
temp.path(),
Some(temp.path().join("target")),
Path::new("reports.md"),
)
.unwrap();
let BookItem::Chapter(parent) = &book.items[0] else {
unreachable!()
};
assert!(
parent
.content
.contains("[Coverage gaps](reports/coverage.html)")
);
assert_eq!(parent.number, number);
let BookItem::Chapter(coverage) = &parent.sub_items[0] else {
unreachable!()
};
assert_eq!(coverage.parent_names, ["Reports", "Requirements index"]);
assert_eq!(
coverage.path.as_deref(),
Some(Path::new("reports/coverage.md"))
);
assert!(coverage.source_path.is_none());
assert_eq!(
coverage.number,
number.as_ref().map(|_| SectionNumber::new(vec![3, 2, 1]))
);
assert_eq!(parent.sub_items.len(), 2);
for (offset, item) in coverage.sub_items.iter().enumerate() {
let BookItem::Chapter(page) = item else {
unreachable!()
};
assert_eq!(
page.parent_names,
["Reports", "Requirements index", "Coverage gaps"]
);
assert_eq!(
page.number,
number
.as_ref()
.map(|_| SectionNumber::new(vec![3, 2, 1, offset as u32 + 1]))
);
assert!(page.source_path.is_none());
assert!(page.content.contains("../coverage.html"));
}
for guidance in [
"habeas test",
"habeas coverage -- --workspace",
"habeas coverage-check",
"static validation test needs no prior coverage",
"80%",
"habeas:coverage",
"current accepted review",
"No project declaration or special configuration",
"after it succeeds,\nrun `habeas coverage-check` as a separate step",
"`habeas test` collects coverage for the whole workspace,\nthen checks it",
"substantive prose justification",
"fenced commentary or a Rust doc comment",
"citation review with `habeas author`",
"Ordinary partly covered functions\nneed no exception when their file meets its target",
] {
assert!(
coverage.content.contains(guidance),
"missing generated guidance: {guidance}"
);
}
assert!(!coverage.content.contains(":::{coverage-index}"));
}
}
Input 5: 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 6: 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 7: outline src/execution_coverage/book.rs mod[tests]/fn[gaps_omit_test_data_and_preserve_saved_profiles_and_sources]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[gaps_omit_test_data_and_preserve_saved_profiles_and_sources] - Kind:
fn src/execution_coverage/book.rs:1987–2144
// {test}`requirements.test-coverage.index.summary`
// {test}`requirements.test-coverage.index.details`
// {test}`requirements.test-coverage.processes.reports`
#[test]
fn gaps_omit_test_data_and_preserve_saved_profiles_and_sources() {
let (temp, book) = fixture();
let root = temp.path();
fs::write(root.join("passing.rs"), "fn passing() {}\n").unwrap();
let first = record(root, "one", 100, "a", &[(1, 1), (2, 0)]);
fs::write(first.join("2-2.profraw"), "child profile fixture").unwrap();
let mut attempt: Attempt = load(&first.join("attempt.json")).unwrap();
attempt.processes.push(Process {
functions: Some(vec![]),
pid: 2,
profiles: vec!["2-2.profraw".into()],
lines: BTreeMap::from([("code.rs".into(), BTreeMap::from([(1, 0), (2, 7)]))]),
diagnostic: None,
});
// A passing file must not appear in the gaps table.
attempt.processes[0]
.lines
.insert("passing.rs".into(), BTreeMap::from([(1, 1)]));
attempt.processes[0]
.functions
.as_mut()
.unwrap()
.push(super::super::FunctionExecution {
file: "passing.rs".into(),
line: 1,
column: 1,
count: 1,
});
save(&first.join("attempt.json"), &attempt).unwrap();
let run_path = first.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&run_path).unwrap();
run.sources
.insert("passing.rs".into(), "fn passing() {}\n".into());
save(&run_path, &run).unwrap();
record(root, "two", 200, "a", &[(1, 1), (2, 0)]);
let captured_attempt = fs::read(first.join("attempt.json")).unwrap();
let captured_run = fs::read(&run_path).unwrap();
let mut combined = book.clone();
populate(&mut combined, root).unwrap();
let index = combined.chapters().next().unwrap();
assert!(index.content.contains("3/3 (100.0%)"));
assert!(
index
.content
.contains("not establish that all current tests were measured")
);
assert!(!map_html(&index.content).contains("data-file=\"passing.rs\""));
assert!(
combined
.chapters()
.all(|chapter| chapter.name != "File notes: passing.rs")
);
for chapter in combined.chapters() {
for omitted in [
"Test process coverage",
"Captured source",
"habeas-coverage-test",
"Test runs and provenance",
"application/json",
"habeasRenderCoverage",
"binary / one",
"binary / two",
"fn passing() {}",
] {
assert!(
!chapter.content.contains(omitted),
"report includes {omitted}"
);
}
assert!(!chapter.name.starts_with("binary /"));
assert!(
!chapter
.path
.as_ref()
.unwrap()
.to_string_lossy()
.ends_with("-source.md")
);
assert!(chapter.name == "Coverage gaps" || chapter.name.starts_with("File notes:"));
}
fs::write(root.join("code.rs"), "rebuilt source\n").unwrap();
let mut historical = book;
populate(&mut historical, root).unwrap();
assert!(
historical
.chapters()
.next()
.unwrap()
.content
.contains("Coverage unavailable")
);
assert_eq!(
fs::read(first.join("attempt.json")).unwrap(),
captured_attempt
);
assert_eq!(fs::read(&run_path).unwrap(), captured_run);
assert_eq!(
fs::read_to_string(first.join("1-1.profraw")).unwrap(),
"retained profile fixture"
);
assert_eq!(
fs::read_to_string(first.join("2-2.profraw")).unwrap(),
"child profile fixture"
);
// Archived reports use the saved source, even though freshness excludes
// these attempts from the current workspace's gaps report.
let saved = load_saved(root, Some(root.join("target")));
let archived = saved
.records
.iter()
.find(|record| record.attempt.test == "one")
.unwrap();
assert!(!archived.fresh);
let captured_lines = |locations: BTreeMap<(String, u32), u64>| {
locations
.into_iter()
.map(|((file, line), count)| {
let source_line = archived.run.sources[&file]
.lines()
.nth(line as usize - 1)
.unwrap();
((file, line), (source_line.to_owned(), count))
})
.collect::<BTreeMap<_, _>>()
};
let individual = |process: &Process| {
captured_lines(
process
.lines
.iter()
.flat_map(|(file, lines)| {
lines
.iter()
.map(move |(&line, &count)| ((file.clone(), line), count))
})
.collect(),
)
};
let parent = individual(&archived.attempt.processes[0]);
let child = individual(&archived.attempt.processes[1]);
let combined = captured_lines(union(std::iter::once(archived)));
assert_eq!(parent[&("code.rs".into(), 1)], ("fn one() {}".into(), 1));
assert_eq!(parent[&("code.rs".into(), 2)], ("fn two() {}".into(), 0));
assert_eq!(child[&("code.rs".into(), 1)], ("fn one() {}".into(), 0));
assert_eq!(child[&("code.rs".into(), 2)], ("fn two() {}".into(), 7));
assert_eq!(combined[&("code.rs".into(), 2)], ("fn two() {}".into(), 7));
assert_eq!(parent.values().filter(|(_, count)| *count > 0).count(), 2);
assert_eq!(combined.values().filter(|(_, count)| *count > 0).count(), 3);
assert!(
combined
.values()
.all(|(source, _)| !source.contains("rebuilt source"))
);
}
Referenced definitions
Input 2: requirements selection requirements.test-coverage.index
requirements.test-coverage.index:md/requirements/test-coverage.md:158–163
:::{req} index
`habeas mdbook` MUST automatically generate exactly one execution-coverage
subchapter under the requirements index of
{cite}`requirements.index.chapter`, whether that requirements index is
explicitly placed or automatically generated.
:::
Input 3: requirements selection requirements.test-coverage.index.file_map.notes
requirements.test-coverage.index.file_map.notes:md/requirements/test-coverage.md:312–316
:::{req} index.file_map.notes
Each listed first-party Rust file in the combined file coverage
map MUST provide access to a file-notes view identifying its
workspace-relative path.
:::
Other sources
Input 1: requirements selection requirements.test-coverage.index.details
requirements.test-coverage.index.details:md/requirements/test-coverage.md:474–480
:::{req} index.details
`habeas mdbook` MUST NOT generate per-test coverage subchapters or captured-source
pages under the execution-coverage chapter of
{cite}`requirements.test-coverage.index`. File-notes pages supporting coverage
gap explanations under {cite}`requirements.test-coverage.index.file_map.notes`
MUST remain available.
:::