diff --git a/test-multi-path/integration_test.py b/test-multi-path/integration_test.py index 20c4274d..460d6265 100755 --- a/test-multi-path/integration_test.py +++ b/test-multi-path/integration_test.py @@ -250,7 +250,7 @@ def create_config(self) -> None: output_dir = str(self.test_dir / "output") # Create config with main path as root, others as additional - self.config = Config( + self.config = Config.from_args( repo_path=str(self.main_path), output_dir=output_dir, dependency_graph_dir=output_dir, diff --git a/test-multi-path/test_multi_path.py b/test-multi-path/test_multi_path.py index 7ef83bef..d964f1a8 100755 --- a/test-multi-path/test_multi_path.py +++ b/test-multi-path/test_multi_path.py @@ -84,7 +84,7 @@ def create_test_config( Returns: Config instance """ - return Config( + return Config.from_args( repo_path=repo_path, output_dir=output_dir, dependency_graph_dir=os.path.join(output_dir, "graphs"), diff --git a/test_clustering_debug.py b/test_clustering_debug.py index eb427a81..63ee67f6 100644 --- a/test_clustering_debug.py +++ b/test_clustering_debug.py @@ -47,11 +47,43 @@ 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 -config = 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.from_args( repo_path=test_repo, output_dir="/tmp/codewiki_test", dependency_graph_dir="/tmp/codewiki_test/deps", @@ -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 a6918e0a..e682e260 100644 --- a/test_clustering_forced.py +++ b/test_clustering_forced.py @@ -16,9 +16,27 @@ from codewiki.src.be.dependency_analyzer.models.core import Node from codewiki.src.config import Config -test_repo = "/Users/michaelassraf/Documents/GitHub/openframe-oss-tenant" -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"), @@ -59,15 +77,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..6af22735 100644 --- a/test_clustering_local.py +++ b/test_clustering_local.py @@ -18,27 +18,54 @@ 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 - config = Config( + # Create minimal config via the required factory method + config = Config.from_args( repo_path=test_repo, output_path="/tmp/codewiki_test_output", + cluster_provider="openai", + cluster_model="gpt-4o", + cluster_api_key=os.getenv("OPENAI_API_KEY") or os.getenv("CLUSTER_API_KEY"), + cluster_base_url="https://api.openai.com/v1", 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"), @@ -120,18 +147,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 +171,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_proof.py b/test_clustering_proof.py index cea51b19..a278a676 100644 --- a/test_clustering_proof.py +++ b/test_clustering_proof.py @@ -10,9 +10,9 @@ from codewiki.src.be.dependency_analyzer.models.core import Node from codewiki.src.config import Config -test_repo = "/Users/michaelassraf/Documents/GitHub/openframe-oss-tenant" +test_repo = os.getenv("TEST_REPO_PATH", os.path.dirname(os.path.abspath(__file__))) -config = Config( +config = Config.from_args( repo_path=test_repo, output_dir="/tmp/test", dependency_graph_dir="/tmp/test/deps", docs_dir="/tmp/test/docs", max_depth=2, main_model="gpt-4o", cluster_model="gpt-4o", fallback_model="claude-opus-4-5-20251101", @@ -96,3 +96,4 @@ more = len(info.get('components', [])) - 5 print(f" - {name}: {comp_count} components {comp_list}{'...' if more > 0 else ''}") sys.exit(0) + diff --git a/test_clustering_real.py b/test_clustering_real.py index 339ad43c..435c0af6 100644 --- a/test_clustering_real.py +++ b/test_clustering_real.py @@ -16,9 +16,9 @@ from codewiki.src.be.dependency_analyzer.models.core import Node from codewiki.src.config import Config -test_repo = "/Users/michaelassraf/Documents/GitHub/openframe-oss-tenant" +test_repo = os.getenv("TEST_REPO_PATH", os.path.dirname(os.path.abspath(__file__))) -config = Config( +config = Config.from_args( 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,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_clustering_simple.py b/test_clustering_simple.py index 5388ddc2..be368e11 100644 --- a/test_clustering_simple.py +++ b/test_clustering_simple.py @@ -18,10 +18,10 @@ from codewiki.src.config import Config # Test repo -test_repo = "/Users/michaelassraf/Documents/GitHub/openframe-oss-tenant" +test_repo = os.getenv("TEST_REPO_PATH", os.path.join(os.getcwd(), "test_repo")) # Create simple config with all required fields -config = Config( +config = Config.from_args( repo_path=test_repo, output_dir="/tmp/codewiki_test", dependency_graph_dir="/tmp/codewiki_test/deps", @@ -106,3 +106,4 @@ comp_count = len(module_info.get("components", [])) print(f" - {module_name}: {comp_count} components") sys.exit(0) + diff --git a/test_subdirectory_fix.py b/test_subdirectory_fix.py index 7fce015d..79ac0d59 100644 --- a/test_subdirectory_fix.py +++ b/test_subdirectory_fix.py @@ -13,7 +13,7 @@ from codewiki.src.config import Config # Create minimal config -config = Config( +config = Config.from_args( repo_path="/tmp/test", output_dir="/tmp/test_output", dependency_graph_dir="/tmp/test_output/deps", @@ -22,9 +22,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 +91,7 @@ else: print("โŒ SOME TESTS FAILED") sys.exit(1) + +FILE>>> +<<