test(desktop): cover localized tool title shimmer

This commit is contained in:
Brooklyn Nicholson 2026-06-24 21:59:41 -05:00
parent f2c45e2c81
commit 281b333cc5

View file

@ -1,4 +1,6 @@
import { describe, expect, it } from 'vitest'
import { afterEach, describe, expect, it } from 'vitest'
import { setRuntimeI18nLocale } from '@/i18n'
import {
buildToolView,
@ -19,6 +21,10 @@ const part = (overrides: Partial<ToolPart>): ToolPart => ({
...overrides
})
afterEach(() => {
setRuntimeI18nLocale('en')
})
describe('buildToolView image handling', () => {
// vision_analyze reports the input image as a local path; an <img> pointed at
// a bare path resolves against the renderer origin and 404s, so we render the
@ -42,8 +48,7 @@ describe('buildToolView image handling', () => {
})
describe('buildToolView terminal exit-code status', () => {
const terminal = (result: Record<string, unknown>) =>
buildToolView(part({ result, toolName: 'terminal' }), '')
const terminal = (result: Record<string, unknown>) => buildToolView(part({ result, toolName: 'terminal' }), '')
// A non-zero exit code with real output is not a failure (grep no-match,
// diff differences, piped commands surfacing the last stage's code, etc.) —
@ -112,6 +117,59 @@ describe('buildToolView file edit diffs', () => {
})
})
describe('buildToolView title actions', () => {
it('marks the pending action separately from the rest of the title', () => {
const read = buildToolView(part({ args: { path: '/tmp/demo.txt' }, result: undefined, toolName: 'read_file' }), '')
const web = buildToolView(
part({ args: { url: 'https://example.com/docs' }, result: undefined, toolName: 'web_extract' }),
''
)
const terminal = buildToolView(
part({ args: { command: 'npm test -- --runInBand' }, result: undefined, toolName: 'terminal' }),
''
)
const code = buildToolView(
part({ args: { code: 'print("hello")' }, result: undefined, toolName: 'execute_code' }),
''
)
expect(read.title).toBe('Reading file')
expect(read.titleAction).toEqual({ prefix: '', text: 'Reading', suffix: ' file' })
expect(web.title).toBe('Reading example.com/docs')
expect(web.titleAction).toEqual({ prefix: '', text: 'Reading', suffix: ' example.com/docs' })
expect(terminal.title).toBe('Running · npm test -- --runInBand')
expect(terminal.titleAction).toEqual({ prefix: '', text: 'Running', suffix: ' · npm test -- --runInBand' })
expect(code.title).toBe('Scripting · print("hello")')
expect(code.titleAction).toEqual({ prefix: '', text: 'Scripting', suffix: ' · print("hello")' })
})
it('does not mark completed tool titles as pending actions', () => {
const view = buildToolView(part({ args: { url: 'https://example.com/docs' }, toolName: 'web_extract' }), '')
expect(view.title).toBe('Read example.com/docs')
expect(view.titleAction).toBeUndefined()
})
it('uses the runtime locale for title text and action placement', () => {
setRuntimeI18nLocale('ja')
const read = buildToolView(part({ args: { path: '/tmp/demo.txt' }, result: undefined, toolName: 'read_file' }), '')
const web = buildToolView(
part({ args: { url: 'https://example.com/docs' }, result: undefined, toolName: 'web_extract' }),
''
)
expect(read.title).toBe('ファイルを読み取り中')
expect(read.titleAction).toEqual({ prefix: 'ファイルを', text: '読み取り中', suffix: '' })
expect(web.title).toBe('example.com/docs を読み取り中')
expect(web.titleAction).toEqual({ prefix: 'example.com/docs を', text: '読み取り中', suffix: '' })
})
})
describe('clampForDisplay', () => {
it('passes short payloads through untouched', () => {
expect(clampForDisplay('hello')).toBe('hello')