diff --git a/.github/workflows/package-smoke.yml b/.github/workflows/package-smoke.yml index 69b8b068d2..f278b7fc61 100644 --- a/.github/workflows/package-smoke.yml +++ b/.github/workflows/package-smoke.yml @@ -4,50 +4,40 @@ on: pull_request: paths: - ".github/workflows/package-smoke.yml" - - "packages/loopx-core/**" - - "packages/loopx-capability-agent-turn-recall/**" - - "loopx/**" + - "packages/**" - "tests/test_core_distribution.py" - "tests/test_core_recall_distribution.py" - - "tests/control_plane/test_installed_core_context.py" - - "packages/loopx-repo-health/**" - - "packages/loopx-obelisk/**" - - "packages/loopx-codex-provider-routing/**" - - "loopx/capabilities/decision_context/extension_provider.py" - - "loopx/extensions/runtime.py" - - "packages/loopx-capability-pull-request-review/**" - - "packages/loopx-capability-issue-fix/**" - "tests/test_core_pr_review_distribution.py" - "tests/test_core_issue_fix_distribution.py" - "tests/test_core_standard_distribution.py" + - "tests/control_plane/test_installed_core_context.py" + - "loopx/extensions/runtime.py" + - "loopx/capabilities/decision_context/extension_provider.py" + - "pyproject.toml" push: branches: - main paths: - ".github/workflows/package-smoke.yml" - - "packages/loopx-core/**" - - "packages/loopx-capability-agent-turn-recall/**" + - "packages/**" - "loopx/**" - "tests/test_core_distribution.py" - "tests/test_core_recall_distribution.py" - - "tests/control_plane/test_installed_core_context.py" - - "packages/loopx-repo-health/**" - - "packages/loopx-obelisk/**" - - "packages/loopx-codex-provider-routing/**" - - "loopx/capabilities/decision_context/extension_provider.py" - - "loopx/extensions/runtime.py" - - "packages/loopx-capability-pull-request-review/**" - - "packages/loopx-capability-issue-fix/**" - "tests/test_core_pr_review_distribution.py" - "tests/test_core_issue_fix_distribution.py" - "tests/test_core_standard_distribution.py" + - "tests/control_plane/test_installed_core_context.py" + - "pyproject.toml" + schedule: + - cron: "47 20 * * *" + workflow_dispatch: permissions: contents: read concurrency: - group: package-smoke-${{ github.ref }} - cancel-in-progress: true + group: package-smoke-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: core: diff --git a/.github/workflows/postgresql-integration.yml b/.github/workflows/postgresql-integration.yml index bad716be3c..8aa8d85e99 100644 --- a/.github/workflows/postgresql-integration.yml +++ b/.github/workflows/postgresql-integration.yml @@ -17,6 +17,8 @@ on: - "package.json" - "package-lock.json" workflow_dispatch: + schedule: + - cron: "11 21 * * *" push: branches: - main diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 64f96879d7..8421b2ee5e 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -51,6 +51,8 @@ jobs: outputs: core_tests: ${{ steps.classify.outputs.core_tests }} backend_tests: ${{ steps.classify.outputs.backend_tests }} + frontend_tests: ${{ steps.classify.outputs.frontend_tests }} + compat_tests: ${{ steps.classify.outputs.compat_tests }} change_kind: ${{ steps.classify.outputs.change_kind }} python_tests: ${{ steps.classify.outputs.python_tests }} stage2c_tests: ${{ steps.classify.outputs.stage2c_tests }} @@ -97,8 +99,15 @@ jobs: summary.write("## CI job exemptions\n\n") summary.write(f"Change kind: **{plan['change_kind']}**; Python shards: **{plan['python_shards']}**.\n\n") summary.write(plan['reason'] + ".\n\n") - summary.write(f"Backend: {plan['backend_tests']}; Python: {plan['python_tests']}; Stage2c: {plan['stage2c_tests']}; frontend: {plan['core_tests']}; freshness: {plan['presentation_tests']}.\n\n") - summary.write(plan["coverage_scope"] + ". Unknown/mixed changes and main run full. Label ci:full forces full qualification.\n") + summary.write( + f"Backend: {plan['backend_tests']}; Frontend browser: {plan['frontend_tests']}; " + f"Compat: {plan['compat_tests']}; Python: {plan['python_tests']}; " + f"Stage2c: {plan['stage2c_tests']}; freshness: {plan['presentation_tests']}.\n\n" + ) + summary.write( + plan["coverage_scope"] + + ". Normal PRs run fast static/contract/TS checks; Nightly schedule, main, merge_group, CI-policy/manifest edits and ci:full run full.\n" + ) PY - uses: actions/upload-artifact@v7 with: @@ -147,7 +156,7 @@ jobs: chat-bundle-browser: needs: [changes, chat-bundle] - if: needs.changes.outputs.core_tests == 'true' && !cancelled() && needs.chat-bundle.result == 'success' + if: needs.changes.outputs.frontend_tests == 'true' && !cancelled() && needs.chat-bundle.result == 'success' runs-on: ubuntu-latest # The packaged scenario catalog outgrew one 15-minute runner, so the # catalog is partitioned like dashboard-browser and the companion smokes @@ -255,6 +264,8 @@ jobs: python -m pytest -q --no-cov tests/test_stage2c_dependency_lock.py tests/architecture/test_top_level_module_budget.py + tests/test_repository_instruction_delivery.py + tests/test_contributing_guide.py - name: Lint test suite run: >- @@ -422,7 +433,7 @@ jobs: dashboard-browser: needs: [changes, chat-bundle] - if: needs.changes.outputs.core_tests == 'true' && !cancelled() && needs.chat-bundle.result == 'success' + if: needs.changes.outputs.frontend_tests == 'true' && !cancelled() && needs.chat-bundle.result == 'success' runs-on: ubuntu-latest timeout-minutes: 25 strategy: @@ -508,7 +519,7 @@ jobs: dashboard-acceptance: needs: [changes, dashboard-browser] - if: needs.changes.outputs.core_tests == 'true' && !cancelled() && needs.dashboard-browser.result == 'success' + if: needs.changes.outputs.frontend_tests == 'true' && !cancelled() && needs.dashboard-browser.result == 'success' runs-on: ubuntu-latest timeout-minutes: 5 steps: @@ -550,7 +561,7 @@ jobs: node-minimum-compatibility: needs: [changes, chat-bundle] - if: needs.changes.outputs.backend_tests == 'true' && !cancelled() && needs.chat-bundle.result == 'success' + if: needs.changes.outputs.compat_tests == 'true' && !cancelled() && needs.chat-bundle.result == 'success' runs-on: ubuntu-latest # The full suite runs under this exact Node version in typescript-core. timeout-minutes: 10 @@ -577,7 +588,7 @@ jobs: needs: [changes, chat-bundle] # Probe the future runtime once per night or on demand, outside the PR/main # critical path. The supported runtime still runs on every full candidate. - if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && needs.changes.outputs.backend_tests == 'true' && !cancelled() && needs.chat-bundle.result == 'success' + if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && needs.changes.outputs.compat_tests == 'true' && !cancelled() && needs.chat-bundle.result == 'success' continue-on-error: true runs-on: ubuntu-latest # This runs the full core conformance suite. Allow forward-runtime/runner diff --git a/.github/workflows/release-artifacts.yml b/.github/workflows/release-artifacts.yml index b7ce17a6f8..87893c676c 100644 --- a/.github/workflows/release-artifacts.yml +++ b/.github/workflows/release-artifacts.yml @@ -7,22 +7,17 @@ on: - "examples/release-artifacts-smoke.py" - "examples/personal-workspace-browser/**" - "examples/personal-workspace-browser-smoke.mjs" - - "loopx/**" - - "package.json" - - "package-lock.json" - "pyproject.toml" - "setup.py" - "MANIFEST.in" - - "apps/presentation/dashboard/**" - - "scripts/chat_bundle.py" - - "scripts/verify_installed_chat.py" - - "README.md" - "scripts/release_artifacts.py" - "scripts/runtime_artifact.py" - "scripts/qualify_runtime_artifact.py" - - "tsconfig.control-plane.json" release: types: [published] + schedule: + # Nightly release-artifact and packaged browser verification without publishing assets. + - cron: "41 21 * * *" workflow_dispatch: inputs: tag: @@ -692,7 +687,7 @@ jobs: JS - name: Attest release packages and checksum manifest - if: github.event_name != 'pull_request' + if: github.event_name == 'release' || github.event_name == 'workflow_dispatch' uses: actions/attest@v4 with: subject-path: | @@ -712,7 +707,7 @@ jobs: upload-release: if: >- !cancelled() && github.repository == 'loopx-project/loopx' && - github.event_name != 'pull_request' && + (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && (needs.build.result == 'success' || (inputs.validated_run_id != '' && needs.build.result == 'skipped')) needs: build @@ -774,7 +769,8 @@ jobs: publish-pypi: if: >- - !cancelled() && github.event_name != 'pull_request' && + !cancelled() && + (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && needs.upload-release.result == 'success' && vars.PYPI_PUBLISH_ENABLED == 'true' needs: upload-release diff --git a/AGENTS.md b/AGENTS.md index 7f4891e1d2..0448772325 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -126,6 +126,10 @@ and unchanged head, and refresh the review packet (Drafts are excluded from the review queue). A reviewer must obey the packet's action authority and may not mark another author's Draft ready without authorization. Keep exact-head review, required validation, first-screen evidence and merge authorization separate. +Agents/subagents must not wait on or poll remote CI during development, review or +readiness when local gates pass (`wait_for_ci=false`); see +[local-first CI](docs/development/testing-and-quality.md#local-first-premerge-gate-vs-asynchronous-ci--本地优先门禁与异步-ci) +and [two-tier CI](docs/development/ci-impact-selection.md). ### DCO Sign-Off diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b772c03d17..5a19152f31 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -178,24 +178,33 @@ the CI, local/manual, and release-only boundaries. Only two checks block a merge: - `Sign-off`, the DCO check; -- `merge-gate`, which aggregates the Python Tests workflow. +- `merge-gate`, which aggregates the Python Tests workflow under a two-tier + lightweight-PR / heavy-nightly plan (agents and subagents do not wait on or + poll remote CI once local deterministic verification and `wait_for_ci=false` + exact-head review pass; see + [testing and quality](docs/development/testing-and-quality.md#local-first-premerge-gate-vs-asynchronous-ci--本地优先门禁与异步-ci)). `merge-gate` stays green only when these Python Tests jobs succeed or were -correctly skipped for your paths: `checks`, `pytest`, +correctly skipped for your tier/paths: `checks`, `pytest`, `node-minimum-compatibility`, `stage2c-correctness-e2e`, `windows-powershell`, -and `presentation`. The other workflows are path-filtered, advisory, or do not -run on pull requests. If an advisory workflow fails on a path you did not -touch, mention it in the PR instead of fixing it there. +and `presentation`. Normal backend PRs run fast static, contract, and TypeScript +checks while deferring unrelated browser suites and heavy matrices (6-shard +`pytest`, `node-minimum-compatibility`, `stage2c-correctness-e2e`, +`windows-powershell`) to Nightly `schedule`, `main` pushes, `merge_group`, +`ci:full` PRs, and CI-policy/manifest changes. The other workflows are +narrowly path-filtered, scheduled nightly, advisory, or manual. If an advisory +workflow fails on a path you did not touch, mention it in the PR instead of +fixing it there. | Workflow file | Runs on a PR | Blocks merge | What it checks | | --- | --- | --- | --- | -| `python-tests.yml` | every PR | yes (`merge-gate`) | lint, mypy, sharded pytest, TypeScript core and coverage, minimum Node.js, Windows PowerShell, dashboard presentation | +| `python-tests.yml` | every PR (tiered: lightweight PR vs full nightly/`main`/`merge_group`/`ci:full`) | yes (`merge-gate`) | fast lint, mypy, kernel contracts, TypeScript core/coverage on PRs; browser lanes on UI changes; full 6-shard pytest, minimum Node.js, Windows PowerShell, Stage 2C on full runs | | `dco.yml` | every PR | yes (`Sign-off`) | `Signed-off-by` on contribution commits; verified GitHub-generated two-parent merges are exempt | | `ci-maintenance.yml` | opened, reopened, edited, updated or closed PR (`pull_request_target`, trusted base code only) | no | inspects potential stale PR comparisons without mutating the head or target; cancels obsolete Python qualification runs after rechecking the PR and source branch | | `dependency-review.yml` | every PR | no | dependency changes introduced by the PR | -| `postgresql-integration.yml` | control-plane or npm lockfile paths | no | PostgreSQL authority store and service on a temporary instance | -| `package-smoke.yml` | `loopx-core` and extension package paths | no | `loopx-core` and extension packages install, entrypoints, and example schemas | -| `release-artifacts.yml` | `loopx/`, packaging, and lockfile paths | no | release identity and a release build from this source | +| `postgresql-integration.yml` | control-plane or npm lockfile paths (plus nightly schedule) | no | PostgreSQL authority store and service on a temporary instance | +| `package-smoke.yml` | `packages/**`, distribution tests, extension entrypoints, and `pyproject.toml` (plus `main` push and nightly schedule) | no | `loopx-core` and extension packages install, entrypoints, and example schemas | +| `release-artifacts.yml` | release, installer, packaging metadata, and browser recovery paths (plus `release` and read-only nightly schedule) | no | release identity and a release build from this source | | `runtime-snapshots.yml` | runtime artifact, installer, and updater paths | no | qualified, revision-addressed runtime archives and the main channel pointer | | `ark-turn.yml` | Turn driver and collaboration paths | no | optional Ark Turn package, stdio MCP, and DSH parity | | `memt-turn.yml` | optional MemT package, Turn driver, lock, and packaging paths | no | explicit optional dependency installation, complete adapter workflow, stdio MCP, and driver binding | diff --git a/docs/development/ci-impact-selection.md b/docs/development/ci-impact-selection.md index bd028eb2f9..bd180e65d1 100644 --- a/docs/development/ci-impact-selection.md +++ b/docs/development/ci-impact-selection.md @@ -1,28 +1,47 @@ -# CI job exemptions / 按职责免跑重型 CI +# CI job exemptions and two-tier cadence / CI 按职责分层与双层门禁 ## Policy, not a hand-maintained test selection Every PR receives the same stable merge gate. The classifier reads the complete NUL-delimited Git diff at immutable base/head revisions; a PR title, label or -author description cannot claim that runtime changes are “just UI”. - -| Whole PR | Backend TS/lint/contracts | Full Python / Windows | Stage2c | Packaged Dashboard | -| --- | --- | --- | --- | --- | -| Existing Markdown-only documentation exemption | Skip | Skip | Skip | Not published by Frontstage Pages | -| Client Dashboard source/assets only, optionally with docs | Skip | Skip | Skip | Required type-check, build, coverage, freshness and browser smoke | -| Backend, prompt, tests, dependency, build, CI policy, mixed or unknown | Run | Run | Run | Required type-check, build, coverage and browser smoke; extra freshness for CI-policy rehearsal or forced-full UI | -| main push / daily / manual / merge queue | Run | Run | Run | Required type-check, build, coverage and browser smoke | +author description cannot claim that runtime changes are “just UI” or exempt +build manifests. + +Under the repository's **zero CI waiting + two-tier CI** rule, agents and +subagents never wait for, poll, or block on remote GitHub Actions CI when local +deterministic gates and Goal-bound exact-head `loopx pr-review` (`wait_for_ci=false`) +pass; see [local-first premerge gate](testing-and-quality.md#local-first-premerge-gate-vs-asynchronous-ci--本地优先门禁与异步-ci). +Remote CI provides fast per-PR feedback (`backend`, `mixed`, `presentation`, `docs`) +and runs heavyweight cross-OS, full 6-shard Python/coverage, Node compatibility, +Stage 2C, and release/package dry-run matrices on Nightly `schedule`, `push` to +`main`, `merge_group`, `workflow_dispatch`, CI-policy/manifest changes, and `ci:full`. + +| Whole PR / Event (`change_kind`) | Backend static/TS/contracts (`backend_tests`) | Browser / UI (`frontend_tests`, `presentation_tests`) | Node compat (`compat_tests`) | 6-shard Python / Windows (`python_tests`) | Stage 2C (`stage2c_tests`) | +| --- | --- | --- | --- | --- | --- | +| Allowlisted root Markdown or `docs/**/*.md` (`docs`) | Skip | Skip | Skip | Skip | Skip | +| Client Dashboard/chat assets only, optionally with docs (`presentation`) | Skip | Run (`chat-bundle-browser`, `dashboard-browser`, `dashboard-acceptance`, `presentation`) | Skip | Skip | Skip | +| Backend/control-plane/tests/prompts without UI or manifest edits (`backend`) | Run (`kernel-static-checks`, `kernel-contracts`, `typescript-core`, `typescript-coverage`) | Skip | Skip | Skip | Skip | +| Backend + frontend/UI changes without CI policy or manifest edits (`mixed`) | Run | Run | Skip | Skip | Skip | +| CI policy, packaging/dependency manifests, unknown/symlinks, `ci:full`, `main` push, Nightly `schedule`, `merge_group`, `workflow_dispatch` (`full`) | Run | Run | Run (`node-minimum-compatibility`, plus `node-forward-compatibility` on `schedule`/`workflow_dispatch`) | Run (`test-shard` x6, `pytest`, `windows-powershell`) | Run (`stage2c-suite` x4, `stage2c-correctness-e2e`) | The presentation boundary is deliberately small: Dashboard `src/`, `public/` and packaged `loopx/web/chat/`, with explicit client-code/image/font extensions. -Package manifests, Vite/build configuration, native desktop code, backend Python -and arbitrary JSON are not exempt. Both sides of renames are classified; moving -runtime code into a UI directory stays full. Symlinks/type changes cannot qualify. - -The new exemption is available only when the selector, gate and workflow blobs -match the already-reviewed target branch. Changing CI policy cannot exempt its -own PR. Missing policy or uncertain ownership runs full; missing Git revisions -fail classification. The pre-existing documentation exemption remains supported. +Package manifests (`pyproject.toml`, `setup.py`, `MANIFEST.in`, `package.json`, +`package-lock.json`, `pnpm-lock.yaml`, `pnpm-workspace.yaml`, +`tsconfig.control-plane.json`, `uv.lock`, `Cargo.toml`, `Cargo.lock`, +subpackage/app/example manifests under `packages/`, `apps/`, and `examples/`, +and Dashboard `vite.config.ts`), `scripts/ci/**`, `.github/**`, +`packages/loopx-core/**`, `examples/shared-goal-authority-e2e/**`, +`tests/requirements-*`, and unknown root files force `full` qualification on PRs. Both sides of renames are classified; +moving runtime code into a UI directory runs backend + browser checks (`mixed`), +and moving files into `docs/` runs backend checks rather than `docs`. Symlinks +and nonregular Git objects always stay `full`. + +Exemption kinds (`presentation`, `backend`, `mixed`) activate only when the +selector, gate and workflow blobs in `POLICY_PATHS` already match the reviewed +target branch (`trusted_policy`). Changing CI policy cannot exempt its own PR. +Missing policy or uncertain ownership runs `full`; missing Git revisions fail +classification. The pre-existing documentation exemption remains supported. Frontstage Pages qualifies its own public artifact: homepage and projection-demo builds, bilingual Blog catalog, public-safe bundle, docs, analytics, search and @@ -47,10 +66,11 @@ Frontstage Pages 只验收并发布公共网站和 projection demo,保留构 仍由 Python Tests 承担。新合并不会中断正在运行的正式发布,只替换等待中的下一次 发布;同一 PR 的旧验证仍会取消。 -本方案是明确重型 job 的职责。纯前端变化不需要 -重跑后端持久化与崩溃恢复矩阵,但前端自己的实际构建与浏览器验收成为必需项。 -预算、静态宿主 prompt 和后端 Python/TS 逻辑暂不享受免跑;它们仍可能改变核心行为。 -新增一种豁免只需审阅其业务边界和保留的验收,不要求列举全部替代测试文件。 +本方案落实**轻量 PR / 夜间全量(Two-Tier CI)与本地优先零等待 CI**: +- 在本地确定性测试、`loopx canary premerge` 与受管 Goal(`wait_for_ci=false`)精确头评审通过后,Agent 与子 Agent 不再等待或轮询远端 GitHub Actions CI。 +- 普通后端 PR(`backend`)只跑轻量静态、内核契约与 TypeScript 核心/覆盖率检查;涉及 UI/前端的混合 PR(`mixed`)额外运行三个浏览器验收通道;纯前端(`presentation`)与纯文档(`docs`)保留原有精确豁免;而 6 分片 Python 全量、Windows PowerShell、Node 兼容矩阵、Stage 2C E2E/mutation/wheel-sdist 安装验收仅在夜间 `schedule`、`main` push、`merge_group`、手动调度、`ci:full` 标签及 CI 策略/依赖清单/未知路径 PR 中运行。 +- 所有豁免类型均受目标分支 `trusted_policy` 约束,更改 CI 策略自身的 PR 必须全量运行。 +本方案继续按改动面清晰分工,而非逐条手工挑选单测文件。 ## Six complete Python shards @@ -213,18 +233,24 @@ merge-gate 的摘要记录源码 head、实际 checkout、事件 base 与本次 摘要不根据状态猜根因;API 不可用时明确标记证据缺口。它也会列出 advisory 检查,但是否通过仍由原门禁规则决定,不因摘要失败而放行,不自动豁免历史失败。 -Specialized workflows already use GitHub's PR path filters: release artifacts -follow packaged source/build inputs, desktop artifacts follow native/Desktop -and shared Dashboard inputs, optional Ark follows its adapter and shared turn -boundaries, and Frontstage follows its published content. Their filters remain -separate from the required Python merge gate, which starts for every PR and -decides exemptions inside the workflow. Regression fixtures cover both related -and unrelated paths, including a mixed PR that still triggers Ark. - -按需触发以整个 PR 的累计改动为输入,先判断职责,再决定运行哪些完整 job。 -文档与纯前端 PR 已有明确豁免;后端、桌面、共享依赖或混合改动仍保留完整 -Python 主门禁。桌面、发布、Ark 和 Frontstage 的专用 workflow 则继续按各自 -路径触发。当前没有实现逐个测试的依赖图选择,也不声称所有后端 PR 都能缩减。 +Specialized workflows also follow strict PR path filters plus nightly schedules: +`release-artifacts.yml` triggers on PRs only for release, installer, packaging +metadata, and browser recovery harness files (removing broad `loopx/**`, +`README.md`, and `apps/presentation/dashboard/**` triggers) and runs a +read-only nightly verification at `21:41 UTC` (`upload-release`, `publish-pypi`, +and attestation stay gated to `release` and `workflow_dispatch`); `package-smoke.yml` +triggers on PRs only for `packages/**`, standalone `loopx-core`/extension distribution +tests, extension entrypoints, and `pyproject.toml`, plus `main` pushes and a +nightly `20:47 UTC` sweep; `postgresql-integration.yml` runs on control-plane/authority +changes plus a nightly `21:11 UTC` sweep; `desktop-release-artifacts.yml` follows +Desktop and Dashboard inputs; `ark-turn.yml` follows its adapter and turn +boundaries; and `frontstage-pages.yml` follows published site/docs inputs. + +专用 workflow 同样遵循严格 PR 路径过滤与夜间全量日程: +`release-artifacts.yml` 在 PR 上仅响应发布、打包与浏览器恢复脚本路径(不再因普通 `loopx/**`、`README.md` 或前端改动触发),并于每日 `21:41 UTC` 在主干执行只读干跑校验(`upload-release`、`publish-pypi` 与 provenance attestation 严格仅允许 `release` / `workflow_dispatch`); +`package-smoke.yml` 在 PR 上仅响应 `packages/**`、核心包分发测试、扩展入口与 `pyproject.toml`,并保留 `main` 与每日 `20:47 UTC` 夜间检查; +`postgresql-integration.yml` 除控制面改动外每日 `21:11 UTC` 执行夜间真库校验; +桌面、Ark 与 Frontstage 继续沿用各自专用触发规则。 Stage2c retains all correctness cases: its E2E lane uses two runners with two workers each, while mutants and installed-package lanes remain separate. The @@ -237,9 +263,10 @@ Stage2c E2E 从单 runner 的 4 个 worker 改为两个 runner 各 2 个 worker 数不增加,但不再挤在同一台机器。按完整模块分片,并保留 loadfile 与模块内顺序。 真实回归以共享状态、顺序敏感的模块验证两路并集完整且互斥,避免盲目按单测试分片。 -The supported minimum-Node contract runs for full candidates. The non-blocking -next-Node probe runs only with daily or manual Python Tests, outside the -per-push critical path. There is no hand-maintained per-test selection list. +The supported minimum-Node contract runs for `full` candidates (`compat_tests=true`). +The non-blocking next-Node probe runs only with daily or manual Python Tests when +`compat_tests=true`, outside the PR/main critical path. There is no hand-maintained +per-test selection list. ## Resource cadence and supersession diff --git a/docs/development/testing-and-quality.md b/docs/development/testing-and-quality.md index a4e92fa1b3..5b96825926 100644 --- a/docs/development/testing-and-quality.md +++ b/docs/development/testing-and-quality.md @@ -62,23 +62,37 @@ without pretending that the repository is fully qualified. ### Local-First Premerge Gate vs. Asynchronous CI / 本地优先门禁与异步 CI Remote CI stays asynchronous safety coverage, not a mandatory serial bottleneck -when local deterministic verification is already complete. When a managed Goal -sets `pull_request_review.wait_for_ci=false`, callers pass `--registry` and -`--goal-id GOAL` to `loopx pr-review` and `--check-merge-readiness`, resolving -`ci_policy="not_consulted"` so local `pytest`/`ruff`/`mypy` checks, -`loopx canary premerge --from-git-diff --git-diff-base "$PR_BASE_REF"`, and -exact-head review complete merge readiness without waiting on or polling remote CI -once local gates pass. `ci_policy="not_consulted"` separates CI waiting from -merge and self-merge authority: it never authorizes merging or auto-self-merging -ready PRs, and the default remains leaving PRs open for maintainer/owner -authorization. Standalone or unconfigured callers keep the safe default -`wait_for_ci=true`. - -当本地确定性验证已完整通过时,远端 CI 作为异步安全兜底,而不应成为串行阻塞点。对于配置了 +when local deterministic verification is already complete. Agents and subagents +must not wait on, poll, or block on remote GitHub Actions CI during development, +exact-head `loopx pr-review`, or `--check-merge-readiness` once local verification +passes. When a managed Goal sets `pull_request_review.wait_for_ci=false`, callers +pass `--registry` and `--goal-id GOAL` to `loopx pr-review` and +`--check-merge-readiness`, resolving `ci_policy="not_consulted"` so local +`pytest`/`ruff`/`mypy`/TypeScript checks, `loopx canary premerge --from-git-diff +--git-diff-base "$PR_BASE_REF"`, and exact-head review complete merge readiness +without waiting on or polling remote CI once local gates pass. Remote CI follows +a [two-tier cadence](ci-impact-selection.md): normal PRs run lightweight static, +contract, and TypeScript checks (plus browser lanes only when UI/frontend files +change), while heavyweight cross-OS, 6-shard Python/coverage, Node +compatibility, Stage 2C, and release/package dry-run matrices run on Nightly +`schedule`, `push` to `main`, `merge_group`, `workflow_dispatch`, CI +policy/manifest edits, and `ci:full`. `ci_policy="not_consulted"` separates CI +waiting from merge and self-merge authority: it never authorizes merging or +auto-self-merging ready PRs, and the default remains leaving PRs open for +maintainer/owner authorization. Standalone or unconfigured callers keep the safe +default `wait_for_ci=true`. + +当本地确定性验证已完整通过时,远端 CI 作为异步安全兜底,而不应成为串行阻塞点。 +在本地验证通过后,Agent 与子 Agent 在开发、精确头 `loopx pr-review` 与 +`--check-merge-readiness` 期间禁止等待、轮询或阻塞在远端 GitHub Actions CI 上。对于配置了 `pull_request_review.wait_for_ci=false` 的受管 Goal,调用 `loopx pr-review` 与 `--check-merge-readiness` 时须显式传入 `--registry` 与 `--goal-id GOAL`(解析为 `ci_policy="not_consulted"`),在本地测试、`loopx canary premerge` 与精确头评审等本地 -门禁通过后即可完成就绪判断,不再等待或轮询远端 CI。`ci_policy="not_consulted"` 仅控制 +门禁通过后即可完成就绪判断,不再等待或轮询远端 CI。远端 CI 采用[双层分层](ci-impact-selection.md): +普通 PR 只跑轻量静态、契约与 TypeScript 检查(仅在改动 UI/前端路径时加跑浏览器检查), +跨系统 Windows、6 分片全量 Python 与覆盖率、Node 兼容、Stage 2C 及发布/安装包干跑矩阵 +集中到夜间 `schedule`、合入 `main` 的 `push`、`merge_group`、`workflow_dispatch`、 +CI 策略/依赖清单改动与 `ci:full` 运行。`ci_policy="not_consulted"` 仅控制 CI 等待策略,合入与自合并授权仍保持独立:它不会自动批准或触发自合并,默认仍保持 PR 开启等待 维护者或所有者授权;未配置 Goal 的独立调用保持默认 `wait_for_ci=true`。 @@ -141,13 +155,20 @@ shell;不能因为过滤了 `CI` 就恢复采集。不能按系统、安装渠 ### Required Merge Check / 必需合并检查 -`python-tests.yml` publishes `merge-gate` for every open pull request. Code, -workflow, policy and unknown paths require the existing `pytest` aggregate -(including TypeScript checks and all six Python shards), Stage 2C correctness -aggregate, and Windows tests to succeed. Failed, cancelled, missing or -unexpectedly skipped results cannot pass the gate. The client-only exception -below retains common checks and substitutes packaged Dashboard qualification -for unrelated backend jobs. +`python-tests.yml` publishes `merge-gate` for every open pull request under a +fail-closed two-tier plan. Normal backend PRs (`backend`) run fast static, +contract, and TypeScript checks (`kernel-static-checks`, `kernel-contracts`, +`typescript-core`, `typescript-coverage`) and require explicit skips for +untriggered browser and heavyweight lanes. Mixed backend+UI PRs (`mixed`) add +the browser qualification lanes (`chat-bundle-browser`, `dashboard-browser`, +`dashboard-acceptance`, `presentation`). Pure client-UI PRs (`presentation`) run +built frontend and browser checks without backend Python/TS matrices. Nightly +`schedule`, `push` to `main`, `merge_group`, `workflow_dispatch`, `ci:full` PRs, +and PRs changing CI policy, packaging, dependency manifests, symlinks, or +unknown paths require full qualification across all lanes including 6-shard +`pytest`, `node-minimum-compatibility`, `stage2c-correctness-e2e`, and +`windows-powershell`. Failed, cancelled, missing or unexpectedly skipped results +cannot pass the gate. For a change limited to allowlisted root Markdown or `docs/**/*.md`, the classifier explicitly skips the expensive core jobs and the aggregate checks @@ -170,11 +191,18 @@ merge method `merge`. The trigger is inert until the live ruleset enables a merge queue. Enabling the queue, and then relaxing the up-to-date-branch requirement, is a ruleset decision for the lead maintainer. -每个开放 PR 都会收到 `merge-gate` 结果。代码、工作流、治理规则和未知路径必须通过 -原有核心测试;失败、取消、缺失或意外跳过均不能通过。仅白名单根目录 Markdown -或 `docs/**/*.md` 的修改可显式跳过昂贵测试;运行时 prompt、可执行文档、代码删除 -及代码移入文档均不享受豁免。实际启用状态以在线规则为准,使用 owner bypass -必须留下版本、原因、验证和已知失败的记录。 +每个开放 PR 都会收到按双层分级策略计算的 `merge-gate` 结果。普通后端 PR(`backend`) +运行轻量快速的静态、契约与 TypeScript 检查(`kernel-static-checks`、`kernel-contracts`、 +`typescript-core`、`typescript-coverage`),并要求未触发的浏览器与重型矩阵保持显式跳过; +同时改动后端与 UI 的混合 PR(`mixed`)加跑浏览器验收通道(`chat-bundle-browser`、 +`dashboard-browser`、`dashboard-acceptance`、`presentation`);纯前端 PR(`presentation`) +仅验证编译后的前端与浏览器检查。夜间 `schedule`、合入 `main` 的 `push`、`merge_group`、 +`workflow_dispatch`、带 `ci:full` 标签的 PR,以及修改 CI 策略、打包清单、依赖锁文件或未知 +路径的 PR 一律执行完整全量门禁(含 6 分片 `pytest`、`node-minimum-compatibility`、 +`stage2c-correctness-e2e` 与 `windows-powershell`)。任何必需项失败、取消、缺失或意外跳过 +均不能通过门禁。仅白名单根目录 Markdown 或 `docs/**/*.md` 的修改可显式跳过昂贵测试;运行时 +prompt、可执行文档、代码删除及代码移入文档均不享受豁免。实际启用状态以在线规则为准,使用 +owner bypass 必须留下版本、原因、验证和已知失败的记录。 两个必需工作流同样响应 `merge_group`,合并队列可在合入 `main` 前验证确切候选; 队列候选一律全量验证、不享受豁免。队列合并方式应设为 `merge`,因为 `Sign-off` 只豁免已验证的 GitHub 双父合并提交。在线规则启用合并队列前该触发不生效;启用 @@ -240,14 +268,23 @@ CI Maintenance 清理任务处理 closed 与 synchronize 事件(更新规则 触发清理。清理需要一个短 runner 任务;这会释放过期 容量。 -The [job exemption policy](ci-impact-selection.md) additionally permits pure -Dashboard-client changes to skip backend Python/Windows and Stage2c, while -requiring frontend type-check/build, scoped coverage and real packaged Dashboard -browser smoke. Backend-only TS/lint/minimum-Node jobs are also exempt. -Mixed, prompt, dependency and unknown changes stay full. Full Python runs six -complete shards and combines all six coverage files. The `ci:full` label forces -full qualification; main stays full. No selected-only report impersonates full -coverage. 新的前端豁免由目标分支已审阅的策略控制;CI 自身变更仍全量验证。 +The [job exemption policy](ci-impact-selection.md) tiers per-PR execution by +changed surface while preserving fail-closed verification: documentation-only +exempts all heavy jobs; client-only Dashboard PRs (`presentation`) skip +backend checks and heavy matrices while requiring compiled frontend and browser +smokes; normal backend PRs (`backend`) run fast static checks, kernel +contracts, and sharded TypeScript unit/coverage checks while skipping unrelated +browser suites and deferring 6-shard Python, Windows, Node compatibility, and +Stage 2C matrices to Nightly `schedule`, `main`, `merge_group`, and `ci:full`; +and `mixed` backend+UI PRs run both fast backend checks and frontend browser +smokes. CI policy, packaging, dependency-lock, and unknown changes stay `full`. +Agents and subagents rely on local deterministic verification plus Goal-bound +exact-head review under `wait_for_ci=false` rather than blocking on remote CI. +双层豁免策略按改动面分层门禁:纯文档跳过重型检查;纯前端仅验证前端与浏览器验收; +普通后端 PR 只跑快速静态、契约与 TS 测试并把多机/长程矩阵移入夜间、主干、队列与 +`ci:full`;混合 PR 兼跑后端轻量项与前端浏览器检查;CI 策略、依赖锁与未知路径仍跑全量。 +Agent 与子 Agent 在本地确定性验证及 `wait_for_ci=false` 精确头评审完成后即可交付, +不串行等待远端 CI。 PRs opened before activation may need a branch update to produce the new required check; an old green suite alone does not supply a missing aggregate. diff --git a/scripts/ci/impact_plan.py b/scripts/ci/impact_plan.py index 596d01def9..5be44b0017 100644 --- a/scripts/ci/impact_plan.py +++ b/scripts/ci/impact_plan.py @@ -11,9 +11,82 @@ SCHEMA = "loopx_ci_job_plan_v1" ROOT_DOCS = {"README.md", "README.zh-CN.md", "README.ja.md", "CHANGELOG.md", "CONTRIBUTING.md"} POLICY_PATHS = ("scripts/ci/impact_plan.py", "scripts/ci/review_gate.py", ".github/workflows/python-tests.yml") -OUTPUTS = ("core_tests", "backend_tests", "python_tests", "stage2c_tests", "presentation_tests") +OUTPUTS = ( + "core_tests", + "backend_tests", + "frontend_tests", + "compat_tests", + "python_tests", + "stage2c_tests", + "presentation_tests", +) +CHANGE_KINDS = ("docs", "presentation", "backend", "mixed", "full") PRESENTATION_ROOTS = ("apps/presentation/dashboard/src/", "apps/presentation/dashboard/public/", "loopx/web/chat/") PRESENTATION_SUFFIXES = {".ts", ".tsx", ".js", ".mjs", ".css", ".html", ".svg", ".png", ".jpg", ".jpeg", ".webp", ".ico", ".woff", ".woff2"} +FRONTEND_ROOTS = ("apps/presentation/", "loopx/web/chat/", "loopx/presentation/", "examples/personal-workspace-browser/") +FRONTEND_SCRIPTS = ("scripts/chat_bundle.py", "scripts/chat_bundle_launcher.mjs", "scripts/verify_installed_chat.py") +FULL_EXACT_PATHS = { + "pyproject.toml", + "setup.py", + "MANIFEST.in", + "package.json", + "package-lock.json", + "tsconfig.control-plane.json", + "uv.lock", + "sonar-project.properties", + "apps/presentation/dashboard/package.json", + "apps/presentation/dashboard/package-lock.json", + "apps/presentation/dashboard/vite.config.ts", +} +FULL_PREFIXES = ( + "scripts/ci/", + ".github/", + "examples/shared-goal-authority-e2e/", + "packages/loopx-core/", + "tests/requirements-", +) +FULL_MANIFEST_PREFIXES = ("packages/", "apps/", "examples/") +FULL_MANIFEST_NAMES = { + "pyproject.toml", + "setup.py", + "setup.cfg", + "MANIFEST.in", + "package.json", + "package-lock.json", + "pnpm-lock.yaml", + "pnpm-workspace.yaml", + "yarn.lock", + "uv.lock", + "Cargo.toml", + "Cargo.lock", + "requirements.txt", +} +LIGHT_EXACT_PATHS = { + "AGENTS.md", + "CLAUDE.md", + "CONTEXT.md", + "ADOPTERS.md", + "CODE_OF_CONDUCT.md", + "DCO", + "LICENSE", + "LICENSE-MIT", + "NOTICE", + "mkdocs.yaml", +} +LIGHT_PREFIXES = ( + "loopx/", + "tests/", + "scripts/", + "examples/", + "packages/", + "apps/", + "docs/", + "skills/", + "demo/", + "man/", + "regression/", + "benchmark/", +) @dataclass(frozen=True) @@ -26,6 +99,28 @@ def is_document(path: str) -> bool: return path in ROOT_DOCS or (path.startswith("docs/") and PurePosixPath(path).suffix == ".md") +def is_frontend_path(path: str) -> bool: + if path.startswith(FRONTEND_ROOTS) or path in FRONTEND_SCRIPTS: + return True + if path.startswith("examples/"): + name = PurePosixPath(path).name + return any(token in name for token in ("browser", "dashboard")) or name.startswith(("chat-", "frontstage-")) + return False + + +def _is_subpackage_manifest(path: str) -> bool: + if not path.startswith(FULL_MANIFEST_PREFIXES): + return False + name = PurePosixPath(path).name + return name in FULL_MANIFEST_NAMES or name.startswith(("requirements-", "requires-")) + + +def is_full_risk_path(path: str) -> bool: + if path in FULL_EXACT_PATHS or path.startswith(FULL_PREFIXES) or _is_subpackage_manifest(path): + return True + return path not in LIGHT_EXACT_PATHS and not path.startswith(LIGHT_PREFIXES) + + def candidate(changes: list[Change], *, pull_request: bool = True) -> tuple[str, str]: if not pull_request: return "full", "non-PR runs retain full qualification" @@ -40,14 +135,25 @@ def candidate(changes: list[Change], *, pull_request: bool = True) -> tuple[str, return "docs", "documentation only; existing runtime exemption" if all(item.path.startswith(PRESENTATION_ROOTS) and PurePosixPath(item.path).suffix in PRESENTATION_SUFFIXES for item in code): return "presentation", "client-only source/assets; retain frontend type-check, build and browser checks" - return "full", "runtime, prompts, tests, dependencies, build policy or unknown paths may affect backend behavior" + if any(is_full_risk_path(item.path) for item in code): + return "full", "build, dependency, packaging, CI policy or unknown paths require full qualification" + if any(is_frontend_path(item.path) for item in code): + return "mixed", "backend and UI changes; run fast static/contract/TS checks plus frontend browser checks (heavy matrices nightly/main/ci:full)" + return "backend", "backend/tests/docs-support changes without UI or manifest edits; run fast static/contract/TS checks (heavy matrices nightly/main/ci:full)" def job_flags(kind: str, *, presentation: bool = False) -> dict[str, bool]: - if kind not in {"docs", "presentation", "full"}: + if kind not in CHANGE_KINDS: raise ValueError("unknown CI change kind") - return {"core_tests": kind != "docs", "backend_tests": kind == "full", "python_tests": kind == "full", - "stage2c_tests": kind == "full", "presentation_tests": kind == "presentation" or presentation} + return { + "core_tests": kind != "docs", + "backend_tests": kind in {"backend", "mixed", "full"}, + "frontend_tests": kind in {"presentation", "mixed", "full"}, + "compat_tests": kind == "full", + "python_tests": kind == "full", + "stage2c_tests": kind == "full", + "presentation_tests": kind in {"presentation", "mixed"} or presentation, + } def git(*args: str) -> bytes: @@ -102,7 +208,7 @@ def plan(base: str, head: str, *, pull_request: bool = True, force_full: bool = merge_base = git("merge-base", base_sha, head_sha).decode().strip() changes = diff_changes(merge_base, head_sha) kind, reason = candidate(changes, pull_request=pull_request) - presentation = kind == "presentation" + presentation = kind in {"presentation", "mixed"} policy_change = any(item.path.startswith("scripts/ci/") or item.path == POLICY_PATHS[-1] for item in changes) if kind != "full": for item in changes: @@ -112,15 +218,22 @@ def plan(base: str, head: str, *, pull_request: bool = True, force_full: bool = kind, reason = "full", "symlinks and nonregular Git objects cannot grant an exemption" if force_full: kind, reason = "full", "explicit force-full override" - elif kind == "presentation" and not trusted_policy(base_sha, head_sha): - kind, reason = "full", "presentation exemption policy is not already trusted on the target branch" + elif kind in {"presentation", "backend", "mixed"} and not trusted_policy(base_sha, head_sha): + kind, reason = "full", "CI exemption policy is not already trusted on the target branch" flags = job_flags(kind, presentation=presentation or policy_change) checkout_sha = revision("HEAD") + coverage_scope = ( + "full Python suite" + if flags["python_tests"] + else "fast static/contract/TS checks (heavy matrices nightly/main/merge_group/ci:full)" + if flags["backend_tests"] + else "no Python coverage claim" + ) return {"schema_version": SCHEMA, "base_sha": base_sha, "head_sha": head_sha, "merge_base_sha": merge_base, "checkout_sha": checkout_sha, "change_kind": kind, "force_full": force_full, "reason": reason, **flags, "changes": [{"status": item.status, "path": item.path} for item in changes], - "coverage_scope": "full Python suite" if flags["python_tests"] else "no Python coverage claim", + "coverage_scope": coverage_scope, "python_shards": declared_python_shards(checkout_sha) if flags["python_tests"] else 0} diff --git a/scripts/ci/review_gate.py b/scripts/ci/review_gate.py index b38da94d9f..0bc3dc6a10 100644 --- a/scripts/ci/review_gate.py +++ b/scripts/ci/review_gate.py @@ -10,7 +10,7 @@ JOB_OUTPUT = { "checks": "core_tests", "pytest": "python_tests", - "node-minimum-compatibility": "backend_tests", + "node-minimum-compatibility": "compat_tests", "stage2c-correctness-e2e": "stage2c_tests", "windows-powershell": "python_tests", "presentation": "presentation_tests", @@ -19,8 +19,8 @@ "kernel-static-checks": "backend_tests", "kernel-contracts": "backend_tests", "typescript-coverage": "backend_tests", - "dashboard-acceptance": "core_tests", - "chat-bundle-browser": "core_tests", + "dashboard-acceptance": "frontend_tests", + "chat-bundle-browser": "frontend_tests", } diff --git a/scripts/ci/test_impact_plan.py b/scripts/ci/test_impact_plan.py index 6001700e01..bb6b553aef 100644 --- a/scripts/ci/test_impact_plan.py +++ b/scripts/ci/test_impact_plan.py @@ -13,11 +13,23 @@ class ImpactTests(unittest.TestCase): def test_whole_pr_job_requirements_are_owned_by_the_change_kind(self): self.assertEqual(job_flags("presentation"), { - "core_tests": True, "backend_tests": False, "python_tests": False, + "core_tests": True, "backend_tests": False, "frontend_tests": True, + "compat_tests": False, "python_tests": False, + "stage2c_tests": False, "presentation_tests": True, + }) + self.assertEqual(job_flags("backend"), { + "core_tests": True, "backend_tests": True, "frontend_tests": False, + "compat_tests": False, "python_tests": False, + "stage2c_tests": False, "presentation_tests": False, + }) + self.assertEqual(job_flags("mixed"), { + "core_tests": True, "backend_tests": True, "frontend_tests": True, + "compat_tests": False, "python_tests": False, "stage2c_tests": False, "presentation_tests": True, }) self.assertEqual(job_flags("full"), { - "core_tests": True, "backend_tests": True, "python_tests": True, + "core_tests": True, "backend_tests": True, "frontend_tests": True, + "compat_tests": True, "python_tests": True, "stage2c_tests": True, "presentation_tests": False, }) self.assertFalse(any(job_flags("docs").values())) @@ -36,21 +48,42 @@ def test_root_readme_locales_are_documents(self): self.assertEqual(candidate([Change(status, path)])[0], "docs") self.assertEqual(candidate([Change("M", path) for path in readmes])[0], "docs") - def test_one_shared_unknown_prompt_test_or_dependency_forces_full(self): + def test_backend_mixed_and_full_risk_tiering(self): for path in ("loopx/cli.py", "loopx/control_plane/goals/vision_checkpoint.ts", "loopx/claude_goal_mode/commands/loopx.md", "tests/test_ui.py", - "apps/presentation/dashboard/package-lock.json", "apps/presentation/dashboard/vite.config.ts", - "apps/desktop/src/main.rs", "scripts/ci/impact_plan.py", ".github/workflows/python-tests.yml", - "loopx/web/chat/backend.py", "loopx/web/chat/config.json", "unknown", "docs/build.py"): - with self.subTest(path=path): + "AGENTS.md", "docs/build.py", + "packages/dsh-loopx-plugin/src/cli.ts", "packages/loopx-ark-turn/tests/test_cli.py", + "packages/dsh-loopx-plugin/smoke/dsh-legacy-host.package.json", + "tests/fixtures/change_quality/oracles/typescript/package.json"): + with self.subTest(backend_path=path): + self.assertEqual(candidate([Change("M", path)])[0], "backend") + self.assertEqual(candidate([Change("M", "loopx/web/chat/index.html"), Change("M", path)])[0], "mixed") + self.assertEqual(candidate([Change("D", "loopx/code.py"), Change("A", "docs/code.md")])[0], "backend") + for path in ("apps/desktop/src/main.rs", "loopx/web/chat/backend.py", "loopx/web/chat/config.json"): + with self.subTest(mixed_or_non_presentation=path): + self.assertNotEqual(candidate([Change("M", "loopx/web/chat/index.html"), Change("M", path)])[0], "presentation") + for path in ("apps/presentation/dashboard/package-lock.json", "apps/presentation/dashboard/vite.config.ts", + "apps/desktop/loopx-control-plane/src-tauri/Cargo.toml", + "examples/dsh-loopx-demo/package.json", + "packages/loopx-capability-benchmark-toolkit/pyproject.toml", + "packages/loopx-jev/uv.lock", + "packages/loopx-memt-turn/MANIFEST.in", + "packages/dsh-loopx-plugin/package.json", + "packages/dsh-loopx-plugin/pnpm-lock.yaml", + "packages/dsh-loopx-plugin/pnpm-workspace.yaml", + "scripts/ci/impact_plan.py", ".github/workflows/python-tests.yml", + "pyproject.toml", "package-lock.json", "examples/shared-goal-authority-e2e/mutants.py", + "packages/loopx-core/prepare.py", "unknown"): + with self.subTest(full_path=path): + self.assertEqual(candidate([Change("M", path)])[0], "full") self.assertEqual(candidate([Change("M", "loopx/web/chat/index.html"), Change("M", path)])[0], "full") - def test_invalid_empty_non_pr_and_move_out_of_runtime_are_not_exempt(self): + def test_invalid_empty_and_non_pr_are_full(self): for changes in ([], [Change("T", "docs/a.md")], [Change("M", "docs/../code.md")], - [Change("M", "/docs/a.md")], [Change("M", "docs//a.md")], - [Change("D", "loopx/code.py"), Change("A", "docs/code.md")]): + [Change("M", "/docs/a.md")], [Change("M", "docs//a.md")]): self.assertEqual(candidate(changes)[0], "full") self.assertEqual(candidate([Change("M", "docs/a.md")], pull_request=False)[0], "full") + self.assertEqual(candidate([Change("M", "loopx/cli.py")], pull_request=False)[0], "full") def test_real_git_policy_force_full_and_type_boundaries(self): script = str(Path(__file__).with_name("review_gate.py")) @@ -111,11 +144,28 @@ def classify(base, *extra, head="HEAD"): write("loopx/cli.py", "backend change") git("add", "loopx/cli.py") git("commit", "-qm", "earlier backend commit") + backend_only, _ = classify(before_backend) + self.assertEqual(backend_only["change_kind"], "backend") + self.assertTrue(backend_only["core_tests"]) + self.assertTrue(backend_only["backend_tests"]) + self.assertFalse(backend_only["frontend_tests"]) + self.assertFalse(backend_only["compat_tests"]) + self.assertFalse(backend_only["python_tests"]) + self.assertFalse(backend_only["stage2c_tests"]) + self.assertFalse(backend_only["presentation_tests"]) + self.assertEqual(backend_only["python_shards"], 0) + forced_backend, _ = classify(before_backend, "--force-full") + self.assertEqual(forced_backend["change_kind"], "full") + self.assertEqual(forced_backend["python_shards"], 6) + self.assertTrue(forced_backend["compat_tests"]) write(path, "later client change") git("commit", "-qam", "latest client commit") cumulative, _ = classify(before_backend) - self.assertEqual(cumulative["change_kind"], "full") + self.assertEqual(cumulative["change_kind"], "mixed") self.assertTrue(cumulative["backend_tests"]) + self.assertTrue(cumulative["frontend_tests"]) + self.assertTrue(cumulative["presentation_tests"]) + self.assertFalse(cumulative["python_tests"]) self.assertEqual({item["path"] for item in cumulative["changes"]}, {"loopx/cli.py", path}) before_link = git("rev-parse", "HEAD") (root / "docs").mkdir() @@ -160,6 +210,107 @@ def classify(base, *extra, head="HEAD"): self.assertFalse(packet["python_tests"]) self.assertEqual(packet["python_shards"], 0) + def test_subpackage_dependency_manifests_require_full_under_trusted_policy(self): + script = str(Path(__file__).with_name("review_gate.py")) + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + env = {k: v for k, v in os.environ.items() if not k.startswith(("PYTEST", "COVERAGE", "COV_CORE"))} + + def git(*args): + return subprocess.check_output(["git", *args], cwd=root, env=env, text=True).strip() + + def write(path, content): + target = root / path + target.parent.mkdir(parents=True, exist_ok=True) + target.write_text(content) + + git("init", "-q") + git("config", "user.name", "CI Fixture") + git("config", "user.email", "ci@example.invalid") + git("config", "core.hooksPath", str(root / "no-hooks")) + for policy in POLICY_PATHS: + write( + policy, + "jobs:\n test-shard:\n strategy:\n matrix:\n shard: [1, 2, 3, 4, 5, 6]\n" + if policy.endswith(".yml") + else "reviewed policy", + ) + for manifest_path in ( + "packages/loopx-capability-benchmark-toolkit/pyproject.toml", + "packages/dsh-loopx-plugin/package.json", + "packages/dsh-loopx-plugin/pnpm-lock.yaml", + ): + write(manifest_path, "initial") + git("add", ".") + git("commit", "-qm", "trusted base") + + for manifest_path in ( + "packages/loopx-capability-benchmark-toolkit/pyproject.toml", + "packages/dsh-loopx-plugin/package.json", + "packages/dsh-loopx-plugin/pnpm-lock.yaml", + ): + with self.subTest(manifest_path=manifest_path): + base = git("rev-parse", "HEAD") + write(manifest_path, f"updated {manifest_path}") + git("add", "--", manifest_path) + git("commit", "-qm", f"update {manifest_path}") + plan_file = root / "plan.json" + classified = subprocess.run( + [sys.executable, script, "classify", "--base", base, "--head", "HEAD", "--plan", str(plan_file)], + cwd=root, + env=env, + capture_output=True, + text=True, + ) + self.assertEqual(classified.returncode, 0, classified.stderr) + packet = json.loads(plan_file.read_text()) + self.assertEqual(packet["change_kind"], "full") + self.assertTrue(packet["core_tests"]) + self.assertTrue(packet["backend_tests"]) + self.assertTrue(packet["frontend_tests"]) + self.assertTrue(packet["compat_tests"]) + self.assertTrue(packet["python_tests"]) + self.assertTrue(packet["stage2c_tests"]) + self.assertFalse(packet["presentation_tests"]) + self.assertEqual(packet["python_shards"], 6) + outputs = { + "change_kind": packet["change_kind"], + **{ + key: str(bool(packet[key])).lower() + for key in ( + "core_tests", "backend_tests", "frontend_tests", + "compat_tests", "python_tests", "stage2c_tests", "presentation_tests", + ) + }, + } + all_full = { + "changes": {"result": "success", "outputs": outputs}, + "checks": {"result": "success"}, + "pytest": {"result": "success"}, + "node-minimum-compatibility": {"result": "success"}, + "stage2c-correctness-e2e": {"result": "success"}, + "windows-powershell": {"result": "success"}, + "presentation": {"result": "skipped"}, + } + ok = subprocess.run( + [sys.executable, script, "verify"], + cwd=root, + env={**env, "NEEDS_JSON": json.dumps(all_full)}, + capture_output=True, + text=True, + ) + self.assertEqual(ok.returncode, 0, ok.stderr) + for blocked in ("pytest", "node-minimum-compatibility", "stage2c-correctness-e2e", "windows-powershell"): + skipped_needs = {**all_full, blocked: {"result": "skipped"}} + bad = subprocess.run( + [sys.executable, script, "verify"], + cwd=root, + env={**env, "NEEDS_JSON": json.dumps(skipped_needs)}, + capture_output=True, + text=True, + ) + self.assertNotEqual(bad.returncode, 0, blocked) + if __name__ == "__main__": unittest.main() diff --git a/scripts/ci/test_review_gate.py b/scripts/ci/test_review_gate.py index 28dff3290c..30f948c976 100644 --- a/scripts/ci/test_review_gate.py +++ b/scripts/ci/test_review_gate.py @@ -16,13 +16,17 @@ # Independent acceptance: client-only work retains compiled frontend/browser # qualification but does not claim backend conformance or coverage. PROFILE_FLAGS = { - "docs": dict(core_tests=False, backend_tests=False, python_tests=False, stage2c_tests=False, presentation_tests=False), - "presentation": dict(core_tests=True, backend_tests=False, python_tests=False, stage2c_tests=False, presentation_tests=True), - "full": dict(core_tests=True, backend_tests=True, python_tests=True, stage2c_tests=True, presentation_tests=False), + "docs": dict(core_tests=False, backend_tests=False, frontend_tests=False, compat_tests=False, python_tests=False, stage2c_tests=False, presentation_tests=False), + "presentation": dict(core_tests=True, backend_tests=False, frontend_tests=True, compat_tests=False, python_tests=False, stage2c_tests=False, presentation_tests=True), + "backend": dict(core_tests=True, backend_tests=True, frontend_tests=False, compat_tests=False, python_tests=False, stage2c_tests=False, presentation_tests=False), + "mixed": dict(core_tests=True, backend_tests=True, frontend_tests=True, compat_tests=False, python_tests=False, stage2c_tests=False, presentation_tests=True), + "full": dict(core_tests=True, backend_tests=True, frontend_tests=True, compat_tests=True, python_tests=True, stage2c_tests=True, presentation_tests=False), } PROFILE_JOBS = { "docs": set(), "presentation": {"checks", "presentation", "dashboard-acceptance", "chat-bundle-browser"}, + "backend": {"checks", "kernel-static-checks", "kernel-contracts", "typescript-coverage"}, + "mixed": {"checks", "presentation", "kernel-static-checks", "kernel-contracts", "typescript-coverage", "dashboard-acceptance", "chat-bundle-browser"}, "full": {"checks", "pytest", "node-minimum-compatibility", "stage2c-correctness-e2e", "windows-powershell", "kernel-static-checks", "kernel-contracts", "typescript-coverage", "dashboard-acceptance", "chat-bundle-browser"}, @@ -30,7 +34,7 @@ def needs(kind="full", *, presentation=False, jobs=JOB_OUTPUT): - flags = {**PROFILE_FLAGS[kind], "presentation_tests": kind == "presentation" or presentation} + flags = {**PROFILE_FLAGS[kind], "presentation_tests": kind in {"presentation", "mixed"} or presentation} required = PROFILE_JOBS[kind] | ({"presentation"} if presentation else set()) return {"changes": {"result": "success", "outputs": {"change_kind": kind, **{key: str(value).lower() for key, value in flags.items()}}}, @@ -296,7 +300,7 @@ def test_summary_runs_the_real_renderer_without_changing_the_gate_verdict(self): "GATE_RESULT": "failure", "NEEDS_JSON": json.dumps(needs())}) def test_legal_profiles_and_policy_rehearsal(self): - for kind in ("docs", "presentation", "full"): + for kind in ("docs", "presentation", "backend", "mixed", "full"): verify(needs(kind)) verify_checks(needs(kind, jobs=CHECK_OUTPUT)) verify(needs("full", presentation=True)) @@ -309,7 +313,7 @@ def test_every_missing_failure_cancel_or_unexpected_skip_is_rejected(self): self.check_results(CHECK_OUTPUT, verify_checks) def check_results(self, jobs, verifier): - for kind in ("docs", "presentation", "full"): + for kind in ("docs", "presentation", "backend", "mixed", "full"): good = needs(kind, jobs=jobs) for job in jobs: for state in ("success", "skipped", "failure", "cancelled", "neutral", None): @@ -326,8 +330,8 @@ def check_results(self, jobs, verifier): verifier(value) def test_bad_and_contradictory_classification_cannot_skip_work(self): - for kind in ("docs", "presentation", "full"): - for field in ("change_kind", "core_tests", "backend_tests", "python_tests", "stage2c_tests", "presentation_tests"): + for kind in ("docs", "presentation", "backend", "mixed", "full"): + for field in ("change_kind", "core_tests", "backend_tests", "frontend_tests", "compat_tests", "python_tests", "stage2c_tests", "presentation_tests"): for replacement in (None, "", True, "unknown"): value = needs(kind) value["changes"]["outputs"][field] = replacement @@ -346,7 +350,7 @@ def test_bad_and_contradictory_classification_cannot_skip_work(self): verify({**needs(), "extra": {"result": "success"}}) def test_backend_flag_cannot_waive_a_full_pr_or_create_client_coverage(self): - for kind in ("docs", "presentation", "full"): + for kind in ("docs", "presentation", "backend", "mixed", "full"): for jobs, verifier in ((JOB_OUTPUT, verify), (CHECK_OUTPUT, verify_checks)): value = needs(kind, jobs=jobs) outputs = value["changes"]["outputs"] @@ -396,13 +400,14 @@ def test_only_explicit_diagnostics_can_admit_a_failed_static_candidate(self): self.assertEqual(bundle["needs"], ["changes", "kernel-static-checks"]) self.assertIn("!cancelled()", bundle["if"]) for event in ("pull_request", "push", "merge_group", "schedule", "workflow_dispatch"): - for kind in PROFILE_FLAGS: + for kind, flags in PROFILE_FLAGS.items(): for state in ("success", "failure", "cancelled", "skipped", ""): for cancelled in (False, True): - expected = not cancelled and ( - (kind == "presentation" and state == "skipped") or - (kind == "full" and (state == "success" or - state == "failure" and event in {"schedule", "workflow_dispatch"}))) + static_ok = (not flags["backend_tests"] and state == "skipped") or ( + flags["backend_tests"] + and (state == "success" or (state == "failure" and event in {"schedule", "workflow_dispatch"})) + ) + expected = not cancelled and flags["core_tests"] and static_ok with self.subTest(event=event, kind=kind, state=state, cancelled=cancelled): self.assertEqual(self.admitted("chat-bundle", event, {"kernel-static-checks": state}, kind=kind, cancelled=cancelled), expected) @@ -417,10 +422,10 @@ def test_only_explicit_diagnostics_can_admit_a_failed_static_candidate(self): def test_every_heavy_lane_uses_the_admitted_bundle_and_retains_its_scope(self): lanes = {"kernel-contracts": "backend_tests", "typescript-core": "backend_tests", - "chat-bundle-browser": "core_tests", "dashboard-browser": "core_tests", + "chat-bundle-browser": "frontend_tests", "dashboard-browser": "frontend_tests", "test-shard": "python_tests", "stage2c-suite": "stage2c_tests", "windows-powershell": "python_tests", "presentation": "presentation_tests", - "node-minimum-compatibility": "backend_tests", "node-forward-compatibility": "backend_tests"} + "node-minimum-compatibility": "compat_tests", "node-forward-compatibility": "compat_tests"} for name, output in lanes.items(): job = self.workflow["jobs"][name] self.assertEqual(job["needs"], ["changes", "chat-bundle"]) diff --git a/tests/test_ci_resource_policy.py b/tests/test_ci_resource_policy.py index ef372d8594..aa3df0a2ec 100644 --- a/tests/test_ci_resource_policy.py +++ b/tests/test_ci_resource_policy.py @@ -29,7 +29,16 @@ def event(name: str, *, pr: int = 101, tag: str = "", backend: bool = True) -> d "inputs": SimpleNamespace(tag=tag), "cancelled": lambda: False, "needs": SimpleNamespace(chat_bundle=SimpleNamespace(result="success"), changes=SimpleNamespace(outputs=SimpleNamespace(**{ - key: str(backend).lower() for key in ("backend_tests", "core_tests", "python_tests", "stage2c_tests") + key: str(backend).lower() + for key in ( + "backend_tests", + "core_tests", + "frontend_tests", + "compat_tests", + "python_tests", + "stage2c_tests", + "presentation_tests", + ) }))), } @@ -297,9 +306,17 @@ def test_required_merge_gate_workflow_is_not_suppressed_by_path_filters() -> Non @pytest.mark.parametrize("name,paths,expected", [ - ("release-artifacts", ["loopx/cli.py"], True), + ("release-artifacts", ["loopx/cli.py"], False), + ("release-artifacts", ["README.md"], False), ("release-artifacts", ["docs/development/testing-and-quality.md"], False), - ("release-artifacts", ["apps/presentation/dashboard/src/App.tsx"], True), + ("release-artifacts", ["apps/presentation/dashboard/src/App.tsx"], False), + ("release-artifacts", ["scripts/release_artifacts.py"], True), + ("release-artifacts", ["pyproject.toml"], True), + ("package-smoke", ["loopx/cli.py"], False), + ("package-smoke", ["README.md"], False), + ("package-smoke", ["packages/loopx-core/prepare.py"], True), + ("package-smoke", ["loopx/extensions/runtime.py"], True), + ("package-smoke", ["pyproject.toml"], True), ("desktop-release-artifacts", ["loopx/cli.py"], False), ("desktop-release-artifacts", ["apps/desktop/loopx-control-plane/src-tauri/src/main.rs"], True), ("desktop-release-artifacts", ["apps/presentation/dashboard/src/App.tsx"], True), @@ -357,3 +374,25 @@ def test_daily_smokes_keep_every_shard_and_verify_one_shared_source_artifact() - assert consumers["steps"].index(download) < consumers["steps"].index(verify) < consumers["steps"].index(run) assert "continue-on-error" not in verify assert jobs["smoke-fleet-health"]["needs"] == "full-public-smokes" + + +def test_nightly_schedules_exist_and_release_publication_never_fires_on_schedule() -> None: + for name in ("python-tests", "release-artifacts", "package-smoke", "postgresql-integration"): + triggers = workflow(name)[True] + assert "schedule" in triggers and triggers["schedule"], name + + release = workflow("release-artifacts") + for job_name in ("upload-release", "publish-pypi"): + cond = release["jobs"][job_name]["if"] + assert "github.event_name == 'release'" in cond + assert "github.event_name == 'workflow_dispatch'" in cond + assert "github.event_name != 'pull_request'" not in cond + build_attest = next( + step for step in release["jobs"]["build"]["steps"] + if step.get("name") == "Attest release packages and checksum manifest" + ) + assert "github.event_name == 'release'" in build_attest["if"] + assert "github.event_name == 'workflow_dispatch'" in build_attest["if"] + + package_smoke = workflow("package-smoke") + assert package_smoke["concurrency"]["cancel-in-progress"] == "${{ github.event_name == 'pull_request' }}" diff --git a/tests/test_python_ci_workflow.py b/tests/test_python_ci_workflow.py index b2a1238440..1e51c5c1a2 100644 --- a/tests/test_python_ci_workflow.py +++ b/tests/test_python_ci_workflow.py @@ -86,7 +86,7 @@ def test_dashboard_acceptance_and_kernel_checks_run_independently() -> None: ) in aggregate -@pytest.mark.parametrize("kind", ["full", "presentation"]) +@pytest.mark.parametrize("kind", ["full", "mixed", "backend", "presentation"]) @pytest.mark.parametrize("kernel", ["success", "failure", "cancelled", "skipped"]) @pytest.mark.parametrize("typescript", ["success", "failure", "cancelled", "skipped"]) @pytest.mark.parametrize("dashboard", ["success", "failure", "cancelled", "skipped"]) @@ -98,12 +98,18 @@ def test_checks_aggregate_requires_every_planned_parallel_lane( command = gate.split("run: ", 1)[1].splitlines()[0] args = shlex.split(command) args[0] = sys.executable - backend = kind == "full" + backend = kind in {"full", "mixed", "backend"} + frontend = kind in {"full", "mixed", "presentation"} + heavy = kind == "full" needs = { "changes": {"result": "success", "outputs": { "change_kind": kind, "core_tests": "true", - "backend_tests": str(backend).lower(), "python_tests": str(backend).lower(), - "stage2c_tests": str(backend).lower(), "presentation_tests": str(not backend).lower(), + "backend_tests": str(backend).lower(), + "frontend_tests": str(frontend).lower(), + "compat_tests": str(heavy).lower(), + "python_tests": str(heavy).lower(), + "stage2c_tests": str(heavy).lower(), + "presentation_tests": str(kind in {"presentation", "mixed"}).lower(), }}, "kernel-static-checks": {"result": kernel}, "kernel-contracts": {"result": kernel}, @@ -117,8 +123,9 @@ def test_checks_aggregate_requires_every_planned_parallel_lane( capture_output=True, check=False, ) required_backend = "success" if backend else "skipped" + required_frontend = "success" if frontend else "skipped" assert (result.returncode == 0) == ( - kernel == typescript == required_backend and dashboard == browser == "success" + kernel == typescript == required_backend and dashboard == browser == required_frontend ) @@ -283,7 +290,7 @@ def test_presentation_exemption_retains_real_frontend_checks_and_force_full() -> assert producer.index("chat_bundle.py verify --source") < producer.index("actions/upload-artifact") assert "smoke:" not in producer assert "needs: [changes, chat-bundle]" in browser - assert "if: needs.changes.outputs.core_tests == 'true'" in browser + assert "if: needs.changes.outputs.frontend_tests == 'true'" in browser assert "name: chat-bundle-${{ github.sha }}" in browser assert "chat_bundle.py build" not in browser assert ( @@ -293,11 +300,14 @@ def test_presentation_exemption_retains_real_frontend_checks_and_force_full() -> < browser.index("npm run smoke:chat-upgrade") ) assert "continue-on-error" not in browser - for name in ("kernel-static-checks", "kernel-contracts", "typescript-core", "typescript-coverage", "node-minimum-compatibility"): + for name in ("kernel-static-checks", "kernel-contracts", "typescript-core", "typescript-coverage"): header = WORKFLOW.split(f" {name}:\n", 1)[1].split(" steps:", 1)[0] assert "if: needs.changes.outputs.backend_tests == 'true'" in header - dashboard = WORKFLOW.split(" dashboard-acceptance:\n", 1)[1].split(" steps:", 1)[0] - assert "if: needs.changes.outputs.core_tests == 'true'" in dashboard + compat_header = WORKFLOW.split(" node-minimum-compatibility:\n", 1)[1].split(" steps:", 1)[0] + assert "if: needs.changes.outputs.compat_tests == 'true'" in compat_header + for name in ("dashboard-browser", "dashboard-acceptance"): + dashboard = WORKFLOW.split(f" {name}:\n", 1)[1].split(" steps:", 1)[0] + assert "if: needs.changes.outputs.frontend_tests == 'true'" in dashboard assert "scripts/chat_bundle.py verify --source" in job assert "status --short --untracked-files=all -- loopx/web/chat" not in job assert "continue-on-error" not in job