refactor: units - #513
Merged
Merged
Conversation
…rter with standardized units
…s in pool status updates
Binary Size Analysis✅ Size Decreased or Stable
|
❌ Test Failures on
|
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.
Greptile Summary
This PR completes a units refactor across the whole codebase: the custom
ConvertBytesToHumanReadable(base-1000) and the scatteredKB/MB/GBconstants intypesandconfigpackages are replaced with a single canonicalutils.KiB/MiB/GiBset andFormatBytes/FormatSpeedhelpers that usego-humanize's IEC standard. All speed values are now stored as raw bytes/s throughout, and display formatting is pushed entirely to the presentation layer.internal/utils/units.gois added as the single source of truth for size constants and byte/speed formatting;size_converter.gois deleted.internal/engine/types/config.goandinternal/config/settings.godrop their localKB/MB/GBconstants, importingutilsinstead.local_service.go,pool.go, andmodel.goare corrected to store and pass speeds in raw bytes/s, removing a unit-mismatch bug where completed-download speeds were displayed as ~1 million× too slow.Confidence Score: 5/5
Safe to merge — all unit-mismatch bugs from the previous review round are corrected, the migration is consistent across all 47 changed files, and no regressions were found in the core download logic.
The refactor is mechanical and thorough: every former reference to types.KB/types.MB/config.MB has been replaced, speed storage is uniformly bytes/s, and the display layer now uses the single FormatBytes/FormatSpeed helpers. Previously broken files (switch_429_test.go conflict markers, completedSpeedMBps unit mismatch, model.go double-multiply) are all addressed.
No files require special attention. The two minor style nits are in cmd/cli_test.go and internal/utils/units.go.
Important Files Changed
Comments Outside Diff (3)
internal/tui/update_events.go, line 170-189 (link)events.go:speedis computed in bytes/s (float64(d.Total) / elapsed.Seconds()), so dividing byutils.MiBproduces MiB/s, but the format string reads "MB/s". This TUI log entry for download completion was missed during the unit label sweep.Prompt To Fix With AI
internal/download/pool.go, line 741 (link)status.Speedis now stored as raw bytes/s, not MB/s.Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
internal/core/local_service.go, line 22-33 (link)completedSpeedMBpsreturns MiB/s but callers now expect bytes/sAfter this refactor, every other path that writes
status.Speedstores raw bytes/s (e.g.,pool.goline 248 andlocal_service.goline 453). HowevercompletedSpeedMBpsstill dividesentry.AvgSpeed(bytes/s) byutils.MiB, returning MiB/s. BothList()(line 499) andGetStatus(line 751) assign its return value directly tostatus.Speed. Any downstream formatter that callsutils.FormatSpeed(d.Speed)or the TUI model path (dm.Speed = s.Speed) will treat the MiB/s value as bytes/s, displaying completed-download speeds as ~1 million times too slow (e.g., 10 MiB/s completed download shows as "10 B/s").Prompt To Fix With AI
Reviews (6): Last reviewed commit: "fix: check write return values in 429 te..." | Re-trigger Greptile