Repository navigation
fix(web): a 9.996 KB file reads "10.0 KB", not "10.00 KB" - #42682
juliusmarminge merged 3 commits into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…rounding-boundaries
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EvidenceAttached text files of exactly 10,235, 102,350 and 10,480,518 bytes and sent without message text using Replay (dev) / Command output. Captured settled sent-message cards in Chromium, 1280×800, dark theme, with fresh synthetic state on both commits.
Scenario driver · Before recording · After recording The scenario fails on base and passes on head; scenarios:prove exited 0. Not shown:
|


Problem
formatScaledinapps/web/src/lib/formatBytes.tspicked 2, 1, or 0 decimal places from the unrounded value. Values just below 10 or 100 rounded up across the threshold while keeping the extra decimal place: 10,235 B (9.9951 KB) printed"10.00 KB"instead of"10.0 KB", and 102,350 B (99.951 KB) printed"100.0 KB"instead of"100 KB". The same rounding-before-precision bug affects MB, GB, and TB (for example, 10,480,518 B printed"10.00 MB"). This is the same class of bug fixed in #42492, where a 9.96 s workflow step read"10.0s".Users see
formatBytesoutput in chat file cards (UserFileCardinapps/web/src/components/chat/TimelineUserMessageRow.tsx, shown when a message holds only attached files), Settings > Diagnostics and resource telemetry (memory and I/O), Settings > Storage, and the add-project-to-machine dialog. Desktop uses the same web bundle.Change
In
apps/web/src/lib/formatBytes.ts, I updatedformatScaledto round at 2 decimals first. If the rounded value is under 10, it returns that string. Otherwise it rounds at 1 decimal and returns it if under 100, else it rounds to 0 decimals. The unit carry from #26067 (1023.6 KB->"1.00 MB", not"1024 KB") still holds.In
apps/web/src/lib/formatBytes.test.ts, I added five cases to the existingit.eachtable:10_234("9.99 KB"),10_235("10.0 KB"),102_348("99.9 KB"),102_350("100 KB"), and10_480_518("10.0 MB").Scope
Bug fix only, covering the web bundle (and desktop via the shared web bundle). No separate issue was filed because this is a small fix for an obvious bug. Mobile has its own
formatByteshelper covered by another author's open PR #41599, so I left mobile untouched. Composer and inline message chips useformatAttachmentSize("10 KB"/"100 KB"), which does not have this bug and is unchanged.Verification
Setup: Linux (Ubuntu 26.04), web dev build (
vp run dev) in the T3 Code Browser panel at 2560x1600, fresh isolated T3 home with synthetic data only, server labelled "Test machine", and the freeReplay (dev)provider.Steps: Add a throwaway git project → start a new thread → attach
notes-10235.txt(10,235 bytes) andnotes-102350.txt(102,350 bytes) with a short message and send → attach the same two files with no text and send → read the file cards.c6c8b205)a95df3da)Base c6c8b20: file cards for 10,235 B and 102,350 B read "TXT · 10.00 KB" and "TXT · 100.0 KB"
Head a95df3d: file cards for 10,235 B and 102,350 B read "TXT · 10.0 KB" and "TXT · 100 KB"
Tests (Node 26.13.1): On base
c6c8b205with the new test rows,vp test run src/lib/formatBytes.test.tsfails 3 of 16 tests (received"10.00 KB","100.0 KB","10.00 MB"). On heada95df3da, all 16 tests pass across 3 runs, andvp run check:changedpasses (format, lint, knip 1/2, knip 2/2, typecheck across 2 packages, test on 1 file, and react compiler on 1 file).Test and check:changed output
Not checked: macOS and Windows hosts, the desktop app shell, mobile (separate helper), and Settings diagnostics screens (same function, covered by unit tests).
Who tested: An AI agent ran every check.
Generated with Gemini 4 Neon in T3 Code Nightly