|
1 | 1 | import { TEST_AGENT_RUNTIME_IMPL } from '@codebuff/common/testing/impl/agent-runtime' |
2 | 2 | import { describe, test, expect, mock } from 'bun:test' |
3 | 3 |
|
4 | | -import { getAgentPrompt } from '../strings' |
| 4 | +import { PLACEHOLDER } from '../types' |
| 5 | +import { formatCurrentDate, getAgentPrompt } from '../strings' |
5 | 6 |
|
6 | 7 | import type { AgentTemplate } from '../types' |
7 | 8 | import type { AgentState } from '@codebuff/common/types/session-state' |
@@ -81,6 +82,38 @@ const createMockAgentTemplate = ( |
81 | 82 | }) |
82 | 83 |
|
83 | 84 | describe('getAgentPrompt', () => { |
| 85 | + test('replaces CURRENT_DATE when formatting prompts', async () => { |
| 86 | + const agentTemplate = createMockAgentTemplate({ |
| 87 | + id: 'date-agent', |
| 88 | + systemPrompt: `Today is ${PLACEHOLDER.CURRENT_DATE}.`, |
| 89 | + }) |
| 90 | + const agentTemplates: Record<string, AgentTemplate> = { |
| 91 | + 'date-agent': agentTemplate, |
| 92 | + } |
| 93 | + |
| 94 | + const result = await getAgentPrompt({ |
| 95 | + agentTemplate, |
| 96 | + promptType: { type: 'systemPrompt' }, |
| 97 | + fileContext: createMockFileContext(), |
| 98 | + agentState: createMockAgentState('date-agent'), |
| 99 | + agentTemplates, |
| 100 | + additionalToolDefinitions: async () => ({}), |
| 101 | + logger: createMockLogger(), |
| 102 | + apiKey: TEST_AGENT_RUNTIME_IMPL.apiKey, |
| 103 | + databaseAgentCache: TEST_AGENT_RUNTIME_IMPL.databaseAgentCache, |
| 104 | + fetchAgentFromDatabase: TEST_AGENT_RUNTIME_IMPL.fetchAgentFromDatabase, |
| 105 | + }) |
| 106 | + |
| 107 | + expect(result).toBe(`Today is ${formatCurrentDate(new Date())}.`) |
| 108 | + expect(result).not.toContain(PLACEHOLDER.CURRENT_DATE) |
| 109 | + }) |
| 110 | + |
| 111 | + test('formats current date for prompts', () => { |
| 112 | + expect(formatCurrentDate(new Date('2026-05-22T12:00:00Z'))).toBe( |
| 113 | + 'May 22, 2026', |
| 114 | + ) |
| 115 | + }) |
| 116 | + |
84 | 117 | describe('spawnerPrompt inclusion in instructionsPrompt', () => { |
85 | 118 | test('includes spawnerPrompt for each spawnable agent with spawnerPrompt defined', async () => { |
86 | 119 | const filePickerTemplate = createMockAgentTemplate({ |
|
0 commit comments