-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-tool-display.js
More file actions
127 lines (114 loc) · 3.11 KB
/
test-tool-display.js
File metadata and controls
127 lines (114 loc) · 3.11 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env node
/**
* 测试工具执行双行显示功能
*/
import { generateToolSummary } from './src/tools.js';
console.log('=== 测试工具执行双行显示 ===\n');
// 测试用例
const testCases = [
{
name: 'Bash 命令',
tool: 'bash',
input: { command: 'npm run build:main --minify' },
result: { success: true, exitCode: 0 }
},
{
name: 'Bash 命令失败',
tool: 'bash',
input: { command: 'invalid-command' },
result: { success: false, error: 'command not found' }
},
{
name: '读取小文件',
tool: 'readFile',
input: { filePath: '/path/to/package.json' },
result: { success: true, size: 1024 }
},
{
name: '读取大文件(截断)',
tool: 'readFile',
input: { filePath: '/path/to/large-file.js' },
result: { success: true, size: 1024000, truncated: true }
},
{
name: '写入文件',
tool: 'writeFile',
input: { filePath: '/path/to/new-file.js' },
result: { success: true, size: 2048 }
},
{
name: '编辑文件',
tool: 'editFile',
input: { filePath: '/path/to/app.js' },
result: { success: true, replacements: 3 }
},
{
name: '区域编辑',
tool: 'regionConstrainedEdit',
input: { filePath: '/path/to/app.js' },
result: { success: true, replacements: 1, region: { begin: 10, end: 20 } }
},
{
name: '搜索文件',
tool: 'searchFiles',
input: { pattern: '**/*.js' },
result: { success: true, count: 42 }
},
{
name: '列出目录',
tool: 'listFiles',
input: { dirPath: '/src' },
result: { success: true, files: [{ name: 'app.js' }, { name: 'utils.js' }] }
}
];
let passed = 0;
let failed = 0;
for (const testCase of testCases) {
console.log(`\n📋 ${testCase.name}`);
console.log(`工具: ${testCase.tool}`);
try {
const { summary, detailInfo } = generateToolSummary(
testCase.tool,
testCase.input,
testCase.result
);
console.log(`\n第一行(摘要):`);
console.log(` ${summary}`);
console.log(`\n第二行(详细信息):`);
console.log(` ${detailInfo}`);
// 验证返回值
if (!summary || typeof summary !== 'string') {
console.log(`\n❌ 失败:summary 无效`);
failed++;
continue;
}
if (!detailInfo || typeof detailInfo !== 'string') {
console.log(`\n❌ 失败:detailInfo 无效`);
failed++;
continue;
}
// 验证特定工具的详细信息
if (testCase.tool === 'bash') {
if (!detailInfo.includes(testCase.input.command.substring(0, 20))) {
console.log(`\n⚠️ 警告:bash 命令可能被截断`);
}
}
console.log(`\n✅ 通过`);
passed++;
} catch (error) {
console.log(`\n❌ 失败:${error.message}`);
failed++;
}
}
// 总结
console.log('\n' + '='.repeat(60));
console.log(`\n测试结果:`);
console.log(`✅ 通过: ${passed}/${testCases.length}`);
console.log(`❌ 失败: ${failed}/${testCases.length}`);
if (failed === 0) {
console.log('\n🎉 所有测试通过!\n');
process.exit(0);
} else {
console.log('\n⚠️ 部分测试失败\n');
process.exit(1);
}