Skip to content

refactor: one zod schema per JSON shape, parse at the call site - #56

Merged
Octember merged 3 commits into
mainfrom
refactor/zod-dedup
Aug 24, 2026
Merged

refactor: one zod schema per JSON shape, parse at the call site#56
Octember merged 3 commits into
mainfrom
refactor/zod-dedup

Conversation

@Octember

@Octember Octember commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Shared zod schemas for the things we actually parse (Config, Scope, Pr, sweep status, App token/installation, agent hook settings). Types are z.infer where the schema is the source of truth.
  • parseJson / readJsonFile are gone. Call sites use Schema.parse(JSON.parse(...)).
  • Malformed gh --json / App / exe payloads throw. safeParse is only for parseReview (null = don't post). State files and the App token cache still treat missing/corrupt as a fresh start.
  • Derived shapes (Comment, ParsedFinding, ReviewVerdict) stay as TypeScript. Same for ReviewOutcome, SweepReviewResult, PriorState, DiffRead.

Test plan

  • bun run typecheck
  • bun run lint
  • bun test (44)

Config, scope, Comment, ParsedFinding, ReviewVerdict, and agent hook settings are schemas you infer from. gh pr view reuses Pr.pick instead of a second object.

Co-authored-by: Cursor <cursoragent@cursor.com>

@exe-dev-github-integration exe-dev-github-integration 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.

LGTM ✅

Drop parseJson/readJsonFile. .parse on gh/App/exe payloads; safeParse only for parseReview. Docs no longer mention isPr or skipping bad rows.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Octember Octember changed the title refactor: drop duplicate types in favor of zod refactor: one zod schema per JSON shape, parse at the call site Aug 24, 2026
Also oxfmt the two files that failed fmt:check.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Octember
Octember merged commit f1aab04 into main Aug 24, 2026
1 check passed

@exe-dev-github-integration exe-dev-github-integration 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.

one sweep-crasher hiding in the stricter parse 👇

Comment thread src/sweep/github.ts
.optional(),
data: z.object({
repository: z.object({
pullRequest: z.object({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 src/sweep/github.ts:120 · bug · conf 0.89
This makes the GraphQL review-state shape fully required, so a normal race like the PR disappearing between listPrs and prReviews turns into an uncaught Zod throw. prReviews is typed to return null, and collectCandidates already has the per-PR retry/status path for that case; this bypasses it and can crash the whole sweep.
→ Fix: keep pullRequest/nested nodes nullable or optional at this boundary and use safeParse/return null so the existing skip-and-retry path runs.

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