| 1 | import fs from 'fs' |
| 2 | import path from 'path' |
| 3 | import { describe, expect, it } from 'vitest' |
| 4 | import { normalizeSessionPageEditPlan } from '../../../src/shared/generation' |
| 5 | |
| 6 | describe('single-page edit plan contract', () => { |
| 7 | it('accepts a complete, bounded user-confirmable plan', () => { |
| 8 | expect( |
| 9 | normalizeSessionPageEditPlan({ |
| 10 | intent: 'layout', |
| 11 | target: '第 2 页图表区', |
| 12 | summary: '调整图表区的层级与留白。', |
| 13 | changes: ['增加标题与图表间距'], |
| 14 | confirmationQuestion: '确认按此计划修改吗?' |
| 15 | }) |
| 16 | ).toMatchObject({ intent: 'layout', changes: ['增加标题与图表间距'] }) |
| 17 | }) |
| 18 | |
| 19 | it('rejects incomplete plans and lets the ReAct assessment choose confirmation', () => { |
| 20 | expect(normalizeSessionPageEditPlan({ intent: 'layout', target: '第 2 页' })).toBeUndefined() |
| 21 | |
| 22 | const serviceSource = fs.readFileSync( |
| 23 | path.resolve('src/main/edit-jobs/page-edit-job-service.ts'), |
| 24 | 'utf8' |
| 25 | ) |
| 26 | expect(serviceSource).toContain("ipcMain.handle('page-edit:assess'") |
| 27 | expect(serviceSource).toContain("ipcMain.handle('page-edit:start'") |
| 28 | expect(serviceSource).toContain('!input.approvedPlan && !input.autoApply') |
| 29 | const editFlowSource = fs.readFileSync( |
| 30 | path.resolve('src/main/generation/edit-flow.ts'), |
| 31 | 'utf8' |
| 32 | ) |
| 33 | expect(editFlowSource).toContain('record_session_page_edit_assessment') |
| 34 | expect(editFlowSource).toContain('requiresConfirmation=false only when the request has a concrete target') |
| 35 | expect(serviceSource).toContain('请先确认页面修改计划,再执行编辑。') |
| 36 | }) |
| 37 | |
| 38 | it('uses the ReAct assessment instead of a client-side wording heuristic', () => { |
| 39 | const controllerSource = fs.readFileSync( |
| 40 | path.resolve('src/renderer/src/components/session-detail/hooks/useChatPanelController.ts'), |
| 41 | 'utf8' |
| 42 | ) |
| 43 | expect(controllerSource).toContain('ipc.assessPageEdit(generatePayload)') |
| 44 | expect(controllerSource).not.toContain('isExplicitSessionPageEditRequest') |
| 45 | expect(controllerSource).toContain('const autoApplyPayload = { ...generatePayload, autoApply: true }') |
| 46 | }) |
| 47 | }) |
| 48 |