返回 oh-my-ppt
source-plan.test.ts
根目录 / tests / unit / thinking / source-plan.test.ts
1 import { describe, expect, it } from 'vitest'
2 import {
3 buildThinkingPageOutline,
4 buildThinkingSourcePlan
5 } from '../../../src/main/thinking/source-plan'
6
7 describe('thinking source plan', () => {
8 it('returns null when thinking.md has no page headings', () => {
9 const sourcePlan = buildThinkingSourcePlan(
10 ['# Thinking Brief', '', '## Topic', '只有主题,没有页面'].join('\n'),
11 '/tmp/thinking.md'
12 )
13
14 expect(sourcePlan).toBeNull()
15 })
16
17 it('builds compact range-bound skeletons for 100-page thinking briefs', () => {
18 const pages = Array.from({ length: 100 }, (_, index) => {
19 const pageNumber = index + 1
20 return [
21 `## Page ${pageNumber}: 第 ${pageNumber} 页主题`,
22 '- Role: content',
23 `- Objective: 说明第 ${pageNumber} 页的核心任务`,
24 '',
25 `这一页总结第 ${pageNumber} 个主题的关键背景、判断和行动方向。`,
26 '',
27 `- 保留第 ${pageNumber} 页的事实边界`,
28 `- 展开第 ${pageNumber} 页的关键论据`,
29 `- 给出第 ${pageNumber} 页的表达重点`
30 ].join('\n')
31 })
32 const thinkingMd = ['# Thinking Brief', '## Topic', '百页方案', '', ...pages].join('\n')
33
34 const sourcePlan = buildThinkingSourcePlan(thinkingMd, '/tmp/thinking.md')
35
36 expect(sourcePlan?.pageSkeleton).toHaveLength(100)
37 expect(sourcePlan?.pageSkeleton[0]).toMatchObject({
38 pageNumber: 1,
39 title: '第 1 页主题',
40 sourceHeading: 'Page 1: 第 1 页主题'
41 })
42 expect(sourcePlan?.pageSkeleton[99]).toMatchObject({
43 pageNumber: 100,
44 title: '第 100 页主题'
45 })
46 for (const item of sourcePlan?.pageSkeleton ?? []) {
47 expect(item.lineEnd).toBeGreaterThanOrEqual(item.lineStart)
48 expect(item.reason).toContain(`第 ${item.pageNumber} 页`)
49 expect(item.reason.length).toBeLessThanOrEqual(520)
50 }
51 })
52
53 it('keeps summary and key points in a bounded page outline', () => {
54 const outline = buildThinkingPageOutline([
55 '- Role: content',
56 '- Objective: 建立核心判断',
57 '',
58 '总结第一句。',
59 '总结第二句。',
60 '',
61 '- 关键点一',
62 '- 关键点二',
63 '- 关键点三',
64 '- 关键点四',
65 '- 关键点五',
66 '- 关键点六',
67 '- 关键点七',
68 '- 关键点八',
69 '- 关键点九',
70 '- 关键点十',
71 '- 关键点十一'
72 ])
73
74 expect(outline).toContain('建立核心判断')
75 expect(outline).toContain('总结第一句。 总结第二句。')
76 expect(outline).toContain('关键点十')
77 expect(outline).not.toContain('关键点十一')
78 expect(outline.length).toBeLessThanOrEqual(520)
79 })
80 })
81
81 lines TYPESCRIPT