refactor(server): 消除与 Core 的重复类型定义

- 删除 Server 中 60+ 个与 Core 重复的类型定义
- 将动态导入 (await import) 改为静态类型导入 (import type)
- 保留必要的运行时静态导入
- 修复测试文件中的 mock 初始化问题
- 净删除约 960 行重复代码

重构文件:
- routes/checkpoints.ts: 删除 155 行重复类型
- routes/agents.ts: 删除 93 行重复类型
- routes/commands.ts: 删除 83 行重复类型
- routes/mcp.ts: 修复类型窄化
- routes/hooks.ts: 已使用静态导入
- routes/providers.ts: 删除 63 行重复类型
- session/manager.ts: 删除 41 行重复类型
- routes/sessions.ts: 添加类型导入
- permission/handler.ts: 添加类型导入
This commit is contained in:
2025-12-16 20:19:24 +08:00
parent 026429cb2f
commit 1b7d55848d
14 changed files with 283 additions and 1240 deletions
@@ -35,15 +35,7 @@ const mockCommandModule = vi.hoisted(() => ({
createCommandManager: vi.fn(() => mockCommandManager),
}));
// Track if module should be available
let moduleAvailable = true;
vi.mock('@ai-assistant/core', () => {
if (!moduleAvailable) {
throw new Error('Module not found');
}
return mockCommandModule;
});
vi.mock('@ai-assistant/core', () => mockCommandModule);
vi.mock('../../../src/routes/config.js', () => ({
getConfig: vi.fn(() => ({ workdir: '/test/workdir' })),
@@ -58,7 +50,6 @@ app.route('/commands', commandsRouter);
describe('Commands Route', () => {
beforeEach(() => {
vi.clearAllMocks();
moduleAvailable = true;
mockCommandRegistry.list.mockReturnValue([]);
mockCommandRegistry.getStats.mockReturnValue({ total: 0, bySource: {} });
});