Skip to content

fix: restore zod 4 schema output type inference (CI auto-fix for #1405) - #1406

Closed
github-actions[bot] wants to merge 1 commit into
sincere-ponyfrom
claude-fix-pr-1405-31245613692
Closed

fix: restore zod 4 schema output type inference (CI auto-fix for #1405)#1406
github-actions[bot] wants to merge 1 commit into
sincere-ponyfrom
claude-fix-pr-1405-31245613692

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

CI Auto-Fix

Original PR: #1405
Failed CI Run: PR Build Check
Failed Job: Code Quality Check (tsgo typecheck)

Root Cause

The repo ships no lockfile (bun.lock is gitignored since 58f6657), so CI resolves zod@^4.4.3 to the latest 4.x on every run. A recent zod 4 release marks the schema output type parameter as out (covariant). The JsonBodySchema<T> constraint in request-body.ts inferred T from a value (parameter) position, which TypeScript cannot do for a covariant type parameter — so every parsed body regressed to unknown, producing 39 typecheck errors across all v1 resource handlers.

This is pre-existing on dev (PR #1405 does not touch any of these files) and surfaces on this PR because the merge commit inherits dev's typecheck.

Fixes Applied

File Fix Type
src/lib/api/v1/_shared/request-body.ts Switch parseJsonBody/parseHonoJsonBody from generic <T> (inferred from variance-blocked param) to generic <S extends JsonBodySchema> + SchemaOutput<S> conditional on zod's _output phantom property type-only
src/app/api/v1/resources/providers/handlers.ts Apply the same SchemaOutput<S> pattern to the local parseJson wrapper type-only
src/lib/api/v1/schemas/audit-logs.ts Annotate .transform() callback param ("true" | "false" | undefined) type-only
src/lib/api/v1/schemas/me.ts Annotate .transform() callback param (boolean | "true" | "false") type-only
src/lib/api/v1/schemas/system-config.ts Annotate .refine() callback param (string) type-only
src/lib/api/v1/schemas/usage-logs.ts Annotate .transform() callback param (boolean | "true" | "false") type-only

All changes are type-only — no runtime behavior is modified. The parsed.data as SchemaOutput<S> cast is correct because safeParse has already validated the data against schema S, so SchemaOutput<S> is by definition the validated output type.

Verification

  • bun run typecheck (tsgo) passes — all 39 errors resolved
  • bun run lint passes
  • tests/unit/api/v1/ — 156 tests pass (34 files)
  • No logic changes; only type annotations and a generic-parameter refactor

Auto-generated by Claude AI

Greptile Summary

This PR restores Zod 4 output-type inference for management API JSON body parsing without changing runtime validation behavior.

  • Extracts validated schema output through Zod’s _output phantom type in shared and provider-specific body parsers.
  • Adds callback parameter annotations to query transforms and timezone refinement to satisfy type checking.
  • Preserves the existing request parsing, validation-error, and action-dispatch paths.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code defect identified.

The schema output extraction preserves types for the Zod schemas used by current callers, and each callback annotation matches the input type of its immediately preceding schema without altering runtime behavior.

Important Files Changed

Filename Overview
src/lib/api/v1/_shared/request-body.ts Replaces variance-sensitive generic inference with schema-based output extraction while retaining the existing parsing and validation flow.
src/app/api/v1/resources/providers/handlers.ts Updates the local provider body parser to propagate the shared schema output type into action calls.
src/lib/api/v1/schemas/audit-logs.ts Explicitly types the optional success-query transform input consistently with its enum schema.
src/lib/api/v1/schemas/me.ts Explicitly types the boolean-query transform input with no runtime behavior change.
src/lib/api/v1/schemas/system-config.ts Explicitly types the timezone refinement callback consistently with the preceding string schema.
src/lib/api/v1/schemas/usage-logs.ts Explicitly types the boolean-query transform input with no runtime behavior change.

Reviews (1): Last reviewed commit: "fix(api): restore zod 4 schema output ty..." | Re-trigger Greptile

Context used:

zod 4 marks the schema output type parameter as `out` (covariant), so the
compiler can no longer infer it from a value parameter. The JsonBodySchema<T>
constraint in request-body.ts tried to infer T that way, which regressed to
`unknown` for every parsed body and produced 39 typecheck errors across all
v1 resource handlers.

Switch parseJsonBody/parseHonoJsonBody to be generic over the schema type S
and derive its output via a SchemaOutput<S> conditional on the `_output`
phantom property (which zod still resolves correctly). Also annotate four
zod .transform()/.refine() callbacks whose input type stopped being inferred.

Type-only changes; no runtime behavior modified.

CI Run: https://github.com/ding113/claude-code-hub/actions/runs/31245429109

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant