Skip to content

fix(codegen): TS7056 post-processor emits typed z.ZodType<T, T> - #1924

Merged
bokelley merged 1 commit into
mainfrom
bokelley/codegen-ts7056-on-main
May 22, 2026
Merged

bokelley merged 1 commit into
mainfrom
bokelley/codegen-ts7056-on-main

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Targeting `main` directly — purely codegen-tooling, no wire/API change. Patch bump.

Problem

The Zod-from-TS post-processor (`scripts/generate-zod-from-ts.ts`) annotates schemas that hit TypeScript's `.d.ts` serialization limit (TS7056) so `tsc --declaration` stops trying to write the inferred shape. The previous bare `z.ZodType` annotation makes `z.input` resolve to `unknown` — breaking `AdcpToolMap[K]['params']` narrowing for any annotated request schema. Surfaced during the 8.0-beta cut (#1902) when 3.1.0-beta.2's compound schemas pushed four more entries past the TS7056 limit.

Changes

  • `TS7056_SCHEMAS` entries gain an optional `tsType` field. When present, the annotation uses the 2-type-param Zod v4 form `z.ZodType<T, T>` with `& Record<string, unknown>` widening to reflect runtime `.passthrough()` semantics. Callers' `z.input<...>` reads resolve to the typed shape; downstream destructures keep their field types.
  • Auto-injects `import type { ... } from './tools.generated'` for the typed annotations.
  • Pre-emptively annotates five additional schemas that hit TS7056 on 3.1.0-beta.2 (PreviewCreativeRequest, UpdateMediaBuyRequest/Response, BuildCreativeResponse, SyncEventSourcesResponse). The annotation is harmless on the current 3.0.12 pin and primes `main` for any future 3.0.x patch that introduces compound-schema complexity.
  • One-line cast at the `withOptionalAccount(UpdateMediaBuyRequestSchema)` call site so the framework helper's `z.ZodObject<...>` constraint is satisfied after the annotation widening. Runtime shape unchanged.

Why land on `main` instead of stacking on the 8.0-beta foundation

Verification on `main` (3.0.12 pin)

  • `tsc --noEmit` clean
  • `npm run build:lib` succeeds, dist .d.ts emitted cleanly
  • 77/77 buyer-retry-policy + zod-schemas tests pass
  • prettier clean

Verification on `bokelley/cut-8-0-beta` (3.1.0-beta.2 pin)

