Skip to content

test(search): pin envelope evidence equivalence - #1564

Merged
Sinity merged 1 commit into
masterfrom
feature/test/search-envelope-evidence-equivalence
May 25, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/test/search-envelope-evidence-equivalence

Conversation

@Sinity

@Sinity Sinity commented May 25, 2026 •

Copy link
Copy Markdown
Owner

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() in polylogue/api/search_envelope_builder.py for callers that already have a full ConversationQuerySpec. 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.py now compares the canonical match explanation 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.
  • pre-push devtools verify --quick — exit 0; total 37.35s.

Ref #873

Summary by CodeRabbit

  • Bug Fixes

    • Search operations now return explicit error responses when invalid cursors are provided during conversation search.
  • Tests

    • Strengthened cross-surface search result verification with enhanced validation of scoring metadata across different access methods.

Review Change Stack

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
@coderabbitai

coderabbitai Bot commented May 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, we couldn't start this review because you've used your available PR reviews for now.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1fbac8be-cd18-4f9a-a4a4-6120098e6802

📥 Commits

Reviewing files that changed from the base of the PR and between 265b5e7 and 21c0be5.

📒 Files selected for processing (3)
  • polylogue/api/search_envelope_builder.py
  • polylogue/daemon/http.py
  • tests/unit/surfaces/test_search_envelope_contract.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/test/search-envelope-evidence-equivalence

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Sinity
Sinity merged commit cbe6d90 into master May 25, 2026
5 of 6 checks passed
@Sinity
Sinity deleted the feature/test/search-envelope-evidence-equivalence branch May 25, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant