Skip to content

chore: Add modular validation system for API routes leading to integration tests#43

Draft
waqasshaukat wants to merge 5 commits intomainfrom
ws/chat-refactor
Draft

chore: Add modular validation system for API routes leading to integration tests#43
waqasshaukat wants to merge 5 commits intomainfrom
ws/chat-refactor

Conversation

@waqasshaukat
Copy link
Contributor

@waqasshaukat waqasshaukat commented Nov 29, 2025

Purpose of this PR

  1. Shared Validation Logic for Chat API Routes

  2. PURPOSE OF EXTRACTION:
    The validation logic is used by BOTH:
    -Real API routes (app/api/chat/route.ts, app/api/ymax/route.ts, app/api/support/route.ts)
    -(in the subsequent PR)Test mocks (test/setup.ts - MSW handlers)

  3. By extracting validation into shared functions, we ensure:

  • Single source of truth for validation rules
  • Tests automatically stay in sync with API changes
  • If a developer changes validation logic here, both API and tests update together
  • Impossible for tests to return different status codes than real API
  1. ARCHITECTURE:
    Each validation concern is separated into its own function for:
  • Better modularity and reusability
  • Easier testing of individual validators
  • Ability to compose validators based on endpoint needs
  • Future extensibility (add new validators without modifying existing ones)
  1. **This PR also fixes an existing but of not picking up the MCP server on the chat/[id] route if the page is hard-refreshed. Reason of doing in this PR is that while validating the correct MCP (during development) the prescribed route giving an error **

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 29, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ai 1622973 Commit Preview URL

Branch Preview URL
Dec 01 2025, 08:25 AM

@waqasshaukat waqasshaukat changed the title [WIP]chore: Add modular validation system for API routes leading to integration tests chore: Add modular validation system for API routes leading to integration tests Dec 1, 2025
@waqasshaukat waqasshaukat marked this pull request as draft December 4, 2025 06:08
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