forked from FSoft-AI4Code/CodeWiki
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_subdirectory_fix.py
More file actions
97 lines (85 loc) · 2.93 KB
/
Copy pathtest_subdirectory_fix.py
File metadata and controls
97 lines (85 loc) · 2.93 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
#!/usr/bin/env python3
"""
Test to verify that ALL modules now create subdirectories.
"""
import os
import sys
# Add CodeWiki to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from codewiki.src.be.documentation_generator import DocumentationGenerator
from codewiki.src.config import Config
# Create minimal config
config = Config(
cluster_api_key=os.getenv("CLUSTER_API_KEY", os.getenv("OPENAI_API_KEY", "")),
main_api_key=os.getenv("MAIN_API_KEY", os.getenv("OPENAI_API_KEY", "")),
fallback_api_key=os.getenv("FALLBACK_API_KEY", os.getenv("ANTHROPIC_API_KEY", "")),
repo_path="/tmp/test",
output_dir="/tmp/test_output",
dependency_graph_dir="/tmp/test_output/deps",
docs_dir="/tmp/test_output/docs",
max_depth=2,
main_model="gpt-4o",
cluster_model="gpt-4o",
fallback_model="claude-opus-4-5-20251101",
cluster_base_url="https://api.openai.com/v1",
main_base_url="https://api.openai.com/v1",
fallback_base_url="https://api.anthropic.com/v1"
)
# Create generator instance
generator = DocumentationGenerator(config)
# Test cases
base_dir = "/tmp/test_docs"
test_cases = [
{
"name": "Root-level module",
"module_path": ["gateway_service_core"],
"expected": "/tmp/test_docs/gateway_service_core"
},
{
"name": "Single nested module",
"module_path": ["Backend", "Authentication"],
"expected": "/tmp/test_docs/Backend/Authentication"
},
{
"name": "Deep nested module",
"module_path": ["Backend", "Authentication", "JWT"],
"expected": "/tmp/test_docs/Backend/Authentication/JWT"
},
{
"name": "Empty path (repository overview)",
"module_path": [],
"expected": "/tmp/test_docs"
}
]
print("Testing subdirectory creation logic...")
print("=" * 80)
all_passed = True
for test in test_cases:
result = generator._get_nested_working_dir(base_dir, test["module_path"])
expected = os.path.abspath(test["expected"])
passed = result == expected
status = "✅ PASS" if passed else "❌ FAIL"
print(f"\n{status}: {test['name']}")
print(f" Module path: {test['module_path']}")
print(f" Expected: {expected}")
print(f" Got: {result}")
if not passed:
all_passed = False
print("\n" + "=" * 80)
if all_passed:
print("✅✅✅ ALL TESTS PASSED ✅✅✅")
print("\n🎉 The fix works! Root-level modules now create subdirectories!")
print("\nExample structure:")
print(" docs/reference/architecture/")
print(" ├── gateway_service_core/")
print(" │ └── gateway_service_core.md")
print(" ├── api_endpoints/")
print(" │ └── api_endpoints.md")
print(" └── Backend/")
print(" └── Authentication/")
print(" └── JWT/")
print(" └── JWT.md")
sys.exit(0)
else:
print("❌ SOME TESTS FAILED")
sys.exit(1)