requirements.test-coverage.index.file_map.notes.current
Requirements index · View definition
Requirement
The view of
MUST use the current workspace source at book-render time and explicitly identify its contents as current workspace source notes.
Rationale
The tests adequately cover requirements.test-coverage.index.file_map.notes.current. The requirement has two obligations: the notes view uses the current workspace source at book-render time, and the view explicitly identifies its contents as current workspace source notes.
Current source at render time
src/execution_coverage/book.rs#mod[tests]/fn[gap_notes_use_current_source_without_collecting]records a run, then writes newcode.rscontent with a citation explanation (“Current explanation, added after capture.”). It then callspopulateand finds the notes chapter. It asserts that the chapter contains the post-capture text, so a view built from captured data would fail.- The same test checks that the view is unique per file and that its path is distinct for
code.rs,src/a.rsandsrc/nested/a.rs. Each view containsFile: <code>{file}</code>. src/execution_coverage/notes.rs#mod[tests]/fn[each_render_reads_current_notes_and_validates_saved_reviews_without_writing]renders, edits the source, and renders again. It asserts that the second render has the “Updated platform explanation.” text and that the original explanation is gone from the notes part.- The same test shows the review changing to “not accepted” with “citations changed”, which confirms each render re-reads the source.
Explicit identification
- Both tests assert that the view content contains “Current workspace source notes”.
src/execution_coverage/notes.rs#fn[pages]emits this label as “Current workspace source notes, read at book-render time”. - The label assertion runs against the real rendered view in both tests, so it is not a tautology.
Test marking
- Both tests carry
{test}references to the subject.
I found no obligation, boundary or failure case in the subject text that goes untested.
Inputs
Implementation
Input 5: 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 3: outline src/execution_coverage/book.rs mod[tests]/fn[gap_notes_use_current_source_without_collecting]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[gap_notes_use_current_source_without_collecting] - Kind:
fn src/execution_coverage/book.rs:1644–1718
// {test}`requirements.test-coverage.index.file_map.notes`
// {test}`requirements.test-coverage.index.file_map.notes.current`
// {test}`requirements.test-coverage.index.file_map.notes.render_only`
#[test]
fn gap_notes_use_current_source_without_collecting() {
let (temp, mut book) = fixture();
let root = temp.path();
fs::create_dir(root.join("md")).unwrap();
fs::write(root.join("book.toml"), "[book]\nsrc='md'\n").unwrap();
fs::write(root.join("md/SUMMARY.md"), "# Summary\n").unwrap();
fs::create_dir_all(root.join("src/nested")).unwrap();
for file in ["src/a.rs", "src/nested/a.rs"] {
fs::write(root.join(file), "fn another() {}\n").unwrap();
}
let attempt = record(root, "one", 1, "a", &[(1, 1)]);
let run_path = attempt.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&run_path).unwrap();
let mut process: Attempt = load(&attempt.join("attempt.json")).unwrap();
for file in ["src/a.rs", "src/nested/a.rs"] {
run.sources
.insert(file.into(), fs::read_to_string(root.join(file)).unwrap());
process.processes[0]
.lines
.insert(file.into(), BTreeMap::from([(1, 1)]));
}
save(&run_path, &run).unwrap();
save(&attempt.join("attempt.json"), &process).unwrap();
let captured = fs::read(attempt.join("attempt.json")).unwrap();
fs::write(root.join("code.rs"),
"// :::{cite} habeas:coverage\n// Current explanation, added after capture.\n// :::\nfn current() {}\n").unwrap();
populate(&mut book, root).unwrap();
let index = book.chapters().next().unwrap();
let notes_path = super::super::notes::path(index.path.as_ref().unwrap(), "code.rs");
let notes = book
.chapters()
.find(|chapter| chapter.path.as_ref() == Some(¬es_path))
.unwrap();
assert!(
notes
.content
.contains("Current explanation, added after capture.")
);
assert!(notes.content.contains("Current workspace source notes"));
assert!(notes.content.contains("code.rs"));
assert_eq!(
book.chapters()
.filter(|chapter| chapter.path.as_ref() == Some(¬es_path))
.count(),
1
);
let mut distinct = BTreeSet::new();
for file in ["code.rs", "src/a.rs", "src/nested/a.rs"] {
let path = super::super::notes::path(index.path.as_ref().unwrap(), file);
assert!(
distinct.insert(path.clone()),
"files must have distinct views"
);
let notes = book
.chapters()
.find(|chapter| chapter.path.as_ref() == Some(&path))
.unwrap();
assert!(
notes
.content
.contains(&format!("File: <code>{file}</code>"))
);
assert!(index.content.contains("Coverage unavailable"));
}
assert_eq!(fs::read(attempt.join("attempt.json")).unwrap(), captured);
assert_eq!(
fs::read_to_string(attempt.join("1-1.profraw")).unwrap(),
"retained profile fixture"
);
assert!(!root.join("evidence").exists());
}
Input 4: outline src/execution_coverage/notes.rs mod[tests]/fn[each_render_reads_current_notes_and_validates_saved_reviews_without_writing]
- File:
src/execution_coverage/notes.rs - Selector:
mod[tests]/fn[each_render_reads_current_notes_and_validates_saved_reviews_without_writing] - Kind:
fn src/execution_coverage/notes.rs:495–523
// {test}`requirements.test-coverage.index.file_map.notes.current`
// {test}`requirements.test-coverage.index.file_map.notes.render_only`
#[test]
fn each_render_reads_current_notes_and_validates_saved_reviews_without_writing() {
let source = "// :::{cite} habeas:coverage\n// Original platform explanation.\n// :::\nfn other() {}\n";
let temp = fixture(source);
let reviews = write_reviews(temp.path(), true);
let saved_review = fs::read(&reviews[0]).unwrap();
assert!(render(temp.path()).contains("current and accepted"));
fs::write(
temp.path().join("code.rs"),
source.replace("Original platform", "Updated platform"),
)
.unwrap();
let content = render(temp.path());
assert!(content.contains("Updated platform explanation."));
assert!(
!content
.split("Review:")
.next()
.unwrap()
.contains("Original platform explanation.")
);
assert!(content.contains("Current workspace source notes"));
assert!(content.contains("Review: **not accepted**"));
assert!(content.contains("citations changed"));
assert_eq!(fs::read(&reviews[0]).unwrap(), saved_review);
assert!(!temp.path().join("target").exists());
}
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.
:::
Other sources
Input 1: requirements selection requirements.test-coverage.index.file_map.notes.current
requirements.test-coverage.index.file_map.notes.current:md/requirements/test-coverage.md:332–336
:::{req} index.file_map.notes.current
The view of {cite}`requirements.test-coverage.index.file_map.notes` MUST use
the current workspace source at book-render time and explicitly identify its
contents as current workspace source notes.
:::