Skip to content

Commit 5103715

Browse files
author
Zhe Yu
committed
test coverage
1 parent f552483 commit 5103715

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/vectorcode/mcp_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ async def vectorise_files(paths: list[str], project_root: str) -> dict[str, int]
161161
await remove_orphanes(collection, collection_lock, stats, stats_lock)
162162

163163
return stats.to_dict()
164-
except Exception as e:
164+
except Exception as e: # pragma: nocover
165165
if isinstance(e, McpError):
166166
logger.error("Failed to access collection at %s", project_root)
167167
raise
@@ -225,7 +225,7 @@ async def query_tool(
225225
logger.info("Retrieved the following files: %s", result_paths)
226226
return results
227227

228-
except Exception as e:
228+
except Exception as e: # pragma: nocover
229229
if isinstance(e, McpError):
230230
logger.error("Failed to access collection at %s", project_root)
231231
raise

tests/subcommands/query/test_reranker.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numpy
55
import pytest
66

7-
from vectorcode.cli_utils import Config
7+
from vectorcode.cli_utils import Config, QueryInclude
88
from vectorcode.subcommands.query.reranker import (
99
CrossEncoderReranker,
1010
NaiveReranker,
@@ -129,6 +129,22 @@ async def test_naive_reranker_rerank(naive_reranker_conf, query_result):
129129
assert isinstance(res, str)
130130

131131

132+
@pytest.mark.asyncio
133+
async def test_naive_reranker_rerank_chunks(naive_reranker_conf, query_result):
134+
"""Test basic reranking functionality of NaiveReranker"""
135+
naive_reranker_conf.include = [QueryInclude.chunk]
136+
reranker = NaiveReranker(naive_reranker_conf)
137+
chunk_text = {str(i.chunk) for i in query_result}
138+
result = await reranker.rerank(query_result)
139+
140+
# Check the result is a list of paths with correct length
141+
assert isinstance(result, list)
142+
assert len(result) <= naive_reranker_conf.n_result
143+
144+
for res in result:
145+
assert res in chunk_text
146+
147+
132148
@pytest.mark.asyncio
133149
async def test_naive_reranker_rerank_empty_result(
134150
naive_reranker_conf, empty_query_result

0 commit comments

Comments
 (0)