"""Tests for the deterministic Hermes handoff mutation gate.""" from __future__ import annotations from pathlib import Path from testing.quality_handoff_mutation import ( MUTATIONS, Mutation, MutationReport, main, run_gate, ) ROOT = Path(__file__).parents[2] def test_every_security_mutant_is_killed() -> None: report = run_gate(ROOT) assert report.issues == () assert report.score == 100.0 assert report.killed == report.total >= 9 def test_invalid_anchor_baseline_syntax_and_survivor_are_reported() -> None: path = "hermes_handoff_model.py" cases = ( Mutation("missing", path, "not present", "x", "pass"), Mutation( "baseline", path, "SCHEMA_VERSION = 1", "SCHEMA_VERSION = 2", "raise SystemExit(1)", ), Mutation("syntax", path, "SCHEMA_VERSION = 1", "if", "pass"), Mutation("survivor", path, "SCHEMA_VERSION = 1", "SCHEMA_VERSION = 2", "pass"), ) report = run_gate(ROOT, cases) assert report.killed == 0 assert len(report.issues) == 4 assert report.score == 0.0 def test_main_reports_a_perfect_score(capsys) -> None: """Every mutant must die, and the count must track the declared set.""" assert main() == 0 total = len(MUTATIONS) assert total >= 13 assert f"{total}/{total} (100.00%)" in capsys.readouterr().out def test_main_reports_mutation_issues(monkeypatch, capsys) -> None: monkeypatch.setattr( "testing.quality_handoff_mutation.run_gate", lambda _root: MutationReport(1, 0, ("survivor",)), ) assert main() == 1 assert "survivor" in capsys.readouterr().out