|
1 | 1 | import { describe, expect, test } from 'bun:test' |
2 | 2 |
|
3 | | -import { getAgentDisplayPrompt } from '../agent-display' |
| 3 | +import { |
| 4 | + getAgentDisplayPrompt, |
| 5 | + getBasherFinishedOutputPreview, |
| 6 | + truncateToSingleLinePreview, |
| 7 | +} from '../agent-display' |
4 | 8 |
|
5 | 9 | import type { AgentContentBlock } from '../../types/chat' |
6 | 10 |
|
@@ -64,3 +68,72 @@ describe('getAgentDisplayPrompt', () => { |
64 | 68 | expect(getAgentDisplayPrompt(block)).toBeUndefined() |
65 | 69 | }) |
66 | 70 | }) |
| 71 | + |
| 72 | +describe('getBasherFinishedOutputPreview', () => { |
| 73 | + test('returns undefined while basher is still running', () => { |
| 74 | + const block = createAgentBlock({ |
| 75 | + status: 'running', |
| 76 | + params: { |
| 77 | + what_to_summarize: 'Report the test result', |
| 78 | + }, |
| 79 | + blocks: [{ type: 'text', content: 'Tests passed' }], |
| 80 | + }) |
| 81 | + |
| 82 | + expect(getBasherFinishedOutputPreview(block)).toBeUndefined() |
| 83 | + }) |
| 84 | + |
| 85 | + test('uses finished basher text output before what_to_summarize', () => { |
| 86 | + const block = createAgentBlock({ |
| 87 | + status: 'complete', |
| 88 | + params: { |
| 89 | + what_to_summarize: 'Report the test result', |
| 90 | + }, |
| 91 | + blocks: [ |
| 92 | + { |
| 93 | + type: 'text', |
| 94 | + content: 'Tests passed\n42 assertions completed', |
| 95 | + textType: 'text', |
| 96 | + }, |
| 97 | + ], |
| 98 | + }) |
| 99 | + |
| 100 | + expect(getBasherFinishedOutputPreview(block)).toBe( |
| 101 | + 'Tests passed 42 assertions completed', |
| 102 | + ) |
| 103 | + }) |
| 104 | + |
| 105 | + test('falls back to command output when no text block exists', () => { |
| 106 | + const block = createAgentBlock({ |
| 107 | + status: 'complete', |
| 108 | + blocks: [ |
| 109 | + { |
| 110 | + type: 'tool', |
| 111 | + toolCallId: 'tool-1', |
| 112 | + toolName: 'run_terminal_command', |
| 113 | + input: { command: 'git status --short' }, |
| 114 | + output: ' M cli/src/app.tsx\n', |
| 115 | + }, |
| 116 | + ], |
| 117 | + }) |
| 118 | + |
| 119 | + expect(getBasherFinishedOutputPreview(block)).toBe('M cli/src/app.tsx') |
| 120 | + }) |
| 121 | + |
| 122 | + test('ignores non-basher output', () => { |
| 123 | + const block = createAgentBlock({ |
| 124 | + agentType: 'code-searcher', |
| 125 | + status: 'complete', |
| 126 | + blocks: [{ type: 'text', content: 'Search results' }], |
| 127 | + }) |
| 128 | + |
| 129 | + expect(getBasherFinishedOutputPreview(block)).toBeUndefined() |
| 130 | + }) |
| 131 | +}) |
| 132 | + |
| 133 | +describe('truncateToSingleLinePreview', () => { |
| 134 | + test('collapses whitespace and truncates to the requested length', () => { |
| 135 | + expect(truncateToSingleLinePreview('one\ntwo three four', 13)).toBe( |
| 136 | + 'one two th...', |
| 137 | + ) |
| 138 | + }) |
| 139 | +}) |
0 commit comments