Skip to content

test: enforce response-schema map covers every route#38

Merged
ethanj merged 1 commit intomainfrom
response-schema-completeness-test
Apr 23, 2026
Merged

test: enforce response-schema map covers every route#38
ethanj merged 1 commit intomainfrom
response-schema-completeness-test

Conversation

@ethanj
Copy link
Copy Markdown
Contributor

@ethanj ethanj commented Apr 22, 2026

Summary

Follow-up to #37. Codex flagged that the runtime validator silently skips unmapped routes, so a future route addition or path rename could drop response validation for that endpoint without anyone noticing — the router-level middleware still looks protected.

This closes the maintenance gap with four assertions that walk both createMemoryRouter and createAgentRouter's Express stacks and cross-check against the schema map:

  • Every memory route has a MEMORY_RESPONSE_SCHEMAS entry.
  • Every agent route has an AGENT_RESPONSE_SCHEMAS entry.
  • No MEMORY_RESPONSE_SCHEMAS key points at a non-existent route (catches stale entries left behind when a route is deleted).
  • No AGENT_RESPONSE_SCHEMAS key points at a non-existent route.

Uses stub MemoryService / AgentTrustRepository instances — Express route registration doesn't invoke service methods, so the stack is fully populated without a live DB. Test runs in ~4ms.

Follow-up

Codex's stronger suggestion — deriving the map from the same registration source that builds the OpenAPI spec — would make the gap structurally impossible instead of catching it in CI. That's a larger restructure (typed registerRoute(method, path, { requestBody, responseSchema, handler }) helper used by both openapi.ts and the router). Noted as a separate refactor; this test is the minimum bar.

Test plan

  • Four new assertions pass
  • All 1041 core tests pass (1037 + 4 new)
  • CI green end-to-end

Codex flagged that validateResponse silently skips unmapped routes,
so a new route or a path rename can drop runtime validation without
anyone noticing. This closes the maintenance gap with four assertions
that walk both createMemoryRouter and createAgentRouter's Express
stacks and cross-check against MEMORY_RESPONSE_SCHEMAS /
AGENT_RESPONSE_SCHEMAS:

- Every memory route has a schema map entry.
- Every agent route has a schema map entry.
- No MEMORY_RESPONSE_SCHEMAS key points at a non-existent route
  (catches stale entries left behind when a route is deleted).
- No AGENT_RESPONSE_SCHEMAS key points at a non-existent route.

The test uses stub service / trustRepo instances — Express route
registration doesn't invoke service methods, so the stack is fully
populated without a live DB. Runs in ~4ms.

Follow-up Codex recommended (deriving the map from the same
registration source as the OpenAPI schemas) would make the gap
structurally impossible instead of catching it in CI. Noted as a
separate refactor — this test is the minimum bar.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ethanj ethanj force-pushed the response-schema-completeness-test branch from 162ae7b to 19b1dc3 Compare April 22, 2026 23:59
@ethanj ethanj merged commit f34853d into main Apr 23, 2026
1 check passed
@ethanj ethanj deleted the response-schema-completeness-test branch April 23, 2026 00:03
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