Skip to content

test(mcp): registry-iterating done-bar drift guard + agent-facing error contract tests#37

Merged
mastermanas805 merged 1 commit into
masterfrom
test/mcp-tool-coverage-donebar
Jun 4, 2026
Merged

test(mcp): registry-iterating done-bar drift guard + agent-facing error contract tests#37
mastermanas805 merged 1 commit into
masterfrom
test/mcp-tool-coverage-donebar

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

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. No src/ 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:

  1. No registry-iterating done-bar / drift guard existed.
  2. The 402 over-limit → agent_action path was never exercised end-to-end through a real tool call (only via the pure formatError unit + an unreachable x-mock-tier mock header).

Added

test/tool-coverage.test.ts — done-bar drift guard (matrix §4.2, rule 18)

Iterates the live server._registeredTools registry (not a hand-typed slice) and FAILS CI if any registered tool lacks:

  • a J-row mapping in MAPPED_TOOLS,
  • a callable handler + inputSchema + description, or
  • any test exercising it in test/*.test.ts.

Also reds on stale mappings (renamed/removed tool — both drift directions). Verified failing-then-passing: dropping a MAPPED_TOOLS row reds "no flow-matrix J-row mapping: redeploy".

test/tool-contract.test.ts — agent-facing error + endpoint contract

Drives real tool handlers against the mock api and asserts the envelope the LLM reads aloud:

  • 402 tier-gate (create_deploy({private:true}) on hobby) → Action: + Upgrade: block surfaced verbatim (rule 12 / FIX-E #C7), with a 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).

test/mock-api.ts

Adds HOBBY_TOKEN so the tier-gate 402 is reachable through a real create_deploy call (previously only via an x-mock-tier header 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:nocov and the coverage.yml lcov 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 test green — 390 tests (was 373). No src/ lines changed, so the diff-cover 100%-patch gate is trivially satisfied.

🤖 Generated with Claude Code

…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>
@mastermanas805 mastermanas805 enabled auto-merge (squash) June 4, 2026 18:35
@mastermanas805 mastermanas805 merged commit 42f5313 into master Jun 4, 2026
9 checks passed
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