fix(ack-pay): valibot decimals validator rejects negative values instead of clamping - #155
fix(ack-pay): valibot decimals validator rejects negative values instead of clamping#155ygd58 wants to merge 2 commits into
Conversation
…ead of clamping Fixes agentcommercekit#147 The valibot version of paymentOptionSchema used v.toMinValue(0) on the decimals field - a transform that silently clamps a negative number up to 0, rather than a validator that rejects it. This diverged from the zod version of the same schema (z.number().int().nonnegative()), which correctly rejects negative values. Switched to v.minValue(0), valibot's validating counterpart, so a payment option with a malformed negative decimals value is rejected by both schema implementations instead of being silently "fixed" by the valibot one. Added a regression test asserting both schemas reject a negative decimals value and agree on valid (zero/positive) values. Changeset added (patch, @agentcommercekit/ack-pay). AI usage disclosure: this fix was developed with Claude (Anthropic) assistance - identifying the divergence between the valibot and zod schemas, writing the fix, writing the test, and verifying locally. I reviewed and understand the change: it's a one-word swap (toMinValue -> minValue) that changes valibot's decimals validation from a silent clamp to a rejection, matching zod's existing behavior.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. WalkthroughValibot now rejects negative ChangesPayment option decimal validation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Negative payment-option decimals are now rejected instead of silently clamped, matching the existing schema behavior, with regression coverage for negative, zero, and positive values; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Linked Issues checkExplanation The changes satisfy issue
✨ Finishing Touches 💡 1⚔️ Resolve merge conflicts 💡
🧪 Generate unit tests (beta)
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 |
venables
left a comment
There was a problem hiding this comment.
Overall looks good but looks to be failing the linter
Addresses review feedback from @venables (CI check:format failure).
|
Thanks for catching that - fixed. It was an import-order issue in the test file ( |
Fixes #147
The valibot version of
paymentOptionSchemausedv.toMinValue(0)on thedecimalsfield — a transform that silently clamps a negative number up to0, rather than a validator that rejects it. This diverged from the zod version of the same schema (z.number().int().nonnegative()), which correctly rejects negative values.Fix: switched to
v.minValue(0), valibot's validating counterpart, so a payment option with a malformed negativedecimalsvalue is rejected by both schema implementations instead of being silently "fixed" by the valibot one.Tests: added a regression test asserting both schemas reject a negative
decimalsvalue and agree on valid (zero/positive) values.Changeset: added (
@agentcommercekit/ack-pay, patch).Verified locally:
vitest run src/schemas/decimals.test.ts(3/3 passing — confirmed it fails against the oldtoMinValuecode and passes with the fix),oxlintandoxfmt --checkclean.AI usage disclosure (per AI_POLICY.md): this fix was developed with Claude (Anthropic) assistance — identifying the divergence between the valibot and zod schemas, writing the fix, writing the test, and verifying locally. I reviewed and understand the change: it's a one-word swap (
toMinValue→minValue) that changes valibot'sdecimalsvalidation from a silent clamp to a rejection, matching zod's existing behavior.Summary by CodeRabbit
Bug Fixes
Tests