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:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { skillTool } from '../../../../src/tools/skill/skill.js';
|
||||
import { skillTool, updateSkillDescription } from '../../../../src/tools/skill/skill.js';
|
||||
import { getSkillRegistry, resetSkillRegistry } from '../../../../src/skills/registry.js';
|
||||
import type { Skill } from '../../../../src/skills/types.js';
|
||||
|
||||
@@ -144,4 +144,62 @@ describe('skillTool - Skill 工具', () => {
|
||||
expect(result.metadata?.source).toBe('builtin');
|
||||
});
|
||||
});
|
||||
|
||||
describe('工具描述', () => {
|
||||
it('更新后描述包含可用 Skill 列表', () => {
|
||||
// beforeEach 中已初始化 registry,现在更新描述
|
||||
updateSkillDescription();
|
||||
|
||||
expect(skillTool.description).toContain('code-review');
|
||||
expect(skillTool.description).toContain('代码审查');
|
||||
});
|
||||
|
||||
it('更新后描述包含分类信息', () => {
|
||||
updateSkillDescription();
|
||||
expect(skillTool.description).toContain('[development]');
|
||||
});
|
||||
|
||||
it('更新后描述包含使用示例', () => {
|
||||
updateSkillDescription();
|
||||
expect(skillTool.description).toContain('使用示例');
|
||||
expect(skillTool.description).toContain('skill_name');
|
||||
});
|
||||
|
||||
it('禁用的 Skill 不在描述中', () => {
|
||||
updateSkillDescription();
|
||||
expect(skillTool.description).not.toContain('disabled-skill');
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateSkillDescription', () => {
|
||||
it('调用后描述被更新', async () => {
|
||||
updateSkillDescription();
|
||||
|
||||
// 描述应该包含当前注册的 Skill
|
||||
expect(skillTool.description).toContain('code-review');
|
||||
expect(typeof skillTool.description).toBe('string');
|
||||
});
|
||||
});
|
||||
|
||||
describe('边界情况', () => {
|
||||
it('params 为 undefined 时使用空对象', async () => {
|
||||
const result = await skillTool.execute({
|
||||
skill_name: 'code-review',
|
||||
// 不提供 params
|
||||
});
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.error).toContain('缺少必需参数');
|
||||
});
|
||||
|
||||
it('skill_name 为空字符串时返回错误', async () => {
|
||||
const result = await skillTool.execute({
|
||||
skill_name: '',
|
||||
params: {},
|
||||
});
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.error).toContain('不存在');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user