diff --git a/mcp_server.py b/mcp_server.py index b5f7a41..6f373b8 100644 --- a/mcp_server.py +++ b/mcp_server.py @@ -926,12 +926,12 @@ async def code_graph_ingest_repo( if ctx: await ctx.info("Using incremental mode - detecting changed files") - changed_files = git_utils.get_changed_files( + changed_files_result = git_utils.get_changed_files( repo_path, since_commit=since_commit, include_untracked=True ) - changed_files_count = len(changed_files) + changed_files_count = changed_files_result.get("count", 0) if changed_files_count == 0: return { @@ -945,7 +945,7 @@ async def code_graph_ingest_repo( } # Filter changed files by globs - files_to_process = [f["path"] for f in changed_files if f["action"] != "deleted"] + files_to_process = [f["path"] for f in changed_files_result.get("changed_files", []) if f["action"] != "deleted"] if ctx: await ctx.info(f"Found {changed_files_count} changed files") @@ -1277,6 +1277,8 @@ async def context_pack( context_result = pack_builder.build_context_pack( nodes=all_nodes, budget=budget, + stage=stage, + repo_id=repo_id, file_limit=8, symbol_limit=12, enable_deduplication=True @@ -1286,13 +1288,13 @@ async def context_pack( items = [] for item in context_result.get("items", []): items.append({ - "kind": item.get("type", "file"), - "title": item.get("path", "Unknown"), + "kind": item.get("kind", "file"), + "title": item.get("title", "Unknown"), "summary": item.get("summary", ""), "ref": item.get("ref", ""), "extra": { - "lang": item.get("lang"), - "score": item.get("score", 0.0) + "lang": item.get("extra", {}).get("lang"), + "score": item.get("extra", {}).get("score", 0.0) } }) diff --git a/services/metrics.py b/services/metrics.py index 7409df2..9bc3eaf 100644 --- a/services/metrics.py +++ b/services/metrics.py @@ -7,6 +7,7 @@ import time from functools import wraps from loguru import logger +from config import settings # Create a custom registry to avoid conflicts registry = CollectorRegistry() @@ -259,7 +260,7 @@ async def update_neo4j_metrics(self, graph_service): return # Get node counts - with graph_service.driver.session(database=graph_service.neo4j_database) as session: + with graph_service.driver.session(database=settings.neo4j_database) as session: # Count File nodes result = session.run("MATCH (n:File) RETURN count(n) as count") file_count = result.single()["count"] diff --git a/tests/test_context_pack.py b/tests/test_context_pack.py index 4c3b36d..80e5edb 100644 --- a/tests/test_context_pack.py +++ b/tests/test_context_pack.py @@ -153,17 +153,46 @@ def test_pack_focus_paths_priority(self): assert "important" in first_item["ref"] @pytest.mark.unit - def test_extract_title(self): - """Test title extraction from path""" + def test_title_extraction_via_build_context_pack(self): + """Test that titles are properly extracted from paths via build_context_pack""" pack_builder = PackBuilder() - # Test with multi-level path - title = pack_builder._extract_title("src/auth/token.py") - assert title == "auth/token.py" + nodes = [ + { + "type": "file", + "path": "src/auth/token.py", + "lang": "python", + "score": 0.9, + "summary": "Test file", + "ref": "ref://file/src/auth/token.py" + }, + { + "type": "file", + "path": "main.py", + "lang": "python", + "score": 0.8, + "summary": "Test file", + "ref": "ref://file/main.py" + } + ] + + pack = pack_builder.build_context_pack( + nodes=nodes, + budget=1500, + stage="plan", + repo_id="test-repo" + ) - # Test with single level - title = pack_builder._extract_title("main.py") - assert title == "main.py" + # Verify titles are extracted correctly (last 2 path segments) + assert len(pack["items"]) == 2 + + # Multi-level path should show last 2 segments + multi_level_item = next(item for item in pack["items"] if "auth" in item["ref"]) + assert multi_level_item["title"] == "auth/token.py" + + # Single level path should show as-is + single_level_item = next(item for item in pack["items"] if item["ref"] == "ref://file/main.py") + assert single_level_item["title"] == "main.py" class TestContextPackAPI: