MCPcopy
hub / github.com/MinishLab/semble / test_format_results

Function test_format_results

tests/test_mcp.py:98–118  ·  view source on GitHub ↗

format_results: consistent flat schema regardless of max_snippet_lines.

(max_snippet_lines: int | None, has_content: bool, content_key: str | None)

Source from the content-addressed store, hash-verified

96 ids=["full", "truncated", "location_only"],
97)
98def test_format_results(max_snippet_lines: int | None, has_content: bool, content_key: str | None) -> None:
99 """format_results: consistent flat schema regardless of max_snippet_lines."""
100 empty_out = format_results("query", [], max_snippet_lines)
101 assert empty_out == {"query": "query", "results": []}
102
103 chunks = [make_chunk(f"line1\nline2\nline3\nline4\ndef fn_{i}(): pass", f"f{i}.py") for i in range(3)]
104 results = [SearchResult(chunk=c, score=round(0.1 * (i + 1), 3)) for i, c in enumerate(chunks)]
105 out = format_results("foo", results, max_snippet_lines)
106 assert out["query"] == "foo"
107 for entry in out["results"]:
108 assert "file_path" in entry
109 assert "start_line" in entry
110 assert "end_line" in entry
111 assert "score" in entry
112 assert "chunk" not in entry
113 if has_content:
114 assert content_key in entry
115 if max_snippet_lines is not None:
116 assert entry[content_key].count("\n") < max_snippet_lines
117 else:
118 assert "content" not in entry
119
120
121@pytest.mark.anyio

Callers

nothing calls this directly

Calls 3

format_resultsFunction · 0.90
make_chunkFunction · 0.90
SearchResultClass · 0.90

Tested by

no test coverage detected