Repository navigation
test(search): pin envelope evidence equivalence - #1564
Conversation
Problem: #873 now exposes ranked-hit explanation evidence, but daemon HTTP still duplicated API envelope construction and the cross-surface contract test compared only ids, ranks, and lanes. That left score/snippet/component evidence able to drift between API, MCP, CLI, and HTTP surfaces without a focused failure.\n\nWhat changed: added a spec-based search envelope builder shared by the Python API and daemon HTTP, leaving each caller responsible only for parameter parsing. Strengthened the cross-surface envelope contract test so it compares the canonical per-hit match evidence fields, including score kind, score components, lane rank/contribution, raw score, snippet, terms, and match surface.\n\nVerification: pytest -q tests/unit/api/test_search_envelope_builder.py tests/unit/surfaces/test_search_envelope_contract.py tests/unit/surfaces/test_search_explanation_contract.py tests/unit/daemon/test_web_reader.py -k "search_envelope or query_search or no_results_query or bad_date" --tb=short; ruff format --check polylogue/api/search_envelope_builder.py polylogue/daemon/http.py tests/unit/surfaces/test_search_envelope_contract.py; ruff check polylogue/api/search_envelope_builder.py polylogue/daemon/http.py tests/unit/surfaces/test_search_envelope_contract.py; mypy polylogue/api/search_envelope_builder.py polylogue/daemon/http.py tests/unit/surfaces/test_search_envelope_contract.py tests/unit/surfaces/test_search_explanation_contract.py tests/unit/api/test_search_envelope_builder.py; devtools verify --json (415 selected tests passed).\n\nRef #873
|
Warning Review limit reached
Your plan includes 1 review of capacity. Refill in 29 minutes and 59 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
This hardens #873 by making ranked-search envelope construction converge for API and daemon HTTP, then strengthening the cross-surface contract test so API, MCP, and CLI JSON must preserve the same per-hit explanation evidence.
Problem
#1562 exposed lane rank, lane contribution, and raw backend scores on ranked hits, but the cross-surface envelope test still compared only conversation ids, ranks, and lanes. A surface could silently drop or rewrite snippets, score kind, matched terms, score components, lane contribution, or raw score without failing that contract. Daemon HTTP also duplicated the API envelope builder’s cursor, diagnostics, and payload-assembly logic, increasing the chance of exactly that drift.
Solution
Added
build_search_envelope_for_spec()inpolylogue/api/search_envelope_builder.pyfor callers that already have a fullConversationQuerySpec. The public API keyword builder now parses parameters and delegates to it, while daemon HTTP keeps its broader HTTP filter parser and delegates the ranked envelope construction to the same spec-based path.tests/unit/surfaces/test_search_envelope_contract.pynow compares the canonicalmatchexplanation fields across API/helper, MCP, and CLI JSON: match surface, message id, snippet, score, score kind, matched terms, score components, lane rank, lane contribution, and raw score.Verification
pytest -q tests/unit/api/test_search_envelope_builder.py tests/unit/surfaces/test_search_envelope_contract.py tests/unit/surfaces/test_search_explanation_contract.py tests/unit/daemon/test_web_reader.py -k "search_envelope or query_search or no_results_query or bad_date" --tb=short— 11 passed, 68 deselected.ruff format --check polylogue/api/search_envelope_builder.py polylogue/daemon/http.py tests/unit/surfaces/test_search_envelope_contract.py— passed.ruff check polylogue/api/search_envelope_builder.py polylogue/daemon/http.py tests/unit/surfaces/test_search_envelope_contract.py— passed.mypy polylogue/api/search_envelope_builder.py polylogue/daemon/http.py tests/unit/surfaces/test_search_envelope_contract.py tests/unit/surfaces/test_search_explanation_contract.py tests/unit/api/test_search_envelope_builder.py— passed.devtools verify --json— exit 0; 415 pytest-testmon selected tests passed; total 98.24s.devtools verify --quick— exit 0; total 37.35s.Ref #873
Summary by CodeRabbit
Bug Fixes
Tests