requirements.test-coverage.index.file_map.combined.details
Requirements index · View definition
Requirement
The combined coverage overview MUST restrict its expandable details to coverage gaps, explanation status, and coverage-check findings. It MUST NOT include a test-run provenance table or embed per-test coverage data.
Rationale
Obligations in requirements.test-coverage.index.file_map.combined.details
- Expandable details are limited to coverage gaps, explanation status and coverage-check findings.
- No test-run provenance table appears.
- No per-test coverage data is embedded.
Mapping to tests
- Obligation 1.
src/execution_coverage/check.rs#mod[tests]/fn[book_verdict_and_gaps_follow_the_native_policy_and_current_reviews]defines theassert_detailsclosure.- The closure scans every
<details class="…">in the rendered “Coverage gaps” chapter. It requires each class to be one ofgap-directory,gap-explanation,gap-accepted-grouporgap-footer. The implementation emits these classes inGapDirectory::render,explanation_htmlandgap_map. They are the directory grouping of gaps, explanation status, documented accepted gaps and coverage-check findings. - The test applies the closure in several states: missing review, accepted, rejected, and below-target with file-level and function-level obligations. It also asserts that the “Coverage-check findings” footer renders in the rejected state. Any other expandable section class would fail the test.
- The closure scans every
- Obligation 2.
assert_detailsasserts that “Test runs and provenance” is absent in every state.src/execution_coverage/book.rs#mod[tests]/fn[gaps_union_process_locations_and_omit_per_test_reports]asserts the same on the rendered combined index. That test also asserts that nobinary / oneper-test label appears. - Obligation 3. Both marked tests assert that
habeas-coverage-testis absent. Thebook.rstest also asserts thatbinary / one(a per-test label) is absent. It checks that every chapter after the index is a “File notes:” chapter, so no per-test chapters or sections exist. Its fixture includes multi-process, multi-test data, so embedded per-test data would have a chance to appear.
Residual observations (not gaps)
- The
<details class=…>regex does not match a class-less<details>. The checks are only as strong as the markers they look for. The obligations are still exercised with realistic fixtures and negative assertions, which is adequate for a MUST NOT of this kind. gaps_omit_test_data_and_preserve_saved_profiles_and_sourcesalso checks for absent test data, includinghabeas-coverage-test,Test runs and provenanceandapplication/json. It carries no{test}reference to this requirement. That is a marking omission, not an assertion gap, because the marked tests already cover the obligations.
No acknowledged or unacknowledged gaps remain.
Inputs
Tests
Input 2: outline src/execution_coverage/book.rs mod[tests]/fn[gaps_union_process_locations_and_omit_per_test_reports]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[gaps_union_process_locations_and_omit_per_test_reports] - Kind:
fn src/execution_coverage/book.rs:1116–1205
// {test}`requirements.test-coverage.index.file_map`
// {test}`requirements.test-coverage.index.file_map.table`
// {test}`requirements.test-coverage.index.file_map.combined`
// {test}`requirements.test-coverage.index.file_map.test`
// {test}`requirements.test-coverage.index.summary`
// {test}`requirements.test-coverage.index.file_map.combined.details`
// {test}`requirements.test-coverage.index.file_map.notes`
// {test}`requirements.test-coverage.index.details`
#[test]
fn gaps_union_process_locations_and_omit_per_test_reports() {
let (temp, mut book) = fixture();
let root = temp.path();
fs::write(
root.join("code.rs"),
"fn one() {}\nfn two() {}\nfn three() {}\n// not instrumented\n",
)
.unwrap();
fs::write(root.join("zero.rs"), "fn zero() {}\n").unwrap();
fs::write(root.join("unmeasured.rs"), "// no instrumentation\n").unwrap();
fs::write(root.join("executable.rs"), "fn unmeasured() {}\n").unwrap();
let path = record(root, "one", 1, "a", &[(1, 2), (2, 0)]);
let run_path = path.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&run_path).unwrap();
for file in ["zero.rs", "unmeasured.rs", "executable.rs"] {
run.sources
.insert(file.into(), fs::read_to_string(root.join(file)).unwrap());
}
save(&run_path, &run).unwrap();
let mut attempt: Attempt = load(&path.join("attempt.json")).unwrap();
attempt.processes[0]
.lines
.insert("zero.rs".into(), BTreeMap::from([(1, 0)]));
fs::write(path.join("2-child.profraw"), "child profile fixture").unwrap();
attempt.processes.push(Process {
functions: Some(vec![]),
pid: 2,
profiles: vec!["2-child.profraw".into()],
diagnostic: None,
lines: BTreeMap::from([("code.rs".into(), BTreeMap::from([(1, 0), (3, u64::MAX)]))]),
});
save(&path.join("attempt.json"), &attempt).unwrap();
populate(&mut book, root).unwrap();
let index = &book.chapters().next().unwrap().content;
assert!(index.contains("Line coverage: **2/4 (50.0%)**"));
let map = map_html(index);
assert!(file_card(map, "code.rs").contains("2/3 instrumented lines covered"));
assert!(file_card(map, "code.rs").contains("66.7%"));
assert!(file_card(map, "code.rs").contains("--gap-covered: 66.666667%"));
let notes_path = super::super::notes::path(Path::new("reports/coverage.md"), "code.rs");
let href = crate::chapter_href(Path::new("reports/coverage.md"), ¬es_path, None);
assert!(file_card(map, "code.rs").contains(&format!("href=\"{href}\"")));
let notes = book
.chapters()
.find(|chapter| chapter.path.as_ref() == Some(¬es_path))
.unwrap();
assert!(notes.content.contains("File: <code>code.rs</code>"));
assert!(file_card(map, "zero.rs").contains("0.0%"));
assert!(file_card(map, "zero.rs").contains("--gap-covered: 0.000000%"));
assert!(
!map.contains("data-file=\"unmeasured.rs\""),
"a non-executable file has no gap"
);
let unmeasured = file_card(map, "executable.rs")
.split("</tr>")
.next()
.unwrap();
assert!(unmeasured.contains("not measured"));
assert!(!unmeasured.contains('%'));
assert!(!unmeasured.contains("gap-coverage-bar"));
assert!(map.contains("<th>File</th><th>Coverage</th>"));
assert_eq!(
map.matches("class=\"gap-file-row habeas-coverage-file\"")
.count(),
3
);
let mut html = String::new();
pulldown_cmark::html::push_html(
&mut html,
pulldown_cmark::Parser::new_ext(index, pulldown_cmark::Options::all()),
);
assert!(html.contains("Unresolved coverage gaps"));
assert!(!html.contains("habeas-coverage-test"));
assert!(!html.contains("Test runs and provenance"));
assert!(!html.contains("binary / one"));
assert!(
book.chapters()
.skip(1)
.all(|chapter| chapter.name.starts_with("File notes:"))
);
}
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);
}
Other sources
Input 1: requirements selection requirements.test-coverage.index.file_map.combined.details
requirements.test-coverage.index.file_map.combined.details:md/requirements/test-coverage.md:401–405
:::{req} index.file_map.combined.details
The combined coverage overview MUST restrict its expandable details to coverage
gaps, explanation status, and coverage-check findings. It MUST NOT include a
test-run provenance table or embed per-test coverage data.
:::
Input 4: outline src/execution_coverage/book.rs impl[GapDirectory<'_>]/fn[render]
- File:
src/execution_coverage/book.rs - Selector:
impl[GapDirectory<'_>]/fn[render] - Kind:
fn src/execution_coverage/book.rs:87–182
fn render(
&self,
html: &mut String,
folder: &str,
policy: &super::check::PolicyReport,
index: &Path,
next: &mut usize,
) {
if !self.files.is_empty() {
html.push_str("<table class=\"gap-file-table\"><colgroup><col><col><col><col></colgroup><thead><tr><th>File</th><th>Coverage</th><th>Uncovered obligations</th><th>Explanation</th></tr></thead><tbody>\n");
for file in &self.files {
let id = format!("habeas-gap-file-{}", *next);
*next += 1;
let gaps: Vec<_> = file
.obligations
.iter()
.filter(|gap| !gap.accepted())
.collect();
let threshold = gaps.iter().any(|gap| gap.selector.is_empty());
let functions = gaps.len() - usize::from(threshold);
let undocumented = gaps.iter().filter(|gap| gap.exception.is_none()).count();
let description = match (threshold, functions) {
(true, 0) => "file below target".to_owned(),
(true, n) => format!("file + {n} functions"),
(false, 1) => "1 function".to_owned(),
(false, n) => format!("{n} functions"),
};
let explanation = if undocumented == gaps.len() {
"Missing"
} else {
"Review needed"
};
let percentage = if file.total == 0 {
"not measured".to_owned()
} else {
percentage_label(file.covered, file.total)
};
let indicator = if file.total == 0 {
String::new()
} else {
format!(
"<span class=\"gap-coverage-bar\" aria-hidden=\"true\" style=\"--gap-covered: {:.6}%\"></span>",
100.0 * file.covered as f64 / file.total as f64
)
};
html.push_str(&format!("<tr class=\"gap-file-row habeas-coverage-file\" data-file=\"{}\" data-status=\"{}\"><td><button class=\"gap-file-button\" aria-expanded=\"false\" aria-controls=\"{id}\" onclick=\"const row=document.getElementById(this.getAttribute('aria-controls'));row.hidden=!row.hidden;this.setAttribute('aria-expanded',String(!row.hidden));this.querySelector('.gap-chevron').textContent=row.hidden?'▸':'▾'\"><span class=\"gap-chevron\" aria-hidden=\"true\">▸</span><code>{}</code></button></td><td class=\"gap-percentage\">{percentage}{indicator}</td><td>{description}</td><td class=\"gap-unresolved\">{explanation}</td></tr>\n", escaped(&file.file), if file.total == 0 { "not measured" } else { "measured" }, escaped(&file.file)));
let notes =
crate::chapter_href(index, &super::notes::path(index, &file.file), None);
html.push_str(&format!("<tr class=\"gap-detail-row\" id=\"{id}\" hidden><td colspan=\"4\"><p class=\"gap-detail-title\"><code>{}</code> · {}/{} instrumented lines covered · <a href=\"{}\">Current source notes</a></p><table class=\"gap-obligation-table\"><thead><tr><th>Source item</th><th>Measurement</th><th>Explanation</th></tr></thead><tbody>", escaped(&file.file), file.covered, file.total, escaped(¬es)));
for gap in gaps {
html.push_str(&format!("<tr><td><code>{}</code><br><span class=\"gap-meta\">{}:{}</span></td><td>{}</td><td>{}</td></tr>\n", escaped(if gap.selector.is_empty() { "File root" } else { &gap.selector }), escaped(&file.file), gap.line, escaped(&gap.measurement), explanation_html(gap)));
}
html.push_str("</tbody></table></td></tr>\n");
}
html.push_str("</tbody></table>\n");
}
for (name, directory) in &self.directories {
let path = if folder.is_empty() {
name.clone()
} else {
format!("{folder}/{name}")
};
let prefix = format!("{path}/");
let minimum = policy
.files
.iter()
.filter(|file| file.file.starts_with(&prefix) && file.total > 0)
.min_by(|a, b| {
((a.covered as u128) * (b.total as u128))
.cmp(&((b.covered as u128) * (a.total as u128)))
});
let min = minimum.map_or_else(|| "No measured files".to_owned(), |file| format!("Minimum measured file coverage: <strong data-min-covered=\"{}\" data-min-instrumented=\"{}\">{}</strong>", file.covered, file.total, percentage_label(file.covered, file.total)));
let not_measured = policy
.files
.iter()
.filter(|file| {
file.file.starts_with(&prefix)
&& file.total == 0
&& file.obligations.iter().any(|gap| !gap.accepted())
})
.count();
let counts = if policy.counts_complete {
format!("{} uncovered obligations", directory.count())
} else if policy.measured {
format!(
"Gap counts incomplete: {} established uncovered obligations",
directory.count()
)
} else {
"Gap counts unavailable".to_owned()
};
html.push_str(&format!("<details class=\"gap-directory\" data-directory=\"{}\" open><summary><code>{}/</code><span class=\"gap-meta\">{min} · {counts}{} </span></summary>\n", escaped(&path), escaped(&path), if not_measured > 0 { format!(" · {not_measured} not measured") } else { String::new() }));
directory.render(html, &path, policy, index, next);
html.push_str("</details>\n");
}
}
Input 5: outline src/execution_coverage/book.rs fn[explanation_html]
- File:
src/execution_coverage/book.rs - Selector:
fn[explanation_html] - Kind:
fn src/execution_coverage/book.rs:185–211
// {impl}`requirements.test-coverage.index.gaps.explanations`
fn explanation_html(gap: &super::check::Obligation) -> String {
let Some(exception) = &gap.exception else {
return "<span class=\"gap-unresolved\">Missing habeas:coverage proposal</span>".into();
};
let state = if exception.accepted {
"Current and accepted"
} else if exception.review_missing {
"Review missing"
} else {
"Review not accepted"
};
let mut html = format!("<details class=\"gap-explanation\"><summary>{state}</summary>");
if exception.justification.trim().is_empty() {
html.push_str("<p>No tracked justification is present.</p>");
} else {
html.push_str(&format!(
"<pre>{}</pre>",
escaped(&crate::redaction::redact_text(&exception.justification))
));
}
for finding in &exception.findings {
html.push_str(&format!("<p>{}</p>", escaped(finding)));
}
html.push_str("</details>");
html
}
Input 6: 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
}
Input 7: outline src/execution_coverage/book.rs mod[tests]/fn[gaps_omit_test_data_and_preserve_saved_profiles_and_sources]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[gaps_omit_test_data_and_preserve_saved_profiles_and_sources] - Kind:
fn src/execution_coverage/book.rs:1987–2144
// {test}`requirements.test-coverage.index.summary`
// {test}`requirements.test-coverage.index.details`
// {test}`requirements.test-coverage.processes.reports`
#[test]
fn gaps_omit_test_data_and_preserve_saved_profiles_and_sources() {
let (temp, book) = fixture();
let root = temp.path();
fs::write(root.join("passing.rs"), "fn passing() {}\n").unwrap();
let first = record(root, "one", 100, "a", &[(1, 1), (2, 0)]);
fs::write(first.join("2-2.profraw"), "child profile fixture").unwrap();
let mut attempt: Attempt = load(&first.join("attempt.json")).unwrap();
attempt.processes.push(Process {
functions: Some(vec![]),
pid: 2,
profiles: vec!["2-2.profraw".into()],
lines: BTreeMap::from([("code.rs".into(), BTreeMap::from([(1, 0), (2, 7)]))]),
diagnostic: None,
});
// A passing file must not appear in the gaps table.
attempt.processes[0]
.lines
.insert("passing.rs".into(), BTreeMap::from([(1, 1)]));
attempt.processes[0]
.functions
.as_mut()
.unwrap()
.push(super::super::FunctionExecution {
file: "passing.rs".into(),
line: 1,
column: 1,
count: 1,
});
save(&first.join("attempt.json"), &attempt).unwrap();
let run_path = first.parent().unwrap().parent().unwrap().join("run.json");
let mut run: Run = load(&run_path).unwrap();
run.sources
.insert("passing.rs".into(), "fn passing() {}\n".into());
save(&run_path, &run).unwrap();
record(root, "two", 200, "a", &[(1, 1), (2, 0)]);
let captured_attempt = fs::read(first.join("attempt.json")).unwrap();
let captured_run = fs::read(&run_path).unwrap();
let mut combined = book.clone();
populate(&mut combined, root).unwrap();
let index = combined.chapters().next().unwrap();
assert!(index.content.contains("3/3 (100.0%)"));
assert!(
index
.content
.contains("not establish that all current tests were measured")
);
assert!(!map_html(&index.content).contains("data-file=\"passing.rs\""));
assert!(
combined
.chapters()
.all(|chapter| chapter.name != "File notes: passing.rs")
);
for chapter in combined.chapters() {
for omitted in [
"Test process coverage",
"Captured source",
"habeas-coverage-test",
"Test runs and provenance",
"application/json",
"habeasRenderCoverage",
"binary / one",
"binary / two",
"fn passing() {}",
] {
assert!(
!chapter.content.contains(omitted),
"report includes {omitted}"
);
}
assert!(!chapter.name.starts_with("binary /"));
assert!(
!chapter
.path
.as_ref()
.unwrap()
.to_string_lossy()
.ends_with("-source.md")
);
assert!(chapter.name == "Coverage gaps" || chapter.name.starts_with("File notes:"));
}
fs::write(root.join("code.rs"), "rebuilt source\n").unwrap();
let mut historical = book;
populate(&mut historical, root).unwrap();
assert!(
historical
.chapters()
.next()
.unwrap()
.content
.contains("Coverage unavailable")
);
assert_eq!(
fs::read(first.join("attempt.json")).unwrap(),
captured_attempt
);
assert_eq!(fs::read(&run_path).unwrap(), captured_run);
assert_eq!(
fs::read_to_string(first.join("1-1.profraw")).unwrap(),
"retained profile fixture"
);
assert_eq!(
fs::read_to_string(first.join("2-2.profraw")).unwrap(),
"child profile fixture"
);
// Archived reports use the saved source, even though freshness excludes
// these attempts from the current workspace's gaps report.
let saved = load_saved(root, Some(root.join("target")));
let archived = saved
.records
.iter()
.find(|record| record.attempt.test == "one")
.unwrap();
assert!(!archived.fresh);
let captured_lines = |locations: BTreeMap<(String, u32), u64>| {
locations
.into_iter()
.map(|((file, line), count)| {
let source_line = archived.run.sources[&file]
.lines()
.nth(line as usize - 1)
.unwrap();
((file, line), (source_line.to_owned(), count))
})
.collect::<BTreeMap<_, _>>()
};
let individual = |process: &Process| {
captured_lines(
process
.lines
.iter()
.flat_map(|(file, lines)| {
lines
.iter()
.map(move |(&line, &count)| ((file.clone(), line), count))
})
.collect(),
)
};
let parent = individual(&archived.attempt.processes[0]);
let child = individual(&archived.attempt.processes[1]);
let combined = captured_lines(union(std::iter::once(archived)));
assert_eq!(parent[&("code.rs".into(), 1)], ("fn one() {}".into(), 1));
assert_eq!(parent[&("code.rs".into(), 2)], ("fn two() {}".into(), 0));
assert_eq!(child[&("code.rs".into(), 1)], ("fn one() {}".into(), 0));
assert_eq!(child[&("code.rs".into(), 2)], ("fn two() {}".into(), 7));
assert_eq!(combined[&("code.rs".into(), 2)], ("fn two() {}".into(), 7));
assert_eq!(parent.values().filter(|(_, count)| *count > 0).count(), 2);
assert_eq!(combined.values().filter(|(_, count)| *count > 0).count(), 3);
assert!(
combined
.values()
.all(|(source, _)| !source.contains("rebuilt source"))
);
}