Skip to content

fix(ack-pay): valibot decimals validator rejects negative values instead of clamping - #155

Open
ygd58 wants to merge 2 commits into
agentcommercekit:mainfrom
ygd58:fix/decimals-clamp-not-validate
Open

fix(ack-pay): valibot decimals validator rejects negative values instead of clamping#155
ygd58 wants to merge 2 commits into
agentcommercekit:mainfrom
ygd58:fix/decimals-clamp-not-validate

Conversation

@ygd58

@ygd58 ygd58 commented Aug 13, 2026

Copy link
Copy Markdown

Fixes #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.

Fix: 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.

Tests: added a regression test asserting both schemas reject a negative decimals value 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 old toMinValue code and passes with the fix), oxlint and oxfmt --check clean.


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 (toMinValueminValue) that changes valibot's decimals validation from a silent clamp to a rejection, matching zod's existing behavior.

Summary by CodeRabbit

  • Bug Fixes

    • Payment option decimal values now consistently reject negative numbers.
    • Zero and positive decimal values continue to be accepted across supported validation formats.
  • Tests

    • Added coverage to verify consistent decimal validation behavior.

…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.
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: f6a81bb5-aacf-463a-9a72-850e73687a48

📥 Commits

Reviewing files that changed from the base of the PR and between f542358 and e0e0521.

📒 Files selected for processing (1)
  • packages/ack-pay/src/schemas/decimals.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/ack-pay/src/schemas/decimals.test.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

Valibot now rejects negative paymentOptionSchema.decimals values instead of clamping them to zero. Tests cover both Valibot and Zod schemas. A patch changeset documents the fix.

Changes

Payment option decimal validation

Layer / File(s) Summary
Reject invalid decimal values
packages/ack-pay/src/schemas/valibot.ts, packages/ack-pay/src/schemas/decimals.test.ts, .changeset/decimals-clamp-fix.md
Valibot uses v.minValue(0) for decimals. Tests verify negative values are rejected and zero or positive values are accepted. The changeset records the patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to e0e05

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: the Valibot decimals validator now rejects negative values instead of clamping them.
Linked Issues check ✅ Passed The changes satisfy issue #147. The Valibot schema now uses v.minValue(0), aligning with the Zod schema and rejecting negative decimal values. Regression tests cover negative, zero, and positive val…
Out of Scope Changes check ✅ Passed The schema fix, regression tests, patch changeset, and formatting correction directly support issue #147 and the stated pull request objectives. No unrelated code changes are identified.
Full details: Linked Issues check

Explanation

The changes satisfy issue #147. The Valibot schema now uses v.minValue(0), aligning with the Zod schema and rejecting negative decimal values. Regression tests cover negative, zero, and positive values.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch fix/decimals-clamp-not-validate
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@venables venables left a comment

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.

Overall looks good but looks to be failing the linter

Addresses review feedback from @venables (CI check:format failure).
@ygd58

ygd58 commented Sep 2, 2026

Copy link
Copy Markdown
Author

Thanks for catching that - fixed. It was an import-order issue in the test file (oxfmt wants valibot before vitest), pushed the corrected formatting. pnpm run check:format passes locally now.

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.

bug: paymentOptionSchema.decimals uses toMinValue (clamps) instead of minValue (validates)

2 participants