Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AppendMessage } from '@assistant-ui/react'
import { describe, expect, it } from 'vitest'
import { describe, expect, it, vi } from 'vitest'

import type { ChatMessage } from '@/lib/chat-messages'

Expand Down Expand Up @@ -207,6 +207,18 @@ describe('renderRpcResult', () => {
)
})

it('pins English usage copy to en-US number formatting', () => {
const localeSpy = vi.spyOn(Number.prototype, 'toLocaleString').mockImplementation(function (this: number) {
return String(this)
})

renderRpcResult({ calls: 12, input: 1_234, output: 56, total: 1_290 }, 'usage')

expect(localeSpy).toHaveBeenCalledTimes(4)
expect(localeSpy.mock.calls).toEqual([['en-US'], ['en-US'], ['en-US'], ['en-US']])
localeSpy.mockRestore()
})

it('appends credits_lines when present', () => {
const body = renderRpcResult(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export function renderRpcResult(response: unknown, name: string): string {
const total = Number(r.total ?? 0)

const lines: string[] = [
`Usage: ${calls.toLocaleString()} calls Β· ${input.toLocaleString()} in / ${output.toLocaleString()} out Β· ${total.toLocaleString()} total`
`Usage: ${calls.toLocaleString('en-US')} calls Β· ${input.toLocaleString('en-US')} in / ${output.toLocaleString('en-US')} out Β· ${total.toLocaleString('en-US')} total`
]

if (Array.isArray(r.credits_lines)) {
Expand Down
27 changes: 27 additions & 0 deletions apps/desktop/src/app/settings/billing/billing-amounts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { afterEach, describe, expect, it, vi } from 'vitest'

import { formatMoney } from './billing-amounts'

afterEach(() => {
vi.restoreAllMocks()
})

describe('formatMoney', () => {
it('pins hard-coded USD copy to en-US formatting', () => {
const OriginalNumberFormat = Intl.NumberFormat
const seenLocales: Array<Intl.LocalesArgument | undefined> = []

vi.spyOn(Intl, 'NumberFormat').mockImplementation(
class {
constructor(locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions) {
seenLocales.push(locales)

return new OriginalNumberFormat(locales ?? 'en-DE', options)
}
} as typeof Intl.NumberFormat
)

expect(formatMoney(25)).toBe('$25')
expect(seenLocales).toEqual(['en-US'])
})
})
2 changes: 1 addition & 1 deletion apps/desktop/src/app/settings/billing/billing-amounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function formatMoney(value?: null | number | string): string {
return EMPTY_BILLING_VALUE
}

return new Intl.NumberFormat(undefined, {
return new Intl.NumberFormat('en-US', {
currency: 'USD',
maximumFractionDigits: amount % 1 === 0 ? 0 : 2,
minimumFractionDigits: amount % 1 === 0 ? 0 : 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, describe, expect, it } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'

import { setRuntimeI18nLocale } from '@/i18n'

Expand Down Expand Up @@ -372,6 +372,15 @@ describe('clampForDisplay', () => {
expect(clamped).toContain('5,000 more characters truncated')
expect(clamped).toContain('Copy')
})

it('pins the English truncation copy to en-US number formatting', () => {
const localeSpy = vi.spyOn(Number.prototype, 'toLocaleString').mockReturnValue('5,000')

clampForDisplay('x'.repeat(MAX_TOOL_RENDER_CHARS + 5_000))

expect(localeSpy).toHaveBeenCalledWith('en-US')
localeSpy.mockRestore()
})
})

// A large tool result (e.g. a 100KB read_file during a `/learn` run) must not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function clampForDisplay(value: string, max = MAX_TOOL_RENDER_CHARS): str

const omitted = value.length - max

return `${value.slice(0, max)}\n\n… ${omitted.toLocaleString()} more characters truncated β€” use Copy for the full output.`
return `${value.slice(0, max)}\n\n… ${omitted.toLocaleString('en-US')} more characters truncated β€” use Copy for the full output.`
}

export function prettyJson(value: unknown): string {
Expand Down
Loading