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:
@@ -251,5 +251,76 @@ describe('AgentManager - Agent 管理器', () => {
|
||||
// 这里只验证 cleanup 不会崩溃
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
|
||||
it('使用默认 maxAge', async () => {
|
||||
const agentId = await manager.runInBackground(
|
||||
mockAgentInfo,
|
||||
'任务',
|
||||
'执行',
|
||||
mockConfig,
|
||||
{} as any,
|
||||
mockContext
|
||||
);
|
||||
|
||||
// 等待完成
|
||||
await new Promise((r) => setTimeout(r, 300));
|
||||
|
||||
// 使用默认 maxAge(1 小时),不应该清理刚完成的
|
||||
manager.cleanup();
|
||||
|
||||
// Agent 应该还在(因为未超过 1 小时)
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('完成回调', () => {
|
||||
it('多个等待者都收到通知', async () => {
|
||||
const agentId = await manager.runInBackground(
|
||||
mockAgentInfo,
|
||||
'任务',
|
||||
'执行',
|
||||
mockConfig,
|
||||
{} as any,
|
||||
mockContext
|
||||
);
|
||||
|
||||
// 并发等待
|
||||
const [result1, result2] = await Promise.all([
|
||||
manager.getAgentOutput(agentId, true, 5),
|
||||
manager.getAgentOutput(agentId, true, 5),
|
||||
]);
|
||||
|
||||
expect(result1).not.toBeNull();
|
||||
expect(result2).not.toBeNull();
|
||||
expect(result1!.id).toBe(agentId);
|
||||
expect(result2!.id).toBe(agentId);
|
||||
});
|
||||
});
|
||||
|
||||
describe('已完成 Agent 的阻塞查询', () => {
|
||||
it('已完成的 Agent 阻塞查询立即返回', async () => {
|
||||
const agentId = await manager.runInBackground(
|
||||
mockAgentInfo,
|
||||
'任务',
|
||||
'执行',
|
||||
mockConfig,
|
||||
{} as any,
|
||||
mockContext
|
||||
);
|
||||
|
||||
// 等待完成
|
||||
await manager.getAgentOutput(agentId, true, 5);
|
||||
|
||||
// 再次阻塞查询应立即返回
|
||||
const startTime = Date.now();
|
||||
const result = await manager.getAgentOutput(agentId, true, 10);
|
||||
const elapsed = Date.now() - startTime;
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.status).not.toBe('running');
|
||||
// 应该立即返回,不需要等 10 秒
|
||||
expect(elapsed).toBeLessThan(1000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user