requirements.test-coverage.setup.configuration
Requirements index · View definition
Requirement
habeas setupMUST configure native nextest settings in.config/nextest.tomlat the Cargo workspace root so the coverage workflow ofroutes each executed test attempt through the per-process collector of
. Those settings MUST use nextest’s own configuration format. Repeating setup MUST avoid duplicate configuration, preserve unrelated nextest settings, and report conflicting settings for review rather than overwrite them.
Rationale
I judge the tests adequate for requirements.test-coverage.setup.configuration. I read the implementation in src/execution_coverage/configuration.rs (configure, check, workspace_root) only to see what the tests’ assertions exercise. I took the expected behavior from the requirement text.
Obligations and the tests that cover them
-
Configure native nextest settings in
.config/nextest.tomlat the Cargo workspace root.mod[tests]/fn[workspace_member_uses_the_native_config_at_the_workspace_root]checks thatconfigurerun from a workspace member returns the root’s.config/nextest.toml. It also checks that nothing is created under the member ortarget.- The same test covers a member excluded from the workspace, where the member’s own path is used.
tests/setup.rs#fn[coverage_setup_is_idempotent_and_hook_needs_no_coverage_chapter]runs the realhabeas setupand checks that the file is written and containscoverage-process.
-
Route each executed test attempt through the per-process collector.
native_settings_inheritance_and_precedencerunscheckon the generated config for profileciand on inheriting profiles. The check proves an unconditional firstrun-wrapperrule with filterall()and no platform.- The same test rejects the following:
- a rule with a narrower filter or a platform;
- an inheritance cycle;
- a wrong command (
wrongin place ofcoverage-process); - a wrong
target-runner.
- It also checks that a child profile’s own wrapper rule overrides a conflicting parent rule.
-
Use nextest’s own configuration format.
- The generated text is validated structurally by
check. It requiresexperimentalto containwrapper-scripts, ascripts.wrapper.habeas-coveragetable with command["habeas","coverage-process"]andtarget-runner = "within-wrapper", and aprofile.default.scriptsrun-wrapper rule. - Tests assert that this check passes on the output of
configure. I found no test that runs real nextest against the file.
- The generated text is validated structurally by
-
Repeating setup avoids duplicate configuration.
- The unit test asserts
configureon its own output returns identical text. - The CLI test runs
habeas setuptwice and asserts that.config/nextest.tomlis byte-identical.
- The unit test asserts
-
Repeating setup preserves unrelated nextest settings.
- The unit test seeds
experimental = ['setup-scripts'],retries = 2, and a setup-script rule. It asserts that all three surviveconfigure. - Other CLI tests assert that the coverage chapter and
SUMMARY.mdare left alone.
- The unit test seeds
-
Report conflicting settings for review rather than overwrite them.
setup_conflicts_name_the_setting_and_preserve_existing_native_configurationcovers six conflicts:- a wrong collector command;
- a wrong
target-runner; experimentalof the wrong type;scriptsof the wrong type;profile.default.scriptsof the wrong type;- a conflicting
run-wrapperrule.
- For each, it asserts that the error names the setting and
.config/nextest.toml, and that the file is unchanged. tests/setup.rs#fn[setup_reports_a_conflicting_nextest_wrapper_without_writing_project_files]does this end to end through the CLI. It asserts a failing exit status, stderr naming the file and setting, and no change to the config,book.toml,SUMMARY.mdorCargo.toml. It also asserts that no coverage chapter ortests/habeas.rsis created.coverage_setup_is_idempotent_and_hook_needs_no_coverage_chapteralso rewrites the file with a conflicting filter and asserts it is not overwritten.
Gaps considered
- I found no unresolved gap.
- Some branches have no direct test, such as converting an inline-table
scriptsarray to an array of tables. The requirement does not single these out as separate obligations. - Another example is a pre-existing
experimentalarray that already containswrapper-scripts. The idempotency tests exercise this by re-running on generated output.
Every obligation has a test that exercises it and asserts its outcome, and the tests carry {test} references to the subject.
Inputs
Implementation
Input 16: outline src/execution_coverage/configuration.rs fn[workspace_root]
- File:
src/execution_coverage/configuration.rs - Selector:
fn[workspace_root] - Kind:
fn src/execution_coverage/configuration.rs:10–57
// {impl}`requirements.test-coverage.setup.configuration`
pub fn workspace_root(root: &Path) -> io::Result<PathBuf> {
let root = fs::canonicalize(root)?;
let manifest = root.join("Cargo.toml");
let parsed: toml::Table = fs::read_to_string(&manifest)?
.parse()
.map_err(io::Error::other)?;
if let Some(workspace) = parsed
.get("package")
.and_then(|package| package.get("workspace"))
.and_then(toml::Value::as_str)
{
return fs::canonicalize(root.join(workspace));
}
if parsed.contains_key("workspace") {
return Ok(root);
}
for ancestor in root.ancestors().skip(1) {
let path = ancestor.join("Cargo.toml");
if path.is_file() {
let source: toml::Table = fs::read_to_string(path)?
.parse()
.map_err(io::Error::other)?;
if source.contains_key("workspace") {
if let Some(excludes) = source
.get("workspace")
.and_then(|workspace| workspace.get("exclude"))
.and_then(toml::Value::as_array)
{
for exclude in excludes.iter().filter_map(toml::Value::as_str) {
let pattern = glob::Pattern::new(exclude).map_err(io::Error::other)?;
if pattern.matches_path_with(
root.strip_prefix(ancestor).unwrap(),
glob::MatchOptions {
require_literal_separator: true,
..Default::default()
},
) {
return Ok(root);
}
}
}
return Ok(ancestor.to_path_buf());
}
}
}
Ok(root)
}
Input 22: outline src/execution_coverage/configuration.rs fn[configure]
- File:
src/execution_coverage/configuration.rs - Selector:
fn[configure] - Kind:
fn src/execution_coverage/configuration.rs:219–283
// Returns planned content; callers preflight all conflicts before writing anything.
// {impl}`requirements.test-coverage.setup.configuration`
// {impl}`requirements.test-coverage.setup`
pub fn configure(root: &Path) -> io::Result<(PathBuf, String)> {
let path = workspace_root(root)?.join(".config/nextest.toml");
let source = if path.exists() {
fs::read_to_string(&path)?
} else {
String::new()
};
let mut config: DocumentMut = source.parse().map_err(|error| invalid(&path, error))?;
let experimental = &mut config["experimental"];
if experimental.is_none() {
*experimental = value(Array::new());
}
let features = experimental
.as_array_mut()
.ok_or_else(|| invalid(&path, "experimental must be an array"))?;
if !features
.iter()
.any(|feature| feature.as_str() == Some("wrapper-scripts"))
{
features.push("wrapper-scripts");
}
table(&mut config["scripts"], &path, "scripts")?;
table(&mut config["scripts"]["wrapper"], &path, "scripts.wrapper")?;
let wrapper = &mut config["scripts"]["wrapper"][WRAPPER];
if wrapper.is_none() {
let mut table = Table::new();
let mut args = Array::new();
args.push("habeas");
args.push("coverage-process");
table["command"] = value(args);
table["target-runner"] = value("within-wrapper");
*wrapper = Item::Table(table);
}
table(&mut config["profile"], &path, "profile")?;
table(&mut config["profile"]["default"], &path, "profile.default")?;
let scripts = &mut config["profile"]["default"]["scripts"];
if scripts.is_none() {
*scripts = Item::ArrayOfTables(ArrayOfTables::new());
}
if let Some(array) = scripts.as_array() {
let mut rules = ArrayOfTables::new();
for rule in array {
let rule = rule
.as_inline_table()
.ok_or_else(|| invalid(&path, "profile.default.scripts must contain tables"))?;
rules.push(rule.clone().into_table());
}
*scripts = Item::ArrayOfTables(rules);
}
let rules = scripts
.as_array_of_tables_mut()
.ok_or_else(|| invalid(&path, "profile.default.scripts must be an array of tables"))?;
if !rules.iter().any(|rule| rule.get("run-wrapper").is_some()) {
let mut rule = Table::new();
rule["filter"] = value("all()");
rule["run-wrapper"] = value(WRAPPER);
rules.push(rule);
}
let desired = config.to_string();
check(&desired, &path, "default")?;
Ok((path, desired))
}
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 src/execution_coverage/configuration.rs mod[tests]/fn[setup_conflicts_name_the_setting_and_preserve_existing_native_configuration]
- File:
src/execution_coverage/configuration.rs - Selector:
mod[tests]/fn[setup_conflicts_name_the_setting_and_preserve_existing_native_configuration] - Kind:
fn src/execution_coverage/configuration.rs:362–399
// {test}`requirements.test-coverage.setup.configuration`
#[test]
fn setup_conflicts_name_the_setting_and_preserve_existing_native_configuration() {
let temp = tempfile::tempdir().unwrap();
fs::write(temp.path().join("Cargo.toml"), "[workspace]\n").unwrap();
let (path, valid) = configure(temp.path()).unwrap();
fs::create_dir_all(path.parent().unwrap()).unwrap();
for (source, setting) in [
(
valid.replace("coverage-process", "other-command"),
"scripts.wrapper.habeas-coverage",
),
(
valid.replace("within-wrapper", "overrides-wrapper"),
"scripts.wrapper.habeas-coverage",
),
(
"experimental = 'wrong'\n".to_owned(),
"experimental must be an array",
),
("scripts = 'wrong'\n".to_owned(), "scripts must be a table"),
(
"[profile.default]\nscripts = 'wrong'\n".to_owned(),
"profile.default.scripts must be an array of tables",
),
(
"[[profile.default.scripts]]\nfilter = 'test(x)'\nrun-wrapper = 'custom'\n"
.to_owned(),
"profile.default.scripts",
),
] {
fs::write(&path, &source).unwrap();
let error = configure(temp.path()).unwrap_err().to_string();
assert!(error.contains(setting), "{setting}: {error}");
assert!(error.contains(".config/nextest.toml"), "{error}");
assert_eq!(fs::read_to_string(&path).unwrap(), source);
}
}
Input 6: outline src/execution_coverage/configuration.rs mod[tests]/fn[workspace_member_uses_the_native_config_at_the_workspace_root]
- File:
src/execution_coverage/configuration.rs - Selector:
mod[tests]/fn[workspace_member_uses_the_native_config_at_the_workspace_root] - Kind:
fn src/execution_coverage/configuration.rs:401–435
// {test}`requirements.test-coverage.setup.configuration`
// {test}`requirements.test-coverage.setup.validation.static`
#[test]
fn workspace_member_uses_the_native_config_at_the_workspace_root() {
let temp = tempfile::tempdir().unwrap();
fs::write(
temp.path().join("Cargo.toml"),
"[workspace]\nmembers = ['member']\n",
)
.unwrap();
let member = temp.path().join("member");
fs::create_dir(&member).unwrap();
fs::write(
member.join("Cargo.toml"),
"[package]\nname = 'member'\nversion = '0.1.0'\n",
)
.unwrap();
let (path, source) = configure(&member).unwrap();
assert_eq!(path, temp.path().join(".config/nextest.toml"));
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(path, source).unwrap();
validate_setup(&member).unwrap();
assert!(!member.join(".config").exists());
assert!(!temp.path().join("target").exists());
fs::write(
temp.path().join("Cargo.toml"),
"[workspace]\nmembers = []\nexclude = ['mem*']\n",
)
.unwrap();
let (excluded_path, source) = configure(&member).unwrap();
assert_eq!(excluded_path, member.join(".config/nextest.toml"));
fs::create_dir_all(excluded_path.parent().unwrap()).unwrap();
fs::write(excluded_path, source).unwrap();
validate_setup(&member).unwrap();
}
Input 7: 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 8: 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")
);
}
Input 9: outline tests/setup.rs fn[setup_reports_a_conflicting_nextest_wrapper_without_writing_project_files]
- File:
tests/setup.rs - Selector:
fn[setup_reports_a_conflicting_nextest_wrapper_without_writing_project_files] - Kind:
fn tests/setup.rs:195–224
// {test}`requirements.test-coverage.setup.configuration`
#[test]
fn setup_reports_a_conflicting_nextest_wrapper_without_writing_project_files() {
let temp = fixture();
let root = temp.path();
let (path, native) = habeas::execution_coverage::configure(root).unwrap();
fs::create_dir_all(path.parent().unwrap()).unwrap();
let conflict = native.replace("coverage-process", "custom-command");
fs::write(&path, &conflict).unwrap();
let book = fs::read(root.join("book.toml")).unwrap();
let summary = fs::read(root.join("md/SUMMARY.md")).unwrap();
let manifest = fs::read(root.join("Cargo.toml")).unwrap();
let output = Command::new(env!("CARGO_BIN_EXE_habeas"))
.arg("setup")
.current_dir(root)
.output()
.unwrap();
assert!(!output.status.success());
let error = String::from_utf8_lossy(&output.stderr);
assert!(
error.contains(".config/nextest.toml") && error.contains("scripts.wrapper.habeas-coverage"),
"{error}"
);
assert_eq!(fs::read_to_string(path).unwrap(), conflict);
assert_eq!(fs::read(root.join("book.toml")).unwrap(), book);
assert_eq!(fs::read(root.join("md/SUMMARY.md")).unwrap(), summary);
assert_eq!(fs::read(root.join("Cargo.toml")).unwrap(), manifest);
assert!(!root.join("md/test-coverage.md").exists());
assert!(!root.join("tests/habeas.rs").exists());
}
Referenced definitions
Input 2: requirements selection requirements.test-coverage.run
requirements.test-coverage.run:md/requirements/test-coverage.md:33–38
:::{req} run
`habeas coverage [-- <nextest arguments>]` MUST run LLVM-instrumented Rust tests
through `cargo nextest run`, forwarding the supplied arguments and preserving
nextest's configured test concurrency, filtering, and retries. With no supplied
arguments it MUST select the workspace.
:::
Input 3: requirements selection requirements.test-coverage.processes
requirements.test-coverage.processes:md/requirements/test-coverage.md:49–56
:::{req} processes
Each coverage run MUST retain LLVM coverage profiles independently for each
test process, identifying its nextest binary, test name, and attempt. Concurrent
tests, tests with the same name in different binaries, retries, and separate
runs MUST NOT overwrite or combine one another's stored profiles. Profiles from
instrumented child processes MUST remain separate and associated with the test
attempt that spawned them.
:::
Other sources
Input 1: requirements selection requirements.test-coverage.setup.configuration
requirements.test-coverage.setup.configuration:md/requirements/test-coverage.md:514–522
:::{req} setup.configuration
`habeas setup` MUST configure native nextest settings in
`.config/nextest.toml` at the Cargo workspace root so the coverage workflow of
{cite}`requirements.test-coverage.run` routes each executed test attempt through
the per-process collector of {cite}`requirements.test-coverage.processes`.
Those settings MUST use nextest's own configuration format.
Repeating setup MUST avoid duplicate configuration, preserve unrelated nextest
settings, and report conflicting settings for review rather than overwrite them.
:::
Input 10: outline src/execution_coverage/configuration.rs use@e1f72b0ff927
- File:
src/execution_coverage/configuration.rs - Selector:
use@e1f72b0ff927 - Kind:
use src/execution_coverage/configuration.rs:1–1
use std::collections::BTreeSet;
Input 11: outline src/execution_coverage/configuration.rs use@0aa5aad345a4
- File:
src/execution_coverage/configuration.rs - Selector:
use@0aa5aad345a4 - Kind:
use src/execution_coverage/configuration.rs:2–2
use std::fs;
Input 12: outline src/execution_coverage/configuration.rs use@95d18074761c
- File:
src/execution_coverage/configuration.rs - Selector:
use@95d18074761c - Kind:
use src/execution_coverage/configuration.rs:3–3
use std::io;
Input 13: outline src/execution_coverage/configuration.rs use@3970e6901143
- File:
src/execution_coverage/configuration.rs - Selector:
use@3970e6901143 - Kind:
use src/execution_coverage/configuration.rs:4–4
use std::path::{Path, PathBuf};
Input 14: outline src/execution_coverage/configuration.rs use@10e078eeae33
- File:
src/execution_coverage/configuration.rs - Selector:
use@10e078eeae33 - Kind:
use src/execution_coverage/configuration.rs:6–6
use toml_edit::{Array, ArrayOfTables, DocumentMut, Item, Table, value};
Input 15: outline src/execution_coverage/configuration.rs const[WRAPPER]
- File:
src/execution_coverage/configuration.rs - Selector:
const[WRAPPER] - Kind:
const src/execution_coverage/configuration.rs:8–8
const WRAPPER: &str = "habeas-coverage";
Input 17: outline src/execution_coverage/configuration.rs fn[invalid]
- File:
src/execution_coverage/configuration.rs - Selector:
fn[invalid] - Kind:
fn src/execution_coverage/configuration.rs:59–64
fn invalid(path: &Path, message: impl std::fmt::Display) -> io::Error {
io::Error::other(format!(
"{}: {message}; repair the coverage integration with `habeas setup` (review conflicting settings first)",
path.display()
))
}
Input 18: outline src/execution_coverage/configuration.rs fn[command_is_collector]
- File:
src/execution_coverage/configuration.rs - Selector:
fn[command_is_collector] - Kind:
fn src/execution_coverage/configuration.rs:66–73
fn command_is_collector(command: &toml::Value) -> bool {
command.as_str() == Some("habeas coverage-process")
|| command.as_array().is_some_and(|args| {
args.len() == 2
&& args[0].as_str() == Some("habeas")
&& args[1].as_str() == Some("coverage-process")
})
}
Input 19: outline src/execution_coverage/configuration.rs fn[table]
- File:
src/execution_coverage/configuration.rs - Selector:
fn[table] - Kind:
fn src/execution_coverage/configuration.rs:75–85
fn table(item: &mut Item, path: &Path, setting: &str) -> io::Result<()> {
if item.is_none() {
*item = Item::Table(Table::new());
} else if item.is_inline_table() {
let inline = item.as_inline_table().unwrap().clone();
*item = Item::Table(inline.into_table());
} else if !item.is_table() {
return Err(invalid(path, format!("{setting} must be a table")));
}
Ok(())
}
Input 20: outline src/execution_coverage/configuration.rs fn[check]
- File:
src/execution_coverage/configuration.rs - Selector:
fn[check] - Kind:
fn src/execution_coverage/configuration.rs:87–209
// Deliberately prove an unconditional first run-wrapper rule, rather than approximate
// arbitrary nextest filtersets. Unrelated setup/list rules are left to nextest.
// {impl}`requirements.test-coverage.run.configuration`
pub(super) fn check(source: &str, path: &Path, profile: &str) -> io::Result<()> {
let config: toml::Table = source.parse().map_err(|error| invalid(path, error))?;
if !config
.get("experimental")
.and_then(toml::Value::as_array)
.is_some_and(|features| {
features
.iter()
.any(|feature| feature.as_str() == Some("wrapper-scripts"))
})
{
return Err(invalid(path, "experimental must include wrapper-scripts"));
}
let wrapper = config
.get("scripts")
.and_then(|scripts| scripts.get("wrapper"))
.and_then(|wrappers| wrappers.get(WRAPPER))
.and_then(toml::Value::as_table)
.ok_or_else(|| invalid(path, "scripts.wrapper.habeas-coverage is missing"))?;
if !wrapper.get("command").is_some_and(command_is_collector)
|| wrapper.get("target-runner").and_then(toml::Value::as_str) != Some("within-wrapper")
{
return Err(invalid(
path,
"scripts.wrapper.habeas-coverage requires command = [\"habeas\", \"coverage-process\"] and target-runner = \"within-wrapper\"",
));
}
let profiles = config
.get("profile")
.and_then(toml::Value::as_table)
.ok_or_else(|| invalid(path, "profile.default.scripts is missing"))?;
// Validate the entire inheritance chain even if an early wrapper rule is
// unconditional: cycles and an invalid default parent are still malformed.
let mut parent = profile;
let mut chain = BTreeSet::new();
loop {
if !chain.insert(parent) {
return Err(invalid(
path,
format!("profile.{parent}.inherits forms a cycle"),
));
}
let settings = profiles.get(parent).and_then(toml::Value::as_table);
if parent == "default" {
if settings.is_some_and(|settings| settings.contains_key("inherits")) {
return Err(invalid(
path,
"profile.default cannot inherit another profile",
));
}
break;
}
if settings.is_none() && parent != "ci" {
return Err(invalid(path, format!("profile.{parent} is not defined")));
}
parent = match settings.and_then(|settings| settings.get("inherits")) {
Some(value) => value.as_str().ok_or_else(|| {
invalid(path, format!("profile.{parent}.inherits must be a string"))
})?,
None => "default",
};
}
let mut current = profile;
let mut visited = BTreeSet::new();
loop {
if !visited.insert(current) {
return Err(invalid(
path,
format!("profile.{current}.inherits forms a cycle"),
));
}
let settings = profiles.get(current).and_then(toml::Value::as_table);
if current != "default" && settings.is_none() && current != "ci" {
return Err(invalid(path, format!("profile.{current} is not defined")));
}
if let Some(settings) = settings {
if let Some(scripts) = settings.get("scripts") {
let scripts = scripts.as_array().ok_or_else(|| {
invalid(path, format!("profile.{current}.scripts must be an array"))
})?;
for rule in scripts {
let Some(wrapper) = rule.get("run-wrapper") else {
continue;
};
if wrapper.as_str() == Some(WRAPPER)
&& rule.get("filter").and_then(toml::Value::as_str) == Some("all()")
&& rule.get("platform").is_none()
{
return Ok(());
}
return Err(invalid(
path,
format!(
"profile.{current}.scripts: the first run-wrapper rule must unconditionally select {WRAPPER}; its filter/platform or wrapper prevents proving complete coverage"
),
));
}
}
if current == "default" && settings.contains_key("inherits") {
return Err(invalid(
path,
"profile.default cannot inherit another profile",
));
}
}
if current == "default" {
break;
}
current = match settings.and_then(|settings| settings.get("inherits")) {
Some(parent) => parent.as_str().ok_or_else(|| {
invalid(path, format!("profile.{current}.inherits must be a string"))
})?,
None => "default",
};
}
Err(invalid(
path,
format!("profile.{profile}.scripts does not route all attempts through {WRAPPER}"),
))
}
Input 21: outline src/execution_coverage/configuration.rs fn[validate_setup]
- File:
src/execution_coverage/configuration.rs - Selector:
fn[validate_setup] - Kind:
fn src/execution_coverage/configuration.rs:211–217
// {impl}`requirements.test-coverage.setup.validation`
// {impl}`requirements.test-coverage.setup.validation.static`
pub fn validate_setup(root: &Path) -> io::Result<()> {
let path = workspace_root(root)?.join(".config/nextest.toml");
let source = fs::read_to_string(&path).map_err(|error| invalid(&path, error))?;
check(&source, &path, "default")
}