fix(v2): inconsistent threshold in formatModelSize and missing unit test coverage for format utilities

Open
#148 0 comments 0 reactions 0 assignees View on GitHub

@RahulHarihar is already working on this.

Since Sep 18, 2026.

  • #149 by @RahulHarihar — open

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

bug good first issue priority:P3

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

  1. Align the threshold in formatModelSize to mb >= 1024.
  2. 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from karansinghgit/speaktype

All issues in karansinghgit/speaktype

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.