forked from FSoft-AI4Code/CodeWiki
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_clustering_forced.py
More file actions
103 lines (84 loc) · 3.57 KB
/
Copy pathtest_clustering_forced.py
File metadata and controls
103 lines (84 loc) · 3.57 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
#!/usr/bin/env python3
"""
FORCED clustering test - set max_token_per_module=50 to FORCE LLM call.
"""
import os, sys, logging
# Setup logging
logging.basicConfig(level=logging.INFO, format='[%(levelname)s] %(message)s', force=True)
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from dotenv import load_dotenv
load_dotenv('.env.local')
from codewiki.src.be.cluster_modules import cluster_modules
from codewiki.src.be.dependency_analyzer.models.core import Node
from codewiki.src.config import Config
test_repo = os.getenv(
"TEST_REPO_PATH",
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)
class TestResults:
def __init__(self):
self.tests = []
def add_test(self, name, passed, message=""):
self.tests.append((name, passed, message))
def print_summary(self):
print("\n📊 TEST SUMMARY:\n")
for name, passed, message in self.tests:
status = "✅ PASS" if passed else "❌ FAIL"
print(f"{status}: {name}" + (f" - {message}" if message else ""))
return all(passed for _, passed, _ in self.tests)
results = TestResults()
test_repo = os.getenv("TEST_REPO_PATH", os.path.dirname(os.path.abspath(__file__)))
config = Config(
repo_path=test_repo, output_dir="/tmp/test", dependency_graph_dir="/tmp/test/deps",
docs_dir="/tmp/test/docs", max_depth=2,
main_model=os.getenv("MAIN_MODEL", "gpt-4o"),
cluster_model=os.getenv("CLUSTER_MODEL", "gpt-4o"),
fallback_model=os.getenv("FALLBACK_MODEL", "claude-opus-4-5-20251101"),
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", "")),
cluster_base_url="https://api.openai.com/v1",
main_base_url="https://api.openai.com/v1",
fallback_base_url="https://api.anthropic.com/v1",
max_token_per_module=50, # FORCE CLUSTERING (very low threshold)
cluster_max_tokens=4096 # FIX: Lower max_tokens for gpt-4o
)
print(f"🤖 Model: {config.cluster_model}")
print(f"📏 FORCED max tokens: {config.max_token_per_module} (will force LLM call)\n")
# Create 10 components
components = {}
for i in range(10):
components[str(i)] = Node(
id=str(i), name=f"Component{i}", component_type="class",
file_path=f"{test_repo}/test/Component{i}.java",
relative_path=f"test/Component{i}.java", language="java"
)
print(f"📦 Components: {len(components)}\n")
print("🔄 Running clustering (WILL call LLM)...\n")
print("=" * 80)
module_tree = cluster_modules(
leaf_nodes=list(components.keys()), components=components, config=config,
current_module_tree={}, current_module_name=None, current_module_path=[]
)
print("=" * 80)
print("\n📊 RESULTS:\n")
if len(module_tree) == 0:
results.add_test(
"clustering_produces_module_tree", False,
"Empty module tree - LLM did NOT follow <GROUPED_COMPONENTS> tag format"
)
passed = results.print_summary()
sys.exit(0 if passed else 1)
else:
results.add_test(
"clustering_produces_module_tree", True,
f"{len(module_tree)} modules created"
)
print(f"✅ SUCCESS: {len(module_tree)} modules created")
print("\nModules generated:")
for name, info in module_tree.items():
comp_count = len(info.get('components', []))
print(f" - {name}: {comp_count} components")
print("\n🎉 THE FIX WORKS! LLM followed the <GROUPED_COMPONENTS> tag format!")
passed = results.print_summary()
sys.exit(0 if passed else 1)