fix: round durations and sizes before picking the unit

Merged
WA
8d ago
+130-14

What and why

  • formatDuration in markdown-text.ts picked the unit before rounding, so 999.6ms showed as 1000ms and 59.96s as 60.0s in the markdown report (and the GitHub PR comment built from it), trace pages, and failure details.
  • It now rounds first, as #1829 did for the HTML report. Anything that rounds to a minute or more still goes through formatMinutes, which already rounds first, so 119.6s stays 2m 0s.
  • I checked the other unit formatters in the repo. Four more had the same bug and are fixed here too: formatMs (--debug timings), formatBytes (e2e cache stats), formatSize (the HTML reporter's embedded page note), and duration in scripts/bench-ab/markdown.ts. The two size helpers moved into their own small modules so their tests use the production code.
  • Apart from formatTime in report/format.ts, none are left. It prints 1000ms for 999.6ms, but it copies vitest's format, which prints 1000ms for exactly 1000 too, so I left it.

Issue

Fixes #2090

Verified

Ran it locally: yes

formatterinputmainthis branch
formatDuration999.6ms1000ms1.0s
formatDuration59_949ms (unchanged)59.9s59.9s
formatDuration59_960ms60.0s1m 0s
formatDuration119_600ms (unchanged)2m 0s2m 0s
formatMs9_999.6ms10000ms10.0s
formatBytes1_048_575 B1024.0 KiB1.0 MiB
formatSize1_047_553 B1024 KB1.0 MB
bench-ab duration999.6ms1000 ms1.00 s
  • Each fix has a test that fails on main and passes here.
  • The repro from #2090, run against this branch's build, prints 1.0s and 1m 0s.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.