Repository navigation
fix: promote a size that rounds up to a full unit in two more formatters - #556
Conversation
`rocm_core::format_bytes` printed sizes just below a unit boundary as
"1024.0 KiB": it promoted on the raw value (`>= 1024`) but printed with
`{:.1}`, which rounds 1023.95 and up to 1024.0. Two other formatters
carry the same shape:
- `format_bytes_for_user` in the `rocm` binary, behind the
`download: approved up to …` line: 1_048_525..=1_048_575 bytes
printed "1024.0 KB" and 1_073_689_396..=1_073_741_823 printed
"1024.0 MB".
- `mib` and `mib_pair` in the dashboard, for VRAM: 1_048_525..=1_048_575
MiB printed "1024.0 GiB".
Both now promote while the value as printed would reach 1024, comparing
the rounded tenths exactly as the rocm-core fix does. `mib` and
`mib_pair` share one helper, so the pair's unit can no longer drift from
the single value's. Unit labels and the "bytes" wording are unchanged.
Each fix carries pinned boundary examples and a two-edge property test
(never a unit the size has outgrown; never one it has not reached), with
proptest added as a dev-dependency of both crates at the version and
features rocm-core already uses.
Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com>
jussielo-amd
left a comment
There was a problem hiding this comment.
Nice, tightly-scoped fix — matches the #503 pattern exactly where it needs to. The promoted_mib_unit extraction for mib/mib_pair is a good call: it structurally prevents the pair from picking a different unit than the single value would.
Checked the boundary math by hand and ran both test suites locally (rocm-dash-tui's ui::format and rocm's format_bytes_for_user tests) — all pass, including the new proptest properties and their saved regression seeds. Updating the automations render test to hit the boundary through the real renderer instead of just the helper function is a nice touch.
One non-blocking FYI: apps/rocm/src/main.rs::format_bytes (behind rocm storage) already had this same defect fixed, but with a different style (a hardcoded 1023.95 cutoff vs. the rounded-tenths loop used here) — pre-existing, out of scope for this PR, just worth a note for whoever's next in that neighborhood.
…ers (#556) `rocm_core::format_bytes` printed sizes just below a unit boundary as "1024.0 KiB": it promoted on the raw value (`>= 1024`) but printed with `{:.1}`, which rounds 1023.95 and up to 1024.0. Two other formatters carry the same shape: - `format_bytes_for_user` in the `rocm` binary, behind the `download: approved up to …` line: 1_048_525..=1_048_575 bytes printed "1024.0 KB" and 1_073_689_396..=1_073_741_823 printed "1024.0 MB". - `mib` and `mib_pair` in the dashboard, for VRAM: 1_048_525..=1_048_575 MiB printed "1024.0 GiB". Both now promote while the value as printed would reach 1024, comparing the rounded tenths exactly as the rocm-core fix does. `mib` and `mib_pair` share one helper, so the pair's unit can no longer drift from the single value's. Unit labels and the "bytes" wording are unchanged. Each fix carries pinned boundary examples and a two-edge property test (never a unit the size has outgrown; never one it has not reached), with proptest added as a dev-dependency of both crates at the version and features rocm-core already uses. Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com> Signed-off-by: Juho Vainio <juho.vainio@amd.com>
Summary
Follow-up to #503, which fixed
rocm_core::format_bytesprinting a size just below a unit boundary as "1024.0 KiB". Review there found the same defect in two more formatters, and this fixes both the same way.format_bytes_for_user(rocmbinary) formats the size in thedownload: approved up to …line of the automations view. Sizes of 1,048,525–1,048,575 bytes printed as "1024.0 KB", and 1,073,689,396–1,073,741,823 as "1024.0 MB". They now print "1.0 MB" and "1.0 GB".mib/mib_pair(dashboard VRAM): 1,048,525–1,048,575 MiB, just under 1 TiB, printed as "1024.0 GiB" and now prints "1.0 TiB". The two now share one unit-picking helper, so the pair can't pick a different unit from the single value.Unit labels and the "bytes" wording are unchanged; the KB/MB versus KiB/MiB naming is a separate question.
Why
Each formatter promoted on the raw value (
>= 1024) but printed with{:.1}, which rounds 1023.95 and above up to 1024.0, so the loop stopped one unit early. As in #503, they now promote while the value as printed would reach 1024:(value * 10.0).round() >= 10_240.0.Test plan
format_bytes_renders_a_size_in_its_own_unit, pointed atformat_bytes_for_user, atmib, and atmib_pair's total.rocmandrocm-dash-tui, with the version and featuresrocm-corealready uses. No new crate enters the lockfile, and nothing ships.download: approved up to 1.0 MBline is checked at the boundary through the real renderer.>= 1024.0comparison fails both the examples and the properties, at 1,048,525.download: approved up toline is only reached through the assistant's in-process, read-onlyautomationscommand, and no current scenario seeds automation proposals. Coverage is the render-level test above.cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test -p rocm --bin rocm,cargo test -p rocm-dash-tui --lib(ui::format),cargo test -p xtask,cargo xtask manifest --check.Independent of #503's code; it can land in either order.