Same change applied (verified on stacked PR #1912) — closes the final compile gap on the 8.0-beta foundation. #1912 will be closed in favor of this PR.

Closes #1912 (superseded — same change, broader landing target).

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

The Zod-from-TS post-processor annotates schemas that hit TypeScript's
.d.ts serialization limit (TS7056) so the compiler stops trying to
serialize the inferred shape. The previous bare z.ZodType annotation
made z.input<typeof X> resolve to `unknown` — breaking
AdcpToolMap[K]['params'] narrowing for any annotated request schema.

Changes:
- TS7056_SCHEMAS entries now carry an optional `tsType`. When present,
  the annotation uses the 2-type-param Zod v4 form
  `z.ZodType<T, T>` with `& Record<string, unknown>` widening to
  reflect runtime passthrough() semantics. z.input<...> resolves
  correctly; downstream destructures keep field types.
- Auto-inject `import type { ... } from './tools.generated'` for the
  typed annotations.
- Pre-emptively annotate 5 schemas that hit TS7056 on 3.1.0-beta.2
  (PreviewCreativeRequest, UpdateMediaBuyRequest/Response,
  BuildCreativeResponse, SyncEventSourcesResponse). Annotation is
  harmless on the current 3.0.12 pin.
- One-line cast at the withOptionalAccount(UpdateMediaBuyRequestSchema)
  call site so the helper's z.ZodObject<...> constraint is satisfied
  after annotation widening. Runtime shape unchanged.

Why pre-emptive: the 8.0-beta cut (#1902) needs this codegen behavior
to compile its dist/. Landing on main decouples it from the 8.0-beta
foundation stack.

Patch bump — purely codegen tooling; no wire change; no API change.
@bokelley
bokelley merged commit db06bd4 into main May 22, 2026
11 checks passed
@bokelley
bokelley deleted the bokelley/codegen-ts7056-on-main branch May 22, 2026 08:06

@aao-ipr-bot aao-ipr-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Codegen fix; the new annotation makes z.input<typeof X> resolve to the typed shape instead of unknown, which is what the AdcpToolMap narrowing depends on. Follow-ups noted below.

Things I checked

  • Regex export const ${name} = in postProcessTS7056Annotations cannot false-match: each affected schema name is uniquely terminated by Schema = and no sibling export shares the prefix at the right boundary (scripts/generate-zod-from-ts.ts:95).
  • Cast site at tool-request-schemas.ts:34 is runtime-safe — UpdateMediaBuyRequestSchema is still z.object(...).passthrough() at runtime, so withOptionalAccount's .shape.account.optional() + .extend(...) still hits a real ZodObject. The annotation widening is type-only.
  • & Record<string, unknown> widening distributes correctly over z.union(...) annotations (UpdateMediaBuyResponseSchema, BuildCreativeResponseSchema, SyncEventSourcesResponseSchema). z.input<typeof X> resolves to X & Record<string, unknown> on each union member. No caller z.infers these schemas today, so the widening is invisible downstream.
  • version.ts 7.10.1 → 7.10.2 is drift correction, not a manual bump. package.json on origin/main is already at 7.10.2 (Release PR #1923) but version.ts was left at 7.10.1 — sync-version output now matches. Next Release PR will carry both to 7.10.3 together.
  • Patch changeset present, type matches impact (codegen-tooling, no wire/API change).

Follow-ups (non-blocking — file as issues)

  1. Missing fail-fast guard on the import-injection step. scripts/generate-zod-from-ts.ts:130 does result.replace(/import { z } from "zod";\n/, ...). If ts-to-zod ever changes its import shape (single quotes, combined import, no trailing newline), the replace silently no-ops and you get a downstream TS error about unresolved PreviewCreativeRequest. The sibling guards in this file (lines 96-100, 152-157) fail loudly with a named error — this one should too. Assert the import landed when typesToImport.length > 0.
  2. Dead objectShape infrastructure. The script's type signature and the if (objectShape) branch at lines 78 and 115 are unreachable today — no entry sets the flag. Either delete it, or leave a one-line comment naming the worked example a future entry would use it for. As-shipped a future reader has to spelunk to understand what it's for.

Minor nits (non-blocking)

  1. Three JSDoc blocks above one constant (scripts/generate-zod-from-ts.ts:49-57, 58-69, 70-77). Only the last binds; the first two are dangling. Collapse into one. Notable — even codegen tolerates two.
  2. Cast helper. If a second TS7056-driven cast lands, as unknown as z.ZodObject<z.ZodRawShape> will get reinvented with a fresh comment. Hoisting a one-liner asZodObject(s) helper near withOptionalAccount keeps the workaround in one place.

Safe to merge.

bokelley added a commit that referenced this pull request May 22, 2026
…al sweep)

Foundation rebased onto main. Picks up:
- Pre-mode entry (#1933) so foundation publishes under @beta
- Codegen TS7056 fix (#1924)
- Wholesale-feed-sync rename (#1932, replaces catalog-sync from earlier branch)
- 3.1.0-beta.3 schema bundle (was beta.2 on the foundation branch)

Resolutions:
- .changeset/pre.json: took main's (initialVersions=8.0.0)
- src/lib/version.ts: regenerated via sync-version --force
- src/lib/types/schemas.generated.ts: regenerated
- ADCP_VERSION: bumped 3.1.0-beta.2 → 3.1.0-beta.3

Demoted foundation changeset major → minor so the foundation merge
publishes as 8.1.0-beta.0 (stays on 8.x line). The 9.0 major bump can
come when v1 deprecation calendar tightens, not from this cut.

Beta.3 spec changes folded in (partial):
- RETENTION_EXPIRED removed from ErrorCodeValues; STALE_RESPONSE added.
  Updated DEFAULT_CODE_POLICY accordingly.
- Envelope `status` REQUIRED on all responses — added 'failed' to two
  synthetic-error envelopes in response-unwrapper.ts.
- ControllerError / SeedSuccess / wrapped store returns updated to
  carry envelope `status` (introduced wrapStoreSuccess helper in
  src/lib/server/test-controller.ts).
- Type guards in src/lib/testing/test-controller.ts widened to handle
  the new union shape with envelope intersection.

KNOWN ISSUE: ~45 more compile errors remain across decisioning/
adapter/middleware code from the envelope-status-required change. Each
is mechanical (add `status: 'completed'` to a success-shape return) but
the sweep is wider than this single merge commit. Pushed for visibility;
follow-up PRs will sweep the remainder.
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