-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_strategies.py
More file actions
executable file
·187 lines (151 loc) · 5.41 KB
/
Copy pathtest_strategies.py
File metadata and controls
executable file
·187 lines (151 loc) · 5.41 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python3
"""
Test script to validate all example strategies work correctly.
"""
import subprocess
import sys
from pathlib import Path
import yaml
def validate_strategy_yaml(file_path):
"""Validate a strategy YAML file."""
print(f"\n🔍 Validating: {file_path.name}")
try:
with open(file_path) as f:
strategy = yaml.safe_load(f)
# Check required fields
required_fields = ["name", "project_name", "project_type", "domain", "goal"]
missing = [field for field in required_fields if field not in strategy]
if missing:
print(f" ❌ Missing required fields: {', '.join(missing)}")
return False
# Check sprints
if "sprints" in strategy:
for sprint in strategy["sprints"]:
if "id" not in sprint or "name" not in sprint:
print(" ❌ Sprint missing id or name")
return False
# Check quality gates
if "quality_gates" in strategy:
for gate in strategy["quality_gates"]:
if "metric" not in gate or "threshold" not in gate:
print(" ❌ Quality gate missing metric or threshold")
return False
print(" ✅ Valid strategy structure")
return True
except yaml.YAMLError as e:
print(f" ❌ YAML error: {e}")
return False
except Exception as e:
print(f" ❌ Error: {e}")
return False
def test_strategy_generation(strategy_path):
"""Test strategy generation with the YAML file."""
print(f"\n🚀 Testing generation with: {strategy_path.name}")
cmd = [
sys.executable,
"-m",
"planfile.cli.commands",
"generate",
"--dry-run",
str(strategy_path),
]
try:
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
if result.returncode == 0:
print(" ✅ Generation successful")
return True
else:
print(f" ❌ Generation failed: {result.stderr}")
return False
except subprocess.TimeoutExpired:
print(" ⏰ Generation timed out")
return False
except Exception as e:
print(f" ❌ Error: {e}")
return False
def test_strategy_validation(strategy_path):
"""Test strategy validation."""
print(f"\n✅ Testing validation for: {strategy_path.name}")
cmd = [sys.executable, "-m", "planfile.cli.commands", "validate", str(strategy_path)]
try:
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
if result.returncode == 0:
print(" ✅ Validation passed")
return True
else:
print(f" ❌ Validation failed: {result.stderr}")
return False
except subprocess.TimeoutExpired:
print(" ⏰ Validation timed out")
return False
except Exception as e:
print(f" ❌ Error: {e}")
return False
def main():
"""Run all tests."""
print("=" * 60)
print("Testing Planfile Example Strategies")
print("=" * 60)
strategies_dir = Path("./strategies")
if not strategies_dir.exists():
print(f"❌ Strategies directory not found: {strategies_dir}")
sys.exit(1)
# Find all YAML files
yaml_files = list(strategies_dir.glob("*.yaml")) + list(strategies_dir.glob("*.yml"))
if not yaml_files:
print("❌ No YAML strategy files found")
sys.exit(1)
print(f"\nFound {len(yaml_files)} strategy files")
# Test each strategy
results = []
for strategy_file in sorted(yaml_files):
print("\n" + "=" * 40)
# Validate YAML structure
valid = validate_strategy_yaml(strategy_file)
if valid:
# Test validation command
validation_ok = test_strategy_validation(strategy_file)
# Test generation (dry run)
generation_ok = test_strategy_generation(strategy_file)
results.append(
{
"file": strategy_file.name,
"valid": valid,
"validation": validation_ok,
"generation": generation_ok,
}
)
else:
results.append(
{
"file": strategy_file.name,
"valid": False,
"validation": False,
"generation": False,
}
)
# Summary
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
total = len(results)
passed = sum(1 for r in results if all([r["valid"], r["validation"], r["generation"]]))
print(f"\nTotal strategies: {total}")
print(f"✅ Passed: {passed}")
print(f"❌ Failed: {total - passed}")
if total - passed > 0:
print("\nFailed strategies:")
for r in results:
if not all([r["valid"], r["validation"], r["generation"]]):
status = []
if not r["valid"]:
status.append("invalid")
if not r["validation"]:
status.append("validation failed")
if not r["generation"]:
status.append("generation failed")
print(f" - {r['file']}: {', '.join(status)}")
# Exit with appropriate code
sys.exit(0 if passed == total else 1)
if __name__ == "__main__":
main()