Repository navigation
test(email): close REST coverage gaps — HTTP×corpus, dead CI tests, error contract (#1897) - #2045
Conversation
Every REST-contract test proves the wire shape against small hand-built fixtures; none exercise the endpoints at corpus scale. Add a true-HTTP test (FastAPI TestClient) covering /search, /prescan, and confirm+archive against the 299-message vendor-derived corpus, with counts derived from the corpus at test time rather than hardcoded. The headline case proves an archived message actually drops out of an INBOX-filtered /search over the wire. Also wires this new test plus the previously-dead test_email_corpus_alignment into the email-agent CI workflow (paths triggers + run list), closing the gap where both ran in no CI job.
…test Two hardening fixes to the new HTTP x corpus coverage: importorskip fastapi so a [dev]-only env skips instead of erroring at collection (matching the sibling e2e test), and make the email workflow fail loudly when either corpus-wired file is skipped — a silently-skipped wired test (e.g. a broken wheel install) previously produced a false-green job. Legitimate skips elsewhere in the run list stay green.
…schema conformance
The OpenAPI spec documented only 200s (plus /init's 503), so npm/native
consumers had no machine-readable error contract, and conformance tests only
checked key presence — {"count": "five"} passed. Three additive changes:
- responses= metadata on every documented route enumerating the codes its
handler actually raises (shared _CONNECTOR_ERROR_RESPONSES 403/502/503
ladder + per-route 400/404/409/413/500 extras; description-only, since
these routes return FastAPI's {"detail": ...}, not a model), with
openapi.email.json regenerated in the same commit (drift guard green).
- a conformance test that derives each route's raisable codes from
api_routes.py (AST + call-graph fixpoint + Depends targets — never a
hand-list) and fails if the spec omits any of them.
- a jsonschema body validator resolving $ref/anyOf against the full committed
spec, called from every 200-conformance test, plus direct-call negative
tests proving a wrong-typed / out-of-enum / missing-required body fails
(bypassing TestClient, which would mask a broken validator). jsonschema
added to the [dev] extras.
…or codes The error branches the spec now documents had almost no route-level coverage: zero tests asserted /triage's 502, none exercised the connector ladder (403/503/502) on the mutate routes, and /calendar/events/respond had no error test at all. Add exact-code tests for each: /triage + /triage/batch 502 on LLMTriageError; a parametrized AuthRequired/Configuration/Connectors ladder across archive, quarantine, unarchive and unquarantine (undo routes broken at backend RESOLUTION — a per-row unarchive failure is collected by design and surfaces as the 409, not the connector codes); calendar respond's full ladder plus its unconnected-provider 400; the post-gate 400 on calendar create (distinct from the pre-gate 422); and a GET /spec HTML smoke test.
…1911) The corpus grew 249->299 when the Enron-spam carve-out landed (#1906/#1911), but _schema.md, the email conftest docstrings, and gen_scorecard's methodology string still said 249 (and 54 PROMOTIONAL / ~312 KB / ~7 spam). Update to the real numbers (299 total, 104 PROMOTIONAL, 57 spam / 97 phishing, ~380 KB, baselines scored: 299) and point readers at generate_mbox.TOTAL_MESSAGES so the next corpus change doesn't re-rot a hardcoded count. The measurement record in quality_gate_thresholds.json is left as-is (it documents the corpus at measurement time, not the current corpus).
|
Verdict: Request changes (one-line fix) This is a strong, well-reasoned test-coverage PR: it drives the full 299-message email corpus through the real HTTP endpoints, wires two previously-orphaned corpus tests into CI behind a fail-on-skip gate, documents every route's real error codes in the OpenAPI spec, and validates response bodies with a real JSON-Schema validator (types + enums, negative-tested). The production change is purely additive One thing to fix before merge: the new dependency floor is too low. The conformance test uses a JSON-Schema API that only exists in newer 🔍 Technical details🟡 Important
Verified locally: the repo env currently has Strengths
|
|
Real-world validation evidence (both tiers run on an AMD Ryzen AI Linux box, Strix Halo — reserved/released via the shared test-machine lock). Proof A — clean-room cold-corpus reproduction: PASS (~4 min, pytest 12s)Fresh shallow clone of this branch, fresh venv matching CI's install, corpus artifacts absent before the run and auto-generated during it — the exact fresh-checkout state the new CI wiring must survive: Proof B —
|
|
🟡
Fix: either tighten the bound to 🔍 Technical details
# only jsonschema is listed
"jsonschema>=4.0.0,<5.0.0",
import jsonschema
from referencing import Registry, Resource # <-- undeclared dep
from referencing.jsonschema import DRAFT202012 # <-- undeclared depMinimal fix option A (tighten lower bound — "jsonschema>=4.18.0,<5.0.0",Minimal fix option B (explicit declaration — cleaner): "jsonschema>=4.0.0,<5.0.0",
"referencing>=0.29.0", |
|
Verdict: Approve with suggestions — one dependency-pin fix, otherwise a genuinely strong, well-reasoned test PR. This closes real REST coverage gaps: the 299-message corpus now runs through the actual HTTP endpoints (including a confirm→archive round trip that proves a message leaves INBOX over the wire), two previously-unwired corpus tests now run on every PR behind a fail-on-skip gate, and the error contract (403/400/503/409/502…) is documented in the published spec and enforced by a source-derived conformance test. The one thing to fix before merge: the new 🔍 Technical details🟡 Important
Strengths
|
Closes #1897
Why this matters
Before this change, a bug that only shows up when the email REST router serves a realistically populated mailbox (pagination, label filtering, archive semantics at scale) was caught by no test layer — the corpus tests bypassed FastAPI entirely and the HTTP tests used tiny hand-built fakes; two corpus integration tests ran in no CI workflow at all; and the OpenAPI spec documented only 200s, with conformance checks that would happily accept
{"count": "five"}. After: the 299-message vendor corpus is driven through the real HTTP endpoints (including a confirm→archive round trip that proves the message actually leaves INBOX over the wire), the dead tests run on every PR behind a fail-on-skip gate, every route's real error codes (403/400/503/409/502/…) are documented in the published spec and enforced by a source-derived conformance test, and response bodies are validated with a real JSON-Schema validator (types + enums, negative-tested).Scope note: #1897 was audited at schema 2.1; this lands re-scoped against current main (schema 2.3, 299-message corpus). Two issue items resolved differently: the
_schema.mdcategory drift was already fixed (only stale counts remained — corrected here), andtest_email_mcp_stdio_parity.pyis not wired into the cred-less ubuntu job because it fundamentally requires Lemonade (triage_requestunconditionally builds a real chat client — both parity sides run live triage); it is proven in the real-world tier instead (evidence below), stated here rather than silently skipped.No agent eval run is required: this PR touches no LLM-affecting surface (no prompts, tool schemas, model config, or error classification changes —
api_routes.pygains only additiveresponses=spec metadata).Test plan
tests/integration/test_email_rest_http_corpus.py:/searchcount equals a corpus-derived N (N≥5),/prescanpopulated-inbox branch, confirm→archive→INBOX-search-absence at 299-message scale — all LLM-freetest_email_corpus_alignment.py+ the new file wired intotest_email_agent.yml(paths + run list) with a CI step that fails if either is skippedresponses=on all 13 documented routes, description-only;openapi.email.jsonregenerated in the same commit; byte-equality drift guard greenDependsfixpoint) error-code check — no hand-list; jsonschema body validation with$ref/anyOfresolution; 4 direct-call negative tests/triage(+batch) 502, 403/503/502 ladder on archive/quarantine/unarchive/unquarantine, calendar respond ladder + create post-gate 400,GET /specsmokeutil/lint.py --allpassingtest_email_agent.yml— the canonical fresh-checkout proof, incl. the new skip gate and the drift guard under CI's dependency set)test_email_mcp_stdio_parity.pyagainst live Lemonade (evidence posted in the comment below; parity's 2 pre-existing failures tracked in test(email): mcp_stdio_parity thread/batch summaries diverge between REST and MCP surfaces (reproducible) #2046)