mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-12 02:37:45 +08:00
feat: Add comprehensive tests for contentPattern and glob pattern matching
- Implemented final verification tests for contentPattern to validate behavior with empty strings, dangerous patterns, and normal patterns. - Created glob pattern matching tests to verify regex conversion and matching functionality. - Developed infinite loop risk tests using Worker threads to isolate potential blocking operations. - Introduced optimized contentPattern tests to validate improvements in the findMatches function. - Added verification tests to assess the effectiveness of contentPattern optimizations. - Conducted safety tests for contentPattern to identify edge cases and potential vulnerabilities. - Implemented unrestricted loop tests to analyze infinite loop risks without match limits. - Developed tests for zero-width pattern detection logic to ensure proper handling of dangerous regex patterns.
This commit is contained in:
67
test-direct-tool-call.js
Normal file
67
test-direct-tool-call.js
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 直接测试 read_file 工具的危险模式拦截
|
||||
*/
|
||||
|
||||
import { executeTool } from './ccw/dist/tools/index.js';
|
||||
|
||||
async function testPatterns() {
|
||||
console.log('=== 直接测试 read_file 工具 ===\n');
|
||||
|
||||
// 测试空字符串模式
|
||||
console.log('1. 测试空字符串模式 ""');
|
||||
try {
|
||||
const result = await executeTool('read_file', {
|
||||
paths: 'README.md',
|
||||
contentPattern: '',
|
||||
includeContent: false
|
||||
});
|
||||
console.log('结果:', result.success ? '成功' : '失败');
|
||||
console.log('文件数:', result.result?.files?.length || 0);
|
||||
} catch (error) {
|
||||
console.log('异常:', error.message);
|
||||
}
|
||||
|
||||
// 测试零宽匹配
|
||||
console.log('\n2. 测试零宽匹配 "x*"');
|
||||
try {
|
||||
const result = await executeTool('read_file', {
|
||||
paths: 'README.md',
|
||||
contentPattern: 'x*',
|
||||
includeContent: false
|
||||
});
|
||||
console.log('结果:', result.success ? '成功' : '失败');
|
||||
console.log('文件数:', result.result?.files?.length || 0);
|
||||
} catch (error) {
|
||||
console.log('异常:', error.message);
|
||||
}
|
||||
|
||||
// 测试或空匹配
|
||||
console.log('\n3. 测试或空匹配 "a|"');
|
||||
try {
|
||||
const result = await executeTool('read_file', {
|
||||
paths: 'README.md',
|
||||
contentPattern: 'a|',
|
||||
includeContent: false
|
||||
});
|
||||
console.log('结果:', result.success ? '成功' : '失败');
|
||||
console.log('文件数:', result.result?.files?.length || 0);
|
||||
} catch (error) {
|
||||
console.log('异常:', error.message);
|
||||
}
|
||||
|
||||
// 测试正常模式
|
||||
console.log('\n4. 测试正常模式 "CCW"');
|
||||
try {
|
||||
const result = await executeTool('read_file', {
|
||||
paths: 'README.md',
|
||||
contentPattern: 'CCW',
|
||||
includeContent: false
|
||||
});
|
||||
console.log('结果:', result.success ? '成功' : '失败');
|
||||
console.log('文件数:', result.result?.files?.length || 0);
|
||||
} catch (error) {
|
||||
console.log('异常:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
testPatterns().catch(console.error);
|
||||
Reference in New Issue
Block a user