Skip to content

Commit 0bced08

Browse files
CiCi503cursoragent
andcommitted
feat: add GitHub CI with 95% diff coverage check and GitHub Pages deployment
- Add pytest and coverage configuration files - Create GitHub Actions workflow for automated testing - Implement diff-cover tool to check new code coverage (≥95%) - Auto-deploy coverage reports to GitHub Pages on cap branch - Add test dependencies (pytest, pytest-cov, diff-cover) Change-Id: Iac9579d473b32765a34f412ada2be3cd3944082c Co-developed-by: Cursor <noreply@cursor.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2f2224a commit 0bced08

9 files changed

Lines changed: 2565 additions & 0 deletions

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Test Coverage
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
test-coverage:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code with full history
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Python 3.10
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: '3.10'
25+
cache: 'pip'
26+
27+
- name: Install dependencies
28+
working-directory: src/code/agent
29+
run: |
30+
pip install -r requirements.txt
31+
pip install -r requirements-dev.txt
32+
33+
- name: Run tests with coverage
34+
working-directory: src/code/agent
35+
run: |
36+
pytest --cov=. --cov-report=xml --cov-report=html --cov-report=term
37+
38+
- name: Check diff coverage against cap branch
39+
working-directory: src/code/agent
40+
run: |
41+
diff-cover coverage.xml --compare-branch=origin/cap --fail-under=95
42+
43+
- name: Upload coverage report
44+
if: always()
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: coverage-report
48+
path: src/code/agent/htmlcov/
49+
retention-days: 30
50+
51+
- name: Generate diff coverage HTML report
52+
if: always()
53+
working-directory: src/code/agent
54+
run: |
55+
diff-cover coverage.xml --compare-branch=origin/cap --html-report=diff-coverage.html
56+
57+
- name: Upload diff coverage report
58+
if: always()
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: diff-coverage-report
62+
path: src/code/agent/diff-coverage.html
63+
retention-days: 30
64+
65+
- name: Create coverage index page
66+
if: github.ref == 'refs/heads/cap'
67+
working-directory: src/code/agent
68+
run: |
69+
mkdir -p gh-pages-deploy
70+
cp -r htmlcov/* gh-pages-deploy/
71+
cp diff-coverage.html gh-pages-deploy/
72+
cat > gh-pages-deploy/index.html << 'EOF'
73+
<!DOCTYPE html>
74+
<html>
75+
<head>
76+
<meta charset="utf-8">
77+
<title>Coverage Reports - cap-comfyui</title>
78+
<style>
79+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; }
80+
h1 { color: #333; }
81+
.report-card { border: 1px solid #ddd; border-radius: 8px; padding: 20px; margin: 20px 0; background: #f9f9f9; }
82+
.report-card h2 { margin-top: 0; color: #0366d6; }
83+
.report-card a { display: inline-block; margin-top: 10px; padding: 8px 16px; background: #0366d6; color: white; text-decoration: none; border-radius: 4px; }
84+
.report-card a:hover { background: #0256c7; }
85+
.timestamp { color: #666; font-size: 14px; }
86+
</style>
87+
</head>
88+
<body>
89+
<h1>Coverage Reports - cap-comfyui Agent</h1>
90+
<p class="timestamp">Last updated: $(date -u +"%Y-%m-%d %H:%M:%S UTC")</p>
91+
92+
<div class="report-card">
93+
<h2>📊 Full Coverage Report</h2>
94+
<p>Complete test coverage report for all source code in src/code/agent/</p>
95+
<a href="htmlcov/index.html">View Full Coverage Report</a>
96+
</div>
97+
98+
<div class="report-card">
99+
<h2>📈 Diff Coverage Report</h2>
100+
<p>Coverage report for code changes compared to the cap branch</p>
101+
<a href="diff-coverage.html">View Diff Coverage Report</a>
102+
</div>
103+
104+
<div class="report-card">
105+
<h2>ℹ️ About</h2>
106+
<p>These reports are automatically generated by GitHub Actions on every push to the cap branch.</p>
107+
<p>Diff coverage threshold: ≥ 95%</p>
108+
</div>
109+
</body>
110+
</html>
111+
EOF
112+
113+
- name: Deploy to GitHub Pages
114+
if: github.ref == 'refs/heads/cap'
115+
uses: peaceiris/actions-gh-pages@v3
116+
with:
117+
github_token: ${{ secrets.GITHUB_TOKEN }}
118+
publish_dir: src/code/agent/gh-pages-deploy
119+
keep_files: false

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@
66
**/dist
77
.DS_Store
88
.vscode/settings.json
9+
10+
# Coverage reports
11+
**/.coverage
12+
**/.coverage.*
13+
**/coverage.xml
14+
**/htmlcov/
15+
**/diff-coverage.html
16+
**/gh-pages-deploy/
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# 背景
2+
文件名:2026-02-25_1_github-ci-coverage.md
3+
创建于:2026-02-25_17:00:00
4+
创建者:cici
5+
主分支:cap
6+
任务分支:task/github-ci-coverage_2026-02-25_1
7+
功能名称:github-ci-coverage
8+
Yolo模式:Off
9+
10+
# 任务描述
11+
setup 一个 github ci,要求新增代码的测试覆盖率高于 95%
12+
13+
具体要求:
14+
1. 测试执行目录:src/code/agent
15+
2. 覆盖率范围:仅 src/code/agent 目录
16+
3. 基准分支:cap
17+
4. CI 触发条件:每次 push 都运行
18+
5. 新增代码覆盖率阈值:≥ 95%
19+
20+
# 项目概览
21+
- Python 版本: 3.10.16
22+
- 测试框架: pytest + coverage.py v7.13.4
23+
- 当前整体覆盖率: 77%
24+
- 测试文件: 18 个单元测试文件位于 test/unit/ 目录
25+
- 项目类型: Flask 应用,包含 WebSocket、进程管理、任务管理等功能
26+
- 依赖管理: requirements.txt (需要新增测试依赖文件)
27+
28+
# 文档结构
29+
本任务相关的文档:
30+
- 设计文档:`docs/github-ci-coverage/design.md` (INNOVATE 阶段创建)
31+
- 开发文档:`docs/github-ci-coverage/development.md` (PLAN 阶段创建)
32+
- 测试文档:`docs/github-ci-coverage/cases.md` (PLAN 阶段创建)
33+
34+
⚠️ 警告:永远不要修改此部分 ⚠️
35+
# RIPER-5 协议规则摘要
36+
37+
## 模式流程
38+
RESEARCH → INNOVATE → PLAN → EXECUTE → REVIEW
39+
40+
## 核心原则
41+
- 每个响应必须声明当前模式:[MODE: MODE_NAME]
42+
- 未经明确信号不得转换模式
43+
- EXECUTE 模式必须 100% 遵循计划
44+
- REVIEW 模式必须标记任何偏差
45+
- 禁止在未经请求时实施更改
46+
47+
## 模式职责
48+
- RESEARCH: 只读、分析、提问
49+
- INNOVATE: 设计方案、评估优劣、创建 design.md
50+
- PLAN: 详细规划、创建 development.md 和 cases.md
51+
- EXECUTE: 严格按计划实施、更新任务进度
52+
- REVIEW: 验证符合度、准备提交
53+
⚠️ 警告:永远不要修改此部分 ⚠️
54+
55+
# 分析 (RESEARCH 阶段)
56+
## 代码结构分析
57+
- 测试代码位于: src/code/agent/test/unit/
58+
- 18 个测试文件覆盖 utils、services、gateway 等模块
59+
- 使用 pytest fixture 和 mock 进行单元测试
60+
- 已有 htmlcov 目录,说明本地已运行过覆盖率测试
61+
62+
## 现有配置缺失
63+
- 无 .github/workflows/ CI 配置
64+
- 无 pytest.ini 或 pyproject.toml
65+
- 无 .coveragerc 覆盖率配置
66+
- requirements.txt 未包含测试依赖
67+
68+
## 技术约束
69+
- Python 3.10.16
70+
- 使用 pytest + coverage.py v7.13.4
71+
- 需要支持差异覆盖率计算(diff-cover)
72+
- 工作目录: src/code/agent
73+
- 基准分支: cap
74+
75+
## 关键需求
76+
- **差异覆盖率**: 不是检查整体覆盖率,而是仅检查新增/修改代码的覆盖率
77+
- **失败条件**: 当新增代码覆盖率 < 95% 时,CI 应该失败
78+
- **触发频率**: 每次 push 都运行(不仅限于 PR)
79+
80+
# 提议的解决方案 (INNOVATE 阶段)
81+
82+
## 推荐方案:diff-cover 工具方案
83+
84+
采用 **diff-cover** 专业工具实现差异覆盖率检查,这是专门为"仅检查新增代码覆盖率"设计的工具。
85+
86+
### 技术架构
87+
- **测试框架**: pytest + pytest-cov
88+
- **覆盖率工具**: coverage.py(生成 XML 报告)
89+
- **差异分析**: diff-cover(对比 cap 分支)
90+
- **CI 平台**: GitHub Actions
91+
92+
### 核心工作流
93+
1. Checkout 代码(完整 git 历史)
94+
2. 设置 Python 3.10 环境
95+
3. 安装依赖(requirements.txt + requirements-dev.txt)
96+
4. 运行 pytest 生成覆盖率数据(XML + HTML + Terminal)
97+
5. 运行 diff-cover 对比 cap 分支,阈值 95%
98+
6. 失败时 CI 返回非零退出码
99+
100+
### 需要创建的文件
101+
- `.github/workflows/test-coverage.yml` - GitHub Actions 配置
102+
- `src/code/agent/requirements-dev.txt` - 测试依赖
103+
- `src/code/agent/pytest.ini` - pytest 配置
104+
- `src/code/agent/.coveragerc` - 覆盖率配置
105+
- 更新 `.gitignore` - 排除覆盖率文件
106+
107+
### 方案优势
108+
✅ 专业工具,专门用于差异覆盖率
109+
✅ 与现有 pytest + coverage.py 无缝集成
110+
✅ 开源免费,本地运行,无隐私问题
111+
✅ 成熟稳定(v9.2.4,生产级)
112+
✅ 配置简单,维护成本低
113+
✅ 支持本地模拟 CI 流程
114+
115+
详细设计见:`docs/github-ci-coverage/design.md`
116+
117+
# 实施计划摘要 (PLAN 阶段)
118+
119+
## 开发计划
120+
分为 7 个阶段,21 个具体步骤:
121+
122+
**阶段 1: 测试依赖配置文件创建(3 个文件)**
123+
- requirements-dev.txt:pytest、pytest-cov、diff-cover
124+
- pytest.ini:测试路径、命名模式、默认选项
125+
- .coveragerc:覆盖率源、排除规则、XML 输出
126+
127+
**阶段 2: GitHub Actions 工作流创建(2 个步骤)**
128+
- 创建 .github/workflows/ 目录
129+
- 创建 test-coverage.yml 工作流(10 个 CI 步骤,含 GitHub Pages 部署)
130+
131+
**阶段 3: gitignore 配置更新(1 个修改)**
132+
- 在 .gitignore 追加 6 行覆盖率文件排除规则(含 gh-pages-deploy/)
133+
134+
**阶段 4: GitHub Pages 配置(1 个步骤)**
135+
- 在 GitHub 仓库 Settings > Pages 启用,配置 gh-pages 分支
136+
137+
**阶段 5: 本地验证测试(3 个步骤)**
138+
- 安装测试依赖
139+
- 运行 pytest 生成覆盖率
140+
- 运行 diff-cover 验证工具
141+
142+
**阶段 6: 提交与 CI 验证(5 个步骤)**
143+
- 暂存、提交、推送代码
144+
- 查看 GitHub Actions 运行状态
145+
- 确认 CI 成功
146+
147+
**阶段 7: GitHub Pages 部署验证(6 个步骤)**
148+
- 合并到 cap 分支
149+
- 验证 Pages 部署成功
150+
- 访问并测试覆盖率报告页面
151+
152+
详细内容见:`docs/github-ci-coverage/development.md`
153+
154+
## 测试计划
155+
定义 20 个测试用例,覆盖:
156+
- 配置文件验证(2 个)
157+
- 本地集成测试(3 个)
158+
- CI 集成测试(5 个,含 GitHub Pages 部署和自动更新验证)
159+
- 边界场景测试(5 个)
160+
- 兼容性、性能、安全测试(各 1-2 个)
161+
162+
详细内容见:`docs/github-ci-coverage/cases.md`
163+
164+
# 当前执行步骤
165+
"设计技术方案"
166+
167+
# 任务进度 (EXECUTE 阶段)
168+
[待记录]
169+
170+
# 最终审查 (REVIEW 阶段)
171+
[待完成]

0 commit comments

Comments
 (0)