Skip to content

refactor(mobile): parse raw HTTP and infer review contracts - #5460

Merged
iscekic merged 8 commits into
mainfrom
audit-w7b-data-contracts-dffd
Aug 26, 2026
Merged

refactor(mobile): parse raw HTTP and infer review contracts#5460
iscekic merged 8 commits into
mainfrom
audit-w7b-data-contracts-dffd

Conversation

@iscekic

@iscekic iscekic commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • An invalid pull-request review link now shows an invalid-link message instead of opening a broken review screen. The screen first checks that the owner name, the repository name, and the pull request number are all valid.

Reviewer Notes

The scope-plus-platform reviewer contract is now a discriminated union. Its personal variant allows only GitHub and GitLab, so a personal Bitbucket route cannot exist, and toPersonalPlatform throws on Bitbucket instead of rewriting it to GitHub. The review-config types ReviewConfigData and ConfigPatch now derive from the tRPC router outputs instead of hand-copied shapes.

Files
  • apps/mobile/src/lib/code-reviewer-config.ts — adds the ReviewerScopePlatform union, parseReviewerPlatform (returns the union or null), and toPersonalPlatform (throws on Bitbucket); derives ReviewConfigData and ConfigPatch from the getReviewConfig router outputs.
  • apps/mobile/src/lib/hooks/use-reviewer-route-params.ts — returns ReviewerScopePlatform | null through parseReviewerPlatform.
  • apps/mobile/src/lib/hooks/use-code-reviewer.ts — guards toPersonalPlatform behind isPersonal so the disabled org query never throws, re-exports it, and consumes the inferred config types.

Four raw HTTP responses are now Zod-parsed instead of cast. Each endpoint gets an exported schema, so an invalid JSON shape throws a parse error rather than silently casting to the expected type. A malformed server reply now surfaces as an error instead of being swallowed.

Files
  • apps/mobile/src/lib/auth/admission.ts — adds AdmissionChallengeResponseSchema and parses the admission-challenge reply.
  • apps/mobile/src/components/agents/mobile-session-manager.ts — adds StreamTicketResponseSchema and parses the stream-ticket reply; keeps the required-field checks for ticket and expiresAt after parse.
  • apps/mobile/src/lib/hooks/use-available-models.ts — adds OpenRouterModelsResponseSchema and OrganizationDefaultsResponseSchema; parses the models-list and org-defaults replies.

The pull-request review route now validates its path segments. Owner, repository, and number are strictly parsed, and a missing or malformed value renders the invalid-route state instead of forwarding a broken value into the screen.

Files
  • apps/mobile/src/app/(app)/pr-review/[owner]/[repo]/[number]/index.tsx — parses owner and repository via parseParam and the number as a positive integer; renders InvalidRouteState on a bad value.

The copied merge and review data shapes now derive from the tRPC router. PrOverviewDto, the merge result, the merge and review-comment inputs, and the check-run type use inferRouterOutputs or inferRouterInputs, so hand-copied shapes cannot drift from the server procedures. The repo-settings type drops the unused viewerLogin field.

Files
  • apps/mobile/src/lib/pr-review/merge/merge-blocked-reasons.ts — derives PrOverviewDto and PrOverviewRepoSettings from getPullRequest; drops the copied DTO and the viewerLogin field.
  • apps/mobile/src/lib/pr-review/merge/merge-result-gate.ts — bases MergePullRequestResult on the inferred mergePullRequest output and re-adds the branchDeleteError variant.
  • apps/mobile/src/lib/pr-review/merge/use-pr-merge-mutations.ts — infers MergePullRequestInput from the mergePullRequest procedure.
  • apps/mobile/src/lib/pr-review/use-pr-review-mutations.ts — infers the comment and submit inputs from the githubPrReview procedures.
  • apps/mobile/src/components/pr-review/merge/pr-merge-sheet.tsx — infers the merge and auto-merge inputs from the router.
  • apps/mobile/src/components/pr-review/pr-review-checks-section.tsx — derives CheckRun from listChecks.
  • apps/mobile/src/lib/hooks/use-code-reviews.ts — infers CreateManualReviewInput from createManualReviewJob.

Tests: 4 files updated — code-reviewer-config.test.ts, admission.test.ts, use-available-models.test.ts, mobile-session-manager.test.ts.
Generated: none.


Verification

  • No manual test paths recorded. The change is a mobile refactor plus parse hardening covered by four updated unit-test files; no E2E report was attached to this handoff.

Human steps: none. The merged code needs no new environment values, secrets, migrations, or flag flips.

Visual Changes

Visual Changes: N/A


Stacked PRs — merge bottom to top. Each level shows only its own diff.

