test(mcp): registry-iterating done-bar drift guard + agent-facing error contract tests#37
Merged
Merged
Conversation
…or contract tests
Raises MCP test coverage toward the flow matrix
(docs/sessions/2026-06-04/USER-FLOW-INVENTORY-AND-TEST-MATRIX.md §4.2)
and the done-bar. Agents are the PRIMARY consumers of instanode, so MCP
tool flows + the agent-facing error surface are P0.
Done-bar drift guard (test/tool-coverage.test.ts, NEW):
iterates the live `server._registeredTools` registry (rule 18 — no
hand-typed slice) and FAILS CI if any registered tool lacks (a) a J-row
mapping in MAPPED_TOOLS, (b) a callable handler + inputSchema +
description, or (c) any test exercising it in test/*.test.ts. Also reds
on stale mappings (renamed/removed tool). Verified failing-then-passing:
dropping a MAPPED_TOOLS row reds "no flow-matrix J-row mapping".
Contract / error-mapping tests (test/tool-contract.test.ts, NEW):
drive real tool handlers against the mock api and assert the agent-facing
envelope mapping the LLM reads aloud:
- 402 tier-gate (create_deploy private on hobby) → Action: + Upgrade:
block surfaced verbatim (rule 12 / FIX-E #C7), + pro negative control
- 401 on auth-required tools → dashboard CTA
- 404 (cross-team / absent, J11+J17) → clean not_found
- endpoint contract for gap tools J5/J6/J7/J14/J15/J16 (correct
endpoint hit + documented response shape)
mock-api: add HOBBY_TOKEN fixture (test/mock-api.ts) so the tier-gate
402 is reachable through a REAL create_deploy({private:true}) call —
previously only reachable via an `x-mock-tier` header the InstantClient
never sends, leaving the agent_action surfacing path unexercised
end-to-end. Tier now derives from the bearer (header override still
wins for backward-compat).
Wire both new files into `npm test`/`test:nocov` and the coverage.yml
lcov step. No src/ changes (diff-cover patch gate trivially satisfied).
Real-backend MUTATING MCP flows still depend on the W0 skip-cohort
guard (matrix §3.W0) and stay STAGING-only — noted in the test header.
Gate: build + npm test green (390 tests, was 373).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Raises MCP test coverage toward the flow matrix (
docs/sessions/2026-06-04/USER-FLOW-INVENTORY-AND-TEST-MATRIX.md§4.2) and the done-bar. Agents are the PRIMARY consumers of instanode, so MCP tool flows + the agent-facing error surface are P0. Nosrc/changes — test + test-harness + CI-wiring only.Tools inventoried (19 registered)
All 19
server.tool(...)already had success-path + network-error handler tests (tools-unit.test.ts) and endpoint/payload tests (client-unit.test.ts). The real gaps this PR closes:agent_actionpath was never exercised end-to-end through a real tool call (only via the pureformatErrorunit + an unreachablex-mock-tiermock header).Added
test/tool-coverage.test.ts— done-bar drift guard (matrix §4.2, rule 18)Iterates the live
server._registeredToolsregistry (not a hand-typed slice) and FAILS CI if any registered tool lacks:MAPPED_TOOLS,inputSchema+description, ortest/*.test.ts.Also reds on stale mappings (renamed/removed tool — both drift directions). Verified failing-then-passing: dropping a
MAPPED_TOOLSrow reds "no flow-matrix J-row mapping: redeploy".test/tool-contract.test.ts— agent-facing error + endpoint contractDrives real tool handlers against the mock api and asserts the envelope the LLM reads aloud:
create_deploy({private:true})on hobby) →Action:+Upgrade:block surfaced verbatim (rule 12 / FIX-E #C7), with a Pro negative control.not_found.test/mock-api.tsAdds
HOBBY_TOKENso the tier-gate 402 is reachable through a realcreate_deploycall (previously only via anx-mock-tierheader the InstantClient never sends). Tier now derives from the bearer; the header override still wins (backward-compat — existing tests stay green).CI wiring
Both new files added to
npm test/test:nocovand thecoverage.ymllcov step.Scope note
Real-backend mutating MCP flows still depend on the W0 skip-cohort guard (matrix §3.W0) and remain STAGING-only — documented in the test header. These tests run hermetically against the in-process mock.
Gate
npm run build && npm testgreen — 390 tests (was 373). Nosrc/lines changed, so the diff-cover 100%-patch gate is trivially satisfied.🤖 Generated with Claude Code