requirements.test-coverage.index.gaps.accepted
Requirements index · View definition
Requirement
Accepted exceptions actually used to satisfy current file or function coverage obligations MUST be shown separately in an initially collapsed documented-gaps section. Each entry MUST identify its source item and source location, its uncovered measurement, its tracked justification, and its current accepted review state, using current source notes under
.
Accepted exceptions MUST NOT increase reported execution-coverage percentages. Citations on items whose measured coverage already satisfies their obligations MUST NOT be listed as active gaps.
Rationale
I judge the two marked tests adequate for requirements.test-coverage.index.gaps.accepted. Both are in src/execution_coverage/check.rs: book_verdict_and_gaps_follow_the_native_policy_and_current_reviews and overview_exposes_parse_and_discovery_findings_and_used_file_exceptions.
- Separate, initially collapsed section.
- Both tests render the book chapter and assert the heading “Documented gaps — N accepted exceptions”.
- The first test asserts the section is not rendered with
open. The rendering insrc/execution_coverage/book.rs#fn[gaps_map]emits a plain<details class="gap-accepted-group">element. - The
assert_detailshelper restricts<details>classes to a known set that includesgap-accepted-group. - The first test asserts “1 unresolved gaps” alongside the documented section, so the accepted item is shown apart from the unresolved gaps. The second test asserts the accepted exceptions are absent from the main per-file gap controls (
data-file="code.rs"). - The collapsed-state check is a weak negative string match. It would miss an
openattribute placed beforeclass. The rendered HTML does not do that, so I do not count this as a gap.
- Entry fields.
- The first test slices out the documented section and asserts it contains the selector
fn[b], the locationcode.rs:5, the measurement “zero execution”, the justification text, the state “current and accepted”, and “Current workspace source notes”. It also asserts a link tocoverage-reports/files/. - The second test does the same for a file-root exception and a function exception:
File root,code.rs:1,code.rs:7,fn[adapter],0/1 (0.0%), and both justification texts. The file-level case is therefore covered as well as the function-level case.
- The first test slices out the documented section and asserts it contains the selector
- Review state and the accepted-only rule.
- With the review determination
false, the test asserts “Review not accepted”, “determination is false”, “2 unresolved gaps” and “Documented gaps — 0 accepted exceptions”. A rejected review is therefore not shown as accepted. - With the review missing, the test asserts “Review missing” and the same unresolved count.
- With the review determination
- No increase in percentages. With one uncovered function accepted, the first test asserts the reported figure is still “80.0%”, which is 4 of 5 lines. The accepted exception is not counted as covered, and the unresolved count is still 1.
- Satisfied citations are not active gaps. After the function counts are raised to 1, the first test asserts “0 unresolved gaps”, that
data-file="code.rs"is absent, and “Documented gaps — 0 accepted exceptions”. The{cite}onfn[b]therefore does not appear as a gap or as a documented exception. - Current workspace notes. The “Current workspace source notes” label and the notes link are asserted in both tests. The cited
file_map.notes.currentrequirement is therefore applied in the subject’s case.
No untested obligation or wrong expectation remains, so there is no gap.
Inputs
Implementation
Input 5: outline src/execution_coverage/book.rs fn[gaps_map]
- File:
src/execution_coverage/book.rs - Selector:
fn[gaps_map] - Kind:
fn src/execution_coverage/book.rs:213–302
// {impl}`requirements.test-coverage.index.file_map.combined`
// {impl}`requirements.test-coverage.index.file_map.combined.measurement`
// {impl}`requirements.test-coverage.index.file_map.table`
// {impl}`requirements.test-coverage.index.file_map.directories`
// {impl}`requirements.test-coverage.index.file_map.directories.initial`
// {impl}`requirements.test-coverage.index.file_map.directories.data`
// {impl}`requirements.test-coverage.index.file_map.minimum`
// {impl}`requirements.test-coverage.index.file_map.minimum.statuses`
// {impl}`requirements.test-coverage.index.gaps`
// {impl}`requirements.test-coverage.index.gaps.summary`
// {impl}`requirements.test-coverage.index.gaps.details`
// {impl}`requirements.test-coverage.index.gaps.details.initial`
// {impl}`requirements.test-coverage.index.gaps.accepted`
// {impl}`requirements.test-coverage.index.file_map.notes`
fn gaps_map(policy: &super::check::PolicyReport, index: &Path, attempts: usize) -> String {
let mut html = format!(
"<style>{}</style>\n<section class=\"habeas-coverage-map habeas-coverage-gaps\" aria-label=\"Coverage gaps\">\n<p class=\"gap-meta\">Combined coverage · {attempts} selected test attempts</p><p class=\"gap-policy gap-meta\">File target: 80% of instrumented lines. Every function needs execution or an accepted explanation.</p>\n",
include_str!("../../assets/coverage-gaps.css")
);
let unresolved: Vec<_> = policy
.files
.iter()
.flat_map(|file| &file.obligations)
.filter(|gap| !gap.accepted())
.collect();
let files = unresolved
.iter()
.filter(|gap| gap.selector.is_empty())
.count();
let functions = unresolved.len() - files;
html.push_str(&format!(
"<div class=\"gap-verdict\" role=\"status\"><strong>CI would {}</strong>",
if policy.report.passed { "pass" } else { "fail" }
));
if policy.counts_complete {
html.push_str(&format!("<span>{} unresolved gaps</span><span class=\"gap-meta\">{files} file obligations · {functions} function obligations</span>", unresolved.len()));
} else if policy.measured {
html.push_str(&format!(
"<span>Gap counts incomplete: {} established unresolved gaps</span>",
unresolved.len()
));
} else {
html.push_str("<span>Coverage unavailable · gap counts unavailable</span>");
}
html.push_str("</div><p class=\"gap-section-label\">Unresolved coverage gaps</p>\n");
let mut directory = GapDirectory::default();
for file in &policy.files {
if !file.obligations.iter().any(|gap| !gap.accepted()) {
continue;
}
let mut dir = &mut directory;
if let Some((folder, _)) = file.file.rsplit_once('/') {
for part in folder.split('/') {
dir = dir.directories.entry(part.into()).or_default();
}
}
dir.files.push(file);
}
directory.render(&mut html, "", policy, index, &mut 0);
if unresolved.is_empty() && policy.counts_complete {
html.push_str("<p>No unsatisfied file or function obligations.</p>\n");
}
let accepted = policy
.files
.iter()
.flat_map(|file| {
file.obligations
.iter()
.filter(|gap| gap.accepted())
.map(move |gap| (file, gap))
})
.collect::<Vec<_>>();
html.push_str(&format!("<details class=\"gap-accepted-group\"><summary>Documented gaps — {} accepted exceptions</summary><p class=\"gap-meta\">Current workspace source notes. Accepted exceptions do not increase measured percentages.</p>\n", accepted.len()));
for (file, gap) in accepted {
let notes = crate::chapter_href(index, &super::notes::path(index, &file.file), None);
html.push_str(&format!("<div class=\"gap-accepted-item\"><p><a href=\"{}\"><code>{}:{} #{}</code></a> · {} · <span class=\"gap-accepted-state\">current and accepted</span></p>{}</div>\n", escaped(¬es), escaped(&file.file), gap.line, escaped(if gap.selector.is_empty() { "File root" } else { &gap.selector }), escaped(&gap.measurement), explanation_html(gap)));
}
html.push_str("</details>\n");
if !policy.findings.is_empty() {
html.push_str(
"<details class=\"gap-footer\"><summary>Coverage-check findings</summary><ul>",
);
for finding in &policy.findings {
html.push_str(&format!("<li>{}</li>", escaped(finding)));
}
html.push_str("</ul></details>\n");
}
html.push_str("<p class=\"gap-footer gap-meta\">Coverage uses the latest compatible attempt for each test, including filtered runs. This does not establish that all current tests were measured. Saved measurements and current exception reviews determine the CI verdict.</p>\n</section>\n\n");
html
}
Tests
Input 3: outline src/execution_coverage/check.rs mod[tests]/fn[book_verdict_and_gaps_follow_the_native_policy_and_current_reviews]
- File:
src/execution_coverage/check.rs - Selector:
mod[tests]/fn[book_verdict_and_gaps_follow_the_native_policy_and_current_reviews] - Kind:
fn src/execution_coverage/check.rs:757–946
// {test}`requirements.test-coverage.index.gaps`
// {test}`requirements.test-coverage.index.gaps.summary`
// {test}`requirements.test-coverage.index.gaps.details`
// {test}`requirements.test-coverage.index.gaps.details.initial`
// {test}`requirements.test-coverage.index.gaps.explanations`
// {test}`requirements.test-coverage.index.gaps.accepted`
// {test}`requirements.test-coverage.index.file_map.combined`
// {test}`requirements.test-coverage.index.file_map.combined.measurement`
// {test}`requirements.test-coverage.index.file_map.minimum`
// {test}`requirements.test-coverage.index.file_map.combined.details`
#[test]
fn book_verdict_and_gaps_follow_the_native_policy_and_current_reviews() {
use mdbook_preprocessor::book::{Book, Chapter};
let source = "fn a() {}\n\n/// Invariant fallback, unreachable through the public API.\n// {cite}`habeas:coverage`\nfn b() {}\n";
let temp = fixture(source);
let root = temp.path();
let mut p = process(root, &[(1, 1), (2, 1), (3, 1), (4, 1), (5, 0)], 0);
p.functions.as_mut().unwrap()[0].count = 0;
let path = record(root, "both", 1, "same", vec![p]);
let render = || {
let mut book = Book::new();
book.push_item(Chapter::new(
"Requirements index",
"# Requirements index\n".into(),
"requirements-index.md",
vec![],
));
book::populate_in(
&mut book,
root,
Some(root.join("target")),
Path::new("requirements-index.md"),
)
.unwrap();
book.chapters()
.find(|chapter| chapter.name == "Coverage gaps")
.unwrap()
.content
.clone()
};
let missing = render();
exercise_file_click(&missing);
let permitted_details = regex::Regex::new(r#"<details class="([^"]+)""#).unwrap();
let assert_details = |html: &str| {
for tag in permitted_details.captures_iter(html) {
assert!(
matches!(
&tag[1],
"gap-directory" | "gap-explanation" | "gap-accepted-group" | "gap-footer"
),
"unexpected expandable section: {}",
&tag[1]
);
}
assert!(!html.contains("Test runs and provenance"));
assert!(!html.contains("habeas-coverage-test"));
};
assert_details(&missing);
let unresolved_rows = missing
.split("class=\"gap-obligation-table\"")
.nth(1)
.unwrap()
.split("</tbody></table>")
.next()
.unwrap();
for row in [
"<code>fn[a]</code><br><span class=\"gap-meta\">code.rs:1</span></td><td>zero execution</td>",
"<code>fn[b]</code><br><span class=\"gap-meta\">code.rs:5</span></td><td>zero execution</td>",
] {
assert!(unresolved_rows.contains(row));
}
assert!(!report(root).passed);
assert!(missing.contains("CI would fail"));
assert!(missing.contains("2 unresolved gaps"));
assert!(missing.contains("0 file obligations · 2 function obligations"));
assert!(missing.contains("Missing habeas:coverage proposal"));
assert!(missing.contains("Review missing"));
assert!(missing.contains("Invariant fallback, unreachable through the public API."));
assert!(missing.contains("aria-expanded=\"false\""));
assert!(missing.contains("class=\"gap-detail-row\" id=\"habeas-gap-file-0\" hidden"));
assert!(missing.contains("code.rs:1"));
assert!(missing.contains("code.rs:5"));
reviews(root, json!(true));
let accepted = render();
assert_details(&accepted);
assert!(accepted.contains("1 unresolved gaps"));
assert!(accepted.contains("Documented gaps — 1 accepted exceptions"));
assert!(!accepted.contains("class=\"gap-accepted-group\" open"));
assert!(accepted.contains("fn[b]"));
assert!(accepted.contains("current and accepted"));
let documented = accepted
.split("class=\"gap-accepted-group\"")
.nth(1)
.unwrap()
.split("class=\"gap-footer\"")
.next()
.unwrap();
for field in [
"fn[b]",
"code.rs:5",
"zero execution",
"Invariant fallback, unreachable through the public API.",
"current and accepted",
"Current workspace source notes",
"coverage-reports/files/",
] {
assert!(
documented.contains(field),
"missing documented field: {field}"
);
}
assert!(accepted.contains("80.0%")); // Accepted exceptions add no execution.
reviews(root, json!(false));
let rejected = render();
assert_details(&rejected);
assert!(
rejected.contains("<details class=\"gap-footer\"><summary>Coverage-check findings")
);
assert!(rejected.contains("2 unresolved gaps"));
assert!(rejected.contains("Review not accepted"));
assert!(rejected.contains("determination is false"));
assert!(rejected.contains("Documented gaps — 0 accepted exceptions"));
reviews(root, json!(true));
let mut attempt: Attempt = load(&path.join("attempt.json")).unwrap();
for entry in attempt.processes[0].functions.as_mut().unwrap() {
entry.count = 1;
}
save(&path.join("attempt.json"), &attempt).unwrap();
let covered = render();
assert!(report(root).passed);
assert!(covered.contains("CI would pass"));
assert!(covered.contains("0 unresolved gaps"));
assert!(!covered.contains("data-file=\"code.rs\""));
assert!(covered.contains("Documented gaps — 0 accepted exceptions"));
fs::remove_file(path.join("profile.profraw")).unwrap();
let unavailable = render();
assert!(!report(root).passed);
assert!(unavailable.contains("CI would fail"));
assert!(unavailable.contains("gap counts unavailable"));
assert!(!unavailable.contains("0 unresolved gaps"));
assert!(
!unavailable
.split("</section>")
.next()
.unwrap()
.contains("zero execution")
);
assert!(unavailable.contains("missing or unreadable coverage"));
fs::write(
root.join("code.rs"),
"fn a() {}\n// {cite}`habeas:coverage`\nfn b() {}\n",
)
.unwrap();
record(
root,
"both",
2,
"same",
vec![process(root, &[(1, 1), (2, 1), (3, 1)], 0)],
);
let no_justification = render();
assert!(no_justification.contains("No tracked justification is present."));
// File-level and function-level obligations share the same file control
// and must both expose their source, measurement and explanation.
record(
root,
"both",
3,
"same",
vec![process(root, &[(1, 1), (2, 0), (3, 0)], 0)],
);
let below_target = render();
exercise_file_click(&below_target);
let rows = below_target
.split("class=\"gap-obligation-table\"")
.nth(1)
.unwrap()
.split("</tbody></table>")
.next()
.unwrap();
assert!(
rows.contains("<code>File root</code><br><span class=\"gap-meta\">code.rs:1</span>")
);
assert!(rows.contains("1/3 (33.3%); 80% target; uncovered lines: 2-3"));
assert!(rows.contains("Missing habeas:coverage proposal"));
assert!(rows.contains("<code>fn[a]</code>"));
assert!(rows.contains("<code>fn[b]</code>"));
assert_details(&below_target);
}
Input 4: outline src/execution_coverage/check.rs mod[tests]/fn[overview_exposes_parse_and_discovery_findings_and_used_file_exceptions]
- File:
src/execution_coverage/check.rs - Selector:
mod[tests]/fn[overview_exposes_parse_and_discovery_findings_and_used_file_exceptions] - Kind:
fn src/execution_coverage/check.rs:948–1068
// {test}`requirements.test-coverage.index.gaps`
// {test}`requirements.test-coverage.index.gaps.summary`
// {test}`requirements.test-coverage.index.file_map.combined`
// {test}`requirements.test-coverage.index.gaps.accepted`
#[test]
fn overview_exposes_parse_and_discovery_findings_and_used_file_exceptions() {
use mdbook_preprocessor::book::{Book, Chapter};
let source = "//! :::{cite} habeas:coverage\n//! This platform adapter is unreachable from the public interface.\n//! :::\n\n/// Same invariant protects entry to this adapter.\n// {cite}`habeas:coverage`\nfn adapter() {}\n";
let temp = fixture(source);
let root = temp.path();
let render = || {
let mut book = Book::new();
book.push_item(Chapter::new(
"Requirements index",
"# Requirements index\n".into(),
"requirements-index.md",
vec![],
));
book::populate_in(
&mut book,
root,
Some(root.join("target")),
Path::new("requirements-index.md"),
)
.unwrap();
book.chapters()
.find(|chapter| chapter.name == "Coverage gaps")
.unwrap()
.content
.clone()
};
reviews(root, json!(true));
record(
root,
"adapter",
1,
"same",
vec![process(root, &[(7, 0)], 0)],
);
let accepted = render();
assert!(report(root).passed);
assert!(accepted.contains("CI would pass"));
assert!(accepted.contains("Documented gaps — 2 accepted exceptions"));
assert!(!accepted.contains("data-file=\"code.rs\""));
let documented = accepted
.split("class=\"gap-accepted-group\"")
.nth(1)
.unwrap()
.split("<p class=\"gap-footer")
.next()
.unwrap();
for text in [
"File root",
"code.rs:1",
"code.rs:7",
"fn[adapter]",
"zero execution",
"0/1 (0.0%)",
"This platform adapter is unreachable",
"Same invariant",
"current and accepted",
"Current workspace source notes",
"coverage-reports/files/",
] {
assert!(
documented.contains(text),
"missing documented field: {text}"
);
}
// Measurement still succeeds when a discovered source cannot be parsed.
fs::create_dir_all(root.join("src/nested")).unwrap();
fs::write(root.join("src/nested/driver.rs"), "fn broken(").unwrap();
let mut p = process(root, &[(7, 0)], 0);
p.lines
.insert("src/nested/driver.rs".into(), BTreeMap::from([(1, 0)]));
let attempt = record(root, "adapter", 2, "same", vec![p]);
let run_path = attempt.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = super::super::load(&run_path).unwrap();
run.sources
.insert("src/nested/driver.rs".into(), "fn broken(".into());
save(&run_path, &run).unwrap();
let broken = render();
assert!(!report(root).passed);
assert!(broken.contains("CI would fail"));
assert!(broken.contains("Gap counts incomplete"));
assert!(broken.to_lowercase().contains("cannot parse rust source"));
assert!(broken.contains("Coverage-check findings"));
assert!(!broken.contains("0 unresolved gaps"));
assert!(broken.contains("driver.rs"));
for directory in ["src", "src/nested"] {
let summary = broken
.split(&format!("data-directory=\"{directory}\""))
.nth(1)
.unwrap()
.split("</summary>")
.next()
.unwrap();
assert!(
summary.contains("Gap counts incomplete: 1 established uncovered obligations"),
"{summary}"
);
}
assert!(
report(root)
.text
.contains("src/nested/driver.rs: below 80%"),
"independent measured file threshold must still run after parse failure"
);
fs::remove_file(root.join("src/nested/driver.rs")).unwrap();
git2::Repository::init(root).unwrap();
fs::write(root.join(".git/index"), "not a valid index").unwrap();
let discovery = render();
assert!(!report(root).passed);
assert!(discovery.contains("CI would fail"));
assert!(discovery.contains("cannot discover reference sources"));
assert!(
discovery.contains("Gap counts incomplete")
|| discovery.contains("gap counts unavailable")
);
assert!(!discovery.contains("0 unresolved gaps"));
}
Referenced definitions
Input 2: 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.
:::
Other sources
Input 1: requirements selection requirements.test-coverage.index.gaps.accepted
requirements.test-coverage.index.gaps.accepted:md/requirements/test-coverage.md:455–466
:::{req} index.gaps.accepted
Accepted exceptions actually used to satisfy current file or function
coverage obligations MUST be shown separately in an initially collapsed
documented-gaps section. Each entry MUST identify its source item and source
location, its uncovered measurement, its tracked justification, and its current
accepted review state, using current source notes under
{cite}`requirements.test-coverage.index.file_map.notes.current`.
Accepted exceptions MUST NOT increase reported execution-coverage percentages.
Citations on items whose measured coverage already satisfies their obligations
MUST NOT be listed as active gaps.
:::