requirements.references.coverage.uncommitted
Requirements index · View definition
Example
The evidence of
requirements.cli.checkreadparse. The requirement is re-authored but not yet committed, and the new record does not readparse. The committed versions in the window still name it, sohabeas status --coveragedoes not warn. If the new record had readparse, its contents on disk would cover it even before the commit.
Rationale
Verdict: the tests adequately check the example requirements.references.coverage.uncommitted.
The example is concrete. It describes one case. rules.check is re-authored but not committed, and its new record no longer reads parse. Earlier committed versions in the window still name parse, so habeas status --coverage does not warn about it. It also states a counterfactual: a new record that did read parse would cover it from its on-disk contents, even before the commit.
Main test. tests/coverage.rs#fn[uncommitted_records_count_as_they_are_on_disk] carries a {test} reference to the example. It uses the fixture project(), whose src/lib.rs has parse, render and helper. Its helpers are record (which writes evidence/<name>.json with the outline inputs read), commit and warned (which lists the function names warned about).
record(rules.check, [parse])thencommit:warnedis[render, helper].parseis covered by the committed record.record(rules.check, [])with no commit:warnedis still[render, helper]. This is the example’s main assertion. The re-authored record on disk no longer readsparse, yetparseis not warned because the committed history still names it.record(rules.render, [render])with no commit:warnedbecomes[helper]. This checks that uncommitted on-disk contents count as coverage before any commit. An implementation that read only committed history would fail here.
Shallow-clone test. tests/coverage.rs#fn[an_uncommitted_record_does_not_make_a_full_shallow_history_incomplete] also carries a {test} reference to the example. It checks that an uncommitted new record that reads helper is counted on disk, with incomplete still false and warned equal to [parse]. This supports the same behavior in a shallow clone.
Limit of the tests. The counterfactual in the example is checked with a new uncommitted record that reads render, not with a re-authored record that reads parse. The mechanism is the same, because on-disk contents cover the item before any commit. The tests would only miss an implementation that treated modified records differently from new ones. The example does not name that edge case, so I do not count it as a gap.
Inputs
Tests
Input 2: outline tests/coverage.rs fn[uncommitted_records_count_as_they_are_on_disk]
- File:
tests/coverage.rs - Selector:
fn[uncommitted_records_count_as_they_are_on_disk] - Kind:
fn tests/coverage.rs:158–173
// {test}`requirements.references.coverage.uncommitted`
// {test}`requirements.references.coverage.history`
#[test]
fn uncommitted_records_count_as_they_are_on_disk() {
let temp = project();
let root = temp.path();
record(root, "rules.check", &["fn[parse]"]);
commit(root, "first");
assert_eq!(warned(root), ["render", "helper"]);
// Re-authored but not committed: the committed version still covers it.
record(root, "rules.check", &[]);
assert_eq!(warned(root), ["render", "helper"]);
// A new record on disk covers what it reads before any commit.
record(root, "rules.render", &["fn[render]"]);
assert_eq!(warned(root), ["helper"]);
}
Input 3: outline tests/coverage.rs fn[an_uncommitted_record_does_not_make_a_full_shallow_history_incomplete]
- File:
tests/coverage.rs - Selector:
fn[an_uncommitted_record_does_not_make_a_full_shallow_history_incomplete] - Kind:
fn tests/coverage.rs:701–724
// {test}`requirements.references.coverage.history`
// {test}`requirements.references.coverage.uncommitted`
#[test]
fn an_uncommitted_record_does_not_make_a_full_shallow_history_incomplete() {
let temp = project();
let root = temp.path();
fs::write(
root.join("habeas.toml"),
"version = 1\n\n[coverage]\nreauthorings = 1\n",
)
.unwrap();
record(root, "rules.check", &["fn[parse]"]);
commit(root, "first");
record(root, "rules.check", &["fn[render]"]);
commit(root, "second");
// The one-commit clone holds the committed record's whole window.
let (_clone, target) = shallow_clone(root, 1);
assert!(!habeas::coverage_warnings(&target).unwrap().incomplete);
// A new record that was never committed has no history to miss.
record(&target, "rules.render", &["fn[helper]"]);
let warnings = habeas::coverage_warnings(&target).unwrap();
assert!(!warnings.incomplete, "{warnings:?}");
assert_eq!(warned(&target), ["parse"]);
}
Other sources
Input 1: requirements selection requirements.references.coverage.uncommitted
requirements.references.coverage.uncommitted:md/requirements/references.md:307–314
:::{example} coverage.uncommitted
The evidence of `requirements.cli.check` read `parse`. The requirement is
re-authored but not yet committed, and the new record does not read `parse`.
The committed versions in the window still name it, so
`habeas status --coverage` does not warn. If the new record had read `parse`,
its contents on disk would cover it even before the commit.
{test}`requirements.references.coverage.history`
:::
Input 4: outline tests/coverage.rs fn[project]
- File:
tests/coverage.rs - Selector:
fn[project] - Kind:
fn tests/coverage.rs:12–38
/// A Git project whose book defines `rules.check` and `rules.render`, and
/// whose `src/lib.rs` holds three functions with no references.
// {cite}`habeas:util`
fn project() -> TempDir {
let temp = tempfile::tempdir().unwrap();
let root = temp.path();
for directory in ["md", "src", "evidence"] {
fs::create_dir_all(root.join(directory)).unwrap();
}
fs::write(root.join("Cargo.toml"), "[package]\nname = 'fixture'\n").unwrap();
fs::write(root.join("book.toml"), "[book]\nsrc = 'md'\n").unwrap();
fs::write(
root.join("md/rules.md"),
":::{req} check\nChecking MUST work.\n:::\n\n:::{req} render\nRendering MUST work.\n:::\n",
)
.unwrap();
fs::write(
root.join("src/lib.rs"),
"fn parse() {}\n\nfn render() {}\n\nfn helper() {}\n\nmod tests {\n fn fixture() {}\n}\n",
)
.unwrap();
git(root, &["init", "--quiet"]);
git(root, &["config", "user.email", "test@example.com"]);
git(root, &["config", "user.name", "Test"]);
common::coverage_setup(root);
temp
}
Input 5: outline tests/coverage.rs fn[record]
- File:
tests/coverage.rs - Selector:
fn[record] - Kind:
fn tests/coverage.rs:63–76
/// Writes `name`'s evidence reading `items` of `src/lib.rs`.
// {cite}`habeas:util`
fn record(root: &Path, name: &str, items: &[&str]) {
let inputs: Vec<_> = items
.iter()
.map(|item| habeas::outline_input(root, "src/lib.rs", item).unwrap())
.collect();
fs::write(
root.join(format!("evidence/{name}.json")),
json!({"requirement": "x", "determination": true, "rationale": "x", "inputs": inputs})
.to_string(),
)
.unwrap();
}
Input 6: outline tests/coverage.rs fn[commit]
- File:
tests/coverage.rs - Selector:
fn[commit] - Kind:
fn tests/coverage.rs:78–82
// {cite}`habeas:util`
fn commit(root: &Path, message: &str) {
git(root, &["add", "-A"]);
git(root, &["commit", "--quiet", "--allow-empty", "-m", message]);
}
Input 7: outline tests/coverage.rs fn[warned]
- File:
tests/coverage.rs - Selector:
fn[warned] - Kind:
fn tests/coverage.rs:84–96
/// The names of the functions warned about.
// {cite}`habeas:util`
fn warned(root: &Path) -> Vec<String> {
habeas::coverage_warnings(root)
.unwrap()
.items
.into_iter()
.filter_map(|line| {
let name = line.split(": function ").nth(1)?;
Some(name.split(' ').next()?.to_owned())
})
.collect()
}
Input 8: outline tests/coverage.rs fn[shallow_clone]
- File:
tests/coverage.rs - Selector:
fn[shallow_clone] - Kind:
fn tests/coverage.rs:488–501
/// A shallow clone of `root` holding its last `depth` commits.
// {cite}`habeas:util`
fn shallow_clone(root: &Path, depth: usize) -> (TempDir, std::path::PathBuf) {
let clone = tempfile::tempdir().unwrap();
let target = clone.path().join("shallow");
let output = Command::new("git")
.args(["clone", "--quiet", "--depth", &depth.to_string()])
.arg(format!("file://{}", root.display()))
.arg(&target)
.output()
.unwrap();
assert!(output.status.success(), "{output:?}");
(clone, target)
}