-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_workflow_refactor.py
More file actions
268 lines (209 loc) · 7.89 KB
/
Copy pathtest_workflow_refactor.py
File metadata and controls
268 lines (209 loc) · 7.89 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
"""Test Workflow After Refactoring
Tests that the system initializes correctly after tools reorganization.
Validates:
- Tool loading from new paths (tools/core/)
- Domain role initialization
- Fast-reply role recognition
- System startup
"""
import asyncio
import logging
import sys
from pathlib import Path
# Add project root to path
sys.path.insert(0, str(Path(__file__).parent))
from llm_provider.factory import LLMFactory
from llm_provider.role_registry import RoleRegistry
from llm_provider.tool_registry import ToolRegistry
logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(name)s - %(message)s")
logger = logging.getLogger(__name__)
async def test_tool_registry():
"""Test ToolRegistry loads tools from new structure."""
print("\n" + "=" * 60)
print("TEST 1: ToolRegistry Initialization")
print("=" * 60)
try:
tool_registry = ToolRegistry()
# Create mock providers
class MockProvider:
pass
providers = type(
"Providers",
(),
{
"memory": MockProvider(),
"communication": MockProvider(),
"weather": None,
"calendar": None,
"timer": None,
"home_assistant": None,
"search": None,
"planning": None,
},
)()
await tool_registry.initialize(config={}, providers=providers)
# Check loaded tools
total_tools = len(tool_registry._tools)
categories = len(tool_registry._categories)
print(f"\n✅ ToolRegistry initialized")
print(f" Total tools loaded: {total_tools}")
print(f" Categories: {categories}")
# Check if memory and notification tools loaded
memory_tools = [
name for name in tool_registry._tools.keys() if name.startswith("memory.")
]
notification_tools = [
name
for name in tool_registry._tools.keys()
if name.startswith("notification.")
]
print(f"\n Memory tools: {memory_tools}")
print(f" Notification tools: {notification_tools}")
if memory_tools:
print(f"\n✅ Memory tools loaded from tools/core/memory.py")
else:
print(f"\n⚠️ No memory tools loaded")
if notification_tools:
print(f"✅ Notification tools loaded from tools/core/notification.py")
else:
print(f"⚠️ No notification tools loaded")
return True
except Exception as e:
print(f"\n❌ ToolRegistry test failed: {e}")
import traceback
traceback.print_exc()
return False
async def test_role_registry():
"""Test RoleRegistry with domain roles."""
print("\n" + "=" * 60)
print("TEST 2: RoleRegistry Initialization")
print("=" * 60)
try:
# Initialize dependencies
tool_registry = ToolRegistry()
class MockProvider:
pass
providers = type(
"Providers",
(),
{
"memory": MockProvider(),
"communication": MockProvider(),
"weather": None,
"calendar": None,
"timer": None,
"home_assistant": None,
"search": None,
"planning": None,
},
)()
await tool_registry.initialize(config={}, providers=providers)
llm_factory = LLMFactory({})
role_registry = RoleRegistry(roles_directory=Path("roles"))
# Initialize domain roles
await role_registry.initialize_domain_roles(tool_registry, llm_factory)
print(f"\n✅ RoleRegistry initialized")
print(f" Total roles: {len(role_registry.llm_roles)}")
print(f" Domain roles: {list(role_registry.domain_role_instances.keys())}")
# Check fast-reply roles
fast_reply_roles = role_registry.get_fast_reply_roles()
print(f"\n Fast-reply roles: {len(fast_reply_roles)}")
print(f" Names: {[r.name for r in fast_reply_roles]}")
# Check domain roles specifically
domain_roles = ["timer", "calendar", "weather", "smart_home"]
domain_fast_reply = [r.name for r in fast_reply_roles if r.name in domain_roles]
if len(domain_fast_reply) == 4:
print(f"\n✅ All 4 domain roles are fast-reply enabled")
else:
print(
f"\n⚠️ Only {len(domain_fast_reply)} domain roles are fast-reply: {domain_fast_reply}"
)
# Check role configs
print(f"\n Domain Role Configurations:")
for role_name in domain_roles:
role_def = role_registry.llm_roles.get(role_name)
if role_def:
role_config = role_def.config.get("role", {})
fast_reply = role_config.get("fast_reply", False)
llm_type = role_config.get("llm_type", "N/A")
print(f" - {role_name}: fast_reply={fast_reply}, llm_type={llm_type}")
return True
except Exception as e:
print(f"\n❌ RoleRegistry test failed: {e}")
import traceback
traceback.print_exc()
return False
async def test_system_integration():
"""Test full system integration."""
print("\n" + "=" * 60)
print("TEST 3: System Integration")
print("=" * 60)
try:
# This simulates what Supervisor does on startup
tool_registry = ToolRegistry()
class MockProvider:
pass
providers = type(
"Providers",
(),
{
"memory": MockProvider(),
"communication": MockProvider(),
"weather": None,
"calendar": None,
"timer": None,
"home_assistant": None,
"search": None,
"planning": None,
},
)()
await tool_registry.initialize(config={}, providers=providers)
llm_factory = LLMFactory({})
role_registry = RoleRegistry(roles_directory=Path("roles"))
await role_registry.initialize_domain_roles(tool_registry, llm_factory)
# Check that domain roles can access their tools
print(f"\n Testing domain role tool access:")
for role_name in ["timer", "calendar", "weather", "smart_home"]:
role_instance = role_registry.get_domain_role(role_name)
if role_instance:
tools = role_instance.get_tools()
print(f" - {role_name}: {len(tools)} tools loaded")
else:
print(f" - {role_name}: ❌ Not found")
print(f"\n✅ System integration successful")
return True
except Exception as e:
print(f"\n❌ System integration test failed: {e}")
import traceback
traceback.print_exc()
return False
async def main():
"""Run all tests."""
print("\n" + "=" * 60)
print("WORKFLOW REFACTORING VALIDATION")
print("Testing tools reorganization impact")
print("=" * 60)
results = []
# Run tests
results.append(("ToolRegistry", await test_tool_registry()))
results.append(("RoleRegistry", await test_role_registry()))
results.append(("System Integration", await test_system_integration()))
# Summary
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
passed = sum(1 for _, result in results if result)
total = len(results)
for name, result in results:
status = "✅ PASS" if result else "❌ FAIL"
print(f"{status} - {name}")
print(f"\nTotal: {passed}/{total} tests passed")
if passed == total:
print("\n✅ ALL TESTS PASSED - System is working correctly!")
return 0
else:
print(f"\n⚠️ {total - passed} test(s) failed - Review errors above")
return 1
if __name__ == "__main__":
exit_code = asyncio.run(main())
sys.exit(exit_code)