From df17fcd8438ef4f57aa6109eb7738084e81e8953 Mon Sep 17 00:00:00 2001 From: Tiance Wang <11400530+wangtiance@users.noreply.github.com> Date: Mon, 16 Nov 2026 16:40:06 +0800 Subject: [PATCH] [ci] Run release and security checks on merge groups ## summary - Trigger Release checks, CodeQL and DSH checks for main merge groups. - Compare the full queue range and validate its SHA/ancestry before allowing documentation-only or unrelated-plugin skips. - Report DSH results on every event with job-internal path selection. - Retain queue CodeQL SARIF evidence and document the platform's missing external queue alert status and pending enforcement policy. - Keep full Python selection and existing main/nightly checks. ## validation - 152 CI scope, summary, security, profile and layer tests passed. - Shared static checks passed against the exact staged blobs. - npm run check:i18n and 42 local documentation links passed. - Live merge-group acceptance remains for queue activation. Refs: #273 --- .github/workflows/ci.yml | 3 + .github/workflows/codeql.yml | 16 +++- .github/workflows/dsh-plugin.yml | 24 ++++-- .github/workflows/release-checks.yml | 6 +- docs/development/validation.md | 50 ++++++++---- scripts/ci/select_checks.py | 73 +++++++++++++---- scripts/ci/summarize_checks.py | 6 +- tests/test_ci_scope.py | 118 ++++++++++++++++++++++++++- tests/test_ci_security.py | 16 +++- tests/test_ci_summary.py | 12 +-- 10 files changed, 269 insertions(+), 55 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84176ddf..37c0ca1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,9 @@ name: Release checks on: pull_request: + merge_group: + types: [checks_requested] + branches: [main] push: branches: [main] workflow_dispatch: diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 95625ebd..1dedb839 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -2,6 +2,9 @@ name: CodeQL on: pull_request: + merge_group: + types: [checks_requested] + branches: [main] push: branches: [main] workflow_dispatch: @@ -36,11 +39,22 @@ jobs: languages: ${{ matrix.language }} build-mode: none queries: security-extended - - name: Analyze and upload results / 扫描并上传结果 + - name: Analyze and record results / 扫描并记录结果 uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3 with: category: /language:${{ matrix.language }} + output: ${{ runner.temp }}/codeql-results + # Code scanning does not report its PR alert check on merge groups. + upload: ${{ github.event_name == 'merge_group' && 'never' || 'always' }} wait-for-processing: true + - name: Save queue scan evidence / 保存队列扫描证据 + if: github.event_name == 'merge_group' + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: codeql-merge-group-${{ matrix.language }}-${{ github.run_attempt }} + path: ${{ runner.temp }}/codeql-results/*.sarif + retention-days: 14 + if-no-files-found: error # Stable required-check candidate, independent of docs-only release skips. checks: diff --git a/.github/workflows/dsh-plugin.yml b/.github/workflows/dsh-plugin.yml index 1724e280..c9ea06e0 100644 --- a/.github/workflows/dsh-plugin.yml +++ b/.github/workflows/dsh-plugin.yml @@ -2,16 +2,11 @@ name: DSH plugin checks on: pull_request: - paths: - - 'plugins/deepseek-harness/**' - - '.github/workflows/dsh-plugin.yml' - - '.nvmrc' + merge_group: + types: [checks_requested] + branches: [main] push: branches: [main] - paths: - - 'plugins/deepseek-harness/**' - - '.github/workflows/dsh-plugin.yml' - - '.nvmrc' permissions: contents: read @@ -26,14 +21,27 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + with: + fetch-depth: 0 + persist-credentials: false + - id: scope + name: Select plugin scope / 判断插件检查范围 + env: + PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} + MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }} + PUSH_BASE_SHA: ${{ github.event.before }} + run: python3 scripts/ci/select_checks.py --dsh - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 + if: steps.scope.outputs.run-dsh != 'false' with: node-version-file: .nvmrc cache: npm cache-dependency-path: plugins/deepseek-harness/package-lock.json - name: Install DSH plugin dependencies + if: steps.scope.outputs.run-dsh != 'false' working-directory: plugins/deepseek-harness run: npm ci - name: DSH plugin tests + if: steps.scope.outputs.run-dsh != 'false' working-directory: plugins/deepseek-harness run: npm test diff --git a/.github/workflows/release-checks.yml b/.github/workflows/release-checks.yml index 9a8ee450..543334d9 100644 --- a/.github/workflows/release-checks.yml +++ b/.github/workflows/release-checks.yml @@ -31,7 +31,7 @@ jobs: steps: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 with: - fetch-depth: ${{ (github.event_name == 'pull_request' || (github.event_name == 'push' && github.event.before && github.event.before != '0000000000000000000000000000000000000000')) && '0' || '1' }} + fetch-depth: ${{ (github.event_name == 'pull_request' || github.event_name == 'merge_group' || (github.event_name == 'push' && github.event.before && github.event.before != '0000000000000000000000000000000000000000')) && '0' || '1' }} - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 with: python-version: '3.12' @@ -42,10 +42,13 @@ jobs: - name: Check static configuration env: PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} + MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }} PUSH_BASE_SHA: ${{ github.event.before }} run: | if [ "$GITHUB_EVENT_NAME" = pull_request ]; then python -m pre_commit run --from-ref "$PR_BASE_SHA" --to-ref HEAD + elif [ "$GITHUB_EVENT_NAME" = merge_group ] && [ -n "$MERGE_GROUP_BASE_SHA" ]; then + python -m pre_commit run --from-ref "$MERGE_GROUP_BASE_SHA" --to-ref HEAD elif [ "$GITHUB_EVENT_NAME" = push ] && [ -n "$PUSH_BASE_SHA" ] && [ "$PUSH_BASE_SHA" != 0000000000000000000000000000000000000000 ]; then python -m pre_commit run --from-ref "$PUSH_BASE_SHA" --to-ref HEAD else @@ -55,6 +58,7 @@ jobs: name: Select check scope / 判断检查范围 env: PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} + MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }} run: python scripts/ci/select_checks.py python: diff --git a/docs/development/validation.md b/docs/development/validation.md index bd3938cd..387af1d0 100644 --- a/docs/development/validation.md +++ b/docs/development/validation.md @@ -53,9 +53,9 @@ Budgets measure stage wall time, not the sum of parallel job limits, and never j ### 过渡与必需检查 / Transition and required checks -当前 [`ci.yml`](../../.github/workflows/ci.yml) 对 PR 和 main push 开启静态门禁;纯文档 PR 按下方白名单跳过重检查,其余仍跑全量 Python。[`nightly.yml`](../../.github/workflows/nightly.yml) 保留 gate-parity 和全量 Python flake 分诊。已注册 CI 层 mark,安全扫描见下方独立工作流;机型轴、合并队列与 main 证据归集仍是后续交付。当前 job 限额见下方静态检查说明;PR 和队列各 30 分钟是阶段目标,不代表已强制端到端总上限。 +当前 [`ci.yml`](../../.github/workflows/ci.yml) 对 PR、`merge_group: checks_requested` 和 main push 开启静态门禁;纯文档 PR / 合并组合按下方白名单跳过重检查,其余仍跑全量 Python。[`nightly.yml`](../../.github/workflows/nightly.yml) 保留 gate-parity 和全量 Python flake 分诊。已注册 CI 层 mark,安全扫描见下方独立工作流;机型轴、合并队列强制配置与 main 证据归集仍是后续交付。当前 job 限额见下方静态检查说明;PR 和队列各 30 分钟是阶段目标,不代表已强制端到端总上限。 -Currently [`ci.yml`](../../.github/workflows/ci.yml) enables static checks on PRs and main pushes. Documentation-only PRs use the allowlist below to skip heavy checks; other changes retain full Python selection. [`nightly.yml`](../../.github/workflows/nightly.yml) retains gate parity and full-suite Python flake triage. CI-layer marks are registered. Security scanning uses the independent workflow below; hardware tagging, the merge queue and main evidence collection remain follow-up delivery. Current job limits are documented below; 30 minutes each for PR and queue are stage targets, not enforced end-to-end deadlines. +Currently [`ci.yml`](../../.github/workflows/ci.yml) enables static checks on PRs, `merge_group: checks_requested` and main pushes. Documentation-only PRs and merge groups use the allowlist below to skip heavy checks; other changes retain full Python selection. [`nightly.yml`](../../.github/workflows/nightly.yml) retains gate parity and full-suite Python flake triage. CI-layer marks are registered. Security scanning uses the independent workflow below; hardware tagging, merge-queue enforcement and main evidence collection remain follow-up delivery. Current job limits are documented below; 30 minutes each for PR and queue are stage targets, not enforced end-to-end deadlines. - 本地 hook 可未安装或被绕过,不能在 GitHub 上普遍阻止 PR 创建。必需 CI 必须复核同一配置;静态失败阻止启动重测试,并使稳定汇总检查失败。/ Local hooks can be absent or bypassed and cannot universally prevent PR creation. Required CI repeats the same configuration; static failure blocks heavy jobs and fails the stable aggregate. - 纯文档变更可跳过重 Python/浏览器任务,但必须保留稳定的必需检查,报告跳过依据并成功结束。合并队列按整个 merge-group 差异判断,不能只看最后一个 PR;无法确定范围时执行完整门禁。/ Documentation-only changes may skip heavy Python/browser jobs, but a stable required check must report the reason and succeed. Queue filtering covers the whole merge-group diff, not only its last PR; uncertain scope runs the full gate. @@ -102,43 +102,61 @@ Checks cover YAML/JSON/TOML and Python syntax, conflict markers, Python debug st Local hooks can be absent or bypassed. PR and main Release checks run the same configuration in a separate static job. PRs compare base to tested merge HEAD; pushes compare before to HEAD. Only the static checkout needing a range comparison fetches full history; other jobs use shallow checkouts. Manual/initial-push full-file audits do not need full history. -静态通过后,范围检查仅对 PR 比较 base 与测试用合并 HEAD 的 merge-base 差异,保留整个 PR 的变更。只有非空差异全部属于根目录 `README.md`、`README.zh-CN.md`、`CONTRIBUTING.md`、`CHANGELOG.md`,或 `docs/` 内的 Markdown、PNG/JPEG/GIF/WebP,才跳过 Python、前端/构建/wheel 和全部 browser matrix。重命名同时检查旧、新路径;文档目录内的代码/配置、AGENTS/skill、工作流、测试、混合变更、空差异或比较失败都跑完整门禁。分类不会访问 PR API,路径使用 NUL 分隔,含空格或中文不会截断。 +静态通过后,PR 比较 base 与测试用合并 HEAD 的 merge-base 差异;合并队列比较事件 `base_sha` 到整个组合 HEAD,包含前序排队 PR。队列范围判定要求实际 HEAD 等于事件 `GITHUB_SHA`,且 base 是 HEAD 的祖先;缺失、错配或分叉都保守跑完整检查。静态门禁对相同范围执行共享 pre-commit 配置。只有非空差异全部属于根目录 `README.md`、`README.zh-CN.md`、`CONTRIBUTING.md`、`CHANGELOG.md`,或 `docs/` 内的 Markdown、PNG/JPEG/GIF/WebP,才跳过 Python、前端/构建/wheel 和全部 browser matrix。重命名同时检查旧、新路径;文档目录内的代码/配置、AGENTS/skill、工作流、测试、混合变更、空差异或比较失败都跑完整门禁。分类不会访问 PR API,路径使用 NUL 分隔,含空格或中文不会截断。 -After static success, scope selection compares the PR base and tested merge HEAD from their merge base, retaining the whole PR diff. Heavy Python, frontend/build/wheel and all browser matrix jobs are skipped only for a nonempty diff entirely within root `README.md`, `README.zh-CN.md`, `CONTRIBUTING.md`, `CHANGELOG.md`, or Markdown/PNG/JPEG/GIF/WebP under `docs/`. Renames check both old and new paths. Code/configuration under docs, AGENTS/skills, workflows, tests, mixed changes, empty diffs and unavailable comparisons keep the full gate. Selection needs no PR API; NUL-delimited paths preserve spaces and non-ASCII names. +After static success, PR scope selection compares the PR base and tested merge HEAD from their merge base. Queue selection compares the event `base_sha` with the entire group HEAD, including preceding queued PRs. Queue selection requires the checked-out HEAD to match the event `GITHUB_SHA` and the base to be its ancestor; missing, mismatched or diverged ranges retain full checks. The static gate runs the shared pre-commit configuration over the same range. Heavy Python, frontend/build/wheel and all browser matrix jobs are skipped only for a nonempty diff entirely within root `README.md`, `README.zh-CN.md`, `CONTRIBUTING.md`, `CHANGELOG.md`, or Markdown/PNG/JPEG/GIF/WebP under `docs/`. Renames check both old and new paths. Code/configuration under docs, AGENTS/skills, workflows, tests, mixed changes, empty diffs and unavailable comparisons keep the full gate. Selection needs no PR API; NUL-delimited paths preserve spaces and non-ASCII names. -main push、手动运行和 nightly 保持完整检查;本次不启用 `merge_group`,也不切换 Python ready 筛选。需要重检查时,Python(导入、契约、全量 pytest、bundled OpenCode)、前端/构建/wheel 和浏览器并行执行,browser `fail-fast: false`;一条失败不取消其余旅程。 +main push、手动运行和 nightly 保持完整检查;`merge_group` 已接入相同完整门禁,不切换 Python ready 筛选。需要重检查时,Python(导入、契约、全量 pytest、bundled OpenCode)、前端/构建/wheel 和浏览器并行执行,browser `fail-fast: false`;一条失败不取消其余旅程。 -Main pushes, manual runs and nightly retain full checks. This change enables neither `merge_group` nor Python ready selection. When heavy checks are required, Python (imports, contracts, full pytest and bundled OpenCode), frontend/build/wheel and browser jobs run in parallel with browser fail-fast disabled; one failure does not cancel other journeys. +Main pushes, manual runs and nightly retain full checks. Merge groups use the same full gate; Python ready selection remains disabled. When heavy checks are required, Python (imports, contracts, full pytest and bundled OpenCode), frontend/build/wheel and browser jobs run in parallel with browser fail-fast disabled; one failure does not cancel other journeys. -最终 `checks` 汇总保留现有必需检查名称并始终执行。只有 static 成功且提供明确的 `docs_only`、正数变更路径数、PR 事件和跳过决定时,才接受三条重检查线的 skipped;汇总会报告依据。任何失败、取消、意外跳过、无效决定或缺失回执仍失败。只有调用方显式关闭静态检查时,static 自身才允许 skipped,且此时必须跑重检查。静态失败造成的依赖跳过不能通过汇总。 +最终 `checks` 汇总保留现有必需检查名称并始终执行。只有 static 成功且提供明确的 `docs_only`、正数变更路径数、PR / merge-group 事件和跳过决定时,才接受三条重检查线的 skipped;汇总会报告依据。任何失败、取消、意外跳过、无效决定或缺失回执仍失败。只有调用方显式关闭静态检查时,static 自身才允许 skipped,且此时必须跑重检查。静态失败造成的依赖跳过不能通过汇总。 -The final `checks` aggregate preserves its required-check name and always runs. Only successful static checks with an explicit `docs_only` decision, a positive changed-path count and a PR event can authorize skipped heavy lanes; the summary reports that evidence. Failures, cancellations, unexpected skips, invalid decisions and missing receipts still fail. Only an explicitly disabled static lane may itself be skipped, in which case heavy lanes must run. Dependency skips after static failure cannot pass the aggregate. +The final `checks` aggregate preserves its required-check name and always runs. Only successful static checks with an explicit `docs_only` decision, a positive changed-path count and a PR or merge-group event can authorize skipped heavy lanes; the summary reports that evidence. Failures, cancellations, unexpected skips, invalid decisions and missing receipts still fail. Only an explicitly disabled static lane may itself be skipped, in which case heavy lanes must run. Dependency skips after static failure cannot pass the aggregate. 可复用工作流的 `static-checks` 默认关闭,由 `ci.yml` 开启;nightly 不重复静态检查。CI 不提交自动修复,hook 修改文件仍视为失败。PR 阶段预算先按 30 分钟;当前 static 上限 10 分钟,Python、前端和每个浏览器 job 各 30 分钟,汇总 5 分钟。这些仍是各 job 限额,不能相加或解释为已强制的阶段总上限;后续按实际测量改进端到端耗时。 The reusable workflow's `static-checks` defaults to false and is enabled by `ci.yml`; nightly does not duplicate static checks. CI never commits automatic fixes; hook edits remain failures. The PR stage budget is 30 minutes for now. Static has 10 minutes, Python/frontend/each browser job 30 minutes, and the aggregate 5 minutes. These remain per-job limits, not a summed or enforced workflow-wide deadline; improve end-to-end time using actual measurements. +### 合并组合与插件检查 / Merge groups and plugin checks + +[`ci.yml`](../../.github/workflows/ci.yml)、[`codeql.yml`](../../.github/workflows/codeql.yml) 和 [`dsh-plugin.yml`](../../.github/workflows/dsh-plugin.yml) 均响应面向 main 的 `merge_group: checks_requested`,默认 checkout GitHub 提供的组合 SHA,不按最后一个 PR 的 head 执行。静态检查仍集成在唯一的可复用 Release checks 中;没有第二份静态工作流。队列运行按 `run_id` 隔离,不会被同一 PR 的更新取消。事件语义见 [GitHub merge_group](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#merge_group)。 + +[`ci.yml`](../../.github/workflows/ci.yml), [`codeql.yml`](../../.github/workflows/codeql.yml) and [`dsh-plugin.yml`](../../.github/workflows/dsh-plugin.yml) handle `merge_group: checks_requested` targeting main. Default checkout tests GitHub's combined SHA, not the final PR's head. Static checks remain inside the single reusable Release checks workflow. Queue runs are isolated by `run_id` and are not cancelled by PR updates. See [GitHub merge_group](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#merge_group). + +DSH 工作流对 PR、main push 及合并组合均返回稳定的 `tests` 结果;移除事件级 `paths` 过滤,以免 required check 永久等待。在任务内用 `select_checks.py --dsh` 比较整个事件差异,仅插件目录、DSH 工作流、`.nvmrc` 或范围选择脚本有变更时安装和运行插件测试。重命名检查新旧两侧;差异为空、基线未知、队列 SHA 不匹配或比较失败时都运行插件测试。无相关变更时任务成功并在 summary 中报告跳过依据,不把失败或取消改写为成功。 + +DSH reports a stable `tests` result on PRs, main pushes and merge groups. Event-level `paths` filters are removed to avoid a required check remaining pending. Inside the job, `select_checks.py --dsh` compares the entire event diff and installs/runs plugin tests only for changes to the plugin directory, DSH workflow, `.nvmrc` or selector script. Both sides of renames count. Empty diffs, unknown baselines, mismatched queue SHAs and comparison errors run plugin tests. Unrelated changes produce a successful job with a summary explaining the skip; failures and cancellations are not rewritten as success. + +本地真实 Git 仓库测试覆盖“前序代码/插件 PR + 最后纯文档 PR”、纯文档组合、分叉/缺失/错配 SHA、重命名、选择结果到汇总结果的传递。它们不等于真实合并队列验收;在 PR7 强制规则前,需在 GitHub 验证并发组合、纯文档组合、失败阻止合入及所有 required check 的实际名称。main、手动及 nightly 仍保留现有完整门槛,PR/队列也未切换 Python 分层筛选。 + +Local real-Git tests cover preceding code/plugin changes plus a final documentation-only PR, all-documentation groups, diverged/missing/mismatched SHAs, renames and selector-to-aggregate receipts. They do not constitute live queue acceptance. Before PR7 enforces rules, GitHub acceptance must verify concurrent groups, documentation-only groups, failures blocking merges and actual required-check names. Main, manual and nightly retain the existing full bar; PR/queue Python layer filtering remains disabled. + ## PR 安全扫描 / PR security scanning -CodeQL、Release checks 和 DSH plugin checks 在入口工作流按“工作流名称 + 事件 + PR 编号”设置并发组;同一 PR 更新会取消该工作流的旧运行,不同 PR 和工作流互不取消。非 PR 事件按 `run_id` 独立分组且不启用取消,保留每次 main push 的检查和扫描基线。DSH 的路径筛选保持不变。参见 [GitHub 并发控制](https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency)。 +CodeQL、Release checks 和 DSH plugin checks 在入口工作流按“工作流名称 + 事件 + PR 编号”设置并发组;同一 PR 更新会取消该工作流的旧运行,不同 PR 和工作流互不取消。非 PR 事件按 `run_id` 独立分组且不启用取消,保留每次 main push 的检查和扫描基线。DSH 的范围判断见下方合并队列说明。参见 [GitHub 并发控制](https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency)。 -CodeQL, Release checks and DSH plugin checks group entry workflows by workflow name, event and PR number. Updates cancel outdated runs of the same workflow for that PR; different PRs and workflows do not cancel each other. Non-PR events use a unique `run_id` group with cancellation disabled, retaining checks and scan baselines for every main push. DSH path filters remain unchanged. See [GitHub concurrency control](https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency). +CodeQL, Release checks and DSH plugin checks group entry workflows by workflow name, event and PR number. Updates cancel outdated runs of the same workflow for that PR; different PRs and workflows do not cancel each other. Non-PR events use a unique `run_id` group with cancellation disabled, retaining checks and scan baselines for every main push. DSH scope selection is described below. See [GitHub concurrency control](https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency). -[`codeql.yml`](../../.github/workflows/codeql.yml) 对每个 PR(包含 draft 和纯文档变更)独立执行 Python 与 JavaScript/TypeScript CodeQL `security-extended` 分析;不等待 Release checks 的范围筛选。main push 建立合并版本基线,另提供手动运行。两条语言任务并行且互不取消,每条上限 30 分钟,汇总上限 5 分钟;这些不是阶段总墙钟上限。 +[`codeql.yml`](../../.github/workflows/codeql.yml) 对每个 PR(包含 draft 和纯文档变更)及 main 目标的合并组合独立执行 Python 与 JavaScript/TypeScript CodeQL `security-extended` 分析;不等待 Release checks 的范围筛选。main push 建立合并版本基线,另提供手动运行。两条语言任务并行且互不取消,每条上限 30 分钟,汇总上限 5 分钟;这些不是阶段总墙钟上限。 -[`codeql.yml`](../../.github/workflows/codeql.yml) independently runs CodeQL `security-extended` analysis for Python and JavaScript/TypeScript on every PR, including drafts and documentation-only changes. It does not depend on Release checks scope selection. Main pushes establish the merged baseline; manual dispatch is also available. Language jobs run in parallel without fail-fast cancellation, with a 30-minute limit each and a 5-minute aggregate limit, not a workflow-wide deadline. +[`codeql.yml`](../../.github/workflows/codeql.yml) independently runs CodeQL `security-extended` analysis for Python and JavaScript/TypeScript on every PR, including drafts and documentation-only changes, and every merge group targeting main. It does not depend on Release checks scope selection. Main pushes establish the merged baseline; manual dispatch is also available. Language jobs run in parallel without fail-fast cancellation, with a 30-minute limit each and a 5-minute aggregate limit, not a workflow-wide deadline. 扫描使用固定提交的官方 Actions、`build-mode: none` 和不保留 Git 凭证的 checkout,不安装应用依赖、不构建应用、不调用模型。默认 token 只读内容,上传分析结果的任务额外拥有 `actions: read` 和 `security-events: write`。使用 `pull_request` 而非 `pull_request_target`,不读取仓库 secrets;fork PR 仍受 GitHub 的首次贡献者审批策略约束。这是源码安全分析,不替代依赖漏洞或容器镜像扫描,也不能证明不存在漏洞。 Scanning uses pinned official Actions, `build-mode: none` and checkout without persisted Git credentials. It does not install application dependencies, build the application or call models. The default token reads contents; analysis upload jobs additionally receive `actions: read` and `security-events: write`. It uses `pull_request`, not `pull_request_target`, with no repository secrets; GitHub contributor approval policies still apply to fork PRs. Source analysis does not replace dependency or container-image scanning and cannot prove the absence of vulnerabilities. -稳定汇总 job `CodeQL / checks` 只接受全部语言分析成功,失败、取消、跳过和缺失结果均失败。它证明扫描执行及上传完成,不根据告警等级自行判断是否允许合并。GitHub 的独立 **Code scanning results / CodeQL** 检查负责 PR 新增行的告警门禁;默认失败阈值包含 error 及 high/critical 安全告警,仓库设置可能覆盖阈值。参见 [PR 告警检查语义](https://docs.github.com/en/code-security/how-tos/manage-security-alerts/manage-code-scanning-alerts/triage-alerts-in-pull-requests)。 +稳定汇总 job `CodeQL / checks` 只接受全部语言分析成功,失败、取消、跳过和缺失结果均失败。它证明扫描执行及证据保存完成(PR 上传至 code scanning,队列保存 SARIF),不根据告警等级自行判断是否允许合并。GitHub 的独立 **Code scanning results / CodeQL** 检查负责 PR 新增行的告警门禁;默认失败阈值包含 error 及 high/critical 安全告警,仓库设置可能覆盖阈值。参见 [PR 告警检查语义](https://docs.github.com/en/code-security/how-tos/manage-security-alerts/manage-code-scanning-alerts/triage-alerts-in-pull-requests)。 + +The stable aggregate job `CodeQL / checks` accepts only successful analyses for every language; failed, cancelled, skipped and missing results fail. It proves analysis and evidence completion (code scanning upload on PRs, SARIF retention on queue runs), without deciding merge eligibility from alert severity. GitHub's separate **Code scanning results / CodeQL** check gates alerts on added PR lines; default failure thresholds include error-level and high/critical security alerts, subject to repository overrides. See [PR alert check semantics](https://docs.github.com/en/code-security/how-tos/manage-security-alerts/manage-code-scanning-alerts/triage-alerts-in-pull-requests). + +队列中仍执行两种语言的完整 CodeQL 分析,但不向 code scanning 上传;结果以 `codeql-merge-group--` SARIF artifact 保存 14 天,缺失证据使语言任务失败。GitHub 官方 [codeql-action#1537](https://github.com/github/codeql-action/issues/1537) 仍记录队列不返回 PR 告警状态的限制,其 [自身工作流](https://github.com/github/codeql-action/blob/main/.github/workflows/codeql.yml) 也在 `merge_group` 禁用上传。因此不能将外部 PR 告警状态直接设为队列必需检查,也不能将执行汇总成功解释为没有漏洞。PR7 必须先验证平台行为,并制定组合告警的阻断策略,再强制相关规则;本改动不伪造告警成功,也不自动放宽现有规则。 -The stable aggregate job `CodeQL / checks` accepts only successful analyses for every language; failed, cancelled, skipped and missing results fail. It proves analysis and upload completion, without deciding merge eligibility from alert severity. GitHub's separate **Code scanning results / CodeQL** check gates alerts on added PR lines; default failure thresholds include error-level and high/critical security alerts, subject to repository overrides. See [PR alert check semantics](https://docs.github.com/en/code-security/how-tos/manage-security-alerts/manage-code-scanning-alerts/triage-alerts-in-pull-requests). +Queue runs still execute full CodeQL analysis for both languages, without code scanning upload. SARIF artifacts named `codeql-merge-group--` are retained for 14 days; missing evidence fails the language job. GitHub's open [codeql-action#1537](https://github.com/github/codeql-action/issues/1537) records that queue runs do not report the PR alert status; its [own workflow](https://github.com/github/codeql-action/blob/main/.github/workflows/codeql.yml) also disables merge-group uploads. The external PR alert status must not simply become a required queue check, and a successful execution aggregate does not prove the absence of vulnerabilities. PR7 must verify platform behavior and define a combined-code alert blocking policy before enforcing those rules. This change neither fabricates alert success nor automatically weakens existing rules. -管理员需确认仓库使用 advanced setup、没有冲突的 default setup,并验证首次扫描、fork PR 上传及告警阈值;之后将执行汇总和告警结果检查一并设为 required。仅合入 YAML 不会自动配置仓库保护规则。合并队列支持在后续 PR6 添加 `merge_group`,规则强制在 PR7 处理;完成这些配置前,不宣称安全门禁不可绕过。配置方式见 [CodeQL advanced setup](https://docs.github.com/en/code-security/how-tos/find-and-fix-code-vulnerabilities/configure-code-scanning/configuring-advanced-setup-for-code-scanning)。 +管理员需确认仓库使用 advanced setup、没有冲突的 default setup,并验证首次扫描、fork PR 上传及告警阈值;再配置执行汇总与 PR 告警门禁,避免队列等待平台不会产生的外部状态。仅合入 YAML 不会自动配置仓库保护规则。工作流已支持 `merge_group`;真实队列验收及规则强制在 PR7 处理;完成这些配置前,不宣称安全门禁不可绕过。配置方式见 [CodeQL advanced setup](https://docs.github.com/en/code-security/how-tos/find-and-fix-code-vulnerabilities/configure-code-scanning/configuring-advanced-setup-for-code-scanning)。 -An administrator must confirm advanced setup without conflicting default setup, verify the first analysis, fork uploads and alert thresholds, then require both the execution aggregate and alert-result checks. Merging YAML does not configure repository protection rules. PR6 adds `merge_group` support and PR7 handles enforcement; security gates are not claimed to be non-bypassable before those settings are complete. See [CodeQL advanced setup](https://docs.github.com/en/code-security/how-tos/find-and-fix-code-vulnerabilities/configure-code-scanning/configuring-advanced-setup-for-code-scanning). +An administrator must confirm advanced setup without conflicting default setup, verify the first analysis, fork uploads and alert thresholds, then configure execution and PR alert gates without making the queue wait for an external status the platform does not produce. Merging YAML does not configure repository protection rules. Workflows support `merge_group`; PR7 handles live queue acceptance and enforcement; security gates are not claimed to be non-bypassable before those settings are complete. See [CodeQL advanced setup](https://docs.github.com/en/code-security/how-tos/find-and-fix-code-vulnerabilities/configure-code-scanning/configuring-advanced-setup-for-code-scanning). 本地契约验证 / Local contract verification: diff --git a/scripts/ci/select_checks.py b/scripts/ci/select_checks.py index 72d791c4..8f546f30 100644 --- a/scripts/ci/select_checks.py +++ b/scripts/ci/select_checks.py @@ -1,4 +1,5 @@ -"""Skip heavy PR checks only for a proven, nonempty documentation-only diff.""" +"""Select checks from the whole PR, merge group or push; fail closed on unknowns.""" +import argparse import json import os from pathlib import Path, PurePosixPath @@ -13,7 +14,9 @@ 'non_documentation': 'Code, configuration or other inputs changed / 代码、配置或其他输入有变更', 'comparison_unavailable': 'Diff could not be proven; run full checks / 无法确认差异,运行完整检查', 'empty_diff': 'Empty diff; run full checks / 差异为空,运行完整检查', - 'event_requires_full': 'Only pull requests may skip heavy checks / 仅 PR 可跳过重检查', + 'event_requires_full': 'This event requires full checks / 本事件要求完整检查', + 'plugin_changed': 'Plugin or its check inputs changed / 插件或其检查输入有变更', + 'plugin_unchanged': 'No plugin check inputs changed; tests skipped / 插件检查输入未变,跳过测试', } @@ -25,24 +28,41 @@ def documentation(path): return PurePosixPath(path).suffix.lower() in DOCUMENT_SUFFIXES -def select(event, base, *, repository=None): - result = {'run-heavy': 'true', 'scope-reason': 'event_requires_full', 'changed-files': '0'} - if event != 'pull_request': - return result - result['scope-reason'] = 'comparison_unavailable' +def changed_paths(event, base, *, head=None, repository=None): + """Return all changed paths, or None when the range cannot be proven.""" if not re.fullmatch(r'[0-9a-f]{40}', base or ''): - return result + return None try: - # Three dots match the pre-commit PR range. Disabling rename detection - # retains both old and new paths: code renamed into docs is still code. + if event == 'merge_group': + if not re.fullmatch(r'[0-9a-f]{40}', head or ''): + return None + actual = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repository, + stderr=subprocess.DEVNULL, timeout=30).decode().strip() + if actual != head: + return None + subprocess.check_output(['git', 'merge-base', '--is-ancestor', base, head], + cwd=repository, stderr=subprocess.DEVNULL, timeout=30) + # PRs use the merge base; queues use the event's base through the entire + # synthetic head, including preceding PRs. Keep both sides of renames. + comparison = base + ('...HEAD' if event == 'pull_request' else '..HEAD') diff = subprocess.check_output( - ['git', 'diff', '--no-ext-diff', '--no-renames', '--name-only', '-z', base + '...HEAD', '--'], + ['git', 'diff', '--no-ext-diff', '--no-renames', '--name-only', '-z', comparison, '--'], cwd=repository, stderr=subprocess.DEVNULL, timeout=30, ) if diff and not diff.endswith(b'\0'): - return result - paths = diff.decode('utf-8').rstrip('\0').split('\0') if diff else [] + return None + return diff.decode('utf-8').rstrip('\0').split('\0') if diff else [] except (OSError, subprocess.SubprocessError, UnicodeError): + return None + + +def select(event, base, *, head=None, repository=None): + result = {'run-heavy': 'true', 'scope-reason': 'event_requires_full', 'changed-files': '0'} + if event not in {'pull_request', 'merge_group'}: + return result + result['scope-reason'] = 'comparison_unavailable' + paths = changed_paths(event, base, head=head, repository=repository) + if paths is None: return result result['changed-files'] = str(len(paths)) if not paths: @@ -54,8 +74,33 @@ def select(event, base, *, repository=None): return result +def select_dsh(event, base, *, head=None, repository=None): + result = {'run-dsh': 'true', 'scope-reason': 'event_requires_full', 'changed-files': '0'} + if event not in {'pull_request', 'merge_group', 'push'}: + return result + paths = changed_paths(event, base, head=head, repository=repository) + if paths is None: + result['scope-reason'] = 'comparison_unavailable' + elif not paths: + result['scope-reason'] = 'empty_diff' + else: + result['changed-files'] = str(len(paths)) + relevant = any(path.startswith('plugins/deepseek-harness/') or path in { + '.github/workflows/dsh-plugin.yml', '.nvmrc', 'scripts/ci/select_checks.py', + } for path in paths) + result.update({'run-dsh': 'true' if relevant else 'false', + 'scope-reason': 'plugin_changed' if relevant else 'plugin_unchanged'}) + return result + + def main(): - result = select(os.environ.get('GITHUB_EVENT_NAME'), os.environ.get('PR_BASE_SHA')) + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--dsh', action='store_true', help='Select plugin checks / 判断插件检查范围') + args = parser.parse_args() + event = os.environ.get('GITHUB_EVENT_NAME') + base = os.environ.get({'merge_group': 'MERGE_GROUP_BASE_SHA', 'push': 'PUSH_BASE_SHA'}.get(event, 'PR_BASE_SHA')) + selector = select_dsh if args.dsh else select + result = selector(event, base, head=os.environ.get('GITHUB_SHA')) print(json.dumps(result)) if path := os.environ.get('GITHUB_OUTPUT'): with Path(path).open('a', encoding='utf-8') as output: diff --git a/scripts/ci/summarize_checks.py b/scripts/ci/summarize_checks.py index 94873b9e..52707ce9 100644 --- a/scripts/ci/summarize_checks.py +++ b/scripts/ci/summarize_checks.py @@ -19,7 +19,7 @@ def main(): docs_only = heavy == 'false' if docs_only and not ( static_enabled and results['static']['result'] == 'success' - and os.environ.get('GITHUB_EVENT_NAME') == 'pull_request' + and os.environ.get('GITHUB_EVENT_NAME') in {'pull_request', 'merge_group'} and scope.get('scope-reason') == 'docs_only' and str(scope.get('changed-files', '')).isdigit() and int(scope['changed-files']) > 0 @@ -39,8 +39,8 @@ def main(): failed.append(name) report = '\n'.join([ '## Release checks / 发布检查', '', - ('Documentation-only PR: static passed; heavy checks intentionally skipped. / ' - '纯文档 PR:静态通过,按明确范围跳过重检查。' if docs_only + ('Documentation-only PR / merge group: static passed; heavy checks intentionally skipped. / ' + '纯文档 PR / 合并组合:静态通过,按明确范围跳过重检查。' if docs_only else 'Full checks required / 需要完整检查'), 'Scope / 范围: ' + str(scope.get('scope-reason', 'full')) + '; changed paths / 变更路径数: ' + str(scope.get('changed-files', 'unknown')), '', diff --git a/tests/test_ci_scope.py b/tests/test_ci_scope.py index 147559cb..0c51c005 100644 --- a/tests/test_ci_scope.py +++ b/tests/test_ci_scope.py @@ -104,7 +104,7 @@ def test_merge_base_excludes_unrelated_base_branch_changes(repository): assert scope.select('pull_request', updated_base, repository=repo)['run-heavy'] == 'false' -@pytest.mark.parametrize('event', ['push', 'workflow_dispatch', 'schedule', 'merge_group', None]) +@pytest.mark.parametrize('event', ['push', 'workflow_dispatch', 'schedule', None]) def test_other_events_always_keep_full_bar(repository, event): repo, base = repository commit(repo, 'docs/guide.md') @@ -143,11 +143,13 @@ def test_unparseable_diff_keeps_full_checks(repository, monkeypatch, output): assert scope.select('pull_request', base, repository=repo)['run-heavy'] == 'true' -def test_real_selector_outputs_drive_real_aggregate(repository, tmp_path): +@pytest.mark.parametrize('event', ['pull_request', 'merge_group']) +def test_real_selector_outputs_drive_real_aggregate(repository, tmp_path, event): repo, base = repository commit(repo, 'docs/guide.md') output, summary = tmp_path / 'outputs', tmp_path / 'summary' - env = {**os.environ, 'GITHUB_EVENT_NAME': 'pull_request', 'PR_BASE_SHA': base, + env = {**os.environ, 'GITHUB_EVENT_NAME': event, 'PR_BASE_SHA': base, + 'MERGE_GROUP_BASE_SHA': base, 'GITHUB_SHA': git(repo, 'rev-parse', 'HEAD'), 'GITHUB_OUTPUT': str(output), 'GITHUB_STEP_SUMMARY': str(summary), 'PYTHONIOENCODING': 'utf-8'} selected = subprocess.run([sys.executable, str(SCRIPT)], cwd=repo, env=env, capture_output=True, text=True, encoding='utf-8', check=True) @@ -162,6 +164,116 @@ def test_real_selector_outputs_drive_real_aggregate(repository, tmp_path): assert 'Documentation-only PR' in summary.read_text(encoding='utf-8') +@pytest.mark.parametrize('earlier,latest,heavy,plugin', [ + ('src/app.py', 'docs/latest.md', 'true', 'false'), + ('plugins/deepseek-harness/index.js', 'docs/latest.md', 'true', 'true'), + ('docs/earlier.md', 'docs/latest.md', 'false', 'false'), + ('docs/earlier.md', 'plugins/deepseek-harness/index.js', 'true', 'true'), +]) +def test_queue_range_includes_preceding_prs(repository, earlier, latest, heavy, plugin): + repo, base = repository + commit(repo, earlier) + commit(repo, latest) + head = git(repo, 'rev-parse', 'HEAD') + decision = scope.select('merge_group', base, head=head, repository=repo) + assert decision['run-heavy'] == heavy + assert decision['changed-files'] == '2' + assert scope.select_dsh('merge_group', base, head=head, repository=repo)['run-dsh'] == plugin + + +@pytest.mark.parametrize('invalid', ['missing_base', 'missing_head', 'wrong_head', 'diverged_base']) +def test_unproven_queue_range_runs_both_suites(repository, invalid): + repo, base = repository + if invalid == 'diverged_base': + git(repo, 'checkout', '-qb', 'other') + commit(repo, 'src/other.py') + other = git(repo, 'rev-parse', 'HEAD') + git(repo, 'checkout', '-q', base) + base = other + commit(repo, 'docs/guide.md') + head = git(repo, 'rev-parse', 'HEAD') + if invalid == 'missing_base': + base = None + elif invalid == 'missing_head': + head = None + elif invalid == 'wrong_head': + head = base + assert scope.select('merge_group', base, head=head, repository=repo)['run-heavy'] == 'true' + assert scope.select_dsh('merge_group', base, head=head, repository=repo)['run-dsh'] == 'true' + + +@pytest.mark.parametrize('name,relevant', [ + ('plugins/deepseek-harness/test/example.mjs', True), + ('.github/workflows/dsh-plugin.yml', True), ('.nvmrc', True), + ('scripts/ci/select_checks.py', True), ('docs/guide.md', False), ('src/app.py', False), +]) +@pytest.mark.parametrize('event', ['pull_request', 'push', 'merge_group']) +def test_plugin_paths_use_the_full_range(repository, name, relevant, event): + repo, base = repository + commit(repo, name) + result = scope.select_dsh(event, base, head=git(repo, 'rev-parse', 'HEAD'), repository=repo) + assert result['run-dsh'] == ('true' if relevant else 'false') + + +def test_plugin_rename_out_of_scope_still_runs_tests(repository): + repo, base = repository + commit(repo, 'plugins/deepseek-harness/guide.md') + base = git(repo, 'rev-parse', 'HEAD') + (repo / 'docs').mkdir() + git(repo, 'mv', 'plugins/deepseek-harness/guide.md', 'docs/guide.md') + git(repo, 'commit', '-qm', 'move plugin input out of scope') + result = scope.select_dsh('merge_group', base, head=git(repo, 'rev-parse', 'HEAD'), repository=repo) + assert result['run-dsh'] == 'true' + assert result['changed-files'] == '2' + + +@pytest.mark.parametrize('base_kind', ['missing', 'empty']) +@pytest.mark.parametrize('event', ['pull_request', 'merge_group']) +def test_plugin_cannot_skip_without_nonempty_proven_diff(repository, base_kind, event): + repo, base = repository + head = git(repo, 'rev-parse', 'HEAD') + result = scope.select_dsh(event, base if base_kind == 'empty' else None, head=head, repository=repo) + assert result['run-dsh'] == 'true' + + +@pytest.mark.parametrize('event', ['pull_request', 'merge_group', 'push']) +@pytest.mark.parametrize('name,relevant', [('docs/guide.md', 'false'), ('.nvmrc', 'true')]) +def test_actual_plugin_command_reports_scope(repository, tmp_path, event, name, relevant): + repo, base = repository + commit(repo, name) + output, summary = tmp_path / 'outputs', tmp_path / 'summary' + env = {**os.environ, 'GITHUB_EVENT_NAME': event, 'PR_BASE_SHA': base, + 'MERGE_GROUP_BASE_SHA': base, 'PUSH_BASE_SHA': base, + 'GITHUB_SHA': git(repo, 'rev-parse', 'HEAD'), 'GITHUB_OUTPUT': str(output), + 'GITHUB_STEP_SUMMARY': str(summary), 'PYTHONIOENCODING': 'utf-8'} + result = subprocess.run([sys.executable, str(SCRIPT), '--dsh'], cwd=repo, env=env, + capture_output=True, text=True, encoding='utf-8', timeout=30) + assert result.returncode == 0, result.stderr + decision = dict(line.split('=', 1) for line in output.read_text(encoding='utf-8').splitlines()) + assert decision == json.loads(result.stdout) + assert decision['run-dsh'] == relevant + assert decision['changed-files'] == '1' + assert 'Plugin' in summary.read_text(encoding='utf-8') or 'plugin' in summary.read_text(encoding='utf-8') + + +def test_all_queue_workflows_report_without_event_path_filters(): + for name in ['ci', 'codeql', 'dsh-plugin']: + workflow = yaml.safe_load((ROOT / f'.github/workflows/{name}.yml').read_text(encoding='utf-8')) + events = workflow[True] + assert events['merge_group'] == {'types': ['checks_requested'], 'branches': ['main']} + assert events['pull_request'] is None + assert 'github.run_id' in workflow['concurrency']['group'] + assert workflow['concurrency']['cancel-in-progress'] == "${{ github.event_name == 'pull_request' }}" + release = yaml.safe_load((ROOT / '.github/workflows/release-checks.yml').read_text(encoding='utf-8')) + assert release[True]['workflow_call']['inputs']['python-mark-expression']['default'] == '' + static = release['jobs']['static']['steps'] + assert "github.event_name == 'merge_group'" in static[0]['with']['fetch-depth'] + gate = next(step for step in static if step.get('name') == 'Check static configuration') + assert gate['env']['MERGE_GROUP_BASE_SHA'] == '${{ github.event.merge_group.base_sha }}' + assert '--from-ref "$MERGE_GROUP_BASE_SHA" --to-ref HEAD' in gate['run'] + assert static[-1]['env']['MERGE_GROUP_BASE_SHA'] == '${{ github.event.merge_group.base_sha }}' + + def test_workflow_wires_every_heavy_lane_to_successful_static_scope(): jobs = yaml.safe_load((ROOT / '.github/workflows/release-checks.yml').read_text(encoding='utf-8'))['jobs'] assert jobs['static']['steps'][-1]['id'] == 'scope' diff --git a/tests/test_ci_security.py b/tests/test_ci_security.py index 6aa12bce..2c32fb77 100644 --- a/tests/test_ci_security.py +++ b/tests/test_ci_security.py @@ -39,18 +39,26 @@ def test_source_analysis_uses_pinned_actions_and_limited_permissions(workflow): job = workflow['jobs']['analyze'] assert job['permissions'] == {'contents': 'read', 'actions': 'read', 'security-events': 'write'} steps = job['steps'] - assert len(steps) == 3 + assert len(steps) == 4 assert steps[0]['with']['persist-credentials'] is False assert all(re.fullmatch(r'[^@]+@[0-9a-f]{40}', step['uses']) for step in steps) - initialize, analyze = steps[1:] + initialize, analyze, evidence = steps[1:] assert initialize['uses'].startswith('github/codeql-action/init@') assert analyze['uses'].startswith('github/codeql-action/analyze@') assert initialize['uses'].split('@')[1] == analyze['uses'].split('@')[1] assert initialize['with'] == { 'languages': '${{ matrix.language }}', 'build-mode': 'none', 'queries': 'security-extended', } - assert analyze['with'] == {'category': '/language:${{ matrix.language }}', 'wait-for-processing': True} - assert not any('run' in step or 'continue-on-error' in step or 'if' in step for step in steps) + assert analyze['with'] == { + 'category': '/language:${{ matrix.language }}', 'wait-for-processing': True, + 'output': '${{ runner.temp }}/codeql-results', + 'upload': "${{ github.event_name == 'merge_group' && 'never' || 'always' }}", + } + assert not any('run' in step or 'continue-on-error' in step or 'if' in step for step in steps[:3]) + assert evidence['if'] == "github.event_name == 'merge_group'" + assert evidence['uses'].startswith('actions/upload-artifact@') + assert evidence['with']['path'] == '${{ runner.temp }}/codeql-results/*.sarif' + assert evidence['with']['if-no-files-found'] == 'error' assert 'secrets.' not in str(job) diff --git a/tests/test_ci_summary.py b/tests/test_ci_summary.py index c2c55f10..318fa8ac 100644 --- a/tests/test_ci_summary.py +++ b/tests/test_ci_summary.py @@ -72,8 +72,9 @@ def test_missing_receipt_fails_closed(tmp_path, missing): DOC_RESULTS = {'static': 'success', 'python': 'skipped', 'frontend': 'skipped', 'browser': 'skipped'} -def test_proven_docs_only_skip_succeeds_and_reports_reason(tmp_path): - result, summary = run_summary(tmp_path, DOC_RESULTS, scope=DOC_SCOPE) +@pytest.mark.parametrize('event', ['pull_request', 'merge_group']) +def test_proven_docs_only_skip_succeeds_and_reports_reason(tmp_path, event): + result, summary = run_summary(tmp_path, DOC_RESULTS, scope=DOC_SCOPE, event=event) assert result.returncode == 0, result.stderr text = summary.read_text(encoding='utf-8') assert 'Documentation-only PR' in text and 'docs_only' in text @@ -82,8 +83,9 @@ def test_proven_docs_only_skip_succeeds_and_reports_reason(tmp_path): @pytest.mark.parametrize('lane', ['static', 'python', 'frontend', 'browser']) @pytest.mark.parametrize('status', ['failure', 'cancelled']) -def test_docs_only_never_hides_failed_or_cancelled_jobs(tmp_path, lane, status): - result, _ = run_summary(tmp_path, {**DOC_RESULTS, lane: status}, scope=DOC_SCOPE) +@pytest.mark.parametrize('event', ['pull_request', 'merge_group']) +def test_docs_only_never_hides_failed_or_cancelled_jobs(tmp_path, lane, status, event): + result, _ = run_summary(tmp_path, {**DOC_RESULTS, lane: status}, scope=DOC_SCOPE, event=event) assert result.returncode != 0 @@ -97,7 +99,7 @@ def test_missing_or_invalid_skip_evidence_fails_closed(tmp_path, scope): assert result.returncode != 0 -@pytest.mark.parametrize('event', ['push', 'schedule', 'workflow_dispatch', 'merge_group']) +@pytest.mark.parametrize('event', ['push', 'schedule', 'workflow_dispatch']) def test_other_events_cannot_claim_docs_only_skip(tmp_path, event): result, _ = run_summary(tmp_path, DOC_RESULTS, scope=DOC_SCOPE, event=event) assert result.returncode != 0