requirements.test-coverage.index.paths
Requirements index · View definition
Requirement
Generated coverage-index and coverage-report paths MUST be distinct. The preprocessor MUST reject a generated coverage path that conflicts with an existing book chapter, including another generated chapter.
Rationale
The reviewed test adequately checks requirements.test-coverage.index.paths.
Obligations derived from the text
- The generated coverage-index path and the generated coverage-report (file-note) paths MUST be distinct.
- The preprocessor MUST reject a generated coverage path that conflicts with an existing book chapter. The text includes another generated chapter in that.
Implementation question, and why I read it
I read src/execution_coverage/book.rs#fn[populate_in] to see which paths are generated and which checks fire. This was only to understand what the test’s fixtures collide with. The expected behavior comes from the requirement text.
The function builds the index path as <parent>/coverage.md. It builds report paths through notes::path as <parent dir>/coverage-reports/files/<digest>.md. It rejects the index path if it is already an existing chapter. It rejects a report path if it is an existing chapter or has already been generated.
Test mapping
src/execution_coverage/book.rs#mod[tests]/fn[unavailable_runs_are_readable_and_generated_paths_cannot_collide] covers the following scenarios.
- Authored chapter on the index path.
- The test pushes an authored chapter at
reports/coverage.md, which is the index path for parentreports.md. - It asserts that
populatereturns an error whose text containscoverage index path conflicts. - This covers rejection of an index-path conflict, and the message is specific to the index check.
- The test pushes an authored chapter at
- Authored chapter on a report path.
- The test pushes a chapter at
notes::path("reports/coverage.md", "code.rs"). code.rsis created byfixture(), so a note page is generated for it even though there are no runs.- It asserts that
populatereturns an error containingconflicts. - This covers rejection of a report-path conflict with an existing chapter.
- The test pushes a chapter at
- Distinctness of index and report paths.
- The non-colliding
populate(...).unwrap()in the same test succeeds with a note page generated forcode.rs. Other fixture-based tests do the same. - The implementation’s
generatedset would makepopulatereturn an error if a report path equaled the index path, so these successful runs enforce that the two differ. - The path shapes also differ by construction:
coverage-reports/files/<digest>.mdversuscoverage.md.
- The non-colliding
Residual points considered and not treated as gaps
- The
!generated.insert(...)branch handles two generated report pages with the same path. It could only fire on a digest collision, which an ordinary test cannot construct. The requirement’s “another generated chapter” case is also reached through theexisting.containscheck, which is tested. Another generated chapter that is already in the book is, from the preprocessor’s view, an existing chapter at that path, so the tested check covers it. - The notes-collision assertion only checks for
conflicts. The text requires rejection, not a particular message, so this is sufficient.
No obligation of the requirement is left without a test and an assertion, and there are no acknowledgments to consider.
Inputs
Tests
Input 2: outline src/execution_coverage/book.rs mod[tests]/fn[unavailable_runs_are_readable_and_generated_paths_cannot_collide]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[unavailable_runs_are_readable_and_generated_paths_cannot_collide] - Kind:
fn src/execution_coverage/book.rs:2146–2186
// {test}`requirements.test-coverage.index.paths`
// {test}`requirements.test-coverage.index.unavailable`
#[test]
fn unavailable_runs_are_readable_and_generated_paths_cannot_collide() {
let (temp, mut collision) = fixture();
collision.push_item(Chapter::new(
"Authored",
"Keep me".into(),
"reports/coverage.md",
vec![],
));
assert!(
populate(&mut collision, temp.path())
.unwrap_err()
.to_string()
.contains("coverage index path conflicts")
);
let (temp, mut book) = fixture();
populate(&mut book, temp.path()).unwrap();
assert!(
book.chapters()
.next()
.unwrap()
.content
.contains("Run `habeas coverage`")
);
// Current file-note pages are generated reports too, even without runs.
let (temp, mut book) = fixture();
book.push_item(Chapter::new(
"Notes collision",
"".into(),
super::super::notes::path(Path::new("reports/coverage.md"), "code.rs"),
vec![],
));
assert!(
populate(&mut book, temp.path())
.unwrap_err()
.to_string()
.contains("conflicts")
);
}
Other sources
Input 1: requirements selection requirements.test-coverage.index.paths
requirements.test-coverage.index.paths:md/requirements/test-coverage.md:482–486
:::{req} index.paths
Generated coverage-index and coverage-report paths MUST be distinct.
The preprocessor MUST reject a generated coverage path that conflicts with
an existing book chapter, including another generated chapter.
:::
Input 3: 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(())
}
Input 4: outline src/execution_coverage/book.rs mod[tests]/fn[populate]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[populate] - Kind:
fn src/execution_coverage/book.rs:698–722
// Test adapter: expose the generated coverage subtree as the root for
// report-content fixtures. The navigation test exercises the full book.
fn populate(book: &mut Book, root: &Path) -> io::Result<()> {
if !root.join("book.toml").exists() {
fs::create_dir_all(root.join("md"))?;
fs::write(root.join("book.toml"), "[book]\nsrc='md'\n")?;
fs::write(root.join("md/SUMMARY.md"), "# Summary\n")?;
}
let BookItem::Chapter(parent) = &mut book.items[0] else {
unreachable!()
};
parent.path = Some("reports.md".into());
super::populate_in(
book,
root,
Some(root.join("target")),
Path::new("reports.md"),
)?;
let BookItem::Chapter(parent) = &mut book.items[0] else {
unreachable!()
};
let coverage = parent.sub_items.remove(0);
book.items[0] = coverage;
Ok(())
}
Input 5: outline src/execution_coverage/notes.rs fn[path]
- File:
src/execution_coverage/notes.rs - Selector:
fn[path] - Kind:
fn src/execution_coverage/notes.rs:16–22
pub(super) fn path(index: &Path, file: &str) -> PathBuf {
index
.parent()
.unwrap_or(Path::new(""))
.join("coverage-reports/files")
.join(format!("{}.md", super::digest(file.as_bytes())))
}
Input 6: outline src/execution_coverage/book.rs mod[tests]/fn[fixture]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[fixture] - Kind:
fn src/execution_coverage/book.rs:724–736
fn fixture() -> (tempfile::TempDir, Book) {
let temp = tempfile::tempdir().unwrap();
fs::write(temp.path().join("Cargo.toml"), "[workspace]\n").unwrap();
fs::write(temp.path().join("code.rs"), "fn one() {}\nfn two() {}\n").unwrap();
let mut book = Book::new();
book.push_item(Chapter::new(
"Coverage",
":::{coverage-index}\n:::\n".into(),
"reports/coverage.md",
vec![],
));
(temp, book)
}