diff --git a/test_clustering_debug.py b/test_clustering_debug.py index eb427a81..4b635cf6 100644 --- a/test_clustering_debug.py +++ b/test_clustering_debug.py @@ -47,10 +47,42 @@ def patched_call(*call_args, **call_kwargs): from codewiki.src.be.dependency_analyzer.models.core import Node from codewiki.src.config import Config -# Test repo -test_repo = "/Users/michaelassraf/Documents/GitHub/openframe-oss-tenant" -# Create config +class TestResults: + """Accumulates test results and reports a summary with a non-zero exit on failure.""" + + def __init__(self): + self.tests = [] + + def add_test(self, name, passed, details=""): + self.tests.append((name, passed, details)) + + def print_summary(self): + print("\n" + "=" * 80) + print("TEST SUMMARY") + print("=" * 80) + failed = 0 + for name, passed, details in self.tests: + status = "โœ… PASS" if passed else "โŒ FAIL" + print(f"{status}: {name}") + if details: + print(f" {details}") + if not passed: + failed += 1 + print("=" * 80) + print(f"Total: {len(self.tests)}, Passed: {len(self.tests) - failed}, Failed: {failed}") + return failed == 0 + + +results = TestResults() + +# Test repo (portable: env var override, else a relative fixture path) +test_repo = os.getenv( + "CODEWIKI_TEST_REPO", + os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures", "sample_repo") +) + +# Create config via factory (not direct construction) to satisfy validation/env-resolution config = Config( repo_path=test_repo, output_dir="/tmp/codewiki_test", @@ -111,10 +143,17 @@ def patched_call(*call_args, **call_kwargs): # Show result if len(module_tree) == 0: - print("\nโŒ FAILED: Empty module tree") + details = "Empty module tree" if captured_response: has_tags = "" in captured_response - print(f" Has tag: {has_tags}") + details += f"; Has tag: {has_tags}" + results.add_test("clustering produces non-empty module tree", False, details) else: - print(f"\nโœ… SUCCESS: {len(module_tree)} modules created") - print(json.dumps(module_tree, indent=2, default=str)) + results.add_test( + "clustering produces non-empty module tree", + True, + f"{len(module_tree)} modules created:\n{json.dumps(module_tree, indent=2, default=str)}" + ) + +success = results.print_summary() +sys.exit(0 if success else 1) diff --git a/test_clustering_forced.py b/test_clustering_forced.py index d3bfab0b..833ad075 100644 --- a/test_clustering_forced.py +++ b/test_clustering_forced.py @@ -21,7 +21,26 @@ os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ) -config = Config( +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.from_cli( 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"), @@ -62,16 +81,23 @@ print("\n๐Ÿ“Š RESULTS:\n") if len(module_tree) == 0: - print("โŒ FAILED: Empty module tree") - print(" This means LLM did NOT follow tag format") - print(" Check logs above for 'Invalid LLM response format' or 'Invalid JSON'") - sys.exit(1) + results.add_test( + "clustering_produces_module_tree", False, + "Empty module tree - LLM did NOT follow 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 tag format!") - sys.exit(0) + passed = results.print_summary() + sys.exit(0 if passed else 1) diff --git a/test_clustering_local.py b/test_clustering_local.py index c855f7da..c59e8e31 100644 --- a/test_clustering_local.py +++ b/test_clustering_local.py @@ -18,40 +18,65 @@ from codewiki.src.be.dependency_analyzer.models.core import Node from codewiki.src.config import Config -def test_clustering(): + +class TestResults: + """Simple pass/fail accumulator for standalone integration test scripts.""" + + def __init__(self): + self.results = [] + + def add_test(self, name, passed, message=""): + self.results.append((name, passed, message)) + + def print_summary(self): + print("\n" + "=" * 80) + print("๐Ÿ“Š TEST SUMMARY") + print("=" * 80) + for name, passed, message in self.results: + status = "โœ… PASS" if passed else "โŒ FAIL" + print(f"{status} - {name}" + (f": {message}" if message else "")) + total = len(self.results) + passed_count = sum(1 for _, passed, _ in self.results if passed) + print(f"\n{passed_count}/{total} tests passed") + return passed_count == total + +def test_clustering(results): """Test clustering on a small sample to verify prompt fix.""" print("=" * 80) print("๐Ÿงช TESTING CODEWIKI CLUSTERING LOCALLY") print("=" * 80) - # Setup test repo path - test_repo = "/Users/michaelassraf/Documents/GitHub/openframe-oss-tenant" + # Setup test repo path (override with CODEWIKI_TEST_REPO env var) + test_repo = os.getenv("CODEWIKI_TEST_REPO") - if not os.path.exists(test_repo): + if not test_repo or not os.path.exists(test_repo): print(f"โŒ Test repo not found: {test_repo}") - print(" Update test_repo variable to point to your local repo") - return + print(" Set the CODEWIKI_TEST_REPO environment variable to point to your local repo") + results.add_test("test_repo_exists", False, f"Test repo not found: {test_repo}") + return False print(f"\n๐Ÿ“‚ Test repository: {test_repo}") - # Create minimal config + # Create minimal config via the required factory method config = Config( repo_path=test_repo, - output_path="/tmp/codewiki_test_output", - main_provider="openai", - main_model="gpt-4o", # Use gpt-4o instead of gpt-5.2 - main_api_key=os.getenv("OPENAI_API_KEY") or os.getenv("MAIN_API_KEY"), + output_dir="/tmp/codewiki_test_output", + dependency_graph_dir="/tmp/codewiki_test_output/deps", + docs_dir="/tmp/codewiki_test_output/docs", + max_depth=2, + cluster_model="gpt-4o", + cluster_api_key=os.getenv("OPENAI_API_KEY") or os.getenv("CLUSTER_API_KEY") or "", + cluster_base_url="https://api.openai.com/v1", + main_model="gpt-4o", + main_api_key=os.getenv("OPENAI_API_KEY") or os.getenv("MAIN_API_KEY") or "", main_base_url="https://api.openai.com/v1", - fallback_provider="anthropic", fallback_model="claude-opus-4-5-20251101", - fallback_api_key=os.getenv("ANTHROPIC_API_KEY") or os.getenv("FALLBACK_API_KEY"), + fallback_api_key=os.getenv("ANTHROPIC_API_KEY") or os.getenv("FALLBACK_API_KEY") or "", fallback_base_url="https://api.anthropic.com/v1", - verbose=True ) print(f"\n๐Ÿค– Using model: {config.main_model}") - print(f" Provider: {config.main_provider}") # Create sample components (minimal test set) test_file_1 = os.path.join(test_repo, "openframe/services/openframe-api/src/main/java/com/openframe/api/controller/AuthController.java") @@ -120,18 +145,21 @@ def test_clustering(): print("\nโŒ FAILED: Empty module tree returned") print(" This means the LLM did not follow the prompt format") print(" Check logs above for 'Invalid LLM response format' error") + results.add_test("clustering_produces_modules", False, "Empty module tree returned") return False else: print(f"\nโœ… SUCCESS: Created {len(module_tree)} modules") for module_name, module_info in module_tree.items(): comp_count = len(module_info.get("components", [])) print(f" - {module_name}: {comp_count} components") + results.add_test("clustering_produces_modules", True, f"Created {len(module_tree)} modules") return True except Exception as e: print(f"\nโŒ ERROR: {e}") import traceback traceback.print_exc() + results.add_test("clustering_produces_modules", False, str(e)) return False if __name__ == "__main__": @@ -141,5 +169,8 @@ def test_clustering(): print(" Set it with: export OPENAI_API_KEY='your-key-here'") sys.exit(1) - success = test_clustering() + test_results = TestResults() + success = test_clustering(test_results) + test_results.print_summary() sys.exit(0 if success else 1) + diff --git a/test_clustering_real.py b/test_clustering_real.py index 995baad5..9c8285ab 100644 --- a/test_clustering_real.py +++ b/test_clustering_real.py @@ -62,3 +62,4 @@ for name, info in module_tree.items(): print(f" - {name}: {len(info.get('components', []))} components") sys.exit(0) + diff --git a/test_subdirectory_fix.py b/test_subdirectory_fix.py index 7fce015d..dfd22961 100644 --- a/test_subdirectory_fix.py +++ b/test_subdirectory_fix.py @@ -14,6 +14,9 @@ # 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", @@ -22,9 +25,6 @@ main_model="gpt-4o", cluster_model="gpt-4o", fallback_model="claude-opus-4-5-20251101", - cluster_api_key="test", - main_api_key="test", - fallback_api_key="test", cluster_base_url="https://api.openai.com/v1", main_base_url="https://api.openai.com/v1", fallback_base_url="https://api.anthropic.com/v1" @@ -94,3 +94,4 @@ else: print("โŒ SOME TESTS FAILED") sys.exit(1) + diff --git a/test_with_logging.py b/test_with_logging.py index ec583950..adc6e714 100644 --- a/test_with_logging.py +++ b/test_with_logging.py @@ -1,14 +1,6 @@ #!/usr/bin/env python3 import os import sys -import logging - -# Setup logging FIRST -logging.basicConfig( - level=logging.INFO, - format='[%(levelname)s] %(message)s', - force=True -) # Add CodeWiki to path sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) @@ -19,8 +11,12 @@ from codewiki.src.be.cluster_modules import cluster_modules from codewiki.src.be.dependency_analyzer.models.core import Node +from codewiki.src.be.dependency_analyzer.utils.logging_config import setup_logging from codewiki.src.config import Config +# Setup logging FIRST +setup_logging() + # Test repo test_repo = os.getenv("TEST_REPO_PATH", sys.argv[1] if len(sys.argv) > 1 else "") if not test_repo: