refactor: one zod schema per JSON shape, parse at the call site - #56
Merged
Conversation
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>
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>
Also oxfmt the two files that failed fmt:check. Co-authored-by: Cursor <cursoragent@cursor.com>
| .optional(), | ||
| data: z.object({ | ||
| repository: z.object({ | ||
| pullRequest: z.object({ |
There was a problem hiding this comment.
🟠 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Config,Scope,Pr, sweep status, App token/installation, agent hook settings). Types arez.inferwhere the schema is the source of truth.parseJson/readJsonFileare gone. Call sites useSchema.parse(JSON.parse(...)).gh --json/ App / exe payloads throw.safeParseis only forparseReview(null = don't post). State files and the App token cache still treat missing/corrupt as a fresh start.Comment,ParsedFinding,ReviewVerdict) stay as TypeScript. Same forReviewOutcome,SweepReviewResult,PriorState,DiffRead.Test plan
bun run typecheckbun run lintbun test(44)