File size: 3,924 Bytes
81c52a9
 
 
c970469
81c52a9
 
 
 
 
 
c970469
81c52a9
 
 
 
 
 
 
 
 
 
c970469
 
 
 
 
 
 
f144fc4
81c52a9
 
 
 
 
 
 
c970469
 
 
 
 
81c52a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f144fc4
 
 
81c52a9
 
 
 
 
c970469
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81c52a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from __future__ import annotations

import csv
import re
import subprocess
from pathlib import Path

repo_root = Path(__file__).resolve().parents[2]

TRACKER = repo_root / "qa" / "bug_smoke_status.csv"
BENCHMARK_TRACKER = repo_root / "qa" / "ctx_benchmark_status.csv"
GENERATED_NAMES = {".DS_Store"}
GENERATED_SUFFIXES = {".pyc", ".pyo", ".tmp", ".bak", ".orig"}
STATUSES = {
    "Needs Triage",
    "Needs Validation",
    "Needs Fix",
    "Retested Pass",
    "Blocked/Human Decision",
    "False Positive",
}
FIX_STATUSES = {"Fixed", "Blocked", "In Progress", "Not Started", "N/A"}
BENCHMARK_STATUSES = {
    "Resolved",
    "Needs Validation",
    "Needs Fix",
    "Blocked/Human Decision",
}
CLOSED_NEXT_ACTION_PREFIX = "Closed;"


def _tracker_rows() -> list[dict[str, str]]:
    with TRACKER.open(newline="", encoding="utf-8") as handle:
        return list(csv.DictReader(handle))


def _benchmark_tracker_rows() -> list[dict[str, str]]:
    with BENCHMARK_TRACKER.open(newline="", encoding="utf-8") as handle:
        return list(csv.DictReader(handle))


def test_bug_smoke_tracker_has_valid_rows() -> None:
    rows = _tracker_rows()
    required = (
        "finding_id",
        "category",
        "scope",
        "surface",
        "file_or_pattern",
        "source_evidence",
        "severity",
        "expected_behavior",
        "discovery_method",
        "status",
        "bug_summary",
        "repro_or_detection",
        "fix_strategy",
        "fix_status",
        "validation_command",
        "retest_evidence",
        "last_verified_at",
        "owner",
        "review_status",
        "next_action",
    )

    assert rows
    assert len({row["finding_id"] for row in rows}) == len(rows)
    for row in rows:
        assert None not in row, f"{row.get('finding_id', '<unknown>')} has extra CSV columns"
        for key in required:
            assert row[key].strip(), f"{row.get('finding_id', '<unknown>')} missing {key}"
        assert row["severity"] in {"Low", "Medium", "High", "Critical"}
        assert row["status"] in STATUSES
        assert row["fix_status"] in FIX_STATUSES
        if row["status"] == "Retested Pass":
            assert row["fix_status"] == "Fixed"
            assert row["retest_evidence"].startswith("PASS:")
            assert row["next_action"].startswith(CLOSED_NEXT_ACTION_PREFIX), (
                f"{row['finding_id']} has non-closed next_action"
            )
        if row["status"] == "Blocked/Human Decision":
            assert row["owner"] == "Human Owner"
            assert row["fix_status"] == "Blocked"


def test_ctx_benchmark_tracker_has_valid_rows() -> None:
    rows = _benchmark_tracker_rows()
    required = (
        "id",
        "area",
        "user_story",
        "expected_behavior",
        "status",
        "evidence",
        "repro",
        "risk",
        "fix",
        "reviewer_verdict",
        "last_updated",
    )

    assert rows
    assert len({row["id"] for row in rows}) == len(rows)
    for row in rows:
        assert None not in row, f"{row.get('id', '<unknown>')} has extra CSV columns"
        for key in required:
            assert row[key].strip(), f"{row.get('id', '<unknown>')} missing {key}"
        assert re.fullmatch(r"BENCH-\d{3}", row["id"])
        assert row["status"] in BENCHMARK_STATUSES
        assert re.fullmatch(r"\d{4}-\d{2}-\d{2}", row["last_updated"])


def test_git_tracks_no_generated_garbage_artifacts() -> None:
    result = subprocess.run(
        ["git", "ls-files"],
        cwd=repo_root,
        check=True,
        capture_output=True,
        text=True,
    )
    generated = []
    for line in result.stdout.splitlines():
        path = Path(line)
        if path.name in GENERATED_NAMES or path.suffix in GENERATED_SUFFIXES:
            generated.append(line)
        elif "__pycache__" in path.parts:
            generated.append(line)

    assert generated == []