|
| 1 | +import { describe, expect, test } from 'bun:test' |
| 2 | + |
| 3 | +import { |
| 4 | + countCodeSearchResults, |
| 5 | + getCodeSearcherCollapsedPreview, |
| 6 | +} from '../code-search-summary' |
| 7 | + |
| 8 | +import type { AgentContentBlock, ToolContentBlock } from '../../types/chat' |
| 9 | + |
| 10 | +const createCodeSearchToolBlock = ( |
| 11 | + output: string, |
| 12 | + id = 'tool-1', |
| 13 | +): ToolContentBlock => ({ |
| 14 | + type: 'tool', |
| 15 | + toolCallId: id, |
| 16 | + toolName: 'code_search', |
| 17 | + input: { pattern: 'MODEL_ID' }, |
| 18 | + output, |
| 19 | +}) |
| 20 | + |
| 21 | +const createCodeSearcherBlock = ( |
| 22 | + options: Partial<AgentContentBlock> = {}, |
| 23 | +): AgentContentBlock => ({ |
| 24 | + type: 'agent', |
| 25 | + agentId: 'agent-1', |
| 26 | + agentName: 'code-searcher', |
| 27 | + agentType: 'code-searcher', |
| 28 | + content: '', |
| 29 | + status: 'complete', |
| 30 | + params: { |
| 31 | + searchQueries: [ |
| 32 | + { pattern: 'FREEBUFF_MODEL_SELECTOR_MODELS' }, |
| 33 | + { pattern: 'FREEBUFF_MODEL_SELECTOR_MODEL_IDS' }, |
| 34 | + { pattern: 'DEFAULT_FREEBUFF_MODEL_ID' }, |
| 35 | + ], |
| 36 | + }, |
| 37 | + blocks: [], |
| 38 | + ...options, |
| 39 | +}) |
| 40 | + |
| 41 | +describe('code search summary helpers', () => { |
| 42 | + test('counts formatted code search matches from stdout', () => { |
| 43 | + expect( |
| 44 | + countCodeSearchResults(`stdout: |- |
| 45 | + Found 2 matches |
| 46 | + ./message-block-helpers.ts: |
| 47 | + Line 13: export const getAgentBaseName = (type: string): string => { |
| 48 | + Line 196: getAgentBaseName(options.agentType ?? '') === 'code-searcher'`), |
| 49 | + ).toBe(2) |
| 50 | + }) |
| 51 | + |
| 52 | + test('summarizes collapsed code-searcher searches and results', () => { |
| 53 | + const agentBlock = createCodeSearcherBlock({ |
| 54 | + blocks: [ |
| 55 | + createCodeSearchToolBlock('Found 7 matches', 'tool-1'), |
| 56 | + createCodeSearchToolBlock('Found 2 matches', 'tool-2'), |
| 57 | + createCodeSearchToolBlock('Found 7 matches', 'tool-3'), |
| 58 | + ], |
| 59 | + }) |
| 60 | + |
| 61 | + expect(getCodeSearcherCollapsedPreview(agentBlock)).toBe( |
| 62 | + '3 searches · 16 results', |
| 63 | + ) |
| 64 | + }) |
| 65 | + |
| 66 | + test('shows search count before tool outputs arrive', () => { |
| 67 | + expect(getCodeSearcherCollapsedPreview(createCodeSearcherBlock())).toBe( |
| 68 | + '3 searches', |
| 69 | + ) |
| 70 | + }) |
| 71 | + |
| 72 | + test('handles singular labels', () => { |
| 73 | + const agentBlock = createCodeSearcherBlock({ |
| 74 | + params: { |
| 75 | + searchQueries: [{ pattern: 'DEFAULT_FREEBUFF_MODEL_ID' }], |
| 76 | + }, |
| 77 | + blocks: [createCodeSearchToolBlock('Found 1 match')], |
| 78 | + }) |
| 79 | + |
| 80 | + expect(getCodeSearcherCollapsedPreview(agentBlock)).toBe( |
| 81 | + '1 search · 1 result', |
| 82 | + ) |
| 83 | + }) |
| 84 | +}) |
0 commit comments