| 1 | import { describe, expect, it } from 'vitest' |
| 2 | import { createPromptCatalog } from '../../../src/main/agent-runtime/prompt/catalog' |
| 3 | import { renderPromptTemplate } from '../../../src/main/agent-runtime/prompt/render' |
| 4 | |
| 5 | describe('prompt template rendering', () => { |
| 6 | it('renders every declared scalar placeholder', () => { |
| 7 | expect(renderPromptTemplate('Topic: {{ topic }} / count={{count}}', { topic: 'AI', count: 3 })).toBe( |
| 8 | 'Topic: AI / count=3' |
| 9 | ) |
| 10 | }) |
| 11 | |
| 12 | it('rejects missing, unknown and malformed placeholders', () => { |
| 13 | expect(() => renderPromptTemplate('Hello {{name}}', {})).toThrow('missing variables: name') |
| 14 | expect(() => renderPromptTemplate('Hello {{name}}', { name: 'Ada', typo: 'x' })).toThrow( |
| 15 | 'unknown variables: typo' |
| 16 | ) |
| 17 | expect(() => renderPromptTemplate('Hello {{ }}', {})).toThrow('invalid or unresolved') |
| 18 | }) |
| 19 | |
| 20 | it('binds a prompt id to its typed variable shape', () => { |
| 21 | const catalog = createPromptCatalog<{ greeting: { name: string }; count: { total: number } }>({ |
| 22 | greeting: 'Hello {{name}}', |
| 23 | count: 'Total {{total}}' |
| 24 | }) |
| 25 | |
| 26 | expect(catalog.render('greeting', { name: 'Ada' })).toBe('Hello Ada') |
| 27 | expect(catalog.render('count', { total: 2 })).toBe('Total 2') |
| 28 | }) |
| 29 | }) |
| 30 |