requirements.test-coverage.index.source
Requirements index · View definition
Requirement
habeas mdbookMUST NOT require a separate authored coverage chapter or{coverage-index}directive, or use such a directive to control generation of the subchapter under. The generated coverage subchapter MUST have no authored source file or edit target.
Rationale
The tests adequately cover requirements.test-coverage.index.source.
Obligations derived from the text
- Generation must not require an authored coverage chapter or a
{coverage-index}directive. - A
{coverage-index}directive must not control generation or placement of the subchapter underrequirements.test-coverage.index. - The generated coverage subchapter must have no authored source file or edit target.
Test mapping
src/execution_coverage/book.rs#mod[tests]/fn[authored_coverage_directives_do_not_control_generated_placement] is marked {test} for the subject. It runs populate_in on three inputs:
- a plain authored chapter with no directive;
- a chapter with one
:::{coverage-index}directive; - a chapter with two such directives.
For each input it asserts:
- Exactly one chapter named “Coverage gaps” exists, so the directive neither suppresses generation nor causes duplicates (obligations 1 and 2).
- That chapter has path
reports/coverage.mdandparent_names == ["Requirements index"]. It is also the first sub-item of the requirements index chapter, not of the chapter that carried the directive, so the directive does not control placement (obligation 2). source_pathisNoneandmd/reports/coverage.mddoes not exist on disk, so there is no authored source file or edit target (obligation 3).- The authored chapter’s content is unchanged and it has no sub-items, so no generation attaches to the directive-bearing chapter.
generated_reports_inherit_the_requirements_index_hierarchy is also marked {test} for the subject. It runs with the requirements index both numbered and unnumbered, and with no authored coverage chapter or directive, so generation succeeds without them (obligation 1). It asserts coverage.source_path.is_none() for the generated chapter and for each generated sub-page, and it asserts that the generated content does not contain :::{coverage-index}. That covers obligation 3 for the whole generated subtree.
Gaps considered
- A directive inside the requirements index chapter itself is not tested. The text does not single this case out, and the tested directive placements would already fail an implementation that let directives steer generation.
- I found no unacknowledged gap and no marking gap.
Inputs
Tests
Input 3: outline src/execution_coverage/book.rs mod[tests]/fn[generated_reports_inherit_the_requirements_index_hierarchy]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[generated_reports_inherit_the_requirements_index_hierarchy] - Kind:
fn src/execution_coverage/book.rs:870–970
// {test}`requirements.test-coverage.index`
// {test}`requirements.test-coverage.index.navigation`
// {test}`requirements.test-coverage.index.source`
// {test}`requirements.test-coverage.index.guidance`
// {test}`requirements.test-coverage.check.guidance`
// {test}`requirements.test-coverage.check.exceptions.setup`
// {test}`requirements.test-coverage.index.details`
#[test]
fn generated_reports_inherit_the_requirements_index_hierarchy() {
for number in [Some(SectionNumber::new(vec![3, 2])), None] {
let (temp, mut book) = fixture();
let BookItem::Chapter(parent) = &mut book.items[0] else {
unreachable!()
};
parent.path = Some("reports.md".into());
parent.name = "Requirements index".into();
parent.content = "# Requirements index\n".into();
parent.parent_names = vec!["Reports".into()];
parent.number = number.clone();
parent.sub_items.push(BookItem::Chapter(Chapter::new(
"Guide",
"# Guide\n".into(),
"reports/guide.md",
vec![],
)));
record(temp.path(), "one", 1, "a", &[(1, 1)]);
// Build fixture configuration before invoking the production path.
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();
super::populate_in(
&mut book,
temp.path(),
Some(temp.path().join("target")),
Path::new("reports.md"),
)
.unwrap();
let BookItem::Chapter(parent) = &book.items[0] else {
unreachable!()
};
assert!(
parent
.content
.contains("[Coverage gaps](reports/coverage.html)")
);
assert_eq!(parent.number, number);
let BookItem::Chapter(coverage) = &parent.sub_items[0] else {
unreachable!()
};
assert_eq!(coverage.parent_names, ["Reports", "Requirements index"]);
assert_eq!(
coverage.path.as_deref(),
Some(Path::new("reports/coverage.md"))
);
assert!(coverage.source_path.is_none());
assert_eq!(
coverage.number,
number.as_ref().map(|_| SectionNumber::new(vec![3, 2, 1]))
);
assert_eq!(parent.sub_items.len(), 2);
for (offset, item) in coverage.sub_items.iter().enumerate() {
let BookItem::Chapter(page) = item else {
unreachable!()
};
assert_eq!(
page.parent_names,
["Reports", "Requirements index", "Coverage gaps"]
);
assert_eq!(
page.number,
number
.as_ref()
.map(|_| SectionNumber::new(vec![3, 2, 1, offset as u32 + 1]))
);
assert!(page.source_path.is_none());
assert!(page.content.contains("../coverage.html"));
}
for guidance in [
"habeas test",
"habeas coverage -- --workspace",
"habeas coverage-check",
"static validation test needs no prior coverage",
"80%",
"habeas:coverage",
"current accepted review",
"No project declaration or special configuration",
"after it succeeds,\nrun `habeas coverage-check` as a separate step",
"`habeas test` collects coverage for the whole workspace,\nthen checks it",
"substantive prose justification",
"fenced commentary or a Rust doc comment",
"citation review with `habeas author`",
"Ordinary partly covered functions\nneed no exception when their file meets its target",
] {
assert!(
coverage.content.contains(guidance),
"missing generated guidance: {guidance}"
);
}
assert!(!coverage.content.contains(":::{coverage-index}"));
}
}
Input 4: outline src/execution_coverage/book.rs mod[tests]/fn[authored_coverage_directives_do_not_control_generated_placement]
- File:
src/execution_coverage/book.rs - Selector:
mod[tests]/fn[authored_coverage_directives_do_not_control_generated_placement] - Kind:
fn src/execution_coverage/book.rs:972–1028
// {test}`requirements.test-coverage.index.source`
#[test]
fn authored_coverage_directives_do_not_control_generated_placement() {
for content in [
"A plain chapter.\n",
":::{coverage-index}\n:::\n",
":::{coverage-index}\n:::\n\n:::{coverage-index}\n:::\n",
] {
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();
let BookItem::Chapter(parent) = &mut book.items[0] else {
unreachable!()
};
parent.name = "Requirements index".into();
parent.content = "# Requirements index\n".into();
parent.path = Some("reports.md".into());
book.push_item(Chapter::new(
"Authored notes",
content.into(),
"elsewhere.md",
vec![],
));
super::populate_in(
&mut book,
root,
Some(root.join("target")),
Path::new("reports.md"),
)
.unwrap();
let coverage = book
.chapters()
.filter(|chapter| chapter.name == "Coverage gaps")
.collect::<Vec<_>>();
assert_eq!(coverage.len(), 1);
assert_eq!(
coverage[0].path.as_deref(),
Some(Path::new("reports/coverage.md"))
);
assert_eq!(coverage[0].parent_names, ["Requirements index"]);
assert!(coverage[0].source_path.is_none());
assert!(!root.join("md/reports/coverage.md").exists());
let BookItem::Chapter(parent) = &book.items[0] else {
unreachable!()
};
assert!(
matches!(&parent.sub_items[0], BookItem::Chapter(child) if child.name == "Coverage gaps")
);
let BookItem::Chapter(authored) = &book.items[1] else {
unreachable!()
};
assert_eq!(authored.content, content);
assert!(authored.sub_items.is_empty());
}
}
Referenced definitions
Input 2: requirements selection requirements.test-coverage.index
requirements.test-coverage.index:md/requirements/test-coverage.md:158–163
:::{req} index
`habeas mdbook` MUST automatically generate exactly one execution-coverage
subchapter under the requirements index of
{cite}`requirements.index.chapter`, whether that requirements index is
explicitly placed or automatically generated.
:::
Other sources
Input 1: requirements selection requirements.test-coverage.index.source
requirements.test-coverage.index.source:md/requirements/test-coverage.md:170–176
:::{req} index.source
`habeas mdbook` MUST NOT require a separate authored coverage chapter or
`{coverage-index}` directive, or use such a directive to control generation
of the subchapter under {cite}`requirements.test-coverage.index`.
The generated coverage subchapter MUST have no authored source file or edit
target.
:::