-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_stage3.py
More file actions
167 lines (135 loc) · 5.01 KB
/
Copy pathverify_stage3.py
File metadata and controls
167 lines (135 loc) · 5.01 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python3
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (C) 2026 ProtocolWarden
"""Stage 3 Verification Script - Verify all implementation components exist and are syntactically correct."""
import ast
import sys
from pathlib import Path
from typing import List, Tuple
def check_file_exists(path: str) -> Tuple[bool, str]:
"""Check if a file exists."""
p = Path(path)
if p.exists():
return True, f"✓ {path} exists"
return False, f"✗ {path} MISSING"
def check_syntax(path: str) -> Tuple[bool, str]:
"""Check if a Python file has valid syntax."""
try:
with open(path) as f:
ast.parse(f.read())
return True, f"✓ {path} syntax OK"
except SyntaxError as e:
return False, f"✗ {path} syntax error: {e}"
except Exception as e:
return False, f"✗ {path} read error: {e}"
def count_tests(test_file: str) -> Tuple[int, List[str]]:
"""Count test functions in a test file."""
try:
with open(test_file) as f:
tree = ast.parse(f.read())
tests = []
for node in ast.walk(tree):
if isinstance(node, ast.FunctionDef) and node.name.startswith("test_"):
tests.append(node.name)
return len(tests), tests
except Exception:
return 0, []
def main():
print("=" * 70)
print("STAGE 3 VERIFICATION - Flaky Test Reporter Implementation")
print("=" * 70)
results = {"passed": 0, "failed": 0, "tests": 0, "files": []}
# 1. Check implementation files exist
print("\n1. IMPLEMENTATION FILES")
print("-" * 70)
impl_files = [
"src/operations_center/observer/flaky_test_reporter.py",
"src/operations_center/observer/flaky_test_aggregator.py",
"src/operations_center/observer/flaky_test_alerts.py",
"src/operations_center/observer/flaky_test_storage.py",
"src/operations_center/observer/pytest_flaky_plugin.py",
"src/operations_center/observer/collectors/flaky_test_collector.py",
]
for f in impl_files:
exists, msg = check_file_exists(f)
print(msg)
if exists:
results["passed"] += 1
else:
results["failed"] += 1
# 2. Check syntax of implementation files
print("\n2. SYNTAX VALIDATION")
print("-" * 70)
for f in impl_files:
if Path(f).exists():
ok, msg = check_syntax(f)
print(msg)
if ok:
results["passed"] += 1
else:
results["failed"] += 1
# 3. Check test files exist
print("\n3. TEST FILES")
print("-" * 70)
test_files = [
"tests/unit/observer/test_flaky_test_reporter.py",
"tests/unit/observer/test_flaky_test_aggregator.py",
"tests/unit/observer/test_flaky_test_alerts.py",
"tests/unit/observer/test_flaky_test_storage.py",
"tests/unit/observer/test_flaky_test_collector.py",
"tests/integration/observer/test_flaky_test_integration.py",
]
test_counts = {}
total_tests = 0
for f in test_files:
exists, msg = check_file_exists(f)
print(msg)
if exists:
results["passed"] += 1
count, tests = count_tests(f)
test_counts[f] = count
total_tests += count
if count > 0:
print(f" → {count} test functions found")
else:
results["failed"] += 1
# 4. Count and classify tests
print("\n4. TEST BREAKDOWN")
print("-" * 70)
unit_tests = sum(c for k, c in test_counts.items() if "unit" in k)
integration_tests = sum(c for k, c in test_counts.items() if "integration" in k)
print(f"Unit tests (core functionality): {unit_tests}")
print(f"Integration tests: {integration_tests}")
print(f"Total tests: {total_tests}")
# 5. Verify acceptance criteria
print("\n5. ACCEPTANCE CRITERIA")
print("-" * 70)
criteria = [
("Unit tests ≥20", unit_tests >= 20, unit_tests),
("Integration tests ≥15", integration_tests >= 15, integration_tests),
("Edge case tests ≥10", total_tests >= 45, total_tests), # 20+15+10
("All test files syntactically correct", results["failed"] == 0, results["failed"]),
]
criteria_passed = 0
for desc, ok, value in criteria:
status = "✓" if ok else "✗"
print(f"{status} {desc} ({value})")
if ok:
criteria_passed += 1
# 6. Summary
print("\n" + "=" * 70)
print("SUMMARY")
print("=" * 70)
print(f"Files checked: {results['passed']} passed, {results['failed']} failed")
print(f"Tests implemented: {total_tests} total")
print(f" - Unit: {unit_tests}")
print(f" - Integration: {integration_tests}")
print(f"Acceptance criteria met: {criteria_passed}/4")
if criteria_passed == 4 and total_tests >= 45:
print("\n✓ STAGE 3 READY FOR TESTING")
return 0
else:
print("\n✗ STAGE 3 INCOMPLETE - See details above")
return 1
if __name__ == "__main__":
sys.exit(main())