-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_phase3.py
More file actions
233 lines (184 loc) · 7.08 KB
/
Copy pathvalidate_phase3.py
File metadata and controls
233 lines (184 loc) · 7.08 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
"""Phase 3 Validation Script
Validates that all Phase 3 role updates are complete and working.
Tests that roles can be imported, initialized, and declare their tools correctly.
"""
import sys
def validate_role_imports():
"""Test that all role classes can be imported."""
print("=" * 60)
print("Phase 3 Validation: Testing Role Imports")
print("=" * 60)
roles = [
("weather", "roles.weather", "WeatherRole"),
("calendar", "roles.calendar", "CalendarRole"),
("timer", "roles.timer", "TimerRole"),
("smart_home", "roles.smart_home", "SmartHomeRole"),
]
all_passed = True
for domain_name, module_path, class_name in roles:
try:
module = __import__(module_path, fromlist=[class_name])
role_class = getattr(module, class_name)
print(f"✓ {domain_name}: {module_path}.{class_name} imported")
except ImportError as e:
print(f"✗ {domain_name}: Import failed - {e}")
all_passed = False
except AttributeError as e:
print(f"✗ {domain_name}: Class not found - {e}")
all_passed = False
return all_passed
def validate_role_structure():
"""Test that roles have the correct structure and required tools."""
print("\n" + "=" * 60)
print("Phase 3 Validation: Testing Role Structure")
print("=" * 60)
from roles.calendar import CalendarRole
from roles.smart_home import SmartHomeRole
from roles.timer import TimerRole
from roles.weather import WeatherRole
test_cases = [
(
"weather",
WeatherRole,
["weather.get_current_weather", "weather.get_forecast"],
),
(
"calendar",
CalendarRole,
["calendar.get_schedule", "calendar.add_calendar_event"],
),
(
"timer",
TimerRole,
["timer.set_timer", "timer.cancel_timer", "timer.list_timers"],
),
(
"smart_home",
SmartHomeRole,
[
"smart_home.ha_call_service",
"smart_home.ha_get_state",
"smart_home.ha_list_entities",
],
),
]
all_passed = True
for domain_name, role_class, expected_tools in test_cases:
try:
# Check REQUIRED_TOOLS class variable
if not hasattr(role_class, "REQUIRED_TOOLS"):
print(f"✗ {domain_name}: Missing REQUIRED_TOOLS class variable")
all_passed = False
continue
required_tools = role_class.REQUIRED_TOOLS
if not isinstance(required_tools, list):
print(
f"✗ {domain_name}: REQUIRED_TOOLS is not a list, got {type(required_tools)}"
)
all_passed = False
continue
if set(required_tools) != set(expected_tools):
print(
f"✗ {domain_name}: REQUIRED_TOOLS mismatch. Expected {expected_tools}, got {required_tools}"
)
all_passed = False
continue
print(
f"✓ {domain_name}: REQUIRED_TOOLS correct ({len(required_tools)} tools)"
)
# Check for required methods
required_methods = ["__init__", "initialize", "execute"]
for method in required_methods:
if not hasattr(role_class, method):
print(f"✗ {domain_name}: Missing required method '{method}'")
all_passed = False
else:
print(f"✓ {domain_name}: Has method '{method}'")
except Exception as e:
print(f"✗ {domain_name}: Structure validation failed - {e}")
all_passed = False
return all_passed
def validate_role_instantiation():
"""Test that roles can be instantiated with mock dependencies."""
print("\n" + "=" * 60)
print("Phase 3 Validation: Testing Role Instantiation")
print("=" * 60)
from roles.calendar import CalendarRole
from roles.smart_home import SmartHomeRole
from roles.timer import TimerRole
from roles.weather import WeatherRole
# Create mock dependencies
class MockToolRegistry:
def get_tools(self, tool_names):
return [] # Return empty list for mock
class MockLLMFactory:
def create_strands_model(self, llm_type):
return None # Return None for mock
mock_registry = MockToolRegistry()
mock_factory = MockLLMFactory()
test_cases = [
("weather", WeatherRole),
("calendar", CalendarRole),
("timer", TimerRole),
("smart_home", SmartHomeRole),
]
all_passed = True
for domain_name, role_class in test_cases:
try:
role = role_class(mock_registry, mock_factory)
# Check basic attributes
if not hasattr(role, "tool_registry"):
print(f"✗ {domain_name}: Missing 'tool_registry' attribute")
all_passed = False
continue
if not hasattr(role, "llm_factory"):
print(f"✗ {domain_name}: Missing 'llm_factory' attribute")
all_passed = False
continue
if not hasattr(role, "tools"):
print(f"✗ {domain_name}: Missing 'tools' attribute")
all_passed = False
continue
if not hasattr(role, "name"):
print(f"✗ {domain_name}: Missing 'name' attribute")
all_passed = False
continue
print(f"✓ {domain_name}: Role instantiated successfully")
except Exception as e:
print(f"✗ {domain_name}: Instantiation failed - {e}")
all_passed = False
return all_passed
def main():
"""Run all Phase 3 validation tests."""
print("\n" + "=" * 60)
print("PHASE 3 ROLE UPDATES VALIDATION")
print("=" * 60 + "\n")
results = []
# Test imports
results.append(("Role Imports", validate_role_imports()))
# Test structure
results.append(("Role Structure", validate_role_structure()))
# Test instantiation
results.append(("Role Instantiation", validate_role_instantiation()))
# Summary
print("\n" + "=" * 60)
print("VALIDATION SUMMARY")
print("=" * 60)
for test_name, passed in results:
status = "✓ PASSED" if passed else "✗ FAILED"
print(f"{test_name}: {status}")
all_passed = all(passed for _, passed in results)
if all_passed:
print("\n✓ All Phase 3 validation tests PASSED!")
print("\nPhase 3 Complete:")
print("- 4 predefined roles updated to new pattern")
print("- Each role declares REQUIRED_TOOLS")
print("- Roles load tools from central ToolRegistry")
print("- Intent collection integrated into execution")
print("\nNext: Update RoleRegistry and Supervisor initialization")
return 0
else:
print("\n✗ Some Phase 3 validation tests FAILED")
return 1
if __name__ == "__main__":
sys.exit(main())