diff --git a/src/cli/render/stream-progress.test.ts b/src/cli/render/stream-progress.test.ts index 249ca4e6..c23a5e90 100644 --- a/src/cli/render/stream-progress.test.ts +++ b/src/cli/render/stream-progress.test.ts @@ -59,6 +59,36 @@ describe('streamProgress', () => { expect(result).toContain('42 tokens'); }); + it('uses .toFixed(1) just below the 10k boundary', () => { + const result = stripAnsi( + streamProgress({ label: 'test', spinnerFrame: 0, elapsedMs: 1000, tokenCount: 9999 }), + ); + expect(result).toContain('10.0k tokens'); + }); + + it('uses Math.round at exactly the 10k boundary', () => { + const result = stripAnsi( + streamProgress({ label: 'test', spinnerFrame: 0, elapsedMs: 1000, tokenCount: 10000 }), + ); + expect(result).toContain('10k tokens'); + expect(result).not.toContain('10.0k'); + }); + + it('renders 99999 as "100k tokens" not "100.0k tokens"', () => { + const result = stripAnsi( + streamProgress({ label: 'test', spinnerFrame: 0, elapsedMs: 1000, tokenCount: 99999 }), + ); + expect(result).toContain('100k tokens'); + expect(result).not.toContain('100.0k'); + }); + + it('renders 100000 as "100k tokens"', () => { + const result = stripAnsi( + streamProgress({ label: 'test', spinnerFrame: 0, elapsedMs: 1000, tokenCount: 100000 }), + ); + expect(result).toContain('100k tokens'); + }); + it('renders M suffix for large counts', () => { const result = stripAnsi( streamProgress({ diff --git a/src/cli/render/stream-progress.ts b/src/cli/render/stream-progress.ts index 2d03fce0..9beab5e8 100644 --- a/src/cli/render/stream-progress.ts +++ b/src/cli/render/stream-progress.ts @@ -63,7 +63,7 @@ export interface StreamProgressSpec { /** Format token count with k/M suffixes. */ function formatTokenCount(tokens: number): string { if (tokens < 1000) return `${tokens} tokens`; - if (tokens < 100_000) return `${(tokens / 1000).toFixed(1)}k tokens`; + if (tokens < 10_000) return `${(tokens / 1000).toFixed(1)}k tokens`; if (tokens < 1_000_000) return `${Math.round(tokens / 1000)}k tokens`; return `${(tokens / 1_000_000).toFixed(1)}M tokens`; }