Skip to content

test: Give the MCP resource error tests an archive to fail inside - #5175

Merged
Sinity merged 1 commit into
masterfrom
fix/mcp-envelope-contract-fixtures
Sep 15, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/mcp-envelope-contract-fixtures

Conversation

@Sinity

@Sinity Sinity commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Summary

Five MCP resource-error tests were asserting a code they never reached. This clears them, and adds deliberate coverage for the behaviour that exposed them.

Evidence

Receipt .cache/verify/runs/20260914T233651Z-all-207009-89ddea6b (verify_all, job 1699, 22,540 selected, 29 failed).

Caveat on that receipt: its run.json records git_head: f7964acd12b25134c0e2e4cd8f73f9e6557a4a4f — the tip of branch rebase-5165, not master and not an ancestor of it — and final_git_head: 724d17535. The shared checkout advanced across 7 merged PRs during the run, so it is not evidence of a frozen tree. I re-ran all 29 node ids at true master HEAD: 17 reproduce, 12 do not. These 5 are among the 17.

Root cause

All five come from one place, and in none of them did the intended trigger execute. The read_server fixture builds a server with no archive at all. Every one of these resources opens the index tier first, so it returned before touching what the test had patched.

They were green for the wrong reason on both sides:

  • the three internal_error cases: absent tier raised a bare sqlite3.OperationalError, which fell into the generic else of server_support._exception_to_error_json → internal_error;
  • the two not_found cases: the same OperationalError hit an explicit except sqlite3.OperationalError: … code="not_found" arm in server_resources.py.

#5162 typed that refusal as archive_tier_unavailable, and the coincidence stopped holding. git show --stat 817eec6f4 touches no MCP file — these tests were never considered.

Separately, the two not_found cases patched polylogue.mcp.server._get_polylogue, which neither resource calls. That patch was inert regardless of the tier.

Per-failure classification

Failure Classification What it was actually proving
test_stats_resource_internal_error stale test (vacuous) absent-tier OperationalError → generic handler, not the patched ArchiveStore.stats fault
test_sessions_resource_internal_error stale test (vacuous) same; patched archive_session_list_payload never called
test_origin_recent_resource_internal_error stale test (vacuous) same
test_session_resource_not_found stale test (vacuous) absent-tier OperationalError → the not_found arm; _get_polylogue patch inert
test_messages_resource_not_found stale test (vacuous) same

No product defect. archive_tier_unavailable is the correct answer for the input these fixtures actually presented. Notably the expected codes were right all along — the fixtures were wrong — so this does not retarget a single assertion downward.

Solution

  • seeded_read_server: a read-role server whose runtime service scope is a real, seeded archive. build_server() is what installs the scope, so it runs before the scope is read back and swapped.
  • The three internal_error cases move to it, keeping their patches and their expected code. The injected RuntimeError("boom") now actually fires.
  • The two not_found cases move to it and drop the inert _get_polylogue patch, relying on the resource resolving an unresolvable token itself (resolve_session_id → KeyError → code="not_found"). Present tier, absent session — which is what the test names claim.
  • _seed_archive is hoisted to module scope; TestNativeReadSurfaceHonorsContract._seed now delegates to it rather than duplicating the body.
  • New test_resource_on_an_absent_index_tier_is_typed_not_internal, against the bare read_server, so fix: Report an absent index tier as a typed first-run outcome #5162's behaviour has coverage of its own instead of being an accident three other tests leaned on.

Anti-vacuity

Measured, not asserted. With the injected fault deleted from test_sessions_resource_internal_error:

devtools test tests/unit/mcp/test_envelope_contracts.py::TestResourceErrorEnvelopes::test_sessions_resource_internal_error
devtools test: FAILED exit=1 diagnosis=pytest_failed receipt=.cache/verify/runs/20260915T013517Z-focused-test-318227-eaf3d166/run.json

Before this change that same deletion still passed — the definition of vacuous.

  • not_found cases: red if resolve_session_id stops raising KeyError for an unresolvable token, or if server_resources stops catching (KeyError, ValueError) and lets it reach the generic handler as internal_error.
  • New tier-absent case: red if the ArchiveTierUnavailableError branch in _exception_to_error_json is removed — it returns to internal_error.

Verification

devtools test tests/unit/mcp/test_envelope_contracts.py
devtools test: PASSED exit=0 diagnosis=pytest_passed receipt=.cache/verify/runs/20260915T013612Z-focused-test-320419-2a0dc239/run.json

26 passed (21 + the 5 repaired, of which one is new).

Schema closure

devtools schema closure tests/unit/mcp/test_envelope_contracts.py
out  tests/unit/mcp/test_envelope_contracts.py

OUT of the derived schema-identity closure. Test-only change; no product file touched. Does not need to land before an archive rebuild.

Residuals

  • I did not audit whether any test elsewhere still depends on the absent-tier-through-MCP path returning internal_error; the full suite will say.
  • The three sibling internal_error tests that patch a pre-archive call site (tags, session_tree, readiness) were already non-vacuous and are untouched.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK

Five `TestResourceErrorEnvelopes` cases asserted a code they never reached.
`read_server` builds a server with no archive at all, so each resource opened
an absent index tier and returned before touching whatever the test had
patched. The three `internal_error` cases were reaching the generic handler
via a bare `sqlite3.OperationalError`; the two `not_found` cases were reaching
an `except sqlite3.OperationalError` arm. Both were green for the wrong
reason. #5162 typed that refusal as `archive_tier_unavailable` and the
coincidence stopped holding.

The expected codes were right; the fixtures were not. `seeded_read_server`
installs a real seeded archive as the runtime service scope, so the injected
faults now actually fire. The two `not_found` cases drop their
`_get_polylogue` patch entirely -- it was inert, since neither resource calls
it -- and rely on the resource resolving an unresolvable token itself.

Anti-vacuity, measured rather than asserted: deleting the injected fault from
`test_sessions_resource_internal_error` now fails the test. Before this change
it still passed.

The behaviour #5162 introduced keeps deliberate coverage of its own, against
the bare `read_server`, instead of being an accident three other tests
depended on.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DYUNBGoE652b3nfmq3CtqK
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: e47d6ad2-4861-4aec-a8d8-826ae8b8d499

📥 Commits

Reviewing files that changed from the base of the PR and between 724d175 and 04a62e8.

📒 Files selected for processing (1)
  • tests/unit/mcp/test_envelope_contracts.py

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-09-15T01:40:13.333828Z 04a62e8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Sinity
Sinity merged commit ae99faf into master Sep 15, 2026
3 checks passed
@Sinity
Sinity deleted the fix/mcp-envelope-contract-fixtures branch September 15, 2026 01:51
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