From 078a84b608af9c84ee1b38ddb8c3a2355ca791ed Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 1 Jul 2026 23:24:04 -0400 Subject: [PATCH] test(chronology): write Red tests for quality gate (4 checks) --- tests/test_chronology_quality_gate.py | 76 +++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/test_chronology_quality_gate.py diff --git a/tests/test_chronology_quality_gate.py b/tests/test_chronology_quality_gate.py new file mode 100644 index 00000000..860e227d --- /dev/null +++ b/tests/test_chronology_quality_gate.py @@ -0,0 +1,76 @@ +from pathlib import Path +import pytest +from scripts.audit.chronology_quality_gate import run_quality_gate, QualityGateResult + + +def _make_row(status: str, confidence: str, reason: str, summary: str) -> dict: + return { + "status": status, + "confidence": confidence, + "reason": reason, + "summary": summary, + "track_id": "test_track", + "date": "2026-07-01", + "folder_link": "conductor/tracks/test_track", + "init_sha": "abc1234", + "end_sha": "def5678", + "commit_count": 1, + } + + +def test_quality_gate_passes_on_good_rows() -> None: + rows = [ + _make_row("Completed", "high", "completion report found", "A real summary."), + _make_row("Completed", "medium", "3 work commits", "Another real summary."), + _make_row("Active", "medium", "0 work commits in tracks/", "Spec-only track."), + ] + result = run_quality_gate(rows) + assert result.passed is True + assert result.violations == [] + + +def test_quality_gate_fails_on_too_many_needs_review() -> None: + rows = [ + _make_row("Needs Review", "none", "inconclusive", "Summary 1."), + _make_row("Needs Review", "none", "inconclusive", "Summary 2."), + _make_row("Completed", "high", "completion report", "Summary 3."), + ] + result = run_quality_gate(rows) + assert result.passed is False + assert any("Needs Review" in v for v in result.violations) + + +def test_quality_gate_fails_on_zero_completed() -> None: + rows = [ + _make_row("Active", "medium", "0 work commits", "Summary 1."), + _make_row("Active", "medium", "0 work commits", "Summary 2."), + ] + result = run_quality_gate(rows) + assert result.passed is False + assert any("0 rows are Completed" in v for v in result.violations) + + +def test_quality_gate_fails_on_metadata_field_summaries() -> None: + rows = [ + _make_row("Completed", "high", "completion report", "Real summary."), + _make_row("Completed", "high", "completion report", "**Priority:** A (foundational)"), + ] + result = run_quality_gate(rows) + assert result.passed is False + assert any("metadata-field" in v for v in result.violations) + + +def test_quality_gate_fails_on_empty_reason() -> None: + rows = [ + _make_row("Completed", "high", "", "Real summary."), + ] + result = run_quality_gate(rows) + assert result.passed is False + assert any("empty reason" in v for v in result.violations) + + +def test_quality_gate_strict_mode_exits_nonzero() -> None: + rows = [_make_row("Active", "medium", "0 work commits", "Summary.")] + result = run_quality_gate(rows) + assert result.passed is False + assert result.exit_code == 1 \ No newline at end of file