Skip to content

fix: clamp adaptReputation fractions to [0,1] using coerceFraction - #134

Open
rafaio1 wants to merge 1 commit into
MergeFi:mainfrom
rafaio1:fix/issue-91-clamp-reputation-fractions
Open

rafaio1 wants to merge 1 commit into
MergeFi:mainfrom
rafaio1:fix/issue-91-clamp-reputation-fractions

Conversation

@rafaio1

@rafaio1 rafaio1 commented Aug 20, 2026

Copy link
Copy Markdown

Fixes #91.

adaptReputation was computing completionRate and onTimeDeliveryRate by dividing a coerced decimal by 100 without any upper/lower bound clamping. If the backend sent a corrupted value like '150', it would flow through as 1.5 and render as '150%' on the public reputation page.

Replaced the inline division with a call to the previously unused coerceFraction helper (wrapping the division result) to guarantee the output is strictly bounded between 0 and 1.

Added regression tests in src/lib/adapters.test.ts covering:

  • Out-of-range values (>100%) clamping to exactly 1
  • Negative values clamping to exactly 0
  • Normal in-range values preserving without regression
  • Null snapshot fallback to 0

Fixes MergeFi#91.

adaptReputation was computing completionRate and onTimeDeliveryRate by
dividing a coerced decimal by 100 without any upper/lower bound clamping.
If the backend sent a corrupted value like '150', it would flow through
as 1.5 and render as '150%' on the public reputation page.

Replaced the inline division with a call to the previously unused
coerceFraction helper (wrapping the division result) to guarantee the
output is strictly bounded between 0 and 1.

Added regression tests in src/lib/adapters.test.ts covering:
- Out-of-range values (>100%) clamping to exactly 1
- Negative values clamping to exactly 0
- Normal in-range values preserving without regression
- Null snapshot fallback to 0
@vercel

vercel Bot commented Aug 20, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

adaptReputation computes completionRate/onTimeDeliveryRate without clamping, despite an unused coerceFraction helper built for exactly this

1 participant