Port docs-mcp-template upgrades (eval, citations, prefixes) (#26)
Image rebuild (skip scrape) / build (push) Successful in 3m58s
Image rebuild (skip scrape) / build (push) Successful in 3m58s
Co-authored-by: claude <[email protected]>
This commit was merged in pull request #26.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
"""Citation markdown renderer — no Chroma, no mcp."""
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from docs_mcp.format import format_search_hits
|
||||
|
||||
|
||||
class FormatSearchHitsTests(unittest.TestCase):
|
||||
def test_two_hits_numbered_with_urls(self) -> None:
|
||||
out = format_search_hits([
|
||||
("Install on Linux", "https://docs.example.com/install", "chunk one", ""),
|
||||
("HA setup", "https://docs.example.com/ha", "chunk two", ""),
|
||||
])
|
||||
self.assertIn("[1] **Install on Linux** — https://docs.example.com/install", out)
|
||||
self.assertIn("[2] **HA setup** — https://docs.example.com/ha", out)
|
||||
self.assertIn("chunk one", out)
|
||||
self.assertIn("chunk two", out)
|
||||
self.assertNotIn("[3]", out)
|
||||
# [1] before [2]
|
||||
self.assertLess(out.index("[1]"), out.index("[2]"))
|
||||
# each number is followed by its URL on the same logical hit
|
||||
first = out.split("[2]")[0]
|
||||
self.assertIn("https://docs.example.com/install", first)
|
||||
self.assertNotIn("https://docs.example.com/ha", first)
|
||||
|
||||
def test_empty_hits_invents_nothing(self) -> None:
|
||||
self.assertEqual(format_search_hits([]), "")
|
||||
|
||||
def test_missing_url_omits_emdash(self) -> None:
|
||||
out = format_search_hits([("Title only", "", "body", "")])
|
||||
self.assertIn("[1] **Title only**", out)
|
||||
self.assertNotIn("—", out)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user