prompts.test.js
3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Unit Tests — core/prompts.js
*/
import { describe, it, expect } from 'vitest';
const { Prompts } = require('../../src/core/prompts');
describe('Prompts', () => {
describe('initial', () => {
it('should include the requirement text', () => {
const result = Prompts.initial('Build a website', 'coder, verifier');
expect(result).toContain('Build a website');
expect(result).toContain('coder, verifier');
});
it('should include JSON dispatch format instructions', () => {
const result = Prompts.initial('Task', 'agents');
expect(result).toContain('agent');
expect(result).toContain('task');
expect(result).toContain('[CALL:');
});
it('should warn against direct code writing', () => {
const result = Prompts.initial('Task', 'agents');
expect(result).toContain('禁止直接编写代码');
});
});
describe('followup', () => {
it('should include execution results', () => {
const result = Prompts.followup({
currentResults: [
{ agent: 'coder', status: 'DONE', output: 'Code written' },
{ agent: 'verifier', status: 'PASS', message: 'Verified' },
],
passedValidators: ['verifier'],
unpassedValidators: [],
});
expect(result).toContain('coder');
expect(result).toContain('Code written');
expect(result).toContain('Reflection');
expect(result).toContain('Summary');
});
it('should include artifact section when present', () => {
const result = Prompts.followup({
currentResults: [
{ agent: 'coder', status: 'DONE', output: 'ok', artifacts: ['main.py', 'utils.py'] },
],
passedValidators: [],
unpassedValidators: ['verifier'],
});
expect(result).toContain('产出文件');
expect(result).toContain('main.py');
});
it('should handle results without output gracefully', () => {
const result = Prompts.followup({
currentResults: [{ agent: 'coder', status: 'ERROR' }],
passedValidators: [],
unpassedValidators: [],
});
expect(result).toContain('coder');
});
});
describe('forceValidation', () => {
it('should list files and validators', () => {
const result = Prompts.forceValidation(['main.py', 'test.py'], ['code_verifier']);
expect(result).toContain('main.py');
expect(result).toContain('code_verifier');
});
});
describe('forceResume', () => {
it('should list unpassed validators', () => {
const result = Prompts.forceResume(['syntax_checker', 'logic_verifier']);
expect(result).toContain('syntax_checker');
expect(result).toContain('logic_verifier');
expect(result).toContain('尚未完成');
});
});
describe('formatCorrection', () => {
it('should include retry count for validator', () => {
const result = Prompts.formatCorrection({
agentType: 'validator', retryCount: 2, maxRetries: 5,
originalTask: 'Check syntax',
});
expect(result).toContain('2/5');
expect(result).toContain('PASS');
expect(result).toContain('FAIL');
expect(result).toContain('Check syntax');
});
it('should include DONE/ERROR for executor', () => {
const result = Prompts.formatCorrection({
agentType: 'executor', retryCount: 1, maxRetries: 3,
originalTask: 'Write code',
});
expect(result).toContain('DONE');
expect(result).toContain('ERROR');
});
});
});