#!/usr/bin/env python """Verify search quality against concrete acceptance criteria. DONE = every case's expected wiki page appears in the top-3 results, AND no mod/subpage title appears in the top-5 of any probe query. Exits non-zero on any failure so it can gate a build. """ from __future__ import annotations import sys from wikikb.scraper import is_core_title from wikikb.search import search # (query, one-of-these titles must be in the top 3) CASES: list[tuple[str, set[str]]] = [ ("domain limit rank", {"Titles", "Attributes", "Domain"}), ("genius intelligent trait skill bonus", {"Traits"}), ("primogeniture succession heir inheritance", {"Succession"}), ("congenital beauty attraction opinion", {"Traits"}), ("health aging death lifespan", {"Attributes", "Health"}), ] # queries whose top-5 must contain NO mod/subpage results NO_MOD_QUERIES = [ "domain limit", "succession law", "development growth", "knight martial army", "culture names", ] def main() -> int: ok = True print("== relevance (expected page in top-3) ==") for query, expected in CASES: top3 = [r.title for r in search(query, k=5)[:3]] hit = any(t in expected for t in top3) ok &= hit print( f" [{'PASS' if hit else 'FAIL'}] {query!r} -> {top3} (want one of {sorted(expected)})" ) print("== no mod/subpage pollution (top-5) ==") for query in NO_MOD_QUERIES: mods = [r.title for r in search(query, k=5) if not is_core_title(r.title)] clean = not mods ok &= clean print(f" [{'PASS' if clean else 'FAIL'}] {query!r} -> {'clean' if clean else mods}") print(f"\nSEARCH VERIFICATION: {'PASS' if ok else 'FAIL'}") return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())