requirements.test-coverage.index.gaps.details.initial
Requirements index · View definition
Requirement
Per-file uncovered obligations under
MUST be collapsed initially.
Rationale
The subject has one obligation. Per-file uncovered obligations in the combined gaps overview MUST start collapsed.
The marked test is src/execution_coverage/check.rs#mod[tests]/fn[book_verdict_and_gaps_follow_the_native_policy_and_current_reviews]. It renders the real “Coverage gaps” chapter through book::populate_in and asserts the initial state in the generated HTML:
- The file control has
aria-expanded="false". - The detail row carries the
hiddenattribute:class="gap-detail-row" id="habeas-gap-file-0" hidden.
Both assertions are made on the rendered output. A renderer that emitted the rows expanded would fail them.
The test also covers the neighbouring behaviour. exercise_file_click pulls the real handler, aria-controls and the row IDs out of the HTML, then runs the handler in Node. It checks that a click unhides the controlled row and flips aria-expanded and the chevron. This confirms the collapsed state belongs to the generated controls and rows.
The test covers both kinds of obligation behind that file control:
- Function obligations (
fn[a],fn[b]) are checked in the first render. - The file-level obligation (
File root) is checked in thebelow_targetrender, which callsexercise_file_clickagain.
assert_details checks every render for unexpected <details> sections. The accepted-exceptions group is checked not to be open.
Limitation. Only one file appears in the gaps table. No scenario shows that several files are each collapsed. The requirement does not distinguish a first file from later ones, so I don’t treat this as a gap.
The expected results match the requirement, and the assertions enforce them. I found no adequacy gap and no acknowledgments are needed.
Inputs
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);
}
Referenced definitions
Input 2: requirements selection requirements.test-coverage.index.gaps.details
requirements.test-coverage.index.gaps.details:md/requirements/test-coverage.md:429–434
:::{req} index.gaps.details
In the combined gaps overview, clicking a listed file MUST expand or collapse
its uncovered obligations in place. Each expanded file MUST show each
obligation's source item and source location, measurement, and explanation
status.
:::
Other sources
Input 1: requirements selection requirements.test-coverage.index.gaps.details.initial
requirements.test-coverage.index.gaps.details.initial:md/requirements/test-coverage.md:436–440
:::{req} index.gaps.details.initial
Per-file uncovered obligations under
{cite}`requirements.test-coverage.index.gaps.details` MUST be collapsed
initially.
:::
Input 4: outline src/execution_coverage/check.rs mod[tests]/fn[exercise_file_click]
- File:
src/execution_coverage/check.rs - Selector:
mod[tests]/fn[exercise_file_click] - Kind:
fn src/execution_coverage/check.rs:701–755
// Execute the handler emitted by the renderer, using its actual controls
// and row IDs. Node is already part of this repository's CI tooling.
// {cite}`habeas:util`
fn exercise_file_click(html: &str) {
let button = html
.split("class=\"gap-file-button\"")
.nth(1)
.unwrap()
.split('>')
.next()
.unwrap();
let attribute = |name: &str| {
button
.split(&format!("{name}=\""))
.nth(1)
.unwrap()
.split('"')
.next()
.unwrap()
.to_owned()
};
let ids = html
.split("class=\"gap-detail-row\" id=\"")
.skip(1)
.map(|part| part.split('"').next().unwrap().to_owned())
.collect::<Vec<_>>();
let data = json!({"handler": attribute("onclick"), "controls": attribute("aria-controls"), "ids": ids});
let output = std::process::Command::new("node").arg("-e").arg(r#"
const assert = require('node:assert/strict');
const vm = require('node:vm');
const data = JSON.parse(process.argv[1]);
const rows = new Map(data.ids.map(id => [id, {hidden: true}]));
const attributes = {'aria-controls': data.controls, 'aria-expanded': 'false'};
const chevron = {textContent: '▸'};
const button = {getAttribute: name => attributes[name],
setAttribute: (name, value) => {attributes[name] = value},
querySelector: name => {assert.equal(name, '.gap-chevron'); return chevron}};
const document = {getElementById: id => rows.get(id)};
const click = () => vm.runInNewContext('(function(){' + data.handler + '}).call(button)', {button, document});
assert.ok(rows.has(data.controls), 'controls must identify a generated row');
click();
assert.equal(rows.get(data.controls).hidden, false);
assert.equal(attributes['aria-expanded'], 'true');
assert.equal(chevron.textContent, '▾');
click();
assert.equal(rows.get(data.controls).hidden, true);
assert.equal(attributes['aria-expanded'], 'false');
assert.equal(chevron.textContent, '▸');
"#).arg(data.to_string()).output().expect("Node is required for coverage UI tests");
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
}