-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sdk_build.py
More file actions
145 lines (124 loc) Β· 5.24 KB
/
test_sdk_build.py
File metadata and controls
145 lines (124 loc) Β· 5.24 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
#!/usr/bin/env python3
"""
Test: Build Analytics SDK with adversarial validation vs baseline
"""
import sys
from pathlib import Path
from adversarial_coding import adversarial_build, build_with_baseline
import json
# Test task
SDK_TASK = """
Build a JavaScript Analytics SDK for event tracking.
REQUIREMENTS:
- Batching: Queue events and send in batches (configurable batch size)
- Retry logic: Retry failed requests with exponential backoff
- Validation: Reject malformed events before queuing
- Rate limiting: Prevent overwhelming the API
- Offline support: Queue events when offline, send when back online
- Tests: Comprehensive unit tests for all functionality
- Health check: Script that validates SDK is working correctly
SCALE: Must efficiently handle 1M events/day (batching is critical)
OUTPUT:
- sdk.js (or sdk/ directory with modules)
- tests/ directory with test files
- health-check.js script
- README.md with usage examples
- package.json with dependencies
"""
def run_test():
"""Run the validation test"""
print("\n" + "="*70)
print("π§ͺ VALIDATION TEST: Analytics SDK")
print("="*70)
base_dir = Path(__file__).parent
# Test 1: Baseline (single agent)
print("\n\nπ¦ TEST 1: BASELINE BUILD (Single Agent)")
print("="*70)
baseline_dir = base_dir / "test_output" / "baseline_sdk"
baseline_dir.mkdir(parents=True, exist_ok=True)
try:
baseline_result = build_with_baseline(
SDK_TASK,
str(baseline_dir),
agent_type="codex",
verbose=True
)
except Exception as e:
print(f"β Baseline build failed with error: {e}")
baseline_result = {"success": False, "error": str(e)}
# Test 2: Adversarial
print("\n\nβοΈ TEST 2: ADVERSARIAL BUILD")
print("="*70)
adversarial_dir = base_dir / "test_output" / "adversarial_sdk"
adversarial_dir.mkdir(parents=True, exist_ok=True)
try:
adversarial_result = adversarial_build(
SDK_TASK,
str(adversarial_dir),
max_rounds=3,
agent_type="codex",
verbose=True
)
except Exception as e:
print(f"β Adversarial build failed with error: {e}")
adversarial_result = {"success": False, "error": str(e)}
# Compare results
print("\n\n" + "="*70)
print("π COMPARISON")
print("="*70)
comparison = {
"baseline": {
"success": baseline_result.get("success", False),
"rounds": baseline_result.get("rounds", 0),
"files_created": len(baseline_result.get("files_created", [])),
"tests_exist": baseline_result.get("validation", {}).get("tests_exist", False),
"tests_pass": baseline_result.get("validation", {}).get("tests_pass", False),
"workdir": str(baseline_dir)
},
"adversarial": {
"success": adversarial_result.get("success", False),
"rounds": adversarial_result.get("rounds", 0),
"files_created": len(adversarial_result.get("files_created", [])),
"tests_exist": adversarial_result.get("validation", {}).get("tests_exist", False),
"tests_pass": adversarial_result.get("validation", {}).get("tests_pass", False),
"workdir": str(adversarial_dir)
}
}
print("\nBASELINE:")
print(f" Success: {comparison['baseline']['success']}")
print(f" Files: {comparison['baseline']['files_created']}")
print(f" Tests exist: {comparison['baseline']['tests_exist']}")
print(f" Tests pass: {comparison['baseline']['tests_pass']}")
print("\nADVERSARIAL:")
print(f" Success: {comparison['adversarial']['success']}")
print(f" Rounds: {comparison['adversarial']['rounds']}")
print(f" Files: {comparison['adversarial']['files_created']}")
print(f" Tests exist: {comparison['adversarial']['tests_exist']}")
print(f" Tests pass: {comparison['adversarial']['tests_pass']}")
print("\nWINNER:")
if comparison['adversarial']['success'] and not comparison['baseline']['success']:
print(" βοΈ ADVERSARIAL - Only adversarial produced working code")
elif comparison['baseline']['success'] and not comparison['adversarial']['success']:
print(" π¦ BASELINE - Only baseline produced working code")
elif comparison['adversarial']['success'] and comparison['baseline']['success']:
print(" π€ BOTH - Need to compare quality manually")
else:
print(" β NEITHER - Both failed to produce working code")
print(f"\nπ Check outputs:")
print(f" Baseline: {baseline_dir}")
print(f" Adversarial: {adversarial_dir}")
# Save comparison
comparison_file = base_dir / "test_output" / "comparison.json"
with open(comparison_file, 'w') as f:
json.dump(comparison, f, indent=2)
print(f"\nπ Comparison saved to: {comparison_file}")
return comparison
if __name__ == "__main__":
comparison = run_test()
# Exit code: 0 if adversarial is better or equal, 1 otherwise
adversarial_better = (
comparison['adversarial']['success'] and
(not comparison['baseline']['success'] or
comparison['adversarial']['tests_pass'])
)
sys.exit(0 if adversarial_better else 1)