fix(MatchScore): clamp score to avoid invalid array length runtime error - #1171
Merged
Merged
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
kheinrich-eightfold
requested review from
agupta-eightfold and
ychhabra-eightfold
September 22, 2026 21:09
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1171 +/- ##
==========================================
+ Coverage 85.44% 85.45% +0.01%
==========================================
Files 1231 1231
Lines 21775 21780 +5
Branches 8293 8295 +2
==========================================
+ Hits 18606 18613 +7
+ Misses 3081 3079 -2
Partials 88 88 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
agupta-eightfold
approved these changes
Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY:
Previously, the
MatchScorecomponent computed its filled/half/empty circle counts directly from an unboundedscoreprop, so ascoreoutside the[0, total]range (observed in production asscore = -1) produced a negative circle count and threwUncaught RangeError: Invalid array lengthonArray(n).This PR clamps
scoreto[0, total]before it's used in any of the circle/label calculations, so out-of-range scores degrade gracefully (rendering0ortotalcircles) instead of crashing:scorevalues to0.scorevalues abovetotaldown tototal.absScore(it rounded, but never took an absolute value) todisplayScorefor clarity.Additional hardening from review feedback:
score/totalare plainnumberprops, so a caller could also passNaNor a fractionaltotal, which would still throw the sameRangeErroreven with the clamp above. Addressed by:scoreto0and a non-finitetotalto the component's own default (extracted asDEFAULT_SCORE/DEFAULT_TOTALconstants so the fallback can't drift from the prop default).totalbefore use, so a fractionaltotal(e.g.5.5) can't produce a fractional circle count.NaNscore,NaNtotal, and fractional total.GITHUB ISSUE (Open Source Contributors)
JIRA TASK (Eightfold Employees Only):
https://eightfoldai.atlassian.net/browse/ENG-215683
CHANGE TYPE:
TEST COVERAGE:
TEST PLAN:
yarn jest— full suite passingscoreis a valid value between 0 andtotal(5 by default)