From 281b333cc5f048cc37e7b2075bde9c353b9a0496 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Wed, 24 Jun 2026 21:59:41 -0500 Subject: [PATCH] test(desktop): cover localized tool title shimmer --- .../assistant-ui/tool-fallback-model.test.ts | 64 ++++++++++++++++++- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/components/assistant-ui/tool-fallback-model.test.ts b/apps/desktop/src/components/assistant-ui/tool-fallback-model.test.ts index 18d2edffc00..82061c61f0a 100644 --- a/apps/desktop/src/components/assistant-ui/tool-fallback-model.test.ts +++ b/apps/desktop/src/components/assistant-ui/tool-fallback-model.test.ts @@ -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 => ({ ...overrides }) +afterEach(() => { + setRuntimeI18nLocale('en') +}) + describe('buildToolView image handling', () => { // vision_analyze reports the input image as a local path; an 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) => - buildToolView(part({ result, toolName: 'terminal' }), '') + const terminal = (result: Record) => 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')