Skip to content

Commit ce87938

Browse files
authored
test: add unit tests for mcp-config and detector modules (#5)
- Add 9 tests for mcp-config.ts (multi-IDE, edge cases, path validation) - Add 1 test for detector.ts (checkAllDependencies integration) - Improve coverage: detector.ts 3.27% → 68.85%, mcp-config.ts 24.34% → 33.55% - Total tests: 128 → 138 (all passing) - Update test summary in _bmad-output
1 parent e0c5f1b commit ce87938

3 files changed

Lines changed: 163 additions & 181 deletions

File tree

Lines changed: 71 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -1,208 +1,99 @@
11
# Test Automation Summary
22

33
**Generated**: 2026-02-03
4-
**Project**: openmemory-plus CLI
54
**Framework**: Vitest v4.0.18
5+
**Project**: openmemory-plus CLI
66

77
## Generated Tests
88

99
### Unit Tests
1010

11-
| File | Tests | Status | Description |
12-
|------|-------|--------|-------------|
13-
| ✅ tests/platform.test.ts | 18 | NEW | Platform utilities - getPlatform, isTTY, isCI, safeExec, waitForService, isPortInUse |
14-
15-
### Existing Tests
16-
17-
| File | Tests | Status | Description |
18-
|------|-------|--------|-------------|
19-
| ✅ tests/decay.test.ts | 15 | Existing | Memory decay system |
20-
| ✅ tests/graph.test.ts | 12 | Existing | Graph memory system |
21-
| ✅ tests/deps.test.ts | 11 | Existing | Dependencies command |
22-
| ✅ tests/install.test.ts | 9 | Existing | Install command |
23-
| ✅ tests/status.test.ts | 9 | Existing | Status command |
24-
| ✅ tests/cli.test.ts | 7 | Existing | CLI entry point |
25-
| ✅ tests/doctor.test.ts | 6 | Existing | Doctor command |
26-
| ✅ tests/detector.test.ts | 6 | Existing | Dependency detector |
27-
28-
## Coverage Report
29-
30-
### Before QA Automation
31-
32-
| Metric | Value |
33-
|--------|-------|
34-
| Statements | 16.08% |
35-
| Branches | 14.61% ❌ |
36-
| Functions | 25.66% |
37-
| Lines | 16.03% |
38-
39-
### After QA Automation
40-
41-
| Metric | Value | Change |
42-
|--------|-------|--------|
43-
| Statements | 21.87% | +5.79% |
44-
| Branches | 19.72% ✅ | +5.11% |
45-
| Functions | 38.05% | +12.39% |
46-
| Lines | 21.73% | +5.70% |
47-
48-
### Module Coverage
49-
50-
| Module | Statements | Branches | Status |
51-
|--------|------------|----------|--------|
52-
| src/lib/memory/ | 96.39% | 86.79% | ✅ Excellent |
53-
| src/lib/platform.ts | 75.00% | 56.41% | ✅ Good (NEW) |
54-
| src/commands/deps.ts | 17.90% | 16.17% | ⚠️ Needs more |
55-
| src/lib/detector.ts | 3.27% | 13.33% | 🔴 Low |
56-
| src/commands/ (others) | 0% | 0% | 🔴 Low |
11+
| File | Tests Added | Description |
12+
|------|-------------|-------------|
13+
| `tests/mcp-config.test.ts` | +9 | MCP configuration edge cases, multi-IDE support, path validation |
14+
| `tests/detector.test.ts` | +1 | checkAllDependencies integration test |
15+
16+
### Test Details
17+
18+
#### mcp-config.test.ts (New Tests)
19+
- [x] `checkMcpConfigured` - should return false for unknown IDE
20+
- [x] `configureMcpForIdes` - should configure multiple IDEs
21+
- [x] `configureMcpForIdes` - should handle mixed valid and invalid IDEs
22+
- [x] `IDE config paths` - should return correct path for cursor
23+
- [x] `IDE config paths` - should return correct path for claude (CLI)
24+
- [x] `IDE config paths` - should return correct path for claude-desktop on darwin
25+
- [x] `IDE config paths` - should return correct path for gemini on darwin
26+
- [x] `configureMcpForIde edge cases` - should handle invalid JSON in existing config
27+
- [x] `configureMcpForIde edge cases` - should create cursor config in correct location
28+
29+
#### detector.test.ts (New Tests)
30+
- [x] `checkAllDependencies` - should return status for all dependencies
31+
32+
## Coverage
33+
34+
### Before
35+
| Module | Statements | Branches | Functions | Lines |
36+
|--------|------------|----------|-----------|-------|
37+
| All files | 23.12% | 22.74% | 36.00% | 22.99% |
38+
| detector.ts | 3.27% | 13.33% | 10.00% | 3.33% |
39+
| mcp-config.ts | 24.34% | 21.50% | 25.00% | 24.66% |
40+
41+
### After
42+
| Module | Statements | Branches | Functions | Lines |
43+
|--------|------------|----------|-----------|-------|
44+
| All files | **27.67%** | **25.49%** | **45.33%** | **27.65%** |
45+
| detector.ts | **68.85%** | **44.44%** | **100%** | **70.00%** |
46+
| mcp-config.ts | **33.55%** | **25.80%** | **42.85%** | **34.00%** |
47+
48+
### Improvement Summary
49+
- **Total coverage**: +4.55% (23.12% → 27.67%)
50+
- **detector.ts**: +65.58% (3.27% → 68.85%)
51+
- **mcp-config.ts**: +9.21% (24.34% → 33.55%)
52+
- **src/lib overall**: +16.21% (41.44% → 57.65%)
5753

5854
## Test Results
5955

6056
```
6157
✓ tests/status.test.ts (9 tests)
6258
✓ tests/doctor.test.ts (6 tests)
63-
✓ tests/detector.test.ts (6 tests)
59+
✓ tests/providers.test.ts (22 tests)
6460
✓ tests/graph.test.ts (12 tests)
6561
✓ tests/decay.test.ts (15 tests)
62+
✓ tests/mcp-config.test.ts (18 tests) ← +9 new
6663
✓ tests/deps.test.ts (11 tests)
67-
✓ tests/platform.test.ts (18 tests) ← NEW
64+
✓ tests/detector.test.ts (7 tests) ← +1 new
65+
✓ tests/platform.test.ts (18 tests)
6866
✓ tests/cli.test.ts (7 tests)
69-
✓ tests/install.test.ts (9 tests)
67+
✓ tests/install.test.ts (13 tests)
7068
71-
Test Files: 9 passed (9)
72-
Tests: 93 passed (93)
73-
Duration: 2.35s
69+
Test Files: 11 passed
70+
Tests: 138 passed (was 128)
71+
Duration: ~114s
7472
```
7573

76-
## Key Achievements
77-
78-
1.**Branch coverage threshold met**: 19.72% > 15% required
79-
2.**New test file created**: `platform.test.ts` with 18 tests
80-
3.**Platform utilities now tested**: getPlatform, isTTY, isCI, safeExec, waitForService, isPortInUse
81-
4.**All 93 tests passing**
82-
8374
## Next Steps
8475

85-
1. Add more tests for `detector.ts` to improve coverage
86-
2. Add integration tests for command modules (install, status, doctor)
87-
3. Consider mocking external dependencies (Docker, Ollama) for isolated testing
88-
4. Set up CI/CD pipeline with test coverage gates
89-
90-
## Commands
91-
92-
```bash
93-
# Run all tests
94-
npm test
95-
96-
# Run with coverage
97-
npm run test:coverage
98-
99-
# Watch mode
100-
npm run test:watch
101-
```
76+
1. ✅ Run tests in CI (already configured in `prepublishOnly`)
77+
2. Consider adding more edge case tests for:
78+
- `src/commands/install.ts` (0% coverage)
79+
- `src/commands/status.ts` (0% coverage)
80+
- `src/commands/doctor.ts` (0% coverage)
81+
3. Add E2E tests for full CLI workflow
82+
83+
## Validation Checklist
84+
85+
- [x] Tests use standard test framework APIs (Vitest)
86+
- [x] Tests cover happy path
87+
- [x] Tests cover error cases (invalid IDE, invalid JSON)
88+
- [x] All generated tests run successfully
89+
- [x] Tests use proper assertions
90+
- [x] Tests have clear descriptions
91+
- [x] No hardcoded waits or sleeps
92+
- [x] Tests are independent (no order dependency)
93+
- [x] Test summary created
94+
- [x] Tests saved to appropriate directories
95+
- [x] Summary includes coverage metrics
10296

10397
---
10498

10599
**Done!** Tests generated and verified. ✅
106-
107-
**项目**: openmemory-plus
108-
**日期**: 2026-02-02
109-
**测试框架**: Vitest v4.0.18
110-
**执行模式**: YOLO (自动化)
111-
112-
---
113-
114-
## 📊 测试结果
115-
116-
| 指标 | 数值 |
117-
|------|------|
118-
| 测试文件 | 7 |
119-
| 测试用例 | 62 |
120-
| 通过 | 62 ✅ |
121-
| 失败 | 0 |
122-
| 执行时间 | ~2s |
123-
124-
---
125-
126-
## 📁 Generated Tests
127-
128-
### 新增测试文件
129-
130-
| 文件 | 测试数 | 状态 |
131-
|------|--------|------|
132-
| `tests/doctor.test.ts` | 6 | ✅ 新增 |
133-
| `tests/status.test.ts` | 9 | ✅ 新增 |
134-
| `tests/cli.test.ts` | 7 | ✅ 新增 |
135-
136-
### 现有测试文件
137-
138-
| 文件 | 测试数 | 状态 |
139-
|------|--------|------|
140-
| `tests/detector.test.ts` | 6 | ✅ 通过 |
141-
| `tests/decay.test.ts` | 15 | ✅ 通过 |
142-
| `tests/graph.test.ts` | 12 | ✅ 通过 |
143-
| `tests/install.test.ts` | 7 | ✅ 通过 |
144-
145-
---
146-
147-
## 📈 Coverage Report
148-
149-
| 模块 | Statements | Branches | Functions | Lines |
150-
|------|------------|----------|-----------|-------|
151-
| **src/lib/memory** | 96.39% | 86.79% | 100% | 99.03% |
152-
| src/lib/memory/decay.ts | 97.22% | 96.15% | 100% | 97.14% |
153-
| src/lib/memory/graph.ts | 95.94% | 77.77% | 100% | 100% |
154-
| src/lib/memory/types.ts | 100% | 100% | 100% | 100% |
155-
| **src/lib** | 4.08% | 26.08% | 10% | 4.16% |
156-
| src/lib/detector.ts | 4.08% | 26.08% | 10% | 4.16% |
157-
| **src/commands** | 0% | 0% | 0% | 0% |
158-
| **Overall** | 24.88% | 26.94% | 39.34% | 24.64% |
159-
160-
### 覆盖率说明
161-
162-
- **Memory 模块**: 高覆盖率 (96%+),核心逻辑已充分测试
163-
- **Commands 模块**: 低覆盖率,因为测试通过 CLI 集成测试而非单元测试
164-
- **Detector 模块**: 低覆盖率,因为依赖外部系统 (Docker, Ollama)
165-
166-
---
167-
168-
## 🧪 测试类型
169-
170-
### 单元测试
171-
- [x] `detector.test.ts` - 依赖检测逻辑
172-
- [x] `decay.test.ts` - 记忆衰减算法
173-
- [x] `graph.test.ts` - 知识图谱存储
174-
- [x] `doctor.test.ts` - 问题诊断逻辑
175-
- [x] `status.test.ts` - 状态格式化逻辑
176-
177-
### 集成测试
178-
- [x] `install.test.ts` - 安装命令 E2E
179-
- [x] `cli.test.ts` - CLI 入口点 E2E
180-
181-
---
182-
183-
## 🔧 运行命令
184-
185-
```bash
186-
# 运行所有测试
187-
cd cli && npm test
188-
189-
# 运行测试并生成覆盖率
190-
cd cli && npm run test:coverage
191-
192-
# 监听模式
193-
cd cli && npm run test:watch
194-
```
195-
196-
---
197-
198-
## 📋 Next Steps
199-
200-
1. **提高 Commands 覆盖率**: 添加更多 mock 测试
201-
2. **添加 E2E 测试**: 测试完整用户流程
202-
3. **CI 集成**: 在 GitHub Actions 中运行测试
203-
4. **性能测试**: 测试大量记忆的处理性能
204-
205-
---
206-
207-
*由 Quinn QA Automate 生成*
208-

cli/tests/detector.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2-
import { isSystemReady, type SystemStatus } from '../src/lib/detector.js';
2+
import { isSystemReady, checkAllDependencies, type SystemStatus } from '../src/lib/detector.js';
33

44
describe('detector', () => {
5+
describe('checkAllDependencies', () => {
6+
it('should return status for all dependencies', async () => {
7+
const status = await checkAllDependencies();
8+
9+
// Verify all dependency keys exist
10+
expect(status).toHaveProperty('docker');
11+
expect(status).toHaveProperty('ollama');
12+
expect(status).toHaveProperty('qdrant');
13+
expect(status).toHaveProperty('openmemory');
14+
expect(status).toHaveProperty('bgeM3');
15+
16+
// Verify each has required properties
17+
expect(status.docker).toHaveProperty('name');
18+
expect(status.docker).toHaveProperty('installed');
19+
expect(status.ollama).toHaveProperty('name');
20+
expect(status.ollama).toHaveProperty('installed');
21+
});
22+
});
23+
524
describe('isSystemReady', () => {
625
it('should return true when all dependencies are ready', () => {
726
const status: SystemStatus = {

cli/tests/mcp-config.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,78 @@ describe('mcp-config', () => {
155155
expect(configured).toBe(true);
156156
expect(path).toContain('.augment');
157157
});
158+
159+
it('should return false for unknown IDE', () => {
160+
const { configured, path } = checkMcpConfigured('unknown_ide');
161+
expect(configured).toBe(false);
162+
expect(path).toBe('');
163+
});
164+
});
165+
166+
describe('configureMcpForIdes', () => {
167+
it('should configure multiple IDEs', async () => {
168+
const { configureMcpForIdes } = await import('../src/lib/mcp-config.js');
169+
const results = configureMcpForIdes(['augment', 'cursor']);
170+
171+
expect(results.size).toBe(2);
172+
expect(results.get('augment')?.success).toBe(true);
173+
expect(results.get('cursor')?.success).toBe(true);
174+
});
175+
176+
it('should handle mixed valid and invalid IDEs', async () => {
177+
const { configureMcpForIdes } = await import('../src/lib/mcp-config.js');
178+
const results = configureMcpForIdes(['augment', 'invalid_ide']);
179+
180+
expect(results.size).toBe(2);
181+
expect(results.get('augment')?.success).toBe(true);
182+
expect(results.get('invalid_ide')?.success).toBe(false);
183+
});
184+
});
185+
186+
describe('IDE config paths', () => {
187+
it('should return correct path for cursor', () => {
188+
const cursorConfig = IDE_MCP_CONFIGS.cursor;
189+
expect(cursorConfig.getConfigPath()).toContain('.cursor');
190+
expect(cursorConfig.getConfigPath()).toContain('mcp.json');
191+
});
192+
193+
it('should return correct path for claude (CLI)', () => {
194+
const claudeConfig = IDE_MCP_CONFIGS.claude;
195+
expect(claudeConfig.getConfigPath()).toContain('.claude.json');
196+
});
197+
198+
it('should return correct path for claude-desktop on darwin', () => {
199+
const claudeDesktopConfig = IDE_MCP_CONFIGS['claude-desktop'];
200+
const path = claudeDesktopConfig.getConfigPath();
201+
// On darwin (mocked), should be in Library/Application Support
202+
expect(path).toContain('claude_desktop_config.json');
203+
});
204+
205+
it('should return correct path for gemini on darwin', () => {
206+
const geminiConfig = IDE_MCP_CONFIGS.gemini;
207+
const path = geminiConfig.getConfigPath();
208+
expect(path).toContain('gemini');
209+
expect(path).toContain('gemini_mcp_settings.json');
210+
});
211+
});
212+
213+
describe('configureMcpForIde edge cases', () => {
214+
it('should handle invalid JSON in existing config', () => {
215+
const configPath = IDE_MCP_CONFIGS.augment.getConfigPath();
216+
mkdirSync(join(TEST_HOME, '.augment'), { recursive: true });
217+
writeFileSync(configPath, 'invalid json content');
218+
219+
const result = configureMcpForIde('augment');
220+
// Should create new config since existing is invalid
221+
expect(result.success).toBe(true);
222+
});
223+
224+
it('should create cursor config in correct location', () => {
225+
const result = configureMcpForIde('cursor');
226+
expect(result.success).toBe(true);
227+
expect(result.path).toContain('.cursor');
228+
expect(existsSync(result.path)).toBe(true);
229+
});
158230
});
159231
});
160232

0 commit comments

Comments
 (0)