fix(coverage): restore specialized domain ownership and floors

This commit is contained in:
2026-10-14 10:35:41 +01:00
parent bad942fb25
commit ff73f8ad39
5 changed files with 846 additions and 13 deletions
@@ -114,6 +114,111 @@ fn repository_sources_have_exactly_one_coverage_owner() {
);
}
fn repository_policy(script: &str) -> Output {
Command::new("python3")
.arg("-B")
.arg("-c")
.arg(format!(
r#"
import importlib.util
import json
import sys
from pathlib import Path
root = Path(sys.argv[1])
spec = importlib.util.spec_from_file_location("coverage_auditor", root / "scripts/audit-coverage-domains.py")
auditor = importlib.util.module_from_spec(spec)
spec.loader.exec_module(auditor)
config = json.loads((root / "files/config/runtime-edge-coverage-domains.json").read_text())
domains = config["domains"]
trees = [
("crates/console/prometeu-system/src/services/memcard", "system/fs", "system/core"),
("crates/console/prometeu-drivers/src/asset", "asset/bank", "drivers/core"),
]
{script}
"#
))
.arg(repository())
.output()
.unwrap()
}
#[test]
fn specialized_entry_files_and_all_descendants_have_the_expected_owner() {
success(repository_policy(
r#"
for stem, expected, residual in trees:
names = [stem + ".rs"]
descendants = sorted((root / stem).rglob("*.rs"))
assert descendants, stem
names += [path.relative_to(root).as_posix() for path in descendants]
names += [stem + "/future.rs", stem + "/future/nested.rs"]
for name in names:
actual = auditor.owners(name, domains)
assert actual == [expected], (name, expected, actual)
# Exclusive residual fallback would pass the generic audit but is wrong.
import copy
fallback = copy.deepcopy(domains)
fallback[expected]["paths"].remove(stem + "/")
fallback[residual]["exclude_paths"].remove(stem + "/")
name = names[-1]
assert auditor.owners(name, fallback) == [residual]
assert auditor.owners(name, fallback) != [expected]
overlap = copy.deepcopy(domains)
overlap[residual]["exclude_paths"].remove(stem + "/")
assert set(auditor.owners(name, overlap)) == {expected, residual}
"#,
));
}
#[test]
fn specialized_ownership_survives_absent_and_zero_instrumentation() {
success(repository_policy(
r#"
import tempfile
with tempfile.TemporaryDirectory(prefix="prometeu-domain-trees-") as directory:
fixture = Path(directory)
records = []
# Use the real map and source layout, with independent synthetic evidence.
for source in (root / "crates").glob("**/src/**/*.rs"):
name = source.relative_to(root).as_posix()
path = fixture / name
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("// ownership fixture\n")
records.append({"filename": name, "summary": {"lines": {"count": 1, "covered": 1}}})
for stem, expected, residual in trees:
for suffix in ["future/absent.rs", "future/zero.rs"]:
path = fixture / stem / suffix
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("// no executable lines\n")
records.append({"filename": stem + "/future/zero.rs", "summary": {"lines": {"count": 0, "covered": 0}}})
config_path = fixture / "config.json"
config_path.write_text(json.dumps(config))
report_path = fixture / "report.json"
report_path.write_text(json.dumps({"data": [{"files": records}]}))
before = auditor.audit(root, root / "files/config/runtime-edge-coverage-domains.json")
result = auditor.audit(fixture, config_path, report_path)
assert len(result["domains"]) == 15
assert all(domain["gate_passed"] for domain in result["domains"].values())
for stem, expected, residual in trees:
domain = result["domains"][expected]
assert domain["source_files"] == before["domains"][expected]["source_files"] + 2
assert stem + "/future/zero.rs" in domain["files"]
assert stem + "/future/absent.rs" not in domain["files"]
assert result["domains"][residual]["source_files"] == before["domains"][residual]["source_files"]
# Missing residual exclusions must fail even for sources absent from reports.
for stem, expected, residual in trees:
domains[residual]["exclude_paths"].remove(stem + "/")
config_path.write_text(json.dumps(config))
try:
auditor.audit(fixture, config_path, report_path)
except auditor.AuditError as error:
assert "expected exactly one domain" in str(error), error
else:
raise AssertionError("overlapping module trees passed ownership audit")
"#,
));
}
#[test]
fn exclusions_and_absolute_relative_report_names_have_exclusive_ownership() {
let fixture = Fixture::new();