fix(v2): inconsistent threshold in formatModelSize and missing unit test coverage for format utilities
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 20/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- frontend
Research direction
The bug is in formatModelSize in desktop/src/lib/format.ts, where the threshold mb >= 1000 should match the 1024 divisor. Tests belong in desktop/src/lib/format.test.ts under Vitest. Work is already underway in linked PR #149, so check that before starting. Done means the threshold is mb >= 1024, boundary tests for 1000, 1023 and 1024 pass, and the other listed helpers have coverage.
Written by the indexing model from the issue text.
Description
In desktop/src/lib/format.ts, formatModelSize uses an inconsistent combination of a decimal (base-10) threshold and a binary (base-2) divisor:
Typescript
export function formatModelSize(mb: number) {
return mb >= 1000 ? `${(mb / 1024).toFixed(1)} GB` : `${mb} MB`;
}
1. Threshold/Divisor Inconsistency
- The threshold checks mb >= 1000 (decimal), but the calculation uses mb / 1024 (binary).
- By comparison, formatBytes in the same file consistently uses powers of 1024 (1024, 1024 ** 2, 1024 ** 3).
- For values between 1000 MB and 1023 MB (e.g., 1000 MB), this causes the value to prematurely switch to the "GB" unit and format as "1.0 GB", despite being under 1024 MB.
2. Missing Test Coverage
formatModelSize currently has no unit tests in desktop/src/lib/format.test.ts.
Several other exported pure formatting utilities in format.ts are also lacking test coverage in Vitest:
- plural
- countWords
- formatDay
- formatCompact
- formatNumber
- formatTime
Expected Behavior
- formatModelSize should use a consistent threshold matching its divisor: mb >= 1024.
- All exported pure formatting helpers should have test coverage in src/lib/format.test.ts, in accordance with the repository's testing guidelines.
Proposed Solution
- Align the threshold in formatModelSize to mb >= 1024.
- Add comprehensive unit tests in src/lib/format.test.ts covering:
- formatModelSize - sub-GB values
- Boundary values such as 1000, 1023, and 1024
- Multi-GB values
- plural
- countWords
- formatDay
- formatCompact
- formatNumber
- formatTime
I would be happy to submit a pull request for this.
- Dominant language
- Swift
- Stars
- 540
- Forks
- 74
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from karansinghgit/speaktype
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
karansinghgit/speaktype#211 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
karansinghgit/speaktype#183 · 1 comment ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
karansinghgit/speaktype#209 ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
karansinghgit/speaktype#208 · 2 comments ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 52/100
karansinghgit/speaktype#207 ·
All issues in karansinghgit/speaktype
Similar issues
-
feat: 앱 정보에 개인정보처리방침과 고객지원 연결Possibly taken @xrpjwk8 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
DeveloperAcademy-POSTECH/2026-C6-A13-Hear-I-am#120 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
swiftlang/swift-java#955 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
michaelnisi/hanstholm#246 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
jaywcjlove/quick-rss#448 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
VictorKildahl/cra#205 · 1 comment ·
Maintainers usually reply within 1 day