Repository navigation
Expand file tree
/
Copy pathtest_nested_discovery.py
More file actions
192 lines (144 loc) · 5.61 KB
/
Copy pathtest_nested_discovery.py
File metadata and controls
192 lines (144 loc) · 5.61 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
#!/usr/bin/env python3
"""Test script for nested skill discovery (sync and async).
This script validates that both sync and async discovery methods correctly
discover skills in nested directory structures.
"""
import asyncio
from pathlib import Path
from skillkit import SkillManager
def test_sync_nested_discovery():
"""Test synchronous nested skill discovery."""
print("=" * 70)
print("Testing Synchronous Nested Discovery")
print("=" * 70)
# Use the nested-example directory
nested_skills_dir = Path(__file__).parent / "skills" / "nested-example"
if not nested_skills_dir.exists():
print(f"ERROR: Nested skills directory not found: {nested_skills_dir}")
return False
# Create manager with nested skills
manager = SkillManager(project_skill_dir=nested_skills_dir)
# Discover skills synchronously
print(f"\nScanning: {nested_skills_dir}")
manager.discover()
# List discovered skills
skills = manager.list_skills()
print(f"\nDiscovered {len(skills)} skills:")
expected_skills = {
"nested-root-skill",
"nested-mid-skill",
"nested-deep-skill",
"nested-category-b",
}
for metadata in skills:
depth = len(metadata.skill_path.parent.relative_to(nested_skills_dir).parts)
print(f" - {metadata.name}: {metadata.description}")
print(f" Path: {metadata.skill_path.relative_to(nested_skills_dir)}")
print(f" Depth: {depth}")
# Validate all expected skills were found
found_names = {m.name for m in skills}
missing = expected_skills - found_names
extra = found_names - expected_skills
if missing:
print(f"\n❌ FAILED: Missing skills: {missing}")
return False
if extra:
print(f"\n⚠️ WARNING: Extra skills found: {extra}")
print(f"\n✅ PASSED: All {len(expected_skills)} expected skills discovered")
return True
async def test_async_nested_discovery():
"""Test asynchronous nested skill discovery."""
print("\n" + "=" * 70)
print("Testing Asynchronous Nested Discovery")
print("=" * 70)
# Use the nested-example directory
nested_skills_dir = Path(__file__).parent / "skills" / "nested-example"
if not nested_skills_dir.exists():
print(f"ERROR: Nested skills directory not found: {nested_skills_dir}")
return False
# Create manager with nested skills
manager = SkillManager(project_skill_dir=nested_skills_dir)
# Discover skills asynchronously
print(f"\nScanning (async): {nested_skills_dir}")
await manager.adiscover()
# List discovered skills
skills = manager.list_skills()
print(f"\nDiscovered {len(skills)} skills:")
expected_skills = {
"nested-root-skill",
"nested-mid-skill",
"nested-deep-skill",
"nested-category-b",
}
for metadata in skills:
depth = len(metadata.skill_path.parent.relative_to(nested_skills_dir).parts)
print(f" - {metadata.name}: {metadata.description}")
print(f" Path: {metadata.skill_path.relative_to(nested_skills_dir)}")
print(f" Depth: {depth}")
# Validate all expected skills were found
found_names = {m.name for m in skills}
missing = expected_skills - found_names
extra = found_names - expected_skills
if missing:
print(f"\n❌ FAILED: Missing skills: {missing}")
return False
if extra:
print(f"\n⚠️ WARNING: Extra skills found: {extra}")
print(f"\n✅ PASSED: All {len(expected_skills)} expected skills discovered")
return True
async def test_sync_async_consistency():
"""Test that sync and async discovery produce identical results."""
print("\n" + "=" * 70)
print("Testing Sync/Async Consistency")
print("=" * 70)
nested_skills_dir = Path(__file__).parent / "skills" / "nested-example"
# Sync discovery
manager_sync = SkillManager(project_skill_dir=nested_skills_dir)
manager_sync.discover()
sync_skills = {m.name for m in manager_sync.list_skills()}
# Async discovery
manager_async = SkillManager(project_skill_dir=nested_skills_dir)
await manager_async.adiscover()
async_skills = {m.name for m in manager_async.list_skills()}
print(f"Sync discovered: {len(sync_skills)} skills")
print(f"Async discovered: {len(async_skills)} skills")
if sync_skills == async_skills:
print("✅ PASSED: Sync and async produce identical results")
return True
else:
print("❌ FAILED: Sync and async produced different results")
print(f" Sync only: {sync_skills - async_skills}")
print(f" Async only: {async_skills - sync_skills}")
return False
async def main():
"""Run all tests."""
print("\n" + "=" * 70)
print("Nested Skill Discovery Tests")
print("=" * 70)
results = []
# Run sync test
results.append(("Sync Discovery", test_sync_nested_discovery()))
# Run async test
results.append(("Async Discovery", await test_async_nested_discovery()))
# Run consistency test
results.append(("Sync/Async Consistency", await test_sync_async_consistency()))
# Summary
print("\n" + "=" * 70)
print("Test Summary")
print("=" * 70)
all_passed = True
for test_name, passed in results:
status = "✅ PASSED" if passed else "❌ FAILED"
print(f"{test_name}: {status}")
if not passed:
all_passed = False
print("=" * 70)
if all_passed:
print("✅ All tests passed!")
return 0
else:
print("❌ Some tests failed")
return 1
if __name__ == "__main__":
exit_code = asyncio.run(main())
exit(exit_code)