import { describe, expect, it } from 'vitest' import { findSlashToken, insertSlashTrigger, mergeSlashCommands, replaceSlashCommand, } from './composerUtils' describe('composerUtils', () => { it('finds slash token without trailing space', () => { expect(findSlashToken('/rev', 4)).toEqual({ start: 0, filter: 'rev' }) expect(findSlashToken('hello /rev', 10)).toEqual({ start: 6, filter: 'rev' }) }) it('does not treat slash followed by a space as an active token', () => { expect(findSlashToken('/ review', 8)).toBeNull() }) it('inserts a slash trigger without appending a trailing space', () => { expect(insertSlashTrigger('', 0)).toEqual({ value: '/', cursorPos: 1 }) expect(insertSlashTrigger('hello', 5)).toEqual({ value: 'hello /', cursorPos: 7 }) }) it('replaces the current slash token with a command and one trailing separator', () => { expect(replaceSlashCommand('/rev', 4, 'review')).toEqual({ value: '/review ', cursorPos: 8, }) }) it('merges fallback commands so built-in entries like /clear remain visible', () => { expect( mergeSlashCommands([ { name: 'help', description: '' }, ]), ).toEqual( expect.arrayContaining([ { name: 'help', description: 'Show available commands' }, { name: 'clear', description: 'Clear conversation history' }, ]), ) }) it('keeps server-provided descriptions when they exist', () => { expect( mergeSlashCommands([ { name: 'clear', description: 'Server description' }, ]), ).toEqual( expect.arrayContaining([ { name: 'clear', description: 'Server description' }, ]), ) }) })