| 1 | import fs from 'fs' |
| 2 | import path from 'path' |
| 3 | import { describe, expect, it } from 'vitest' |
| 4 | import { buildDeckAgentSystemPrompt } from '../../../src/main/agent-runtime/prompt' |
| 5 | import type { SessionDeckGenerationContext } from '../../../src/main/agent-runtime/agent' |
| 6 | import { resolveSlideSize } from '../../../src/shared/slide-size' |
| 7 | |
| 8 | const baseContext: SessionDeckGenerationContext = { |
| 9 | sessionId: 'session-1', |
| 10 | projectDir: '/tmp/project', |
| 11 | indexPath: '/tmp/project/index.html', |
| 12 | pageFileMap: { 'page-1': '/tmp/project/page-1.html' }, |
| 13 | topic: 'Quarterly report', |
| 14 | deckTitle: 'Quarterly report', |
| 15 | styleId: 'test-style', |
| 16 | styleSkillPrompt: 'Use a clean business style.', |
| 17 | userMessage: 'Create a quarterly report.', |
| 18 | outlineTitles: ['Overview'], |
| 19 | outlineItems: [{ title: 'Overview', contentOutline: 'Summarize the quarter.' }], |
| 20 | slideSize: resolveSlideSize({ id: 'wide-16-9' }), |
| 21 | appLocale: 'en' |
| 22 | } |
| 23 | |
| 24 | describe('deck system prompt template', () => { |
| 25 | it('renders the static deck contract from Markdown without unresolved placeholders', () => { |
| 26 | const composer = fs.readFileSync( |
| 27 | path.resolve('src/main/agent-runtime/prompt/composers/deck-system.ts'), |
| 28 | 'utf8' |
| 29 | ) |
| 30 | const template = fs.readFileSync( |
| 31 | path.resolve('src/main/agent-runtime/prompt/templates/deck-system/system.md'), |
| 32 | 'utf8' |
| 33 | ) |
| 34 | const prompt = buildDeckAgentSystemPrompt('test-style', baseContext) |
| 35 | |
| 36 | expect(composer).toContain("deckSystemTemplate from '../templates/deck-system/system.md?raw'") |
| 37 | expect(composer).toContain('createPromptCatalog<DeckSystemTemplateVars>') |
| 38 | expect(template).toContain('## Hard failure avoidance') |
| 39 | expect(template).toContain('## 最终风格校准(写入前)') |
| 40 | expect(prompt).toContain('## Hard failure avoidance') |
| 41 | expect(prompt).toContain('## 最终风格校准(写入前)') |
| 42 | expect(prompt).not.toMatch(/\{\{[^}]+\}\}/) |
| 43 | }) |
| 44 | |
| 45 | it('keeps template and source-document branches in the typed composer', () => { |
| 46 | const prompt = buildDeckAgentSystemPrompt('test-style', { |
| 47 | ...baseContext, |
| 48 | templatePageReadRequired: true, |
| 49 | selectedPageId: 'page-1', |
| 50 | selectedPageNumber: 1, |
| 51 | sourceDocumentPaths: ['/docs/source.md'] |
| 52 | }) |
| 53 | |
| 54 | expect(prompt).toContain('## 模板还原优先') |
| 55 | expect(prompt).not.toContain('## 创意变化') |
| 56 | expect(prompt).toContain('## Source documents') |
| 57 | expect(prompt).toContain('- /docs/source.md') |
| 58 | expect(prompt).toContain('update_template_page_file') |
| 59 | }) |
| 60 | }) |
| 61 |