requirements.test-coverage.index.file_map.notes.availability
Requirements index · View definition
Requirement
The view of
MUST show a readable statement when successfully read and parsed current source contains no citations within the scope of
.
Missing, unreadable, or unparseable current source MUST instead produce a visible diagnostic, without preventing the rest of the book from rendering. These failures MUST NOT be presented as an absence of coverage explanations.
Rationale
The tests adequately cover requirements.test-coverage.index.file_map.notes.availability.
Obligations derived from the text:
- Source that is read and parsed successfully and has no in-scope citations MUST show a readable statement.
- Missing, unreadable or unparseable source MUST produce a visible diagnostic, and the rest of the book MUST still render.
- Those failures MUST NOT be presented as an absence of coverage explanations.
Mapping to tests in src/execution_coverage/notes.rs:
- Clean source with no citations.
mod[tests]/fn[absent_citations_are_distinct_from_missing_unreadable_and_unparseable_source]rendersfn ordinary() {}. It asserts the “No coverage explanations are present” statement and asserts there is no “Coverage notes unavailable” text.mod[tests]/fn[citations_on_modules_and_citation_text_in_literals_do_not_create_explanations]renders source with a module-level citation, a nested module and citation text inside a string literal. All of these are out of scope, so it asserts the “none present” statement and asserts that no “exception proposal” and no “Module only.” text appears.
- Unparseable source. The first test writes two different syntactically invalid sources. Each must contain “Coverage notes unavailable” and “syntax error”, and must not contain the “No coverage explanations” statement.
- Missing source. The test removes
code.rs. It asserts the diagnostic is shown and the “none present” statement is not. - Unreadable source. The test makes
code.rsa directory. It asserts the diagnostic is shown and the “none present” statement is not. - Failure does not block rendering. The test calls
pageswith two files,code.rsandmissing.rs. Both fail, and it asserts that two chapters are still produced and that each carries the diagnostic. The failure of the first file therefore does not abort the rest. The test never pairs a failing file with a good one, butpagesmaps files independently and returns one chapter per file, so this is not a meaningful gap. - Not presented as absence. Every failure case asserts that the “No coverage explanations are present” statement is absent.
The helpers fixture and render are reached from the marked tests. render also checks the chapter count and path. The assertions match the requirement, and I found no plausible violating behavior that these tests would accept. I read only the implementation code needed to check these assertions, and I did not judge its correctness.
Inputs
Implementation
Input 6: outline src/execution_coverage/notes.rs fn[pages]
- File:
src/execution_coverage/notes.rs - Selector:
fn[pages] - Kind:
fn src/execution_coverage/notes.rs:24–77
// {impl}`requirements.test-coverage.index.file_map.notes`
// {impl}`requirements.test-coverage.index.file_map.notes.justifications`
// {impl}`requirements.test-coverage.index.file_map.notes.current`
// {impl}`requirements.test-coverage.index.file_map.notes.availability`
// {impl}`requirements.test-coverage.index.file_map.notes.reviews`
// {impl}`requirements.test-coverage.index.file_map.notes.render_only`
pub(super) fn pages(root: &Path, files: &BTreeSet<String>, index: &Path) -> Vec<Chapter> {
let outlines = OutlineCache::default();
let mut diagnostics = Vec::new();
let references = crate::evidence::collect_references(root, &mut diagnostics);
let definitions = crate::evidence::load_definitions(root).unwrap_or_else(|error| {
diagnostics.push(error.to_string());
BTreeMap::new()
});
let items = citation_items(root, &definitions, &references, &outlines);
files
.iter()
.map(|file| {
let path = path(index, file);
let mut content = format!(
"# Coverage explanations\n\n[Back to coverage index]({})\n\nFile: <code>{}</code>.\n\n**Current workspace source notes**, read at book-render time. These explanations and review states describe the current source.\n\n",
crate::chapter_href(&path, index, None), escaped(file),
);
match outlines.parse(root, file).as_ref() {
Err(error) => diagnostic(&mut content, error),
Ok(parsed) => {
for error in &diagnostics {
diagnostic(&mut content, error);
}
let mut count = 0;
for item in items.values().filter(|item| item.file == *file) {
let Ok(node) = parsed.resolve(file, &item.item) else {
diagnostic(&mut content, "Cannot resolve the cited source item.");
continue;
};
if !(item.item.is_empty() || parsed.outline.nodes[node].kind == "fn")
|| !item.citations.iter().any(|cite| cite.name == "habeas:coverage")
{
continue;
}
count += 1;
entry(&mut content, root, parsed, node, item, &definitions, &outlines);
}
if count == 0 && diagnostics.is_empty() {
content.push_str("No coverage explanations are present on this file's root or explicitly declared functions and methods.\n");
}
},
}
let mut chapter = Chapter::new(&format!("File notes: {file}"), content, path, vec![]);
chapter.source_path = None;
chapter
})
.collect()
}
Tests
Input 4: outline src/execution_coverage/notes.rs mod[tests]/fn[absent_citations_are_distinct_from_missing_unreadable_and_unparseable_source]
- File:
src/execution_coverage/notes.rs - Selector:
mod[tests]/fn[absent_citations_are_distinct_from_missing_unreadable_and_unparseable_source] - Kind:
fn src/execution_coverage/notes.rs:391–424
// {test}`requirements.test-coverage.index.file_map.notes.availability`
#[test]
fn absent_citations_are_distinct_from_missing_unreadable_and_unparseable_source() {
let temp = fixture("fn ordinary() {}\n");
let empty = render(temp.path());
assert!(empty.contains("No coverage explanations are present"));
assert!(!empty.contains("Coverage notes unavailable"));
for source in ["fn invalid( {", "fn invalid() { let = ; }"] {
fs::write(temp.path().join("code.rs"), source).unwrap();
let invalid = render(temp.path());
assert!(invalid.contains("Coverage notes unavailable"));
assert!(invalid.contains("syntax error"), "{invalid}");
assert!(!invalid.contains("No coverage explanations are present"));
}
fs::remove_file(temp.path().join("code.rs")).unwrap();
let missing = render(temp.path());
assert!(missing.contains("Coverage notes unavailable"));
assert!(!missing.contains("No coverage explanations are present"));
fs::create_dir(temp.path().join("code.rs")).unwrap();
let unreadable = render(temp.path());
assert!(unreadable.contains("Coverage notes unavailable"));
assert!(!unreadable.contains("No coverage explanations are present"));
let chapters = pages(
temp.path(),
&BTreeSet::from(["code.rs".into(), "missing.rs".into()]),
Path::new("coverage.md"),
);
assert_eq!(chapters.len(), 2); // one failure does not abort other chapters
assert!(
chapters
.iter()
.all(|chapter| chapter.content.contains("Coverage notes unavailable"))
);
}
Input 5: outline src/execution_coverage/notes.rs mod[tests]/fn[citations_on_modules_and_citation_text_in_literals_do_not_create_explanations]
- File:
src/execution_coverage/notes.rs - Selector:
mod[tests]/fn[citations_on_modules_and_citation_text_in_literals_do_not_create_explanations] - Kind:
fn src/execution_coverage/notes.rs:426–439
// {test}`requirements.test-coverage.index.file_map.notes.availability`
// {test}`requirements.test-coverage.index.file_map.notes.justifications`
#[test]
fn citations_on_modules_and_citation_text_in_literals_do_not_create_explanations() {
let temp = fixture(
"// :::{cite} habeas:coverage\n// Module only.\n// :::\n\
mod nested { fn inside() {} }\n\
fn ordinary() { let text = \"{cite}`habeas:coverage`\"; }\n",
);
let content = render(temp.path());
assert!(content.contains("No coverage explanations are present"));
assert!(!content.contains("exception proposal"));
assert!(!content.contains("Module only."));
}
Referenced definitions
Input 2: 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.
:::
Input 3: requirements selection requirements.test-coverage.index.file_map.notes.justifications
requirements.test-coverage.index.file_map.notes.justifications:md/requirements/test-coverage.md:318–330
:::{req} index.file_map.notes.justifications
The view of {cite}`requirements.test-coverage.index.file_map.notes` MUST show
each `habeas:coverage` citation attached to the file root or an explicitly
declared function or method. Each entry MUST identify its source item and
source location and show the fenced citation commentary and Rust doc comments
supplying its tracked justification under
{cite}`requirements.test-coverage.check.exceptions.anchor`.
When no tracked justification is present, the entry MUST say so.
File-root citations MUST be labelled as file-threshold exception proposals;
function and method citations MUST be labelled as function exception proposals,
following {cite}`requirements.test-coverage.check.exceptions.anchor`.
:::
Other sources
Input 1: requirements selection requirements.test-coverage.index.file_map.notes.availability
requirements.test-coverage.index.file_map.notes.availability:md/requirements/test-coverage.md:338–347
:::{req} index.file_map.notes.availability
The view of {cite}`requirements.test-coverage.index.file_map.notes` MUST show
a readable statement when successfully read and parsed current source contains
no citations within the scope of
{cite}`requirements.test-coverage.index.file_map.notes.justifications`.
Missing, unreadable, or unparseable current source MUST instead produce a
visible diagnostic, without preventing the rest of the book from rendering.
These failures MUST NOT be presented as an absence of coverage explanations.
:::
Input 7: outline src/execution_coverage/notes.rs fn[diagnostic]
- File:
src/execution_coverage/notes.rs - Selector:
fn[diagnostic] - Kind:
fn src/execution_coverage/notes.rs:79–84
fn diagnostic(content: &mut String, error: &str) {
content.push_str(&format!(
"**Coverage notes unavailable:** {}\n\n",
escaped(error),
));
}
Input 8: outline src/execution_coverage/notes.rs mod[tests]/fn[fixture]
- File:
src/execution_coverage/notes.rs - Selector:
mod[tests]/fn[fixture] - Kind:
fn src/execution_coverage/notes.rs:196–203
fn fixture(source: &str) -> tempfile::TempDir {
let temp = tempfile::tempdir().unwrap();
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();
fs::write(temp.path().join("code.rs"), source).unwrap();
temp
}
Input 9: outline src/execution_coverage/notes.rs mod[tests]/fn[render]
- File:
src/execution_coverage/notes.rs - Selector:
mod[tests]/fn[render] - Kind:
fn src/execution_coverage/notes.rs:205–217
fn render(root: &Path) -> String {
let chapters = pages(
root,
&BTreeSet::from(["code.rs".into()]),
Path::new("reports/index.md"),
);
assert_eq!(chapters.len(), 1);
assert_eq!(
chapters[0].path.as_ref().unwrap(),
&path(Path::new("reports/index.md"), "code.rs")
);
chapters.into_iter().next().unwrap().content
}