Skip to content

Commit b7b96b0

Browse files
committed
feat: add tests
1 parent bf207c9 commit b7b96b0

47 files changed

Lines changed: 7501 additions & 892 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/plan/add-unit-tests.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# 添加单元测试功能 - 执行计划
2+
3+
## 任务背景
4+
为zcf项目添加完整的单元测试功能,参考taze项目的测试架构,达到90%以上的测试覆盖率。
5+
6+
## 技术选型
7+
- 测试框架:Vitest 3.2.4
8+
- 覆盖率工具:@vitest/coverage-v8
9+
- UI工具:@vitest/ui
10+
11+
## 执行计划
12+
13+
### 阶段1:框架搭建 ✅
14+
- [x] 安装Vitest及相关依赖
15+
- [x] 创建vitest.config.ts配置文件
16+
- [x] 更新package.json测试脚本
17+
- [x] 创建测试目录结构
18+
19+
### 阶段2:工具函数测试
20+
需要创建以下测试文件:
21+
- [ ] test/unit/utils/platform.test.ts - 跨平台路径处理
22+
- [ ] test/unit/utils/installer.test.ts - Claude Code安装检测
23+
- [ ] test/unit/utils/config.test.ts - 配置文件管理
24+
- [ ] test/unit/utils/config-operations.test.ts - 配置操作
25+
- [ ] test/unit/utils/config-validator.test.ts - 配置验证
26+
- [ ] test/unit/utils/mcp.test.ts - MCP配置管理
27+
- [ ] test/unit/utils/ai-personality.test.ts - AI个性化配置
28+
- [ ] test/unit/utils/features.test.ts - 功能模块管理
29+
- [ ] test/unit/utils/zcf-config.test.ts - ZCF配置持久化
30+
- [ ] test/unit/utils/prompts.test.ts - 交互提示工具
31+
32+
### 阶段3:命令测试
33+
- [ ] test/unit/commands/init.test.ts - 初始化流程
34+
- [ ] test/unit/commands/update.test.ts - 更新流程
35+
- [ ] test/unit/commands/menu.test.ts - 菜单系统
36+
37+
### 阶段4:CLI测试
38+
- [ ] test/unit/cli.test.ts - 命令行接口
39+
40+
### 阶段5:集成测试
41+
- [ ] test/integration/workflows.test.ts - 工作流集成测试
42+
43+
### 阶段6:E2E测试
44+
- [ ] test/e2e/cli.test.ts - 端到端CLI测试
45+
46+
## 测试覆盖率目标
47+
- 分支覆盖率:90%+
48+
- 函数覆盖率:90%+
49+
- 行覆盖率:90%+
50+
- 语句覆盖率:90%+
51+
52+
## 测试原则
53+
1. 每个测试独立运行,不依赖其他测试
54+
2. 使用mock模拟文件系统和外部依赖
55+
3. 测试覆盖正常路径和异常路径
56+
4. 为交互式命令模拟用户输入
57+
5. 确保测试的可维护性和可读性
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Init Command Test Coverage Enhancement Plan
2+
3+
## Context
4+
The init command is a core feature of ZCF tool that needs comprehensive test coverage. Current coverage is around 77.99% and needs to reach 90%+.
5+
6+
## Task Description
7+
Enhance test coverage for init command by adding missing test cases for uncovered functionality.
8+
9+
## Implementation Plan
10+
11+
### Phase 1: MCP Service Configuration Tests (Highest Priority) ✅
12+
- [x] MCP configuration basic flow
13+
- [x] MCP configuration skip flow
14+
- [x] MCP service requiring API key
15+
- [x] MCP configuration cancellation
16+
- [x] MCP configuration error handling
17+
18+
### Phase 2: API Configuration Enhanced Tests ✅
19+
- [x] API partial modification - URL only
20+
- [x] API partial modification - Key only
21+
- [x] New installation API key configuration
22+
- [x] API action cancellation
23+
- [x] Keep existing API config
24+
25+
### Phase 3: Config Merge Functionality Tests ✅
26+
- [x] Merge configuration option
27+
28+
### Phase 4: Platform-specific and Other Features ✅
29+
- [x] Windows platform MCP configuration
30+
- [x] Force override option
31+
- [x] ZCF config save verification
32+
- [x] MCP service API key cancellation
33+
- [x] Onboarding flag error handling
34+
35+
## Test Strategy
36+
- Add tests incrementally to `init.extended.test.ts`
37+
- Reuse existing mock setup
38+
- Focus on behavior verification, not implementation details
39+
- Ensure test isolation
40+
41+
## Results
42+
- ✅ Coverage increased from 77.99% to 99.22%
43+
- ✅ All critical paths tested
44+
- ✅ Improved code reliability
45+
- Added 21 new test cases covering all major functionality paths