Full verification (E2E, user advocacy, simplify, bot review) runs on the tip PR over every level.
A finding on a level is repaired on that level, then carried upward with stack.sh forward.

  1. audit-w7b-data-contracts-dffdrefactor(mobile): parse raw HTTP and infer review contracts #5460 ← this PR
  2. audit-w7b-data-contracts-dffd-s2feat(web): add org credit and invoice page procedures #5462
  3. audit-w7b-data-contracts-dffd-s3feat(mobile): owner-keyed credits, ledger paging, list freshness #5468
  4. audit-w7b-data-contracts-dffd-s4refactor: route-scoped registry and live custom mode #5472
  5. audit-w7b-data-contracts-dffd-s5feat(mobile): provider-aware new-session and layout extract #5479 (tip)

@iscekic iscekic self-assigned this Aug 25, 2026
@kilo-code-bot

kilo-code-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Incremental review of the strict PR-number validation fix; the previous parseInt prefix issue is resolved and no new changed-code issues were found.

Files Reviewed (4 files)
  • apps/mobile/src/app/(app)/pr-review/[owner]/[repo]/[number]/_layout.tsx
  • apps/mobile/src/app/(app)/pr-review/[owner]/[repo]/[number]/index.tsx
  • apps/mobile/src/lib/route-params.test.ts
  • apps/mobile/src/lib/route-params.ts
Previous Review Summaries (2 snapshots, latest commit 12df0a0)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 12df0a0)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (8 files)
  • apps/mobile/src/components/pr-review/pr-review-checks-section.tsx
  • apps/mobile/src/lib/code-reviewer-config.ts
  • apps/mobile/src/lib/hooks/use-available-models.ts
  • apps/mobile/src/lib/hooks/use-code-reviewer.ts
  • apps/mobile/src/lib/hooks/use-code-reviews.ts
  • apps/mobile/src/lib/pr-review/merge/merge-blocked-reasons.ts
  • apps/mobile/src/lib/pr-review/merge/use-pr-merge-mutations.ts
  • apps/mobile/src/lib/pr-review/use-pr-review-mutations.ts

Previous review (commit bb0c285)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (18 files)
  • apps/mobile/src/app/(app)/pr-review/[owner]/[repo]/[number]/index.tsx
  • apps/mobile/src/components/agents/mobile-session-manager.ts
  • apps/mobile/src/components/agents/mobile-session-manager.test.ts
  • apps/mobile/src/components/pr-review/merge/pr-merge-sheet.tsx
  • apps/mobile/src/components/pr-review/pr-review-checks-section.tsx
  • apps/mobile/src/lib/auth/admission.ts
  • apps/mobile/src/lib/auth/admission.test.ts
  • apps/mobile/src/lib/code-reviewer-config.ts
  • apps/mobile/src/lib/code-reviewer-config.test.ts
  • apps/mobile/src/lib/hooks/use-available-models.ts
  • apps/mobile/src/lib/hooks/use-available-models.test.ts
  • apps/mobile/src/lib/hooks/use-code-reviewer.ts
  • apps/mobile/src/lib/hooks/use-code-reviews.ts
  • apps/mobile/src/lib/hooks/use-reviewer-route-params.ts
  • apps/mobile/src/lib/pr-review/merge/merge-blocked-reasons.ts
  • apps/mobile/src/lib/pr-review/merge/merge-result-gate.ts
  • apps/mobile/src/lib/pr-review/merge/use-pr-merge-mutations.ts
  • apps/mobile/src/lib/pr-review/use-pr-review-mutations.ts

Reviewed by grok-4.6 · Input: 53.9K · Output: 7.5K · Cached: 331.6K

Review guidance: REVIEW.md from base branch main

@iscekic
iscekic marked this pull request as ready for review August 26, 2026 13:32
@iscekic
iscekic requested a review from RSO August 26, 2026 15:18
const parsedOwner = parseParam(owner);
const parsedRepo = parseParam(repo);
const rawNumber = parseParam(number);
const numberValue = rawNumber ? Number.parseInt(rawNumber, 10) : Number.NaN;

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.

bot: The PR number is not strictly validated: Number.parseInt accepts numeric prefixes, so /pr-review/acme/repo/12abc or /1.5 passes Number.isInteger and opens PR 12 or 1 rather than the invalid-route state.

Suggested fix: Validate the full segment before converting it, for example require /^[1-9]\d*$/ and then use Number(rawNumber) with Number.isSafeInteger(numberValue). Add route tests covering 12abc, 1.5, and oversized values.

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.

Better yet, use zod?

Number.parseInt stops at the first non-digit, so /pr-review/acme/repo/12abc
and /1.5 opened PR 12 and PR 1 instead of the invalid-route state. Require
the whole segment to be digits and stay exactly representable.
@iscekic iscekic closed this Aug 26, 2026
@iscekic iscekic reopened this Aug 26, 2026
@iscekic iscekic closed this Aug 26, 2026
@iscekic iscekic reopened this Aug 26, 2026
@iscekic
iscekic merged commit 6041559 into main Aug 26, 2026
29 of 30 checks passed
@iscekic
iscekic deleted the audit-w7b-data-contracts-dffd branch August 26, 2026 16:49
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.

3 participants