export_parity.py¶
scripts/export_parity.py
Check the export API answers what the MCP tools answer, on real indexes.
_answer
dict[str, Any] export_parity._answer(dict[str, Any] reply)
Drop boundary stamps and the export's version stamp.
Source · 11 lines
def _answer(reply: dict[str, Any]) -> dict[str, Any]:
"""@brief Strip stamps. @return The answer."""
out = {k: v for k, v in reply.items() if k not in _BOUNDARY and k != "wire_version"}
if isinstance(out.get("results"), list):
out["results"] = [
{k: v for k, v in e.items() if k not in _BOUNDARY} if isinstance(e, dict) else e
for e in out["results"]
]
return out
Activity · 4 steps
Flows
_dossier_agrees
bool export_parity._dossier_agrees(QueryTools tools, Path db, Path repo, str name)
Compare one subject's dossier, modulo a miss's routing sentence.
Source · 11 lines
def _dossier_agrees(tools: QueryTools, db: Path, repo: Path, name: str) -> bool:
"""@brief One dossier comparison. @return Agreement."""
mcp = _answer(tools.dossier(name, max_neighbors=10**6))
exp = _answer(q.export_dossier(db, name, repo_root=repo, max_neighbors=10**6))
if mcp.get("found") is False:
tail = exp.get("note", "").split("malformed call.", 1)[-1]
mcp.pop("note", ""), exp.pop("note", "")
return mcp == exp and bool(tail)
return mcp == exp
Activity · 7 steps
Flows
_sample
list[str] export_parity._sample(Path db, int n)
Every k-th distinct indexed name, to N.
Source · 8 lines
def _sample(db: Path, n: int) -> list[str]:
"""@brief Deterministic name sample. @return Names."""
with sqlite3.connect(db) as conn:
names = sorted({r[0] for r in conn.execute("SELECT DISTINCT name FROM memberdef") if r[0]})
step = max(1, len(names) // n)
return names[::step][:n]
Activity · 4 steps
Flows
main
int export_parity.main()
Run every comparison and report.
Source · 24 lines
def main() -> int:
"""@brief Entry point. @return 0 when every comparison agrees, else 1."""
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("db", type=Path)
parser.add_argument("repo", type=Path)
parser.add_argument("--sample", type=int, default=400)
args = parser.parse_args()
tools_query.RESPONSE_BUDGET_BYTES = 10**9
tools = QueryTools(lambda: args.db, lambda: args.repo)
names = _sample(args.db, args.sample)
bad = [n for n in names if not _dossier_agrees(tools, args.db, args.repo, n)]
for corpus in CORPORA:
for text in _TEXTS:
mcp = _answer(tools.search(text, corpus=corpus))
exp = _answer(q.export_search(args.db, text, corpus=corpus, repo_root=args.repo))
if mcp != exp:
bad.append(f"search:{corpus}:{text!r}")
total = len(names) + len(CORPORA) * len(_TEXTS)
print(f"{args.db}: {total - len(bad)}/{total} agree")
for item in bad:
print(f" MISMATCH {item}")
return 1 if bad else 0