.claude/plan/test-coverage-100.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 测试覆盖率提升到100%执行计划
2+
3+
## 目标
4+
将项目测试覆盖率从 89.41% 提升到 100%,修复所有跳过的测试。
5+
6+
## 当前状态
7+
- 整体覆盖率: 89.41%
8+
- 跳过的测试: 6个
9+
- 主要问题文件:
10+
- init.ts: 55.98%
11+
- types/config.ts: 0%
12+
- mcp.ts: 83.95%
13+
14+
## 执行步骤
15+
16+
### 步骤1: 修复跳过的测试
17+
- [ ] init.test.ts - 5个测试
18+
- [ ] ai-personality.test.ts - 1个测试
19+
20+
### 步骤2: 提升 init.ts 覆盖率
21+
- [ ] 覆盖 152-265 行
22+
- [ ] 覆盖 283-350 行
23+
24+
### 步骤3: 处理 types/config.ts
25+
- [ ] 添加类型守卫或排除配置
26+
27+
### 步骤4: 提升其他文件覆盖率
28+
- [ ] mcp.ts: 96-115 行
29+
- [ ] ai-personality.ts: 136-138, 164-165 行
30+
- [ ] json-config.ts: 97-100, 129-130 行
31+
32+
### 步骤5: 提升分支覆盖率
33+
- [ ] zcf-config.ts
34+
- [ ] config-operations.ts
35+
- [ ] features.ts
36+
37+
## 进度追踪
38+
开始时间: 2024-08-07

.claude/plan/test-file-merge.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# 测试文件合并计划
2+
3+
## 背景
4+
项目中存在多个源文件对应多个测试文件的情况,导致维护困难。需要按照测试深度分层的方案重新组织测试文件。
5+
6+
## 目标
7+
- 保持测试规范性和可读性
8+
- 维持高测试覆盖率(98%+)
9+
- 每个源文件最多对应 2-3 个测试文件
10+
11+
## 组织原则
12+
1. `*.test.ts` - 核心功能测试(必需)
13+
2. `*.edge.test.ts` - 边界案例和错误处理(可选)
14+
3. `*.integration.test.ts` - 集成场景测试(可选)
15+
16+
## 合并映射关系
17+
18+
### 需要合并的文件列表
19+
1. config-operations (5个文件)
20+
2. features (4个文件)
21+
3. ai-personality (2个文件)
22+
4. config (2个文件)
23+
5. json-config (2个文件)
24+
6. mcp (2个文件)
25+
7. zcf-config (2个文件)
26+
8. init (2个文件)
27+
9. menu (2个文件)
28+
29+
## 执行步骤
30+
1. 创建合并脚本
31+
2. 按模块逐个合并
32+
3. 验证测试覆盖率
33+
4. 清理旧文件
34+
5. 更新配置

.github/workflows/ci.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,15 @@ jobs:
5353
- name: Build package
5454
run: pnpm build
5555

56-
- name: Test build
57-
run: pnpm test
56+
- name: Run tests with coverage
57+
run: pnpm test:coverage
58+
59+
- name: Upload coverage reports
60+
if: matrix.os == 'ubuntu-latest' && matrix.node-version == 20
61+
uses: codecov/codecov-action@v4
62+
with:
63+
token: ${{ secrets.CODECOV_TOKEN }}
64+
directory: ./coverage
65+
flags: unit-tests
66+
name: zcf-coverage
67+
fail_ci_if_error: false

.gitignore

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,28 @@ dist
88
!.env.example
99
package-lock.json
1010
yarn.lock
11-
test.mjs
11+
test.mjs
12+
13+
# Test coverage reports
14+
coverage
15+
.nyc_output
16+
*.lcov
17+
.coverage
18+
19+
# IDE
20+
.vscode/*
21+
!.vscode/settings.json
22+
!.vscode/extensions.json
23+
.idea
24+
25+
# Test artifacts
26+
*.test.tmp
27+
*.spec.tmp
28+
test-results
29+
junit.xml
30+
31+
# Vitest
32+
.vitest-result.json
33+
34+
# Test temporary output files
35+
*-output.txt

0 commit comments

Comments
 (0)