|
| 1 | +import { describe, expect, test } from 'bun:test' |
| 2 | + |
| 3 | +import { getAgentDisplayPrompt } from '../agent-display' |
| 4 | + |
| 5 | +import type { AgentContentBlock } from '../../types/chat' |
| 6 | + |
| 7 | +const createAgentBlock = ( |
| 8 | + overrides: Partial<AgentContentBlock>, |
| 9 | +): AgentContentBlock => ({ |
| 10 | + type: 'agent', |
| 11 | + agentId: 'agent-1', |
| 12 | + agentName: 'Basher', |
| 13 | + agentType: 'basher', |
| 14 | + content: '', |
| 15 | + status: 'running', |
| 16 | + blocks: [], |
| 17 | + initialPrompt: '', |
| 18 | + ...overrides, |
| 19 | +}) |
| 20 | + |
| 21 | +describe('getAgentDisplayPrompt', () => { |
| 22 | + test('uses initial prompt when present', () => { |
| 23 | + const block = createAgentBlock({ |
| 24 | + initialPrompt: 'Run tests', |
| 25 | + params: { |
| 26 | + what_to_summarize: 'Summarize failures', |
| 27 | + }, |
| 28 | + }) |
| 29 | + |
| 30 | + expect(getAgentDisplayPrompt(block)).toBe('Run tests') |
| 31 | + }) |
| 32 | + |
| 33 | + test('uses basher what_to_summarize when prompt is omitted', () => { |
| 34 | + const block = createAgentBlock({ |
| 35 | + params: { |
| 36 | + command: 'bun test', |
| 37 | + what_to_summarize: 'Summarize failing tests only', |
| 38 | + }, |
| 39 | + }) |
| 40 | + |
| 41 | + expect(getAgentDisplayPrompt(block)).toBe('Summarize failing tests only') |
| 42 | + }) |
| 43 | + |
| 44 | + test('normalizes scoped and versioned basher agent ids', () => { |
| 45 | + const block = createAgentBlock({ |
| 46 | + agentType: 'codebuff/basher@1.0.0', |
| 47 | + params: { |
| 48 | + what_to_summarize: 'Summarize command output', |
| 49 | + }, |
| 50 | + }) |
| 51 | + |
| 52 | + expect(getAgentDisplayPrompt(block)).toBe('Summarize command output') |
| 53 | + }) |
| 54 | + |
| 55 | + test('ignores non-basher what_to_summarize params', () => { |
| 56 | + const block = createAgentBlock({ |
| 57 | + agentName: 'code-searcher', |
| 58 | + agentType: 'code-searcher', |
| 59 | + params: { |
| 60 | + what_to_summarize: 'This is not a basher prompt', |
| 61 | + }, |
| 62 | + }) |
| 63 | + |
| 64 | + expect(getAgentDisplayPrompt(block)).toBeUndefined() |
| 65 | + }) |
| 66 | +}) |
0 commit comments