fix(web): keep formatTokens monotonic across the k/M boundaries - #617
Open
aniruddhaadak80 wants to merge 1 commit into
Open
fix(web): keep formatTokens monotonic across the k/M boundaries#617aniruddhaadak80 wants to merge 1 commit into
aniruddhaadak80 wants to merge 1 commit into
Conversation
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
Fixes a rounding-boundary inconsistency in the dashboard token formatter:
formatTokens(999.5)returned the bare string"1000"whileformatTokens(1000)returned"1.0k", so a sub-thousand count displayed identically to a rounded-up thousand and broke monotonicity (999 -> "999",999.5 -> "1000",1000 -> "1.0k"). Same class of defect existed at the k/M edge (999999 -> "1000.0k"vs1000000 -> "1.0M").web/static/js/format.mjs:42-53— round once withMath.round, branch on the rounded value, and promote>= 999950toMso neither boundary can render"1000"/"1000.0k".tests/web/format.test.ts:56-68— regression tests pinning999.5 -> "1.0k",999.4/999 -> "999",999999 -> "1.0M",999949 -> "999.9k".Reproduced before the fix with
node --import=tsximportingweb/static/js/format.mjs:formatTokens(999.5) === "1000",formatTokens(999.6) === "1000". After the fix:1.0k,999,999,1.0k,1.0M,999.9k,1.2k,2.5Mfor the probe sequence.Related issue
No open issue exists (the repo currently has zero open issues). This is a proactive, no-behavior-change-except-the-bug fix discovered by scanning the dashboard formatting helpers (
web/static/js/format.mjs) and its coverage (tests/web/format.test.ts).Type of change
Checklist
npm run lintpasses (no new warnings;format.mjsclean)npm run typecheckpasses (unaffected; dashboard JS is not intsconfig.check.json)npm run buildpasses (unaffected)npm testpasses for the touched area (tests/web/format.test.ts: 8 passed)