Skip to content

fix: resolve FlexibleSchema safeParse errors in chat.test.ts#247

Open
vaishnavijha12 wants to merge 2 commits into
piyushdotcomm:mainfrom
vaishnavijha12:fix/chat-test-schema
Open

fix: resolve FlexibleSchema safeParse errors in chat.test.ts#247
vaishnavijha12 wants to merge 2 commits into
piyushdotcomm:mainfrom
vaishnavijha12:fix/chat-test-schema

Conversation

@vaishnavijha12
Copy link
Copy Markdown

@vaishnavijha12 vaishnavijha12 commented May 22, 2026

Description

This PR fixes TypeScript compilation failures in chat.test.ts caused by the Vercel AI SDK exposing FlexibleSchema instead of raw Zod schemas.

Changes Made

  • Exported reusable Zod schemas from app/api/chat/tools.ts
  • Replaced inline z.object() schemas with exported schema constants
  • Updated tests to use exported schemas directly with .safeParse()
  • Preserved existing runtime validation behavior for AI tools

Issue Fixed

Previously, tests used:

tools.edit_file.inputSchema.safeParse(...)

However, inputSchema is now typed as FlexibleSchema, which does not expose native Zod methods like .safeParse().

The tests now correctly validate against exported Zod schemas.

Closes #243

Summary by CodeRabbit

  • Constraints

    • Batch file modifications are now limited to 50 changes per request.
  • Refactor

    • Consolidated AI tool input validation for improved maintainability.

Review Change Stack

@qodo-code-review
Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@github-actions
Copy link
Copy Markdown

👋 Thanks for opening a PR, @vaishnavijha12!

Your PR has entered the 🚦 PR Review Pipeline.

Standard PR detected — your PR will follow the standard review pipeline.


What happens next

Stage Reviewer Checks
Stage 1 — Automated Validation 🤖 Bot DCO · Format · AI/Slop · Duplicate
Stage 2 — Human Review 👥 Maintainer Code + Quality Review
Stage 3 — PA / Maintainer Review 🔑 Project Admin Final Merge Decision

A pipeline status comment will appear below and update automatically as your PR progresses.


While you wait

  • Sign all commits (git commit -s)
  • Link your issue (Closes #123)
  • Use a feature branch (not main)
  • Avoid unrelated changes

This comment is posted only once.

@github-actions github-actions Bot added the bug Something isn't working label May 22, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d8e7bd7c-a9dc-4d94-8f6f-54a1b7d73010

📥 Commits

Reviewing files that changed from the base of the PR and between 19a3136 and 0bb6c03.

📒 Files selected for processing (2)
  • app/api/chat.test.ts
  • app/api/chat/tools.ts

Walkthrough

Zod tool input schemas are extracted as reusable exported constants in chat/tools.ts with enforced batch and file size limits, the tool definitions are updated to reference these constants, and tests are refactored to import and validate schemas directly rather than accessing them through the tool object.

Changes

Tool Schema Extraction and Validation Refactoring

Layer / File(s) Summary
Schema extraction with batch and file size limits
app/api/chat/tools.ts
Four Zod schemas (readFileSchema, editFileSchema, editMultipleFilesSchema, deleteFileSchema) and MAX_BATCH_CHANGES constant are extracted and exported with enforced constraints: MAX_FILE_CONTENT_CHARS for individual files and MAX_BATCH_CHANGES (50) for batch edit operations.
Tool definitions wired to exported schemas
app/api/chat/tools.ts
The tools object (read_file, edit_file, edit_multiple_files, delete_file) is updated to reference the exported schema constants for inputSchema instead of inline definitions.
Test validation using exported schemas
app/api/chat.test.ts
Imports are updated to use exported schemas and MAX_FILE_CONTENT_CHARS directly; test assertions call safeParse on editFileSchema and editMultipleFilesSchema to validate single-file and batch payloads with the same boundary and rejection expectations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • piyushdotcomm/Editron#66: Both PRs update AI tool definitions to use the inputSchema field for tool request validation in chat tools and route handlers.
  • piyushdotcomm/Editron#96: Both PRs target the same Zod tool input validation for edit_file and edit_multiple_files with content length and batch limits, and update tests to validate against exported schemas.

Suggested labels

maintenance, architecture, mentor:piyushdotcomm

Suggested reviewers

  • piyushdotcomm

Poem

🐰 Schemas hop free from tool's embrace,
Constants guard each file's space,
Tests now safeParse what they trust,
Validation limits keep code just! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: resolving FlexibleSchema safeParse errors in chat.test.ts, which is the primary objective of this PR.
Description check ✅ Passed The description covers the problem, solution, and changes made, though it does not follow the provided template structure with checkboxes for validation steps and related issue references.
Linked Issues check ✅ Passed The PR fully addresses issue #243 by exporting Zod schemas and updating tests to use safeParse on exported schemas, fixing the FlexibleSchema compilation error.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the FlexibleSchema safeParse error: exporting schemas, refactoring tools, and updating tests. Added MAX_BATCH_CHANGES constant appears to be a supporting change for the schema refactor.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@vaishnavijha12
Copy link
Copy Markdown
Author

Implemented the requested fix by exporting reusable Zod schemas and updating validation tests to avoid relying on FlexibleSchema.safeParse() from the AI SDK.

Please let me know if any additional refinements are needed. Thanks!

Copy link
Copy Markdown
Owner

@piyushdotcomm piyushdotcomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. but to verify that you setup the project locally correctly make a playground in the project on your local server and add a screenshot of that
or at least add screenshot of the dashboard

@vaishnavijha12
Copy link
Copy Markdown
Author

vaishnavijha12 commented May 22, 2026

Verified the project locally in Codespaces and attached the screenshot of the running application on my branch (fix/chat-test-schema).

The frontend is running successfully on localhost:3000. The MongoDB-related collab server issue appears environment-specific and unrelated to the schema validation fix in this PR.
Screenshot 2026-05-23 014712

I asked you for the dashboard image.
You have to login first.

@piyushdotcomm
Copy link
Copy Markdown
Owner

show me the dashboard

@vaishnavijha12
Copy link
Copy Markdown
Author

image

@piyushdotcomm
Copy link
Copy Markdown
Owner

@vaishnavijha12
haa haa nice try
that's not my project you didnt configured the project locally because AI is not that much powerful to fetch every site and scrape the variables
so you asked to create a dashboard replica but you are not using enough powerful LLM so it didnt copied exactly
i would highly recommend to not use AI blindly rather just ask for help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: safeParse does not exist on FlexibleSchema in chat.test.ts

2 participants