Skip to content

test(email): pin /v1/email/search query correctness + in-agent parity (#1604) - #1920

Merged
kovtcharov merged 1 commit into
mainfrom
claudia/task-5afd2c14
Jul 2, 2026
Merged

kovtcharov merged 1 commit into
mainfrom
claudia/task-5afd2c14

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Mailbox search became a first-class REST capability in #1883 (POST /v1/email/search, schema 2.1) — but nothing proved a query actually filters. The existing REST tests inject a stub that ignores the query, so a query-handling regression, or drift between the REST route and the agent's in-loop search_messages tool it restores, would pass CI silently. This PR closes that verification gap with tests against the real FakeGmailBackend (mbox store + Gmail-query matcher) and frames "find past mail" as a capability in the email guide — the last unmet acceptance criteria of #1604/#1781.

  • Unit — keyword / from: / subject: queries return exactly the expected message ids; each hit carries the documented metadata (id, from, subject, date, snippet) and never a message body.
  • Parity — the REST path returns the same ids, order, and header metadata as search_messages_impl (the in-agent tool), so the two surfaces can't drift unnoticed.
  • Guide — "What it does" now names search (chat tool + REST route); endpoint spec, OpenAPI, and npm docs already cover it since feat(email): expose search, pre-scan, archive/quarantine & calendar on the REST contract (schema 2.1) #1883, so no contract or version change here.

Closes #1604, closes #1781.

Test plan

  • python -m pytest tests/unit/agents/email/test_rest_search.py — 12 passed
  • python -m pytest tests/unit/agents/email/ hub/agents/python/email/tests/ tests/test_email_openapi_conformance.py — 476 + 151 passed, no regressions
  • python util/lint.py --black --isort — clean

…#1604)

The REST inbox-search route shipped in #1883, but its tests drive an
inject-only stub that ignores the query — they prove the backend was
called, not that a query actually filters (the exact mock-validity gap
the repo testing rules warn about). A regression in query handling, or
drift between POST /v1/email/search and the agent's in-loop
search_messages tool, would pass CI unnoticed.

Close that gap with tests against the real FakeGmailBackend fixture
(mbox-shaped store + Gmail-query matcher), pinning issue #1604's two
test acceptance criteria:

- Unit: keyword / from: / subject: queries return exactly the expected
  message ids, and each hit carries the documented metadata (id, from,
  subject, date, snippet) with no message body.
- Parity: the REST path returns the same ids, order, and header
  metadata as search_messages_impl — the in-agent tool the route
  restores to the contract (#1781).

Also frame search as a first-class capability in the email guide's
"What it does" list (the G1 gap: "ask the agent to find past mail"),
naming both the chat tool and the REST route.
@github-actions github-actions Bot added documentation Documentation changes tests Test changes agent::email Email agent changes labels Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve ✅

This PR adds unit + parity tests for POST /v1/email/search and documents mailbox search as a first-class capability in the email guide. It closes a real verification gap: the prior REST tests used an inject-only stub that ignored the query, so a query-handling regression — or drift between the REST route and the in-agent search_messages tool — would have passed CI silently. The new tests exercise the real fake backend and the actual query matcher, and pin the two surfaces to each other.

No blocking issues. Test-only + docs, no runtime code touched, and the new doc bullet accurately reflects the shipped contract. Nice work.

🔍 Technical details

Verified against the real code (all symbols/contract match):

  • FakeGmailBackend, get_search_backend, search_messages_impl, and build_app all exist and are imported correctly; the sys.path parents[4] resolves to repo root for tests/unit/agents/email/test_rest_search.py.
  • The expected ids trace correctly through _query_matches (tests/fixtures/email/fake_gmail.py:632): free-text matches subject+snippet (invoice → msg-001, msg-003), from: / subject: / is:unread honored as asserted.
  • The metadata assertions match the response contract: _search_inbox builds EmailSearchResponse{count, messages[]} with EmailSearchResultItem fields id/thread_id/subject/from/date/snippet and no body — so assert "body" not in hit is meaningful, not vacuous.
  • Parity holds by construction: both paths hydrate through _format_message_for_llm, and the REST route with a query passes label_ids=None (query-present branch, api_routes.py:934) exactly like the tool.

Strengths

  • 🟢 Directly implements the repo testing rule "mocks prove we called it, not the call is valid" — swaps the query-ignoring stub for the real matcher, which is the whole point of the PR.
  • 🟢 The parity test (REST ids/order/metadata == search_messages_impl) is the right guard against the two surfaces drifting, and is parametrized across keyword / from: / subject: / is:unread.
  • 🟢 Doc bullet is accurate and scoped — names both the chat tool and the REST route, and correctly states results carry metadata only, never bodies.

No nits worth posting.

@kovtcharov
kovtcharov enabled auto-merge July 1, 2026 22:18
@kovtcharov
kovtcharov added this pull request to the merge queue Jul 2, 2026
Merged via the queue into main with commit 8146ccf Jul 2, 2026
37 checks passed
@kovtcharov
kovtcharov deleted the claudia/task-5afd2c14 branch July 2, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent::email Email agent changes documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(email): expose inbox search on the email REST contract for the Agent UI feat(email): expose mailbox search as a first-class capability

2 participants