feat: 添加DACP服务支持,允许通过命令行调用DACP专业服务,增强AI角色的执行能力,同时更新相关依赖和工具定义。
This commit is contained in:
77
src/tests/e2e/dacp-calculator-e2e.test.js
Normal file
77
src/tests/e2e/dacp-calculator-e2e.test.js
Normal file
@ -0,0 +1,77 @@
|
||||
const DACPCommand = require('../../lib/core/pouch/commands/DACPCommand');
|
||||
|
||||
describe('DACP Calculator E2E Tests', () => {
|
||||
let dacpCommand;
|
||||
|
||||
beforeEach(() => {
|
||||
dacpCommand = new DACPCommand();
|
||||
});
|
||||
|
||||
test('should successfully calculate simple math expression', async () => {
|
||||
const result = await dacpCommand.execute({
|
||||
service_id: 'dacp-promptx-service',
|
||||
action: 'calculate',
|
||||
parameters: {
|
||||
user_request: '2加3等于多少'
|
||||
}
|
||||
});
|
||||
|
||||
// 验证DACP协议响应格式
|
||||
expect(result).toHaveProperty('request_id');
|
||||
expect(result).toHaveProperty('success', true);
|
||||
expect(result).toHaveProperty('data');
|
||||
|
||||
// 验证计算结果
|
||||
expect(result.data.execution_result).toMatchObject({
|
||||
expression: '2+3',
|
||||
result: 5,
|
||||
formatted_result: '2+3 = 5',
|
||||
calculation_type: 'addition'
|
||||
});
|
||||
});
|
||||
|
||||
test('should handle complex calculations', async () => {
|
||||
const result = await dacpCommand.execute({
|
||||
service_id: 'dacp-promptx-service',
|
||||
action: 'calculate',
|
||||
parameters: {
|
||||
user_request: '(10 + 5) * 2 - 8 / 4'
|
||||
}
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.data.execution_result).toMatchObject({
|
||||
expression: '(10 + 5) * 2 - 8 / 4',
|
||||
result: 28,
|
||||
formatted_result: '(10 + 5) * 2 - 8 / 4 = 28'
|
||||
});
|
||||
});
|
||||
|
||||
test('should handle Chinese operators', async () => {
|
||||
const result = await dacpCommand.execute({
|
||||
service_id: 'dacp-promptx-service',
|
||||
action: 'calculate',
|
||||
parameters: {
|
||||
user_request: '100减去25再乘以2'
|
||||
}
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
// 修正:计算器把它解析为 100-25*2 = 100-50 = 50
|
||||
expect(result.data.execution_result.result).toBe(50);
|
||||
});
|
||||
|
||||
test('should handle calculation errors gracefully', async () => {
|
||||
const result = await dacpCommand.execute({
|
||||
service_id: 'dacp-promptx-service',
|
||||
action: 'calculate',
|
||||
parameters: {
|
||||
user_request: '无效的表达式'
|
||||
}
|
||||
});
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(result).toHaveProperty('error');
|
||||
expect(result.error.code).toBe('EXECUTION_ERROR');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user