Skip to content

Commit 757bd07

Browse files
committed
fix(search): filter tests in V2 fallback when include_tests=False
Added _is_test_file helper for consistent test detection
1 parent 661706f commit 757bd07

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

backend/services/indexer_optimized.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,28 @@ async def search_v3(
633633
metrics.increment("search_v3_errors")
634634
# fallback to V2
635635
logger.info("Falling back to search_v2")
636-
return await self.search_v2(query, repo_id, top_k, use_reranking)
636+
results = await self.search_v2(query, repo_id, top_k, use_reranking)
637+
# apply test filtering to V2 results (V2 doesn't filter tests by default)
638+
if not include_tests:
639+
results = [r for r in results if not self._is_test_file(r.get("file_path", ""))]
640+
return results
641+
642+
def _is_test_file(self, file_path: str) -> bool:
643+
"""Check if file is a test file (stricter pattern matching)"""
644+
import os
645+
fp = file_path.lower()
646+
# test directories
647+
if "/test/" in fp or "/tests/" in fp:
648+
return True
649+
# basename patterns
650+
basename = os.path.basename(fp)
651+
if basename.startswith("test_") or basename.startswith("test."):
652+
return True
653+
if "_test." in basename or basename.endswith("_test.py"):
654+
return True
655+
if ".spec." in basename:
656+
return True
657+
return False
637658

638659
async def explain_code(
639660
self,

0 commit comments

Comments
 (0)