Skip to content

ci: 在 push / PR 上运行后端测试套件 - #151

Merged
countbot-ai merged 1 commit into
countbot-ai:mainfrom
Liears:ci/run-tests
Oct 30, 2026
Merged

countbot-ai merged 1 commit into
countbot-ai:mainfrom
Liears:ci/run-tests

Conversation

@Liears

@Liears Liears commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

变更说明

仓库只有 .github/workflows/build-desktop.yml(打 tag 时构建 PyInstaller 桌面包),没有任何工作流执行 pytest,所以 main 上同时存在「收集阶段直接中断」和 16 项失败而无人发现(见 #146)。

本 PR:

  1. 新增 .github/workflows/tests.yml
    • 触发:push 到 main + 所有 pull_request + workflow_dispatch
    • 矩阵:ubuntu-latest 与 windows-latest(Windows 是桌面版目标平台,POSIX 假设的回归必须同样暴露),Python 3.12
    • PYTHONIOENCODING=utf-8:中文断言/日志在 Windows 默认代码页下会乱码
  2. 新增 requirements-dev.txt
    -r requirements.txt
    pytest>=8.0
    pytest-asyncio>=0.23
    
    pytest / pytest-asyncio 此前没有声明在任何依赖文件里,贡献者必须自己发现并手装,否则连收集阶段都过不去。

合并顺序说明

这个 PR 单独合并后第一次 CI 会是红的,因为 main 当前还有 16 红 + 1 收集错误。配套修复已经同时提交,建议按下面顺序合并(互不冲突,可分别 review):

PR 关闭 issue 内容
#150 #142 删除引用已删除模块的旧测试,补 backend/modules/compression 覆盖(消除收集错误)
#148 #144 对齐 workspace / provider 路由 / CronJobInfo / 记忆工具的过期断言(10 项)
#149 #145 去掉 shell / 路径断言里的 POSIX 假设(3 项)
#147 #143 取消任务在释放 done_event 前收敛 outcome(2 项)

这四项合并后,本工作流在 ubuntu 与 windows 上应全绿;若仍有失败,就是真的回归——这正是加 CI 的目的。

变更类型

  • 测试相关(CI)

相关 Issue

关闭 #146

测试

  • 本机复现 CI 步骤:.\.venv\Scripts\python.exe -m pip install -r requirements-dev.txt → 解析通过(--dry-run 无冲突)
  • 工作流 YAML 用 PyYAML 解析通过(jobs.pytest 存在)
  • CI 首跑结果(本 PR 触发):ubuntu 与 windows 两条腿都停在同一个收集错误上 —— 正是 [BUG] 全量测试无法收集:tests/test_history_compactor.py 引用已删除模块,compression 包零测试 #142 描述的问题:
    ERROR collecting tests/test_history_compactor.py
    E   ModuleNotFoundError: No module named 'backend.modules.agent.history_compactor'
    !!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
    
    这同时证明了两件事:pip install -r requirements-dev.txt 在 ubuntu / windows 上都能装完(pywebview、pythonnet 等没有阻塞 Linux 安装),且工作流本身可用。
  • 本机 Windows 11 + Python 3.12.10 上的基线:python -m pytest tests -q → 收集阶段中断(1 error);--ignore=tests/test_history_compactor.py → 678 passed / 16 failed。四个修复 PR 合并后(见下方评论)连续两次 python -m pytest tests -q → 708 passed / 0 failed

检查清单

  • 代码遵循项目的代码风格(沿用 build-desktop.yml 的 checkout@v4 / 步骤命名风格)
  • 进行了自我代码审查
  • 添加了必要的注释(矩阵为什么包含 Windows、编码为什么显式指定)
  • 更新了相关文档(新增 requirements-dev.txt,CI 自身即文档)
  • 没有产生新的警告
  • 添加了测试证明修复有效或功能正常工作(CI 跑的就是全套测试)
  • 新的和现有的单元测试都通过(除上表列出的待合并修复)

附加信息

顺带发现但未在本次处理的问题:frontend/package.json 的 build 只跑 vite build,type-check / build:check 闲置,当前有 60 处既有 TS 错误。建议单独开 issue 清理后再纳入 CI,避免本 PR 同时引入一个长期红的前端检查。

The repository only had a tag-triggered desktop build workflow, so nothing
ever executed pytest. That is how a stale test file could abort collection
and sixteen tests could stay red on main with nobody noticing.

Add a Tests workflow (ubuntu + windows, Python 3.12) and declare the test
dependencies in requirements-dev.txt: pytest and pytest-asyncio were not
listed anywhere, so every contributor had to discover and install them by
hand before the suite would even start.
@Liears

Liears commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

合并后验证(本地)

把本工作流依赖的四个修复分支在本地做 octopus merge,然后连续跑两次全量测试:

$ python -m pytest tests -q      # 第 1 次
708 passed, 10 warnings in 26.96s

$ python -m pytest tests -q      # 第 2 次
708 passed, 10 warnings in 26.36s

(环境:Windows 11 + Python 3.12.10,无 --ignore,收集错误已消除。)

合并顺序建议 #150 → #147/#148/#149(任意顺序)→ 本 PR,这样 CI 第一次跑就是绿的。若 #150 先合,本 PR 的 ubuntu/windows 两条腿应直接通过;届时若仍有失败,就是真实回归。

顺带记录一个来自本 PR 首次 CI 的结论:pip install -r requirements-dev.txt 在 ubuntu-latest 与 windows-latest 上都能装完(pywebview / pythonnet 没有阻塞 Linux),所以依赖清单本身不需要为 CI 做平台裁剪。

@countbot-ai
countbot-ai merged commit 522c222 into countbot-ai:main Oct 30, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants