| 1 | import fs from 'fs' |
| 2 | import path from 'path' |
| 3 | import { describe, expect, it } from 'vitest' |
| 4 | |
| 5 | describe('page beautify job boundary', () => { |
| 6 | it('uses dedicated IPC and restricts persistence to the selected page', () => { |
| 7 | const serviceSource = fs.readFileSync( |
| 8 | path.resolve('src/main/edit-jobs/page-beautify-job-service.ts'), |
| 9 | 'utf8' |
| 10 | ) |
| 11 | |
| 12 | expect(serviceSource).toContain("ipcMain.handle('page-beautify:start'") |
| 13 | expect(serviceSource).toContain("mode: 'page-beautify'") |
| 14 | expect(serviceSource).toContain("kind: 'page-beautify'") |
| 15 | expect(serviceSource).toContain('createGenerationRunWithSessionJob') |
| 16 | expect(serviceSource).toContain('resolvePageBeautifyContext') |
| 17 | expect(serviceSource).toContain('runPageBeautifyAgent') |
| 18 | expect(serviceSource).toContain('layoutAudit') |
| 19 | expect(serviceSource).toContain('extractPageBeautifyContent') |
| 20 | expect(serviceSource).toContain('replacePageContentFragment') |
| 21 | expect(serviceSource).toContain("from '../presentation/html/page-writer-core'") |
| 22 | expect(serviceSource).not.toContain("from '../tools/page-writer'") |
| 23 | expect(serviceSource).toContain('recordHistoryOperationStrict') |
| 24 | expect(serviceSource).not.toContain('runDeepAgentEdit') |
| 25 | expect(serviceSource).not.toContain('resolveCommonContext') |
| 26 | expect(serviceSource).not.toContain('update_single_page_file') |
| 27 | expect(serviceSource).not.toContain("from '../generation/edit-flow'") |
| 28 | expect(serviceSource).not.toContain("from './page-edit-job-service'") |
| 29 | expect(serviceSource).not.toContain("from './deck-edit-job-service'") |
| 30 | expect(serviceSource).not.toContain("from './style-switch-job-service'") |
| 31 | |
| 32 | const agentSource = fs.readFileSync( |
| 33 | path.resolve('src/main/edit-jobs/page-beautify-agent.ts'), |
| 34 | 'utf8' |
| 35 | ) |
| 36 | // Beautify uses the same DeepAgents + product-skills machinery as the deck/edit |
| 37 | // pipelines so the model can read_file the layout skill that matches the slide |
| 38 | // size. Custom tool surface stays narrow: only read_page_html + save_current_page_content. |
| 39 | expect(agentSource).toContain("createDeepAgent") |
| 40 | expect(agentSource).toContain("from 'deepagents'") |
| 41 | expect(agentSource).toContain('attachProductSkillsBackend') |
| 42 | expect(agentSource).toContain("name: 'read_page_html'") |
| 43 | expect(agentSource).toContain("name: 'save_current_page_content'") |
| 44 | // The project backend is read-only — beautify never persists by writing files. |
| 45 | expect(agentSource).toContain('ReadOnlyProjectBackend') |
| 46 | expect(agentSource).not.toContain('get_session_context') |
| 47 | expect(agentSource).not.toContain('update_single_page_file') |
| 48 | expect(agentSource).not.toContain('read_current_page_content') |
| 49 | |
| 50 | const promptSource = fs.readFileSync( |
| 51 | path.resolve('src/main/edit-jobs/page-beautify-prompt.ts'), |
| 52 | 'utf8' |
| 53 | ) |
| 54 | expect(promptSource).toContain('ppt-page-root') |
| 55 | expect(promptSource).toContain('read_page_html') |
| 56 | expect(promptSource).toContain('read_file') |
| 57 | expect(promptSource).toContain('layoutSkillName') |
| 58 | expect(promptSource).toContain('styleCase') |
| 59 | expect(promptSource).not.toContain('update_single_page_file') |
| 60 | expect(promptSource).not.toContain('read_current_page_content') |
| 61 | }) |
| 62 | }) |
| 63 |