Files
MyGoNavi/frontend/src/components/ai/aiLocalToolExecutor.connectionFailureInspection.test.ts
Syngnat 7d1e066997 feat(ai-tools): 新增连接失败诊断探针并接入快捷命令
- 新增基于 gonavi.log 的连接失败总结探针与结构化根因分类\n- 接入 slash 命令、内置工具目录、状态文案和系统提示\n- 补齐本地执行、insight 解析、指令筛选和注册链路测试
2026-06-09 09:45:24 +08:00

53 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it, vi } from 'vitest';
import type { AIToolCall } from '../../types';
import { executeLocalAIToolCall } from './aiLocalToolExecutor';
const buildToolCall = (
name: string,
args: Record<string, unknown>,
): AIToolCall => ({
id: `call-${name}`,
type: 'function',
function: {
name,
arguments: JSON.stringify(args),
},
});
describe('aiLocalToolExecutor inspect_recent_connection_failures', () => {
it('returns a structured snapshot for recent connection failures, cooldown hits, and compatibility errors', async () => {
const result = await executeLocalAIToolCall({
toolCall: buildToolCall('inspect_recent_connection_failures', {
keyword: 'mysql',
lineLimit: 120,
}),
connections: [],
mcpTools: [],
toolContextMap: new Map(),
runtime: {
getDatabases: vi.fn(),
getTables: vi.fn(),
readAppLogTail: vi.fn().mockResolvedValue({
success: true,
data: {
logPath: 'C:/Users/demo/.GoNavi/Logs/gonavi.log',
keyword: 'mysql',
requestedLineLimit: 120,
lines: [
'2026/06/07 15:50:35.000000 [ERROR] 建立数据库连接失败:类型=mysql 地址=127.0.0.1:48749 数据库=(default) 用户=root错误链连接建立后验证失败127.0.0.1:48749 [默认兼容参数] 验证失败: Error 1064 (42000): You have an error in your SQL syntax near \'%2Cutf8\' at line 1',
'2026/06/07 15:50:36.000000 [WARN] 命中数据库连接失败冷却:类型=mysql 地址=127.0.0.1:48749 数据库=(default) 用户=root 剩余=29s 原因=连接建立后验证失败127.0.0.1:48749 [禁用 multiStatements 兼容重试] 验证失败: Error 1064 (42000): You have an error in your SQL syntax near \'%2Cutf8\' at line 1',
],
},
}),
},
});
expect(result.success).toBe(true);
expect(result.content).toContain('"primaryCategory":"parameter_compatibility"');
expect(result.content).toContain('"cooldownHitCount":1');
expect(result.content).toContain('127.0.0.1:48749');
expect(result.content).toContain('multiStatements');
});
});