mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-17 13:13:35 +08:00
This merge carries the set/clear /goal behavior from the Codex worktree into local main while preserving main's memory-style desktop goal cards and compact active-goal banner. Constraint: Local main already had unrelated version/Tauri/release-note worktree changes and a newer goal UI style.\nRejected: Overwrite main's goal card UI with the worktree version | user wanted the memory-style visual direction already present on main.\nConfidence: high\nScope-risk: moderate\nTested: bun test src/commands/goal/goal.test.tsx src/goals/goalState.test.ts src/goals/goalEvaluator.test.ts src/server/__tests__/ws-memory-events.test.ts src/server/__tests__/conversations.test.ts\nTested: cd desktop && bun run test -- --run src/stores/chatStore.test.ts src/components/chat/MessageList.test.tsx src/pages/ActiveSession.test.tsx src/components/chat/composerUtils.test.ts\nNot-tested: Full bun run verify on main was not rerun after merge because unrelated dirty release/version files are present in the main worktree.
134 lines
4.8 KiB
TypeScript
134 lines
4.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
filterSlashCommands,
|
|
findSlashToken,
|
|
insertSlashTrigger,
|
|
mergeSlashCommands,
|
|
replaceSlashCommand,
|
|
resolveSlashUiAction,
|
|
} 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('closes slash completion once /goal arguments start', () => {
|
|
expect(findSlashToken('/goal ', 6)).toBeNull()
|
|
expect(findSlashToken('/goal sta', 9)).toBeNull()
|
|
expect(findSlashToken('/goal build app', 15)).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 desktop and agent commands' },
|
|
{ name: 'clear', description: 'Clear conversation history' },
|
|
{ name: 'context', description: 'Show current context usage' },
|
|
]),
|
|
)
|
|
})
|
|
|
|
it('keeps server-provided descriptions when they exist', () => {
|
|
expect(
|
|
mergeSlashCommands([
|
|
{ name: 'clear', description: 'Server description' },
|
|
]),
|
|
).toEqual(
|
|
expect.arrayContaining([
|
|
{ name: 'clear', description: 'Server description' },
|
|
]),
|
|
)
|
|
})
|
|
|
|
it('keeps slash command argument hints and fills missing fallback hints', () => {
|
|
expect(
|
|
mergeSlashCommands([
|
|
{
|
|
name: 'goal',
|
|
description: '',
|
|
argumentHint: '',
|
|
},
|
|
]),
|
|
).toEqual(
|
|
expect.arrayContaining([
|
|
{
|
|
name: 'goal',
|
|
description: 'Set a completion goal',
|
|
argumentHint: '[<condition> | clear]',
|
|
},
|
|
]),
|
|
)
|
|
})
|
|
|
|
it('keeps /goal as a single command with argument hints instead of pseudo subcommands', () => {
|
|
const commands = filterSlashCommands(mergeSlashCommands([]), 'goal')
|
|
|
|
expect(
|
|
commands.map((command) => command.name),
|
|
).toEqual(['goal'])
|
|
expect(commands[0]).toMatchObject({
|
|
description: 'Set a completion goal',
|
|
argumentHint: '[<condition> | clear]',
|
|
})
|
|
expect(mergeSlashCommands([]).map((command) => command.name)).not.toContain('goal status')
|
|
expect(mergeSlashCommands([]).map((command) => command.name)).not.toContain('goal --tokens')
|
|
})
|
|
|
|
it('does not replace /goal arguments as slash command fragments', () => {
|
|
expect(replaceSlashCommand('/goal sta', 9, 'goal status')).toBeNull()
|
|
})
|
|
|
|
it('ranks slash command name matches before broad description matches', () => {
|
|
expect(
|
|
filterSlashCommands([
|
|
{ name: 'lark-calendar', description: 'Includes shortcuts and suggestion helpers' },
|
|
{ name: 'agent-team-orchestrator', description: 'Uses Subagent orchestration' },
|
|
{ name: 'superpowers:brainstorming', description: 'Creative work planning' },
|
|
{ name: 'superpowers:systematic-debugging', description: 'Debug unexpected behavior' },
|
|
], 'su').map((command) => command.name),
|
|
).toEqual([
|
|
'superpowers:brainstorming',
|
|
'superpowers:systematic-debugging',
|
|
'lark-calendar',
|
|
'agent-team-orchestrator',
|
|
])
|
|
})
|
|
|
|
it('resolves hidden settings aliases without displaying duplicate fallback rows', () => {
|
|
expect(resolveSlashUiAction('plugins')).toEqual({ type: 'settings', tab: 'plugins' })
|
|
expect(resolveSlashUiAction('memory')).toEqual({ type: 'settings', tab: 'memory' })
|
|
expect(resolveSlashUiAction('doctor')).toEqual({ type: 'settings', tab: 'diagnostics' })
|
|
expect(mergeSlashCommands([]).map((command) => command.name)).toContain('plugin')
|
|
expect(mergeSlashCommands([]).map((command) => command.name)).toContain('memory')
|
|
expect(mergeSlashCommands([]).map((command) => command.name)).not.toContain('plugins')
|
|
})
|
|
|
|
it('routes session inspection commands to the desktop panel', () => {
|
|
expect(resolveSlashUiAction('cost')).toEqual({ type: 'panel', command: 'cost' })
|
|
expect(resolveSlashUiAction('context')).toEqual({ type: 'panel', command: 'context' })
|
|
expect(resolveSlashUiAction('status')).toEqual({ type: 'panel', command: 'status' })
|
|
})
|
|
})
|