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 1 commit 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: Pro Plus Run ID: 📒 Files selected for processing (3)
WalkthroughValibot now rejects negative ChangesPayment option decimal validation
Mergeability Score: ⚪ Minimal · up to This localized validation fix rejects malformed negative decimal values consistently and includes regression tests; no actionable merge-blocking risk remains after normal checks and review. Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
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