test: add Gate 3 numerical oracle contracts

This commit is contained in:
Joseph Magly
2026-08-15 20:09:21 -04:00
parent 369417fbb4
commit 51529ad1d7
25 changed files with 3443 additions and 170 deletions
+77
View File
@@ -3,9 +3,11 @@
from __future__ import annotations
import json
from pathlib import Path
from types import SimpleNamespace
from scripts import check_mutation_score
from scripts import check_mutation_targets
from scripts import run_repeat_gate
@@ -17,6 +19,13 @@ def test_mutation_score_accepts_exact_floor_and_rejects_regression():
]
def test_mutation_score_validator_default_matches_immutable_policy_floor():
parser = check_mutation_score._parser()
assert check_mutation_score.DEFAULT_MUTATION_SCORE_MINIMUM == 85.0
assert parser.parse_args(["stats.json"]).minimum == 85.0
def test_mutation_score_rejects_malformed_and_interrupted_runs():
assert check_mutation_score.validate_mutation_stats(
{"killed": True, "total": 1}, minimum=70,
@@ -26,6 +35,74 @@ def test_mutation_score_rejects_malformed_and_interrupted_runs():
) == ["mutation run was interrupted"]
def test_mutation_target_guard_invalidates_stale_copied_targets(tmp_path):
pyproject = tmp_path / "pyproject.toml"
pyproject.write_text(
"""
[tool.mutmut]
only_mutate = [
"obliteratus/config.py",
"obliteratus/analysis/whitened_svd.py",
]
required_mutation_targets = [
"obliteratus/analysis/whitened_svd.py",
]
""".lstrip(),
encoding="utf-8",
)
for target in (
"obliteratus/config.py",
"obliteratus/analysis/whitened_svd.py",
):
source = tmp_path / target
source.parent.mkdir(parents=True, exist_ok=True)
source.write_text("pass\n", encoding="utf-8")
valid_meta = tmp_path / "mutants/obliteratus/config.py.meta"
valid_meta.parent.mkdir(parents=True, exist_ok=True)
valid_meta.write_text('{"exit_code_by_key": {"obliteratus.config.x__mutmut_1": null}}')
stale_copy = tmp_path / "mutants/obliteratus/analysis/whitened_svd.py"
stale_copy.parent.mkdir(parents=True, exist_ok=True)
stale_copy.write_text("pass\n", encoding="utf-8")
stale = check_mutation_targets.prepare_required_targets(pyproject)
assert stale == [Path("obliteratus/analysis/whitened_svd.py")]
assert not stale_copy.exists()
assert check_mutation_targets.validate_required_targets(pyproject) == [
"configured mutation target produced zero mutants: obliteratus/analysis/whitened_svd.py",
]
def test_mutation_target_guard_passes_when_each_exact_target_has_mutants(tmp_path):
pyproject = tmp_path / "pyproject.toml"
pyproject.write_text(
"""
[tool.mutmut]
only_mutate = [
"obliteratus/analysis/*.py",
"obliteratus/analysis/numerical_contracts.py",
]
required_mutation_targets = [
"obliteratus/analysis/numerical_contracts.py",
]
""".lstrip(),
encoding="utf-8",
)
source = tmp_path / "obliteratus/analysis/numerical_contracts.py"
source.parent.mkdir(parents=True, exist_ok=True)
source.write_text("pass\n", encoding="utf-8")
meta = tmp_path / "mutants/obliteratus/analysis/numerical_contracts.py.meta"
meta.parent.mkdir(parents=True, exist_ok=True)
meta.write_text(
'{"exit_code_by_key": {"obliteratus.analysis.numerical_contracts.x__mutmut_1": null}}',
encoding="utf-8",
)
assert check_mutation_targets.validate_required_targets(pyproject) == []
def test_repeat_orders_are_distinct_and_deterministic():
paths = ["a", "b", "c", "d"]
assert run_repeat_gate.test_orders(paths) == [