requirements.test-coverage.setup
Requirements index · View definition
Requirement
In addition to
,
habeas setupMUST enable the automatic coverage subchapter ofwithout creating a separate coverage source chapter, adding a coverage entry to
SUMMARY.md, or requiring a coverage source directive. Setup MUST preserve existing authored chapter contents andSUMMARY.md.
Rationale
Verdict: the reviewed tests adequately check requirements.test-coverage.setup.
Obligations derived from the text
- Setup enables the automatic coverage subchapter. In
src/setup.rs#fn[run]this means writing the nextest coverage configuration fromhabeas::execution_coverage::configure. - Setup does not create a separate coverage source chapter.
- Setup does not add a coverage entry to
SUMMARY.md. - Setup does not require a coverage source directive.
- Setup preserves existing authored chapter contents and
SUMMARY.md. - The
requirements.cli.setupbehaviour is cited context. I did not reassess it.
Mapping to tests
- Obligation 1:
tests/setup.rs#fn[coverage_setup_is_idempotent_and_hook_needs_no_coverage_chapter]runs setup and asserts that.config/nextest.tomlexists and containscoverage-process.- A second run leaves the config byte-identical.
src/execution_coverage/configuration.rs#mod[tests]/fn[native_settings_inheritance_and_precedence]checks that the generated config passescheck. It also checks that existing settings (retries,setup-scriptsand a user script) are preserved, and that a conflicting wrapper script is rejected.- The generated subchapter itself is covered by the separate
requirements.test-coverage.indextests, which are out of scope here.
- Obligation 2: both setup tests assert that
md/test-coverage.mddoes not exist after setup. This holds with a default fixture, a custom{coverage-index}chapter, and unlinked or fenced{coverage-index}text. - Obligation 3:
md/SUMMARY.mdis asserted unchanged after the first and second setup runs.md/SUMMARY.mdis asserted unchanged whenmd/test-coverage.mdalready exists.md/SUMMARY.mdis asserted not to containtest-coverage.mdin the unlinked-directive scenario.
- Obligation 4: after setup, the session-start hook gives no setup advice (
advises_setupis false) in the default fixture. The same holds with a bare# Summaryand no coverage directive, and whenmd/custom.mdholds the{coverage-index}directive. The hook does advise setup when the config is removed or conflicting, so the check is meaningful. The hook also does not repair the config. - Obligation 5:
- User content in
md/test-coverage.mdis asserted preserved. md/custom.mdkeeps its custom report text.- A user-edited
SUMMARY.mdis preserved. - A conflicting nextest config is left untouched.
- User content in
Gaps: none. The only weak spot is that the config check in the setup test is a contains("coverage-process") assertion. The native configuration test validates the full structure, so the weakness is covered. No acknowledgments ({fixme}) apply.
Inputs
Implementation
Input 7: outline src/setup.rs fn[run]
- File:
src/setup.rs - Selector:
fn[run] - Kind:
fn src/setup.rs:85–183
// {impl}`requirements.test-coverage.setup`
// {impl}`requirements.cli.mdbook`
pub(crate) fn run(local_crate: Option<&Path>) -> Result<(), Box<dyn Error>> {
let root = project_root()?;
let book_path = root.join("book.toml");
let mut book: DocumentMut = fs::read_to_string(&book_path)?.parse()?;
// {impl}`requirements.cli.setup_project`
let source = book_source(&book)?.to_owned();
let source_path = Path::new(&source);
if source.is_empty()
|| !source_path
.components()
.all(|part| matches!(part, Component::Normal(_) | Component::CurDir))
{
return Err("book.src must be a directory inside this project".into());
}
let source_dir = root.join(source_path);
if !source_dir.join("SUMMARY.md").is_file() {
return Err(format!("cannot find mdBook SUMMARY.md in {}", source_dir.display()).into());
}
let (nextest_path, nextest_source) = habeas::execution_coverage::configure(&root)?;
let css_path = source_dir.join("habeas.css");
let test_path = root.join("tests/habeas.rs");
for (path, desired) in [(&css_path, BADGE_CSS), (&test_path, TEST_SOURCE)] {
if path.exists() && fs::read_to_string(path)? != desired {
return Err(format!("{} already exists with different content", path.display()).into());
}
}
book["preprocessor"]["habeas"]["command"] = value("habeas mdbook");
let mut renderers = Array::new();
renderers.push("html");
book["preprocessor"]["habeas"]["renderers"] = value(renderers);
let css_relative = css_relative(source_path);
// {impl}`requirements.cli.setup_css`
let additional_css = &mut book["output"]["html"]["additional-css"];
if additional_css.is_none() {
let mut css = Array::new();
css.push(css_relative.as_str());
*additional_css = value(css);
} else if let Some(css) = additional_css.as_array_mut() {
if !css
.iter()
.any(|existing| existing.as_str() == Some(css_relative.as_str()))
{
css.push(css_relative.as_str());
}
} else {
return Err("output.html.additional-css must be an array".into());
}
// {impl}`requirements.index.detail_pages`
let fold = &mut book["output"]["html"]["fold"];
if fold.is_none() {
let mut table = Table::new();
table.insert("enable", value(true));
*fold = Item::Table(table);
} else if let Some(fold) = fold.as_table_like_mut() {
if fold.get("enable").is_none() {
fold.insert("enable", value(true));
}
} else {
return Err("output.html.fold must be a table".into());
}
let manifest_path = root.join("Cargo.toml");
let manifest: DocumentMut = fs::read_to_string(&manifest_path)?.parse()?;
let has_dev_dependency = has_habeas_dev_dependency(&manifest);
if !has_dev_dependency {
let mut command = Command::new("cargo");
command
.arg("add")
.arg("--dev")
.arg("habeas")
.arg("--manifest-path")
.arg(&manifest_path);
if let Some(local_crate) = local_crate {
command.arg("--path").arg(fs::canonicalize(local_crate)?);
}
let output = command.current_dir(&root).output()?;
if !output.status.success() {
return Err(format!(
"cargo add habeas --dev failed:\n{}",
String::from_utf8_lossy(&output.stderr)
)
.into());
}
}
write_new_or_same(&css_path, BADGE_CSS)?;
write_new_or_same(&test_path, TEST_SOURCE)?;
fs::write(&book_path, book.to_string())?;
fs::create_dir_all(nextest_path.parent().unwrap())?;
fs::write(nextest_path, nextest_source)?;
println!("Habeas configured in {}", root.display());
Ok(())
}
Tests
Input 4: outline src/execution_coverage/configuration.rs mod[tests]/fn[native_settings_inheritance_and_precedence]
- File:
src/execution_coverage/configuration.rs - Selector:
mod[tests]/fn[native_settings_inheritance_and_precedence] - Kind:
fn src/execution_coverage/configuration.rs:289–360
// {test}`requirements.test-coverage.setup.configuration`
// {test}`requirements.test-coverage.setup`
// {test}`requirements.test-coverage.setup.validation`
// {test}`requirements.test-coverage.run.configuration`
#[test]
fn native_settings_inheritance_and_precedence() {
let temp = tempfile::tempdir().unwrap();
fs::write(temp.path().join("Cargo.toml"), "[workspace]\n").unwrap();
let (path, source) = configure(temp.path()).unwrap();
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(&path, &source).unwrap();
assert_eq!(configure(temp.path()).unwrap().1, source);
check(&source, &path, "ci").unwrap();
let inherited = format!(
"{source}\n[profile.fast]\ninherits = 'ci'\ntest-threads = 3\n[profile.local]\ninherits = 'fast'\n"
);
check(&inherited, &path, "local").unwrap();
let inherited_conflict = format!(
"{inherited}\n[[profile.fast.scripts]]\nfilter = 'all()'\nrun-wrapper = 'other'\n"
);
assert!(
check(&inherited_conflict, &path, "local")
.unwrap_err()
.to_string()
.contains("profile.fast.scripts")
);
let child_override = format!(
"{inherited_conflict}\n[[profile.local.scripts]]\nfilter = 'all()'\nrun-wrapper = 'habeas-coverage'\n"
);
check(&child_override, &path, "local").unwrap();
for extra in [
"\n[[profile.local.scripts]]\nfilter = 'test(x)'\nrun-wrapper = 'other'\n",
"\n[[profile.local.scripts]]\nfilter = 'all()'\nplatform = 'cfg(unix)'\nrun-wrapper = 'habeas-coverage'\n",
"\n[profile.local]\ninherits = 'local'\n",
] {
assert!(check(&format!("{source}{extra}"), &path, "local").is_err());
}
assert!(
check(
&source.replace("coverage-process", "wrong"),
&path,
"default"
)
.is_err()
);
assert!(
check(
&source.replace("within-wrapper", "overrides-wrapper"),
&path,
"default"
)
.is_err()
);
fs::write(&path, "experimental = ['setup-scripts']\n[profile.default]\nretries = 2\n[[profile.default.scripts]]\nfilter = 'all()'\nsetup = 'prepare'\n").unwrap();
let preserved = configure(temp.path()).unwrap().1;
assert!(
preserved.contains("setup-scripts")
&& preserved.contains("retries = 2")
&& preserved.contains("prepare")
);
fs::write(
&path,
"[[profile.default.scripts]]\nfilter = 'test(x)'\nrun-wrapper = 'custom'\n",
)
.unwrap();
assert!(
configure(temp.path())
.unwrap_err()
.to_string()
.contains("conflict")
);
}
Input 5: outline tests/setup.rs fn[coverage_setup_is_idempotent_and_hook_needs_no_coverage_chapter]
- File:
tests/setup.rs - Selector:
fn[coverage_setup_is_idempotent_and_hook_needs_no_coverage_chapter] - Kind:
fn tests/setup.rs:77–133
// {test}`requirements.test-coverage.setup`
// {test}`requirements.test-coverage.setup.configuration`
// {test}`requirements.test-coverage.check.guidance`
// {test}`requirements.test-coverage.check.exceptions.setup`
// {test}`requirements.integration.symposium_setup_hook`
#[test]
fn coverage_setup_is_idempotent_and_hook_needs_no_coverage_chapter() {
let temp = fixture();
let root = temp.path();
let local_crate = env!("CARGO_MANIFEST_DIR");
let summary = fs::read_to_string(root.join("md/SUMMARY.md")).unwrap();
run(root, &["setup", "--path", local_crate]);
let config = fs::read_to_string(root.join(".config/nextest.toml")).unwrap();
assert!(!root.join("md/test-coverage.md").exists());
assert_eq!(
fs::read_to_string(root.join("md/SUMMARY.md")).unwrap(),
summary
);
assert!(config.contains("coverage-process"));
run(root, &["setup", "--path", local_crate]);
assert_eq!(
fs::read_to_string(root.join("md/SUMMARY.md")).unwrap(),
summary
);
assert_eq!(
fs::read_to_string(root.join(".config/nextest.toml")).unwrap(),
config
);
assert!(!advises_setup(&session_start(root, root)));
let conflicting = config.replace("all()", "test(one)");
fs::write(root.join(".config/nextest.toml"), &conflicting).unwrap();
assert!(advises_setup(&session_start(root, root)));
assert_eq!(
fs::read_to_string(root.join(".config/nextest.toml")).unwrap(),
conflicting
);
fs::write(root.join(".config/nextest.toml"), config).unwrap();
fs::write(root.join("md/SUMMARY.md"), "# Summary\n").unwrap();
assert!(!advises_setup(&session_start(root, root)));
assert_eq!(
fs::read_to_string(root.join("md/SUMMARY.md")).unwrap(),
"# Summary\n"
);
fs::write(root.join("md/test-coverage.md"), "User's coverage notes.\n").unwrap();
run(root, &["setup", "--path", local_crate]);
assert_eq!(
fs::read_to_string(root.join("md/test-coverage.md")).unwrap(),
"User's coverage notes.\n"
);
assert!(!advises_setup(&session_start(root, root)));
fs::remove_file(root.join(".config/nextest.toml")).unwrap();
assert!(advises_setup(&session_start(root, root)));
assert!(
!root.join(".config/nextest.toml").exists(),
"hook must not repair configuration"
);
}
Input 6: outline tests/setup.rs fn[coverage_setup_preserves_custom_index_and_preflights_conflicts]
- File:
tests/setup.rs - Selector:
fn[coverage_setup_preserves_custom_index_and_preflights_conflicts] - Kind:
fn tests/setup.rs:135–193
// {test}`requirements.test-coverage.setup`
// {test}`requirements.test-coverage.setup.configuration`
// {test}`requirements.integration.symposium_setup_hook`
#[test]
fn coverage_setup_preserves_custom_index_and_preflights_conflicts() {
let temp = fixture();
let root = temp.path();
fs::write(
root.join("md/custom.md"),
"A custom report.\n\n:::{coverage-index}\n:::\n",
)
.unwrap();
fs::write(
root.join("md/SUMMARY.md"),
"# Summary\n\n- [Custom](custom.md)\n",
)
.unwrap();
run(root, &["setup", "--path", env!("CARGO_MANIFEST_DIR")]);
assert!(!root.join("md/test-coverage.md").exists());
assert!(
!advises_setup(&session_start(root, root)),
"setup requires no separate coverage chapter"
);
assert!(
fs::read_to_string(root.join("md/custom.md"))
.unwrap()
.starts_with("A custom report.")
);
let temp = fixture();
let root = temp.path();
fs::write(root.join("md/test-coverage.md"), "User content\n").unwrap();
let original_summary = fs::read_to_string(root.join("md/SUMMARY.md")).unwrap();
run(root, &["setup", "--path", env!("CARGO_MANIFEST_DIR")]);
assert!(root.join(".config/nextest.toml").exists());
assert_eq!(
fs::read_to_string(root.join("md/test-coverage.md")).unwrap(),
"User content\n"
);
assert_eq!(
fs::read_to_string(root.join("md/SUMMARY.md")).unwrap(),
original_summary
);
let temp = fixture();
let root = temp.path();
fs::write(root.join("md/unlinked.md"), ":::{coverage-index}\n:::\n").unwrap();
fs::write(
root.join("md/rules.md"),
"```text\n:::{coverage-index}\n:::\n```\n",
)
.unwrap();
run(root, &["setup", "--path", env!("CARGO_MANIFEST_DIR")]);
assert!(!root.join("md/test-coverage.md").exists());
assert!(
!fs::read_to_string(root.join("md/SUMMARY.md"))
.unwrap()
.contains("test-coverage.md")
);
}
Referenced definitions
Input 2: requirements selection requirements.cli.setup
requirements.cli.setup:md/requirements/cli.md:11–13
:::{req} setup
Running `habeas setup` in an existing Cargo and mdBook project MUST add Habeas as a dev dependency, configure `habeas mdbook` as its preprocessor, add the badge stylesheet, enable sidebar folding with `output.html.fold.enable` unless the book already sets it, and create `tests/habeas.rs` that calls `habeas::validate()`. Repeating setup MUST avoid duplicate configuration and MUST NOT overwrite a differing test or stylesheet. Setup MUST NOT install or modify agent skills.
:::
Input 3: 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.setup
requirements.test-coverage.setup:md/requirements/test-coverage.md:499–505
:::{req} setup
In addition to {cite}`requirements.cli.setup`, `habeas setup` MUST enable the
automatic coverage subchapter of {cite}`requirements.test-coverage.index`
without creating a separate coverage source chapter, adding a coverage
entry to `SUMMARY.md`, or requiring a coverage source directive.
Setup MUST preserve existing authored chapter contents and `SUMMARY.md`.
:::