test: 补充单元测试提升代码覆盖率
新增测试文件: - agent/executor-extended.test.ts, presets/ - context/manager-extended.test.ts - core/agent.test.ts, providers.test.ts - lsp/cli.test.ts, client-extended.test.ts, index.test.ts - permission/file-prompt.test.ts, prompt.test.ts - skills/builtin/ - tools/filesystem/write_file-extended.test.ts - tools/git/git_commit-extended.test.ts - tools/load_description.test.ts - tools/todo/todo-manager.test.ts - tools/tool-search.test.ts - types/ - utils/config-extended.test.ts, diff-extended.test.ts 修改现有测试: - agent/manager.test.ts - tools/skill/skill.test.ts - utils/config.test.ts, diff.test.ts, image.test.ts
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
presetAgents,
|
||||
getPresetAgentNames,
|
||||
isPresetAgent,
|
||||
generalAgent,
|
||||
exploreAgent,
|
||||
codeReviewerAgent,
|
||||
buildAgent,
|
||||
planAgent,
|
||||
visionAgent,
|
||||
} from '../../../../src/agent/presets/index.js';
|
||||
|
||||
describe('Agent Presets - 预设 Agent', () => {
|
||||
describe('presetAgents 集合', () => {
|
||||
it('包含所有预设 Agent', () => {
|
||||
expect(Object.keys(presetAgents)).toHaveLength(6);
|
||||
});
|
||||
|
||||
it('包含 general Agent', () => {
|
||||
expect(presetAgents['general']).toBeDefined();
|
||||
expect(presetAgents['general']).toBe(generalAgent);
|
||||
});
|
||||
|
||||
it('包含 explore Agent', () => {
|
||||
expect(presetAgents['explore']).toBeDefined();
|
||||
expect(presetAgents['explore']).toBe(exploreAgent);
|
||||
});
|
||||
|
||||
it('包含 code-reviewer Agent', () => {
|
||||
expect(presetAgents['code-reviewer']).toBeDefined();
|
||||
expect(presetAgents['code-reviewer']).toBe(codeReviewerAgent);
|
||||
});
|
||||
|
||||
it('包含 build Agent', () => {
|
||||
expect(presetAgents['build']).toBeDefined();
|
||||
expect(presetAgents['build']).toBe(buildAgent);
|
||||
});
|
||||
|
||||
it('包含 plan Agent', () => {
|
||||
expect(presetAgents['plan']).toBeDefined();
|
||||
expect(presetAgents['plan']).toBe(planAgent);
|
||||
});
|
||||
|
||||
it('包含 vision Agent', () => {
|
||||
expect(presetAgents['vision']).toBeDefined();
|
||||
expect(presetAgents['vision']).toBe(visionAgent);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPresetAgentNames - 获取预设名称', () => {
|
||||
it('返回所有预设 Agent 名称', () => {
|
||||
const names = getPresetAgentNames();
|
||||
|
||||
expect(names).toContain('general');
|
||||
expect(names).toContain('explore');
|
||||
expect(names).toContain('code-reviewer');
|
||||
expect(names).toContain('build');
|
||||
expect(names).toContain('plan');
|
||||
expect(names).toContain('vision');
|
||||
});
|
||||
|
||||
it('返回数组类型', () => {
|
||||
const names = getPresetAgentNames();
|
||||
expect(Array.isArray(names)).toBe(true);
|
||||
});
|
||||
|
||||
it('返回正确数量', () => {
|
||||
const names = getPresetAgentNames();
|
||||
expect(names).toHaveLength(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPresetAgent - 检查是否为预设', () => {
|
||||
it('识别 general', () => {
|
||||
expect(isPresetAgent('general')).toBe(true);
|
||||
});
|
||||
|
||||
it('识别 explore', () => {
|
||||
expect(isPresetAgent('explore')).toBe(true);
|
||||
});
|
||||
|
||||
it('识别 code-reviewer', () => {
|
||||
expect(isPresetAgent('code-reviewer')).toBe(true);
|
||||
});
|
||||
|
||||
it('识别 build', () => {
|
||||
expect(isPresetAgent('build')).toBe(true);
|
||||
});
|
||||
|
||||
it('识别 plan', () => {
|
||||
expect(isPresetAgent('plan')).toBe(true);
|
||||
});
|
||||
|
||||
it('识别 vision', () => {
|
||||
expect(isPresetAgent('vision')).toBe(true);
|
||||
});
|
||||
|
||||
it('不识别未知 Agent', () => {
|
||||
expect(isPresetAgent('unknown')).toBe(false);
|
||||
});
|
||||
|
||||
it('不识别空字符串', () => {
|
||||
expect(isPresetAgent('')).toBe(false);
|
||||
});
|
||||
|
||||
it('区分大小写', () => {
|
||||
expect(isPresetAgent('General')).toBe(false);
|
||||
expect(isPresetAgent('GENERAL')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('generalAgent - 通用 Agent', () => {
|
||||
it('有正确的描述', () => {
|
||||
expect(generalAgent.description).toContain('通用');
|
||||
});
|
||||
|
||||
it('mode 为 subagent', () => {
|
||||
expect(generalAgent.mode).toBe('subagent');
|
||||
});
|
||||
|
||||
it('禁止嵌套 Task', () => {
|
||||
expect(generalAgent.tools?.noTask).toBe(true);
|
||||
});
|
||||
|
||||
it('有 maxSteps 限制', () => {
|
||||
expect(generalAgent.maxSteps).toBeDefined();
|
||||
expect(generalAgent.maxSteps).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('exploreAgent - 探索 Agent', () => {
|
||||
it('有描述', () => {
|
||||
expect(exploreAgent.description).toBeDefined();
|
||||
});
|
||||
|
||||
it('mode 为 subagent', () => {
|
||||
expect(exploreAgent.mode).toBe('subagent');
|
||||
});
|
||||
});
|
||||
|
||||
describe('codeReviewerAgent - 代码审查 Agent', () => {
|
||||
it('有描述', () => {
|
||||
expect(codeReviewerAgent.description).toBeDefined();
|
||||
});
|
||||
|
||||
it('mode 为 subagent', () => {
|
||||
expect(codeReviewerAgent.mode).toBe('subagent');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildAgent - 构建 Agent', () => {
|
||||
it('有描述', () => {
|
||||
expect(buildAgent.description).toBeDefined();
|
||||
});
|
||||
|
||||
it('mode 为 primary(主模式)', () => {
|
||||
expect(buildAgent.mode).toBe('primary');
|
||||
});
|
||||
});
|
||||
|
||||
describe('planAgent - 计划 Agent', () => {
|
||||
it('有描述', () => {
|
||||
expect(planAgent.description).toBeDefined();
|
||||
});
|
||||
|
||||
it('mode 为 primary(主模式)', () => {
|
||||
expect(planAgent.mode).toBe('primary');
|
||||
});
|
||||
});
|
||||
|
||||
describe('visionAgent - 视觉 Agent', () => {
|
||||
it('有描述', () => {
|
||||
expect(visionAgent.description).toBeDefined();
|
||||
});
|
||||
|
||||
it('mode 为 subagent', () => {
|
||||
expect(visionAgent.mode).toBe('subagent');
|
||||
});
|
||||
});
|
||||
|
||||
describe('所有预设 Agent 共同特性', () => {
|
||||
it('都有 description', () => {
|
||||
Object.entries(presetAgents).forEach(([name, agent]) => {
|
||||
expect(agent.description, `${name} 缺少 description`).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('都有 mode', () => {
|
||||
Object.entries(presetAgents).forEach(([name, agent]) => {
|
||||
expect(agent.mode, `${name} 缺少 mode`).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('mode 值是 subagent 或 primary', () => {
|
||||
Object.entries(presetAgents).forEach(([name, agent]) => {
|
||||
expect(['subagent', 'primary'], `${name} mode 无效`).toContain(agent.mode);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user