Skip to content

test: cover zod schema query validation types#1404

Open
alan747271363-art wants to merge 2 commits into
h3js:mainfrom
alan747271363-art:fix/zod-get-validated-query-types
Open

test: cover zod schema query validation types#1404
alan747271363-art wants to merge 2 commits into
h3js:mainfrom
alan747271363-art:fix/zod-get-validated-query-types

Conversation

@alan747271363-art

@alan747271363-art alan747271363-art commented May 31, 2026

Copy link
Copy Markdown

Summary

  • add type coverage for getValidatedQuery(event, z.object(...))
  • cover both defineHandler and the defineEventHandler({ handler }) shape from the issue reproduction
  • ensure the inferred query result is not any and matches the Zod schema output

Closes #1403

Notes

Current main accepts this usage, so this PR adds regression coverage to keep the Zod schema overload working.

Validation

  • corepack pnpm vitest run test/unit/types.test-d.ts
  • corepack pnpm exec oxlint test/unit/types.test-d.ts
  • corepack pnpm exec oxfmt --check test/unit/types.test-d.ts
  • git diff --check

Summary by CodeRabbit

  • Tests
    • Expanded type-level test coverage for query validation using schema-based checks. Added two cases verifying inferred return types when queries are validated, covering both direct handler usage and object-form handler usage to ensure consistent type inference.

@alan747271363-art alan747271363-art requested a review from pi0 as a code owner May 31, 2026 06:37
@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3065b16e-5f1c-4ef9-8bff-db1b981eb50e

📥 Commits

Reviewing files that changed from the base of the PR and between 1d6d865 and 98b0881.

📒 Files selected for processing (1)
  • test/unit/types.test-d.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/unit/types.test-d.ts

📝 Walkthrough

Walkthrough

This PR adds an import of defineEventHandler and two type-level Vitest cases in test/unit/types.test-d.ts that assert the inferred return types of getValidatedQuery when validating queries with Zod, covering direct handler usage and the object-form defineEventHandler({ handler }).

Changes

Type test coverage for getValidatedQuery with Zod

Layer / File(s) Summary
getValidatedQuery type coverage with Zod schemas
test/unit/types.test-d.ts
Import defineEventHandler and add two type-level test cases validating getValidatedQuery return types when driven by Zod schemas, covering both direct handler usage and the object form syntax.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐰 A query walks in with Zod held tight,
Type tests now shine to catch the light,
Schemas dance in defineEventHandler's hold,
Validation stories waiting to be told! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: adding type-level test coverage for Zod schema validation in getValidatedQuery.
Linked Issues check ✅ Passed The PR directly addresses issue #1403 by adding test coverage for getValidatedQuery with Zod schemas in both defineHandler and defineEventHandler({ handler }) shapes as requested.
Out of Scope Changes check ✅ Passed All changes are scoped to test file modifications that directly support the linked issue objective without introducing unrelated changes.
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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/unit/types.test-d.ts`:
- Around line 10-11: The test currently imports defineEventHandler from the
barrel file "../../src/index.ts"; change that to import defineEventHandler
directly from its specific module file (find the import block in
test/unit/types.test-d.ts that lists defineEventHandler) and update the import
path to the module that actually exports defineEventHandler (e.g., the file
where the function is defined) so the test no longer relies on the barrel
export; apply the same direct-module import approach to any other symbols in
that import block if modified.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92bde70d-2c58-4c9d-b9f6-2a4718d9c991

📥 Commits

Reviewing files that changed from the base of the PR and between 84244b4 and 1d6d865.

📒 Files selected for processing (1)
  • test/unit/types.test-d.ts

Comment thread test/unit/types.test-d.ts Outdated
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.

getValidatedQuery doesn't work with zod

1 participant