requirements.test-coverage.index.file_map.notes.reviews
Requirements index · View definition
Requirement
Each citation entry under
MUST show whether its source item’s citation review is current and accepted under
.
Missing, unreadable, stale, invalid, or rejected reviews MUST NOT be presented as accepted. The view MUST distinguish a missing review from a present review that is not accepted and expose the validation findings explaining non-acceptance.
Rationale
The test src/execution_coverage/notes.rs#mod[tests]/fn[notes_distinguish_accepted_missing_rejected_stale_invalid_and_unreadable_reviews] is marked {test} for the subject. It covers each obligation:
- Accepted review. The
acceptedcase builds a fixture with a valid accepted review, using the helpersfixture,write_reviewsandrender. It asserts the text “Review: current and accepted”. - Missing review. The
missingcase deletes the review file. The test asserts “Review: missing” and a “cannot read citation review” finding. Theentryimplementation emits “missing” only when the review path is NotFound, so a missing review is distinct from a present review that is not accepted. - Present reviews that are not accepted. The
rejectedcase (determination false), thestalecase (source changed), theinvalidcase (not JSON) and theunreadablecase (the review path is a directory) each assert “Review: not accepted”. Each also asserts a state-specific finding: “determination is false”, “hash”, “invalid JSON” and “cannot read citation review” respectively. This exposes the validation findings that explain non-acceptance. - Never presented as accepted. For every non-accepted state, the test asserts that “current and accepted” is absent from the output. This enforces the MUST NOT.
Two other tests support this:
notes_show_root_function_and_method_proposals_with_owned_commentary_and_docsasserts “Review: missing” for four entries, so the missing state is also checked across file-root, function and method entries.each_render_reads_current_notes_and_validates_saved_reviews_without_writingchecks the stale “citations changed” path.
The “stale” finding assertion is only the substring “hash”. That is a weak match, but it still distinguishes the stale case from the others. I found no required scenario that is untested.
Inputs
Tests
Input 4: outline src/execution_coverage/notes.rs mod[tests]/fn[notes_distinguish_accepted_missing_rejected_stale_invalid_and_unreadable_reviews]
- File:
src/execution_coverage/notes.rs - Selector:
mod[tests]/fn[notes_distinguish_accepted_missing_rejected_stale_invalid_and_unreadable_reviews] - Kind:
fn src/execution_coverage/notes.rs:441–493
// {test}`requirements.test-coverage.index.file_map.notes.reviews`
#[test]
fn notes_distinguish_accepted_missing_rejected_stale_invalid_and_unreadable_reviews() {
let source = "// :::{cite} habeas:coverage\n// Only supported on another platform.\n// :::\nfn other() { let value = 1; }\n";
for state in [
"accepted",
"missing",
"rejected",
"stale",
"invalid",
"unreadable",
] {
let temp = fixture(source);
let reviews = write_reviews(temp.path(), state != "rejected");
assert_eq!(reviews.len(), 1);
let review = &reviews[0];
match state {
"missing" => fs::remove_file(review).unwrap(),
"stale" => fs::write(
temp.path().join("code.rs"),
source.replace("value = 1", "value = 2"),
)
.unwrap(),
"invalid" => fs::write(review, "not JSON").unwrap(),
"unreadable" => {
fs::remove_file(review).unwrap();
fs::create_dir(review).unwrap();
}
_ => {}
}
let content = render(temp.path());
let expected = match state {
"accepted" => "Review: **current and accepted**",
"missing" => "Review: **missing**",
_ => "Review: **not accepted**",
};
assert!(content.contains(expected), "{state}: {content}");
let finding = match state {
"rejected" => "determination is false",
"stale" => "hash",
"invalid" => "invalid JSON",
"unreadable" | "missing" => "cannot read citation review",
_ => "current and accepted",
};
assert!(content.contains(finding), "{state}: {content}");
if state != "accepted" {
assert!(
!content.contains("current and accepted"),
"{state}: {content}"
);
}
}
}
Referenced definitions
Input 2: 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`.
:::
Input 3: requirements selection requirements.test-coverage.check.exceptions.reviews
requirements.test-coverage.check.exceptions.reviews:md/requirements/test-coverage.md:681–697
:::{req} check.exceptions.reviews
Exception proposals MUST be `{cite}` references to `habeas:coverage`
under {cite}`requirements.test-coverage.check.exceptions.anchor`. Each proposal
MUST have a current, accepted citation review of its source item under
{cite}`requirements.references.citation_review`. The reviewer MUST assess
whether the justification adequately explains the proposed exception, not merely
whether the citation has the right role. An acknowledgment of missing coverage
without an adequate justification MUST NOT authorize an exception.
File-threshold proposals MUST belong to the source file's root item. Proposals
concerning unexecuted or not-measured functions MUST belong to their explicitly
declared function's item. One accepted function proposal MUST cover both zero execution
and absence from otherwise usable measurement, without separate exception kinds.
A proposal in a nested function MUST NOT authorize exceptions
for its enclosing function, and an enclosing function's proposal MUST NOT
authorize exceptions for nested functions.
:::
Other sources
Input 1: requirements selection requirements.test-coverage.index.file_map.notes.reviews
requirements.test-coverage.index.file_map.notes.reviews:md/requirements/test-coverage.md:349–359
:::{req} index.file_map.notes.reviews
Each citation entry under
{cite}`requirements.test-coverage.index.file_map.notes.justifications` MUST
show whether its source item's citation review is current and accepted under
{cite}`requirements.test-coverage.check.exceptions.reviews`.
Missing, unreadable, stale, invalid, or rejected reviews MUST NOT be presented
as accepted. The view MUST distinguish a missing review from a present review
that is not accepted and expose the validation findings explaining
non-acceptance.
:::
Input 5: outline src/execution_coverage/notes.rs fn[entry]
- File:
src/execution_coverage/notes.rs - Selector:
fn[entry] - Kind:
fn src/execution_coverage/notes.rs:115–188
fn entry(
content: &mut String,
root: &Path,
parsed: &ParsedSource,
node: usize,
item: &CitationItem,
definitions: &BTreeMap<String, Declaration>,
outlines: &OutlineCache,
) {
let label = if item.item.is_empty() {
"File root".to_owned()
} else {
item.item.clone()
};
let scope = if item.item.is_empty() {
"File-threshold exception proposal (80% instrumented-line target)"
} else {
"Function exception proposal (zero execution or not measured)"
};
let source = &parsed.outline.nodes[node];
content.push_str(&format!(
"## <code>{}</code>\n\n{scope}.\n\nSource: <code>{}:{}–{}</code>. First source citation at line {}.\n\n",
escaped(&label),
escaped(&item.file),
source.line_start,
source.line_end,
item.line,
));
let commentary = item
.citations
.iter()
.filter(|cite| cite.name == "habeas:coverage")
.map(|cite| cite.commentary.trim())
.filter(|text| !text.is_empty())
.collect::<Vec<_>>()
.join("\n\n");
let docs = doc_comments(parsed, node);
for (heading, text) in [
("Citation commentary", &commentary),
("Rust doc comments", &docs),
] {
if !text.trim().is_empty() {
let text = crate::redaction::redact_text(text);
content.push_str(&format!(
"### {heading}\n\n<pre style=\"white-space:pre-wrap;overflow-wrap:anywhere\">{}</pre>\n\n",
escaped(&text),
));
}
}
if commentary.is_empty() && docs.trim().is_empty() {
content.push_str("**No tracked justification is present.**\n\n");
}
let review = item.review_path();
let mut findings = Vec::new();
validate_review(root, &review, item, definitions, outlines, &mut findings);
if findings.is_empty() {
content.push_str("Review: **current and accepted**.\n\n");
} else {
let state = if root
.join(&review)
.symlink_metadata()
.is_err_and(|error| error.kind() == std::io::ErrorKind::NotFound)
{
"missing"
} else {
"not accepted"
};
content.push_str(&format!("Review: **{state}**.\n\n"));
for finding in findings {
content.push_str(&format!("- {}\n", escaped(&finding)));
}
content.push('\n');
}
}
Input 6: 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 7: 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
}
Input 8: outline src/execution_coverage/notes.rs mod[tests]/fn[write_reviews]
- File:
src/execution_coverage/notes.rs - Selector:
mod[tests]/fn[write_reviews] - Kind:
fn src/execution_coverage/notes.rs:219–248
// Synthetic fixture reviews only; production evidence is model-authored.
fn write_reviews(root: &Path, determination: bool) -> Vec<PathBuf> {
let outlines = OutlineCache::default();
let mut errors = Vec::new();
let references = crate::evidence::collect_references(root, &mut errors);
assert!(errors.is_empty(), "{errors:?}");
citation_items(root, &BTreeMap::new(), &references, &outlines)
.into_values()
.map(|item| {
let parsed = outlines.parse(root, &item.file);
let parsed = parsed.as_ref().as_ref().unwrap();
let node = parsed.resolve(&item.file, &item.item).unwrap();
let path = root.join(item.review_path());
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(
&path,
serde_json::to_vec(&json!({
"file": item.file, "item": item.item, "citations": item.citations_value(),
"determination": determination,
"rationale": "Synthetic review outcome for this test fixture.",
"inputs": [{"file": item.file, "item": item.item,
"hash": parsed.outline.nodes[node].structural_hash}]
}))
.unwrap(),
)
.unwrap();
path
})
.collect()
}
Input 9: outline src/execution_coverage/notes.rs mod[tests]/fn[notes_show_root_function_and_method_proposals_with_owned_commentary_and_docs]
- File:
src/execution_coverage/notes.rs - Selector:
mod[tests]/fn[notes_show_root_function_and_method_proposals_with_owned_commentary_and_docs] - Kind:
fn src/execution_coverage/notes.rs:250–351
// {test}`requirements.test-coverage.index.file_map.notes`
// {test}`requirements.test-coverage.index.file_map.notes.justifications`
#[test]
fn notes_show_root_function_and_method_proposals_with_owned_commentary_and_docs() {
let temp = fixture(
"//! Root documentation.\n\
//! :::{cite} habeas:coverage\n\
//! File threshold justification.\n\
//! :::\n\n\
/// Function documentation.\n\
// :::{cite} habeas:coverage\n\
// Function explanation with <unsafe> text.\n\
// :::\n\
fn ordinary() {}\n\n\
struct Worker;\n\
impl Worker {\n\
/** Method documentation. */\n\
// :::{cite} habeas:coverage\n\
// Method explanation.\n\
// :::\n\
fn work(&self) {}\n\
}\n\n\
// {cite}`habeas:coverage`\n\
fn unexplained() {}\n\n\
// :::{cite} habeas:coverage\n\
// Nested module must not become a file exception.\n\
// :::\n\
mod nested {\n\
/// Child documentation must stay with the child.\n\
fn child() {}\n\
}\n",
);
let content = render(temp.path());
for text in [
"File: <code>code.rs</code>",
"File root",
"File-threshold exception proposal",
"fn[ordinary]",
"impl[Worker]/fn[work]",
"Function exception proposal",
"Root documentation.",
"File threshold justification.",
"Function documentation.",
"Function explanation with <unsafe> text.",
"Method documentation.",
"Method explanation.",
"fn[unexplained]",
"No tracked justification is present.",
"Source: <code>code.rs:",
"First source citation at line",
] {
assert!(content.contains(text), "missing {text}: {content}");
}
assert_eq!(
content.matches("File-threshold exception proposal").count(),
1
);
assert_eq!(content.matches("Function exception proposal").count(), 3);
assert!(!content.contains("Nested module must"));
assert!(!content.contains("Child documentation"));
assert!(!content.contains("<unsafe>"));
assert_eq!(content.matches("Review: **missing**").count(), 4);
assert_eq!(
content
.matches("No tracked justification is present.")
.count(),
1
);
assert!(content.contains("cannot read citation review"));
let unexplained = content
.split("## <code>fn[unexplained]")
.nth(1)
.unwrap()
.split("## <code>")
.next()
.unwrap();
assert!(!unexplained.contains("Rust doc comments"));
assert!(unexplained.contains("No tracked justification is present."));
for (label, first, last, citation) in [
("File root", 1, 30, 2),
("fn[ordinary]", 6, 10, 7),
("impl[Worker]/fn[work]", 14, 18, 15),
("fn[unexplained]", 21, 22, 21),
] {
let heading = format!("## <code>{label}</code>");
let entry = content
.split(&heading)
.nth(1)
.unwrap()
.split("## <code>")
.next()
.unwrap();
assert!(
entry.contains(&format!("Source: <code>code.rs:{first}–{last}</code>")),
"{label}: {entry}"
);
assert!(
entry.contains(&format!("First source citation at line {citation}.")),
"{label}: {entry}"
);
}
}
Input 10: 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());
}