Repository navigation
fix(cli): carry rounded-up seconds and kilobytes into the next unit - #5817
rudycelekli wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
miguel-heygen
left a comment
There was a problem hiding this comment.
Thanks for this, and welcome. The two rollovers reproduce exactly as you describe: on main formatDuration(59_960) prints 60.0s and formatBytes(1_048_575) prints 1024.0 KB, and with your change they print 1m 0.0s and 1.0 MB. I replayed both the old and new functions side by side over a wide sweep of inputs, and the byte path changes only in the 1048528 to 1048575 band, which is precisely the bug.
One small correction to the description rather than to the code. "Output for all other inputs is unchanged" is not quite true for durations: toFixed rounds the binary double while Math.round rounds half up, so exact half tenths shift, for example 350 ms printed 0.3s before and prints 0.4s now. That is the more correct value and it only affects display, so I am happy to take it, but it would be good to say so in the description so the next reader is not surprised.
I checked the callers too. formatBytes and formatDuration are only ever printed, never parsed, and the padStart(9) alignment in the cloud render output still lines up because no output got wider.
Full CI ran at this head and is green, including the Windows lanes and the CLI suites. Good, well scoped fix.
jrusso1020
left a comment
There was a problem hiding this comment.
Approving, adding to Miguel's review rather than repeating it. Reviewed at 2bd49648.
I checked it on a local merge with current main. With your change, format.test.ts passes 26 of 26. With the old format.ts put back, the two new rollover tests fail and nothing else does. So the tests guard the fix. I agree with Miguel's note about half tenths now rounding up (350ms reads 0.4s). That's the more accurate output, and it would be worth a line in the description.
Need: yes, both rollovers reproduce on main. Size: ok. Reuse: n/a. Simpler: already minimal.
— Rames
|
Thanks, @rudycelekli. This one is approved, and it'll go into the merge queue once these are sorted:
Once it's green and signed, we'll queue it at your new head. If you push code changes beyond a rebase, we'll take another look first. — Rames |
|
This is approved, but main requires signed commits. Could you re-sign ( |
|
This PR has had no activity for 14 days, so it is marked stale and will close in 7 days. Push a commit or leave a comment to keep it open. A maintainer can add |
|
Thanks, @rudycelekli. Since main requires signed commits and this branch is still unsigned, we have carried your change over unchanged to #7565, with you credited as co-author, so it can merge. We will close this PR once #7565 lands. — Rames |
|
This change landed on — Rames |
Pull request was closed
…eygen-com#7565) formatDuration rounded seconds after splitting off minutes, so 59.96s printed "60.0s" and 119.97s printed "1m 60.0s". formatBytes compared KB against the MB threshold before rounding, so 1,048,575 bytes printed "1024.0 KB". Round first, then split or compare. Takes over heygen-com#5817 by @rudycelekli, whose commits could not be merged unsigned. Co-authored-by: Rudy Celekli <rudy@gradiahq.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
What
formatDurationandformatBytesinpackages/cli/src/ui/format.tsprint an out-of-range value when rounding reaches the next unit.Why
formatDuration(59_960)prints60.0s, andformatDuration(119_970)prints1m 60.0s. The seconds part is rounded after the minute split, so it can reach 60.formatBytes(1_048_575)prints1024.0 KBinstead of1.0 MB.These feed
hyperframes cloud renderprogress and upload lines,infosize, and Chrome download progress.Related work
No overlapping PR found.
How
Round
formatDurationto tenths of a second before splitting into minutes and seconds. Round the KB value before comparing it with the MB threshold. Output for all other inputs is unchanged.Test plan
mainand pass with the fix (vitest run src/ui/format.test.ts, 26 tests).oxfmt --checkandoxlintclean on the changed files.Not run locally: workspace typecheck, comment citation/ratchet scripts (they failed to start in my minimal install).