-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_assets.py
More file actions
163 lines (136 loc) · 4.98 KB
/
test_assets.py
File metadata and controls
163 lines (136 loc) · 4.98 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
#!/usr/bin/env python3
"""
Test script for NextEvolution asset structures.
"""
import sys
from pathlib import Path
# Add the project root to the Python path
project_root = Path(__file__).parent.absolute()
if str(project_root) not in sys.path:
sys.path.insert(0, str(project_root))
# Import using absolute imports from .core package
from core.assets import Gene, Capsule, EvolutionEvent, Bundle, BundleBuilder
def test_gene():
"""Test Gene creation and validation."""
print("Testing Gene...")
gene = Gene.create(
category="repair",
signals_match=["TypeError", "undefined variable"],
summary="Fix common type errors in variable declarations"
)
print(f" Gene created: {gene.asset_id}")
print(f" Category: {gene.category}")
print(f" Signals: {gene.signals_match}")
print(" Gene validation: PASSED")
return gene
def test_capsule(gene_id):
"""Test Capsule creation and validation."""
print("\nTesting Capsule...")
capsule = Capsule.create(
trigger=["TypeError in main.py"],
gene=gene_id,
summary="Fixed undefined variable bug in main function by adding proper variable declaration",
confidence=0.9,
blast_radius={"files": 1, "lines": 5},
env_fingerprint={"platform": "linux", "arch": "x64"}
)
print(f" Capsule created: {capsule.asset_id}")
print(f" Gene reference: {capsule.gene}")
print(f" Confidence: {capsule.confidence}")
print(" Capsule validation: PASSED")
return capsule
def test_event(capsule_id, gene_id):
"""Test EvolutionEvent creation and validation."""
print("\nTesting EvolutionEvent...")
event = EvolutionEvent.create(
intent="repair",
capsule_id=capsule_id,
genes_used=[gene_id],
outcome={"status": "success", "score": 0.95}
)
print(f" Event created: {event.asset_id}")
print(f" Intent: {event.intent}")
print(f" Outcome: {event.outcome}")
print(" EvolutionEvent validation: PASSED")
return event
def test_bundle(gene, capsule, event):
"""Test Bundle assembly and validation."""
print("\nTesting Bundle assembly...")
bundle = Bundle.assemble(gene, capsule, event)
print(f" Bundle created: {bundle.bundle_id}")
print(f" Summary: {bundle.get_summary()}")
print(f" Asset IDs: {bundle.get_asset_ids()}")
print(" Bundle validation: PASSED")
return bundle
def test_bundle_builder():
"""Test BundleBuilder fluent interface."""
print("\nTesting BundleBuilder...")
builder = BundleBuilder()
bundle = (builder
.with_gene(
category="optimize",
signals_match=["slow loop", "O(n^2)"],
summary="Optimize nested loops for better performance"
)
.with_capsule(
trigger=["slow loop detected"],
summary="Refactored nested loop to use hash map lookup",
confidence=0.85,
blast_radius={"files": 2, "lines": 15},
env_fingerprint={"platform": "darwin", "arch": "arm64"}
)
.with_event(
outcome={"status": "success", "score": 0.88}
)
.with_metadata(test_run=True, version="1.0")
.build())
print(f" Builder bundle created: {bundle.bundle_id}")
print(f" Summary: {bundle.get_summary()}")
print(" BundleBuilder: PASSED")
return bundle
def test_serialization(bundle):
"""Test to_dict serialization."""
print("\nTesting serialization...")
bundle_dict = bundle.to_dict()
print(f" Bundle dict keys: {list(bundle_dict.keys())}")
print(f" Has gene: {'gene' in bundle_dict}")
print(f" Has capsule: {'capsule' in bundle_dict}")
print(f" Has event: {'event' in bundle_dict}")
print(" Serialization: PASSED")
def test_deserialization(bundle_dict):
"""Test from_dict deserialization."""
print("\nTesting deserialization...")
bundle = Bundle.from_dict(bundle_dict)
print(f" Reconstructed bundle ID: {bundle.bundle_id}")
print(f" Gene category: {bundle.gene.category}")
print(f" Capsule confidence: {bundle.capsule.confidence}")
print(" Deserialization: PASSED")
def main():
"""Run all tests."""
print("=" * 60)
print("NextEvolution Asset Structure Tests")
print("=" * 60)
try:
# Test individual components
gene = test_gene()
capsule = test_capsule(gene.asset_id)
event = test_event(capsule.asset_id, gene.asset_id)
# Test bundle assembly
bundle = test_bundle(gene, capsule, event)
# Test serialization
bundle_dict = bundle.to_dict()
test_serialization(bundle)
test_deserialization(bundle_dict)
# Test BundleBuilder
builder_bundle = test_bundle_builder()
print("\n" + "=" * 60)
print("All tests PASSED!")
print("=" * 60)
return 0
except Exception as e:
print(f"\nTest FAILED: {e}")
import traceback
traceback.print_exc()
return 1
if __name__ == "__main__":
sys.exit(main())