Files
hermes-agent/apps/shared/src/format.test.ts
teknium1 c3edad29ba docs(shared): declare M as compactNumber's top rung
The 1e9 → '1000M' test row read as a snapshot of a missing rung; the
formatter comment now states the cap (token/cost figures stay well under a
billion; a B suffix would collide with the bytes reading) and the row cites it.
2026-09-13 06:50:57 -07:00

29 lines
823 B
TypeScript

import { describe, expect, it } from 'vitest'
import { compactNumber } from './format'
describe('compactNumber', () => {
it.each([
[0, '0'],
[999, '999'],
[1000, '1k'],
[1500, '1.5k'],
[128_000, '128k'],
// Promotion guard: a value that would round to "1000k" promotes to M.
[999_949, '999.9k'],
[999_999, '1M'],
[1_000_000, '1M'],
[1_500_000, '1.5M'],
// `M` is the declared top rung (see format.ts): no `B`, so billions stay in M.
[1_000_000_000, '1000M']
])('%d → %s', (value, expected) => {
expect(compactNumber(value)).toBe(expected)
})
it('never emits a unit-boundary artifact like "1000k" or "1000"', () => {
for (const value of [999.5, 999.9, 999_950, 999_999.4]) {
expect(compactNumber(value)).not.toMatch(/^1000(\.\d)?k?$/)
}
})
})