-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
chore: add test for zod branded types #6833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
🚅 Deployed to the trpc-pr-6833 environment in trpc-sse-and-websockets
|
WalkthroughA new test case was added to Changes
Sequence Diagram(s)sequenceDiagram
participant Test
participant TRPC_Router
participant Zod4_Schema
Test->>Zod4_Schema: Define branded schema (AccountId)
Test->>TRPC_Router: Initialize router with procedure using AccountId
Test->>TRPC_Router: Call procedure with branded input
TRPC_Router->>Test: Return input (runtime check)
Test->>Test: Assert input/output types using inferRouterInputs/Outputs
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes found. Poem
✨ Finishing Touches
🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/tests/server/validators.test.ts (1)
922-950: Well-structured test for branded types, but consider adding runtime validation.The test correctly verifies that Zod v4 branded types are preserved through TRPC's type inference system. The type-level assertions using
expectTypeOfare appropriate and comprehensive.However, the test only includes compile-time type checking without runtime validation. Consider adding runtime assertions to ensure the branded types work correctly at runtime as well.
Consider adding runtime validation to make the test more comprehensive:
test('zod4 branded types', () => { const t = initTRPC.create(); const AccountId = zod4.cuid2().brand<'EmailAccount'>(); type Types = NonNullable<(typeof AccountId)['~standard']['types']>; const router = t.router({ num: t.procedure .input( zod4.object({ accountId: AccountId, }), ) .query((opts) => { expectTypeOf(opts.input.accountId).toEqualTypeOf<Types['output']>(); return opts.input; }), }); type RouterInput = inferRouterInputs<typeof router>; type RouterOutput = inferRouterOutputs<typeof router>; type AccountIdInput = RouterInput['num']['accountId']; // ^? type AccountIdOutput = RouterOutput['num']['accountId']; // ^? expectTypeOf<AccountIdInput>().toEqualTypeOf<Types['input']>(); expectTypeOf<AccountIdOutput>().toEqualTypeOf<Types['output']>(); + + // Runtime validation to ensure branded types work correctly + const caller = router.createCaller({}); + const validCuid = 'ckpfn8ueu000001l60fv4j3ka'; // valid CUID2 + expect(() => caller.num({ accountId: validCuid })).not.toThrow(); + expect(() => caller.num({ accountId: 'invalid-cuid' })).toThrow(); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/tests/server/validators.test.ts(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (20)
- GitHub Check: E2E-tests (vercel-edge-runtime)
- GitHub Check: E2E-tests (fastify-server)
- GitHub Check: E2E-tests (next-prisma-todomvc)
- GitHub Check: E2E-tests (express-minimal)
- GitHub Check: E2E-tests (soa)
- GitHub Check: E2E-tests (express-server)
- GitHub Check: E2E-tests (next-formdata)
- GitHub Check: E2E-tests (.experimental/next-app-dir)
- GitHub Check: E2E-tests (.test/diagnostics-big-router)
- GitHub Check: E2E-tests (cloudflare-workers)
- GitHub Check: e2e-legacy-node (next-prisma-starter, 18.x)
- GitHub Check: E2E-tests (.test/internal-types-export)
- GitHub Check: e2e-legacy-node (next-prisma-todomvc, 20.x)
- GitHub Check: e2e-legacy-node (next-prisma-todomvc, 18.x)
- GitHub Check: e2e-legacy-node (next-prisma-starter, 20.x)
- GitHub Check: E2E-tests (Bun) (bun, ubuntu-latest)
- GitHub Check: Release using pkg.pr.new
- GitHub Check: E2E-tests (Deno) (deno-deploy)
- GitHub Check: test
- GitHub Check: Lint and auto-fix
🔇 Additional comments (1)
packages/tests/server/validators.test.ts (1)
5-10: LGTM! Import changes support the new test functionality.The addition of
inferRouterInputsandinferRouterOutputstype utilities is correctly implemented and necessary for the new branded types test case.
@trpc/client
@trpc/next
@trpc/react-query
@trpc/server
@trpc/tanstack-react-query
@trpc/upgrade
commit: |
|
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |
Closes #6831
🎯 Changes
Demo of zod branded types
Summary by CodeRabbit