import { describe, test, expect } from 'vitest' import { getToolLabel } from './get-tool-label' import type { ChatToolItem } from '../types' describe('getToolLabel', () => { test('uses runningLabel when status is running', () => { const tool: ChatToolItem = { id: '1', name: 'execute_sql', status: 'running', runningLabel: 'Running query', } expect(getToolLabel(tool)).toBe('Running query') }) test('falls back to capitalized name when running without runningLabel', () => { const tool: ChatToolItem = { id: '1', name: 'execute_sql', status: 'running', } expect(getToolLabel(tool)).toBe('Execute sql') }) test('uses label for completed status', () => { const tool: ChatToolItem = { id: '1', name: 'execute_sql', status: 'complete', label: 'Database query', } expect(getToolLabel(tool)).toBe('Database query') }) test('uses label for error status', () => { const tool: ChatToolItem = { id: '1', name: 'execute_sql', status: 'error', label: 'Database query', } expect(getToolLabel(tool)).toBe('Database query') }) test('falls back to capitalized name for non-running without label', () => { const tool: ChatToolItem = { id: '1', name: 'add_marker', status: 'complete', } expect(getToolLabel(tool)).toBe('Add marker') }) test('replaces underscores with spaces and capitalizes first letter', () => { const tool: ChatToolItem = { id: '1', name: 'geocode_address_v2', status: 'complete', } expect(getToolLabel(tool)).toBe('Geocode address v2') }) test('preserves names that are already formatted', () => { const tool: ChatToolItem = { id: '1', name: 'Tool #1', status: 'complete', } expect(getToolLabel(tool)).toBe('Tool #1') }) test('runningLabel does not leak into non-running statuses', () => { const tool: ChatToolItem = { id: '1', name: 'execute_sql', status: 'complete', runningLabel: 'Running query', } expect(getToolLabel(tool)).toBe('Execute sql') }) test('label does not leak into running status', () => { const tool: ChatToolItem = { id: '1', name: 'execute_sql', status: 'running', label: 'Database query', } expect(getToolLabel(tool)).toBe('Execute sql') }) })