feat(http): validate API responses at runtime with valibot instead of blind casts#266
feat(http): validate API responses at runtime with valibot instead of blind casts#266Andy00L wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughAdds Valibot schemas for run-related HTTP responses, validates selected successful responses in ChangesRuntime response validation
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant HttpClient
participant Valibot
participant ApiError
HttpClient->>Valibot: Validate successful JSON body
Valibot-->>HttpClient: Parsed output or issues
HttpClient->>ApiError: Return INTERNAL envelope on mismatch
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/lib/response-schemas.test.ts (1)
93-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtend schema tests to the remaining wired schemas.
Only
RUN_RESPONSE_SCHEMA(positive+negative) andTRIGGER_RUN_RESPONSE_SCHEMA(positive-only) are directly tested here.RERUN_RESPONSE_SCHEMA,BATCH_RERUN_RESPONSE_SCHEMA,BATCH_RUN_FRESH_RESPONSE_SCHEMA, andLIST_RUNS_RESPONSE_SCHEMAare all wired intoHttpClientin this PR but have no direct parse test, so a regression in any of those four schemas would only surface indirectly. Mirroring the existingRUN_RESPONSE_SCHEMApattern (valid payload + one missing-required-field case) for each would be low effort and directly serves the issue's stated goal of testing valid/drifted responses for the run-related wire types.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/lib/response-schemas.test.ts` around lines 93 - 104, The response-schema tests currently omit direct coverage for four schemas. Extend the test suite with valid parse cases and missing-required-field negative cases for RERUN_RESPONSE_SCHEMA, BATCH_RERUN_RESPONSE_SCHEMA, BATCH_RUN_FRESH_RESPONSE_SCHEMA, and LIST_RUNS_RESPONSE_SCHEMA, mirroring the existing RUN_RESPONSE_SCHEMA test pattern while retaining the current TRIGGER_RUN_RESPONSE_SCHEMA coverage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/lib/response-schemas.test.ts`:
- Around line 93-104: The response-schema tests currently omit direct coverage
for four schemas. Extend the test suite with valid parse cases and
missing-required-field negative cases for RERUN_RESPONSE_SCHEMA,
BATCH_RERUN_RESPONSE_SCHEMA, BATCH_RUN_FRESH_RESPONSE_SCHEMA, and
LIST_RUNS_RESPONSE_SCHEMA, mirroring the existing RUN_RESPONSE_SCHEMA test
pattern while retaining the current TRIGGER_RUN_RESPONSE_SCHEMA coverage.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 06983a61-e073-4900-aba6-05930bce5a38
📒 Files selected for processing (3)
src/lib/http.tssrc/lib/response-schemas.test.tssrc/lib/response-schemas.ts
Validate API responses on the run paths against valibot schemas at the HTTP client, instead of blind
as Tcasts.src/lib/response-schemas.ts:looseObjectschemas for the run-path payloads (trigger, rerun, batch rerun, batch fresh, get run, list runs); unknown extra keys are preserved so additive server changes stay non-breaking.RequestOptionsgains an optionalschemafield; when present,requestWithMetarunsv.safeParseon the OK-path JSON. Shape drift now surfaces as a typedINTERNALenvelope naming the request path and the first mismatched field paths (never echoing the body), instead ofundefinedoutput or an opaque crash downstream.triggerRun,triggerRunWithMeta,triggerRerun,triggerBatchRerun,triggerBatchRunFresh,getRun,listTestRuns); genericget/post/... callers are unchanged and stay opt-in.valibotdependency already present in the project; no new dependency.Closes #102
Discord: interferon0
Summary by CodeRabbit
New Features
Bug Fixes