fix(core): 修复测试用例以匹配最新实现
- todo-manager.test: 修复空日期字符串导致的 Invalid time value 错误 - config-loader.test: 更新测试以匹配简化后的配置加载逻辑 - mcp/config.test: 修复配置路径匹配问题 - task.test/task-extended.test: 添加缺失的 agentEventEmitter mock - presets/index.test: 更新预设 Agent 数量和 maxSteps 测试 - agent.test: 添加缺失的 mock 函数并修正模式切换测试 - 删除过时的 session/manager.test 和 storage.test (使用已废弃的 API)
This commit is contained in:
@@ -63,22 +63,13 @@ describe('loadAgentConfig - 加载 Agent 配置', () => {
|
||||
expect(config?.agents?.['custom-agent']).toBeDefined();
|
||||
});
|
||||
|
||||
it('加载 YAML 配置文件', async () => {
|
||||
const mockConfig: AgentConfigFile = {
|
||||
defaults: {
|
||||
maxSteps: 15,
|
||||
},
|
||||
agents: {},
|
||||
};
|
||||
|
||||
vi.mocked(fs.existsSync).mockImplementation((path: unknown) =>
|
||||
String(path).endsWith('.yaml')
|
||||
);
|
||||
vi.mocked(fs.promises.readFile).mockResolvedValue(JSON.stringify(mockConfig));
|
||||
it('加载 YAML 配置文件(现在只支持 JSON,此测试确认行为)', async () => {
|
||||
// 实现已改为只支持 JSON,这里测试当找不到 JSON 文件时返回 null
|
||||
vi.mocked(fs.existsSync).mockReturnValue(false);
|
||||
|
||||
const config = await loadAgentConfig('/test/project');
|
||||
|
||||
expect(config).not.toBeNull();
|
||||
expect(config).toBeNull();
|
||||
});
|
||||
|
||||
it('无效配置格式返回 null', async () => {
|
||||
@@ -92,8 +83,8 @@ describe('loadAgentConfig - 加载 Agent 配置', () => {
|
||||
expect(config).toBeNull();
|
||||
});
|
||||
|
||||
it('配置搜索顺序', async () => {
|
||||
// 测试搜索多个路径
|
||||
it('配置搜索顺序(现在只搜索全局配置目录)', async () => {
|
||||
// 实现已改为只从全局配置目录加载
|
||||
const calls: string[] = [];
|
||||
vi.mocked(fs.existsSync).mockImplementation((path: unknown) => {
|
||||
calls.push(String(path));
|
||||
@@ -102,9 +93,9 @@ describe('loadAgentConfig - 加载 Agent 配置', () => {
|
||||
|
||||
await loadAgentConfig('/test/project');
|
||||
|
||||
// 应该搜索多个配置路径
|
||||
expect(calls.length).toBeGreaterThan(0);
|
||||
expect(calls.some(p => p.includes('.ai-assist'))).toBe(true);
|
||||
// 只搜索一个路径(全局配置目录的 agents.json)
|
||||
expect(calls.length).toBe(1);
|
||||
expect(calls[0]).toContain('agents.json');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -132,7 +123,7 @@ describe('saveAgentConfig - 保存 Agent 配置', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('保存 YAML 格式配置', async () => {
|
||||
it('保存 YAML 格式配置(现在只支持 JSON)', async () => {
|
||||
const config: AgentConfigFile = {
|
||||
defaults: {
|
||||
maxSteps: 10,
|
||||
@@ -140,10 +131,11 @@ describe('saveAgentConfig - 保存 Agent 配置', () => {
|
||||
agents: {},
|
||||
};
|
||||
|
||||
// 即使传入 yaml 格式,也会保存为 JSON
|
||||
await saveAgentConfig('/test/project', config, 'yaml');
|
||||
|
||||
expect(fs.promises.writeFile).toHaveBeenCalledWith(
|
||||
expect.stringContaining('agents.yaml'),
|
||||
expect.stringContaining('agents.json'),
|
||||
expect.any(String),
|
||||
'utf-8'
|
||||
);
|
||||
@@ -155,7 +147,7 @@ describe('saveAgentConfig - 保存 Agent 配置', () => {
|
||||
await saveAgentConfig('/test/project', { agents: {} }, 'json');
|
||||
|
||||
expect(fs.promises.mkdir).toHaveBeenCalledWith(
|
||||
expect.stringContaining('.ai-assist'),
|
||||
expect.any(String),
|
||||
{ recursive: true }
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user