Repository navigation
ci(tests): add PR concurrency cancellation, AST selective pytest runs, and clean up conftest - #11468
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="scripts/select_tests.py" line_range="325" />
<code_context>
+ refs = _extract_module_refs(
+ repo_root / rel,
+ path_to_mod.get(rel, ""),
+ top_level_only=not is_test,
+ )
+ for ref in refs:
</code_context>
<issue_to_address>
**Affected tests are skipped**
When a changed application module is imported only inside production functions or classes, including through lazy dispatch, and at least one other test is statically mapped to the change, `top_level_only=not is_test` makes `_extract_module_refs` omit those imports, so the reverse graph has no edge to tests exercising that path; because another test is mapped, the empty-selection fallback does not run, and PR CI passes without running the affected tests.
Include function- and class-local imports from application modules when building the reverse graph so tests exercising those paths are selected.
Also at `scripts/select_tests.py:137-138`.
</issue_to_address>
### Comment 2
<location path=".github/workflows/tests.yml" line_range="40" />
<code_context>
+ shell: bash
+ env:
+ EVENT_NAME: ${{ github.event_name }}
+ FORCE_FULL: ${{ contains(github.event.pull_request.labels.*.name, 'run-full-tests') || contains(github.event.pull_request.title, '[full-test]') }}
+ run: |
+ if [ "$EVENT_NAME" != "pull_request" ]; then
</code_context>
<issue_to_address>
**Override changes do not rerun tests**
When a contributor adds the override label or edits the PR title after the workflow has already run, the workflow does not subscribe to `labeled` or `edited` pull-request activity types, so adding the `run-full-tests` label or changing the title to include `[full-test]` does not start a run that evaluates `FORCE_FULL`. The documented full-suite override therefore has no effect until another triggering event occurs.
Subscribe to the `labeled` and `edited` pull-request activity types, or remove the claim that these changes trigger a full run and provide another way to rerun the workflow.
</issue_to_address>
### Comment 3
<location path="tests/test_select_tests.py" line_range="22" />
<code_context>
+
+
+def _make_sample_repo(tmp_path: Path) -> Path:
+ """Create a minimal synthetic AstrBot-like package and test tree."""
+ _write(tmp_path, "astrbot/__init__.py", "")
+ _write(tmp_path, "astrbot/core/__init__.py", "")
</code_context>
<issue_to_address>
**Helper docstring omits required sections**
`_make_sample_repo` documents a `tmp_path` parameter and `Path` return value without Google-style `Args:` and `Returns:` sections, violating the repository’s docstring format rule.
Add Google-style `Args:` and `Returns:` sections to the docstring.
</issue_to_address>
### Comment 4
<location path="tests/test_select_tests.py" line_range="1" />
<code_context>
+"""Unit tests for AST-based selective pytest target selection."""
+
+from __future__ import annotations
</code_context>
<issue_to_address>
**Tests are added without request**
The review task does not ask for tests, but the PR adds `tests/test_select_tests.py`; this violates the default rule against adding tests unless the task explicitly requests them.
Remove the newly added test file.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: scripts/select_tests.py:325, .github/workflows/tests.yml:40
0bfff93 to
bf81841
Compare
whatevertogo
left a comment
There was a problem hiding this comment.
@mantoujun12 pls have a look
(看一看喵)
|
@Soulter 牢大有空帮忙看下这个 PR~核心目标是加速 PR CI、减少重复跑测并清理遗留测试基建(零新依赖,不改 Required Checks 名称,不影响 1. PR 并发取消 + 按路径分流
2. 新增静态 AST 增量选测(
|
Sha1rholder
left a comment
There was a problem hiding this comment.
Might as well rename dashboard_ci.yml to dashboard-ci.yml and install_script_test.yml to install-script-test.yml to make CI filenames more consistent
|
@Sha1rholder Done in 787b6e5 — renamed .github/workflows/dashboard_ci.yml\ to .github/workflows/dashboard-ci.yml\ and .github/workflows/install_script_test.yml\ to .github/workflows/install-script-test.yml\ (along with internal path filters and test references). Please take another look when convenient! |
|
I'll review this later |
Sha1rholder
left a comment
There was a problem hiding this comment.
This PR includes multiple changes, resulting in a rather large diff. Following the principle of keeping each PR as atomic as possible, could you please split it into the following PRs?
- Move files like
tests/install_script.Tests.ps1totests/ops/install_script.Tests.ps1and update the corresponding relative paths accordingly. - Rename
dashboard_ci.ymltodashboard-ci.ymlandinstall_script_test.ymltoinstall-script-test.yml. This is purely a naming convention issue, but since these files are already touched by this PR, we might as well fix it. - Add
concurrencyconfigurations to the four workflows individually to cancel outdated CI runs triggered by previous commits within the same PR. This essentially saves GitHub some money rather than speeding up CI, but there's no harm in adding it. - Regarding
test_install_script.py, I personally prefer removing it altogether rather than adapting it. I'll open a separate PR proposing its removal. - Clean up
conftest.py. - Put AST-based selective testing and incremental testing into a separate PR.
Otherwise it's unlikely that a human would be able to thoroughly review all these changes.
Additionally, select_tests.py introduced some static type-checking errors. Please make Pyright happy before submitting.
中文
该PR涉及多个改动,diff量过大。根据尽可能使每个PR保持原子化的原则,麻烦您把它分成以下PR: 1. move things like `tests/install_script.Tests.ps1` to `tests/ops/install_script.Tests.ps1`,然后把那堆相对路径同步一下 2. rename `dashboard_ci.yml` to `dashboard-ci.yml` and `install_script_test.yml` to `install-script-test.yml`。仅代码风格问题,这个PR既然涉及到了就是顺手的事 3. 取消同一PR连续commit的旧CI,单独给4个工作流加concurrency,这个其实就是给GitHub省点钱,不会加速,不过加了也没什么问题 4. `test_install_script.py`,这个我个人倾向于直接删了,不要去适配。我会开个PR suggest deletion 5. 清理`conftest.py` 6. AST selective tests和增量测试单独放一个PR不然一个人类不太可能完整认真review这些改动
另外,select_tests.py引入了一些静态类型检查报错。麻烦提交前先过一遍Pyright尽可能不新增报错以顾代码质量
|
起来了起来了你的pr又有合并冲突了 |
好困 |
787b6e5 to
aa1dc2d
Compare
|
就这几个文件我觉得没必要拆了 |
mantoujun12
left a comment
There was a problem hiding this comment.
有一个问题:.github/workflows/tests.yml 的 fail-open 逻辑是反的。changes job 只有在 scripts/select_tests.py 成功执行时才会写出 run_tests / test_mode / test_targets;一旦脚本抛异常、语法错误或环境缺失,job 失败、outputs 为空,smoke-test 的 if: needs.changes.outputs.run_tests == 'true' 判为假,smoke-test 和 unit-tests 会全部 skipped ,一条测试都不跑。
修法:在调用脚本前先往 $GITHUB_OUTPUT 预写 run_tests=true、test_mode=full、test_targets=./tests,让脚本成功后覆盖;或给调用加 || { ... } 兜底。
|
两个建议:
小点:
|
|
@mantoujun12 感谢细看,刚在
请有空再看一眼~ |

Speed up Python PR CI with PR concurrency cancellation and conservative AST-based selective pytest execution, while removing unused test-tiering dead code from
tests/conftest.py.Background
Previously on
pull_request:Testsransmoke-testand the full 3-OS (ubuntu-latest,macos-latest,windows-latest) pytest suite (~11–12 min wall-clock dominated by Windows) even for docs-only, changelog-only, README-only, dashboard-only, or isolated single-adapter/provider PRs.Testshad no PRconcurrencyconfiguration, so rapid follow-up pushes stacked multiple full 3-OS runs concurrently.tests/test_sync_github_project.pyandtests/test_project_events.py, already executed byproject-sync-tests.yml) ran redundantly on every PR inTests.tests/conftest.pycarried ~95 lines of unused manual tiering hooks (--test-profile,tier_c/tier_d, 8 unreferenced custom markers,TEST_PROVIDER_API_KEY/TEST_*_ENABLED). Verified againstmaster:tests/has nointegrationdirectory/paths (sopytest_collection_modifyitemsdid not reorder any tests) and zero test files reference those 8 markers.Modifications
scripts/select_tests.pySelectionResultTypedDictand narrowed AST branches (Pyright clean). Supportsskip/selective/fullmodes, cross-layer mappings (openapi-scopes.md,openapi.json,use/command.md, tested dashboard locale JSONs), per-module fail-open checks,conftest.py/tests/fixtures/guards, GitHub Actions outputs, and$GITHUB_STEP_SUMMARYreporting..github/workflows/tests.ymlconcurrencycancellation; add fail-open job-levelchangesstep runningscripts/select_tests.py(preservingsmoke-testandunit-testsjob names for required checks and failing open even ifselect_tests.pyorchangesfails); run selected targets inunit-testswhenselectiveor./tests --ignore=tests/test_sync_github_project.py --ignore=tests/test_project_events.pywhenfull; remove unusedOPENAI_API_KEYenv.scripts/run_pytests_ci.shOPENAI_API_KEY->ZHIPU_API_KEYcompatibility shim and forward CLI arguments cleanly.tests/conftest.pyASTRBOT_ROOTcleanup intact.AGENTS.md&CONTRIBUTING.mdrun-full-testslabel or[full-test]in PR title + push/re-runTests).PR Test-Selection Flow
flowchart TD PR["Pull Request (fetch-depth=2, --no-renames)"] --> TC["tests.yml: changes -> scripts/select_tests.py (~0.8s)"] TC -->|"Non-PR / [full-test] / run-full-tests / changes or script failure"| Full["mode=full (./tests excluding project-sync scripts on 3 OS)"] TC -->|"All files ignored (docs/README/AGENTS/dashboard/ops tests)"| Skip["mode=skip (skip smoke-test & unit-tests)"] TC -->|"Shared infra / conftest / fixtures / non-.py / deleted / unmapped / fanout >= 50%"| Full TC -->|"Mapped astrbot/tests or cross-layer docs/locales"| Sel["mode=selective (impacted tests + test_smoke.py on 3 OS)"]Safety Guarantees
Required Status Checks compatibility: Job-level
if:gating keepssmoke-testandunit-testsjob names unchanged so skipped PRs never hang in pending state.Two-layer fail-open:
changes: selector failures or missing outputs emit a warning and fall back torun_tests=true/test_mode=full/test_targets=./tests; missing merge parents, shared fixtures/conftest.py, non-Python assets underastrbot/, deleted source files, unmapped changedastrbot/modules, missing cross-layer target tests, or fan-out >= 50% also fall back tofull.smoke-test(!cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.run_tests != 'false')) andunit-tests(!cancelled() && needs.smoke-test.result == 'success') still execute the full 3-OS suite even ifchangesitself fails before writing outputs (e.g., checkout error).Full 3-OS safety net preserved: Selective runs always include
tests/test_smoke.pyacross Ubuntu, macOS, and Windows; everypushtomaster,workflow_dispatch, or PR withrun-full-testslabel /[full-test]title (on push or manual re-run) runs the complete 3-OS suite.This is NOT a breaking change.
Screenshots or Test Results
changes(mode=full, expected since this PR modifiestests.yml,scripts/select_tests.py, andtests/conftest.py),smoke-test, and 3-OSunit-tests(ubuntu-latest,macos-latest,windows-latest) all passed (run #47259123285).pyright scripts/select_tests.py tests/conftest.py-> 0 errors, 0 warnings, 0 informationsruff format --check .&ruff check .-> All checks passedpytest tests/test_smoke.py -v-> 6 passedpytest --collect-only -q ./tests --ignore=tests/test_sync_github_project.py --ignore=tests/test_project_events.py-> 5,918 tests collected, 0 unknown-marker warningsscripts/select_tests.pyacross real repo scenarios:mode=skip(0/265)docs/zh/dev/openapi-scopes.md->mode=selective(2/265:test_smoke.py,tests/unit/test_openapi_scope_docs.py)dashboard/src/i18n/locales/zh-CN/features/command.json->mode=selective(2/265:test_smoke.py,tests/unit/test_conversation_restart.py)astrbot/core/provider/sources/anthropic_source.py->mode=selective(5/265)tests/conftest.py&--force-full->mode=full(265/265)mastercommits (from initial evaluation): 86 / 86 (100.0%) strict recall.Checklist
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc. (CI & test workflow optimization; no new user-facing feature)
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
📚 I checked the affected WebUI instructions and screenshots in
docs/zhanddocs/enagainst the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). (CI/test infra only; no WebUI changes)🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml. (Stdlib only; no new dependencies)😮 My changes do not introduce malicious code.