test: enforce response-schema map covers every route#38
Merged
Conversation
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>
162ae7b to
19b1dc3
Compare
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.
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
createMemoryRouterandcreateAgentRouter's Express stacks and cross-check against the schema map:MEMORY_RESPONSE_SCHEMASentry.AGENT_RESPONSE_SCHEMASentry.MEMORY_RESPONSE_SCHEMASkey points at a non-existent route (catches stale entries left behind when a route is deleted).AGENT_RESPONSE_SCHEMASkey points at a non-existent route.Uses stub
MemoryService/AgentTrustRepositoryinstances — 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 bothopenapi.tsand the router). Noted as a separate refactor; this test is the minimum bar.Test plan