diff --git a/bench/agents/code_graph_adapter.py b/bench/agents/code_graph_adapter.py index f3e6e633..96f5cfdf 100644 --- a/bench/agents/code_graph_adapter.py +++ b/bench/agents/code_graph_adapter.py @@ -102,15 +102,24 @@ def find_symbol(self, repo: str, name: str) -> list[dict[str, Any]]: auto_complete returns prefix matches; the agent often wants exact matches. Doing this client-side keeps the FastAPI surface untouched. + + The auto_complete payload nests the symbol name under + `item["properties"]["name"]` (FalkorDB node properties), so we look + there first and only fall back to a top-level `name` for older / + flatter shapes the tests may pass in. """ payload = self.auto_complete(repo, name) results = payload.get("completions") or payload.get("results") or payload if isinstance(results, dict): results = results.get("items", []) - return [ - item for item in (results or []) - if isinstance(item, dict) and item.get("name") == name - ] + out: list[dict[str, Any]] = [] + for item in (results or []): + if not isinstance(item, dict): + continue + props = item.get("properties") if isinstance(item.get("properties"), dict) else {} + if props.get("name") == name or item.get("name") == name: + out.append(item) + return out def note_edit(self, repo: str, path: str) -> dict[str, Any]: """Tell code-graph the agent just edited `path`; trigger an diff --git a/pyproject.toml b/pyproject.toml index cd840469..6f007651 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,10 @@ bench = [ markers = [ "slow: marks tests that spawn external subprocesses (LSP servers, FalkorDB, etc.); skip with -m 'not slow'", ] +# Keep pytest from walking into per-instance bench worktrees that contain +# their own copies of pytest source — collecting from those breaks the +# host pytest's AST rewriter. +norecursedirs = ["bench/cache", ".venv", "node_modules", "build", "dist", "*.egg-info"] [tool.setuptools.packages.find] where = ["."] diff --git a/tests/test_bench_code_graph_adapter.py b/tests/test_bench_code_graph_adapter.py index 192695ed..6b5ee4a1 100644 --- a/tests/test_bench_code_graph_adapter.py +++ b/tests/test_bench_code_graph_adapter.py @@ -80,6 +80,26 @@ def test_find_symbol_filters_for_exact_match(): assert all(item["name"] == "Foo" for item in out) +def test_find_symbol_reads_nested_properties_name(): + # Regression: the real /api/auto_complete payload nests `name` under + # `properties` (FalkorDB node properties). Before this fix every + # exact-name lookup returned [], so the agent fell back to bash grep. + resp = httpx.Response( + 200, + json={"completions": [ + {"id": 1, "labels": ["Function"], + "properties": {"name": "FooBar", "path": "/a.py"}}, + {"id": 2, "labels": ["Function"], + "properties": {"name": "Foo", "path": "/b.py"}}, + {"id": 3, "labels": ["Function"], + "properties": {"name": "Foo", "path": "/c.py"}}, + ]}, + ) + with _client_with({"POST /api/auto_complete": resp}) as c: + out = c.find_symbol("r", "Foo") + assert [item["id"] for item in out] == [2, 3] + + def test_note_edit_calls_analyze_folder_and_reports_path(): resp = httpx.Response(200, json={"status": "ok"}) with _client_with({"POST /api/analyze_folder": resp}) as c: