- Replace PromptCache with new CacheAnalysis and CacheStrategies modules for improved cache management - Add capability detection system to LLMConfig for provider-specific features (OpenAI reasoning, Google thinking mode, prompt cache retention) - Implement cache source tracking (provider-reported vs derived/estimated) in token usage reporting - Add StablePrefixAnalysis and TextOnlyPrefixAnalysis for intelligent message prefix caching - Introduce CacheStrategies with provider-specific implementations (OpenAI, Google, Anthropic) - Update RequestCache, RequestExecution, and RequestSettings to use new cache strategy system - Enhance StreamingService, StructuredService, and SyncService with improved cache handling - Add ThinkingStrategy for managing reasoning token budgets across providers - Update MessageConverter to support new cache analysis capabilities - Add ProviderCompatibility checks for cache feature support - Extend ContextStatsContent UI to display cache source information - Add llmCapabilities test suite for provider feature detection - Update agent loop and stream handling for new cache strategy integration - Improve token usage conversion in IPC layer with cache source metadata - Consolidate LLM configuration types and persistence logic
测试目录结构
本目录按照项目模块组织测试文件,确保测试代码清晰易维护。
目录结构
tests/
├── setup.ts # 全局测试配置和 mock
├── README.md # 本文件
│
├── unit/ # 单元测试
│ ├── components/ # UI 组件测试
│ │ ├── ToolCallCard.test.ts
│ │ └── GhostTextWidget.test.ts
│ ├── utils/ # 工具函数测试
│ │ └── pathUtils.test.ts
│ └── shared/ # 共享模块测试
│ └── errors.test.ts
│
├── agent/ # Agent 模块测试
│ ├── core/ # 核心功能
│ │ ├── Agent.test.ts
│ │ ├── loop.test.ts
│ │ ├── stream.test.ts
│ │ └── tools.test.ts
│ ├── context/ # 上下文管理
│ │ ├── ContextManager.test.ts
│ │ ├── CompressionManager.test.ts
│ │ └── compaction.test.ts
│ ├── llm/ # LLM 相关
│ │ ├── MessageBuilder.test.ts
│ │ └── ContextBuilder.test.ts
│ ├── tools/ # 工具执行
│ │ ├── toolDefinitions.test.ts
│ │ ├── toolRegistry.test.ts
│ │ └── executors/
│ │ ├── file.test.ts
│ │ ├── command.test.ts
│ │ └── replace_file_content.test.ts
│ ├── store/ # 状态管理
│ │ ├── AgentStore.test.ts
│ │ ├── threadSlice.test.ts
│ │ └── messageSlice.test.ts
│ └── services/ # Agent 服务
│ ├── lintService.test.ts
│ └── gitService.test.ts
│
├── services/ # 渲染进程服务测试
│ ├── lspService.test.ts
│ ├── completionService.test.ts
│ ├── mcpService.test.ts
│ ├── WorkspaceManager.test.ts
│ └── diagnosticsStore.test.ts
│
├── main/ # 主进程测试
│ ├── security/
│ │ └── securityManager.test.ts
│ ├── services/
│ │ └── llm/
│ │ └── providers.test.ts
│ └── indexing/
│ └── treeSitter.test.ts
│
├── integration/ # 集成测试
│ ├── agent-workflow.test.ts
│ ├── file-operations.test.ts
│ └── llm-integration.test.ts
│
└── e2e/ # 端到端测试
├── chat-flow.test.ts
└── plan-mode.test.ts
测试类型说明
单元测试 (unit/)
- 测试单个函数、类或组件
- 完全隔离,使用 mock
- 快速执行
模块测试 (agent/, services/, main/)
- 测试模块内的功能
- 可能涉及多个类/函数的交互
- 使用部分 mock
集成测试 (integration/)
- 测试多个模块的协作
- 最小化 mock,使用真实依赖
- 测试完整的工作流
端到端测试 (e2e/)
- 测试完整的用户场景
- 不使用 mock
- 最接近真实使用
命名规范
- 测试文件名:
[模块名].test.ts - 属性测试:
[模块名].property.test.ts - 性能测试:
[模块名].perf.test.ts - 快照测试:
[模块名].snap.test.ts
运行测试
# 运行所有测试
npm test
# 运行特定模块
npm test agent/
npm test services/
# 运行单个文件
npm test agent/core/Agent.test.ts
# 监听模式
npm run test:watch
# 覆盖率报告
npm run test:coverage