Skip to content

fix(adapters): clamp reputation rates with coerceFraction (#91) - #118

Open
rudra496 wants to merge 1 commit into
MergeFi:mainfrom
rudra496:fix/reputation-clamping-91
Open

fix(adapters): clamp reputation rates with coerceFraction (#91)#118
rudra496 wants to merge 1 commit into
MergeFi:mainfrom
rudra496:fix/reputation-clamping-91

Conversation

@rudra496

Copy link
Copy Markdown

Summary

Closes #91

This PR replaces the inline unclamped division (coerceDecimal(...) / 100) for completionRate and onTimeDeliveryRate in adaptReputation with coerceFraction, and extends coerceFraction to support an optional divisor parameter (defaulting to 1) and clamped fallback values.

Changes

  1. src/lib/utils.ts:
    • Extended coerceFraction(value, fallback = 0, divisor = 1) to accept an optional divisor parameter, ensuring raw percentage values (e.g. "94", "150", "-20") are safely divided by 100 and strictly bounded to [0, 1].
    • Added JSDoc documentation detailing range guarantees and parameter conventions.
  2. src/lib/adapters.ts:
    • Routed completionRate and onTimeDeliveryRate in adaptReputation through coerceFraction(snapshot.completionRate, 0, 100) and coerceFraction(snapshot.onTimeDeliveryPercentage, 0, 100).
    • Audited all adjacent adapter functions (adaptBounty, adaptMilestone, adaptMaintenancePool): confirmed that adaptBounty uses coercePercentage (clamped [0, 100]) and coerceNonNegative, and adaptMilestone/adaptMaintenancePool use coerceNonNegative. No other unclamped fractions/percentages exist.
  3. Tests:
    • Added unit tests in src/lib/utils.test.ts for coerceFraction divisor support, upper/lower clamping, and non-numeric fallbacks.
    • Added unit tests in src/lib/adapters.test.ts verifying out-of-bounds inputs ("150" -> 1.0, "-20" -> 0.0), in-range inputs ("94" -> 0.94, "0" -> 0.0, "100" -> 1.0), corrupted strings (-> 0.0), and null snapshot behavior.

Verification

  • npm test: 3/3 test suites passed (47/47 tests).
  • npx tsc --noEmit: 0 type errors.
  • npm run build: Turbopack production build succeeded cleanly.

Copilot AI lite review requested due to automatic review settings August 19, 2026 16:17
@vercel

vercel Bot commented Aug 19, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@rudra496
rudra496 force-pushed the fix/reputation-clamping-91 branch from 87883c1 to 17349e5 Compare August 26, 2026 10:52
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

2 participants