|
1 | 1 | import { describe, it, expect } from 'vitest'; |
2 | | - |
3 | | -describe('L5 compaction prompt and extraction', () => { |
4 | | - it('should extract summary from dual-tag format', () => { |
5 | | - const raw = `<analysis> |
6 | | -This is analysis section with reasoning. |
7 | | -Multiple lines of thinking. |
8 | | -</analysis> |
9 | | -
|
10 | | -<summary> |
11 | | -## 1. Primary Request and Intent |
12 | | -User wants to add feature X. |
13 | | -
|
14 | | -## 2. Key Technical Concepts |
15 | | -- Concept A |
16 | | -- Concept B |
17 | | -
|
18 | | -## 9. Optional Next Step |
19 | | -Consider optimizing Y next. |
20 | | -</summary> |
21 | | -
|
22 | | -Some trailing text that should be ignored.`; |
23 | | - |
24 | | - const match = raw.match(/<summary>([\s\S]*?)<\/summary>/); |
25 | | - expect(match).toBeDefined(); |
26 | | - expect(match?.[1]).toContain('Primary Request'); |
27 | | - expect(match?.[1]).toContain('Optional Next Step'); |
| 2 | +import { COMPACTION_SYSTEM_PROMPT } from '../../../src/context/compaction-prompt.js'; |
| 3 | + |
| 4 | +// 断言直接读真实提示词常量,避免测试与实现各写一份而悄悄漂移。 |
| 5 | +describe('L5 compaction prompt contract', () => { |
| 6 | + const SECTIONS = [ |
| 7 | + '## 1. Primary Request and Intent', |
| 8 | + '## 2. Key Technical Concepts', |
| 9 | + '## 3. Files and Code Sections', |
| 10 | + '## 4. Errors and Fixes', |
| 11 | + '## 5. Problem Solving', |
| 12 | + '## 6. Decision Rationale and Rejected Approaches', |
| 13 | + '## 7. All User Messages', |
| 14 | + '## 8. Pending Tasks', |
| 15 | + '## 9. Current Work', |
| 16 | + '## 10. Optional Next Step', |
| 17 | + ]; |
| 18 | + |
| 19 | + it('requests all ten sections in order', () => { |
| 20 | + let cursor = -1; |
| 21 | + for (const section of SECTIONS) { |
| 22 | + const at = COMPACTION_SYSTEM_PROMPT.indexOf(section); |
| 23 | + expect(at, `missing or out-of-order section: ${section}`).toBeGreaterThan(cursor); |
| 24 | + cursor = at; |
| 25 | + } |
28 | 26 | }); |
29 | 27 |
|
30 | | - it('should fallback to raw content if no summary tags', () => { |
31 | | - const raw = 'Just raw content without tags'; |
32 | | - const match = raw.match(/<summary>([\s\S]*?)<\/summary>/); |
33 | | - const result = match ? match[1] : raw; |
34 | | - expect(result).toBe(raw); |
| 28 | + it('no longer asks for a separate analysis block', () => { |
| 29 | + expect(COMPACTION_SYSTEM_PROMPT).not.toMatch(/<\/?analysis>/); |
35 | 30 | }); |
36 | 31 |
|
37 | | - it('should validate 9 sections are present in summary structure', () => { |
38 | | - const sections = [ |
39 | | - '## 1. Primary Request and Intent', |
40 | | - '## 2. Key Technical Concepts', |
41 | | - '## 3. Files and Code Sections', |
42 | | - '## 4. Errors and Fixes', |
43 | | - '## 5. Problem Solving', |
44 | | - '## 6. All User Messages', |
45 | | - '## 7. Pending Tasks', |
46 | | - '## 8. Current Work', |
47 | | - '## 9. Optional Next Step', |
48 | | - ]; |
49 | | - |
50 | | - sections.forEach((section) => { |
51 | | - expect(section).toMatch(/^##\s+\d+\./); |
52 | | - }); |
53 | | - expect(sections).toHaveLength(9); |
54 | | - }); |
55 | | - |
56 | | - it('should separate analysis from summary', () => { |
57 | | - const full = `<analysis> |
58 | | -Reasoning and thinking process here. |
59 | | -This is how I approached the problem. |
60 | | -</analysis> |
61 | | -
|
62 | | -<summary> |
63 | | -The final structured output. |
64 | | -</summary>`; |
65 | | - |
66 | | - const analysisMatch = full.match(/<analysis>([\s\S]*?)<\/analysis>/); |
67 | | - const summaryMatch = full.match(/<summary>([\s\S]*?)<\/summary>/); |
68 | | - |
69 | | - expect(analysisMatch?.[1]).toContain('Reasoning'); |
70 | | - expect(summaryMatch?.[1]).toContain('final structured'); |
71 | | - expect(analysisMatch?.[1]).not.toContain('final structured'); |
72 | | - }); |
73 | | - |
74 | | - it('should handle empty sections gracefully', () => { |
75 | | - const raw = `<analysis></analysis> |
76 | | -<summary> |
77 | | -## 1. Primary Request and Intent |
78 | | -</summary>`; |
79 | | - |
80 | | - const match = raw.match(/<summary>([\s\S]*?)<\/summary>/); |
81 | | - expect(match?.[1]).toBeDefined(); |
| 32 | + it('no longer wraps the summary in tags', () => { |
| 33 | + expect(COMPACTION_SYSTEM_PROMPT).not.toMatch(/<\/?summary>/); |
82 | 34 | }); |
83 | 35 | }); |
0 commit comments