From 85a63a553b815825146ed07030a95f36f39a8959 Mon Sep 17 00:00:00 2001 From: "congvc-bot[bot]" <3634010+congvc-bot[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 18:02:06 +0700 Subject: [PATCH 1/2] ci: isolate Python test pass budgets and deduplicate PR runs (CHE-2461) --- .github/tests/test_runner_routing.py | 2 +- .github/workflows/ci.yml | 34 +++++++++++-- tests/unit/test_workflow_runner_policy.py | 58 ++++++++++++++++++++++- 3 files changed, 87 insertions(+), 7 deletions(-) diff --git a/.github/tests/test_runner_routing.py b/.github/tests/test_runner_routing.py index b2c150dd7..8029ea7b8 100644 --- a/.github/tests/test_runner_routing.py +++ b/.github/tests/test_runner_routing.py @@ -8,7 +8,7 @@ class RunnerRoutingTest(unittest.TestCase): def test_artemis_uses_x99_and_provisions_chrome(self): ci = Path(".github/workflows/ci.yml").read_text() whats_new = Path(".github/workflows/whats-new.yml").read_text() - self.assertEqual(ci.count("github.repository_owner == 'cheese-work'"), 3) + self.assertEqual(ci.count("github.repository_owner == 'cheese-work'"), 4) self.assertIn("cheese-x99", whats_new) self.assertIn("browser-actions/setup-chrome@", ci) self.assertIn("CHROME_BIN: ${{ steps.chrome.outputs.chrome-path }}", ci) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85f787994..96ea33a75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,7 @@ name: CI on: push: + branches: [main] pull_request: workflow_dispatch: @@ -23,11 +24,16 @@ env: jobs: # Windows leg removed org-wide per CHE-522 (Cheese: Linux CI only, no # Windows jobs or artifacts). - python-quality: - name: Python 3.12 + python-tests: + name: Python 3.12 (${{ matrix.suite }}) if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }} runs-on: ${{ github.repository_owner == 'cheese-work' && fromJSON('["self-hosted","Linux","X64","cheese-x99"]') || fromJSON('["ubuntu-latest"]') }} - timeout-minutes: 60 # X99 containers have 3 CPUs on a shared host: deterministic tests took 19 min against 9-13 on the previous hosted runner + timeout-minutes: 60 + strategy: + fail-fast: false + max-parallel: 1 + matrix: + suite: [deterministic, reverse] steps: - name: Check out repository @@ -61,15 +67,19 @@ jobs: run: uv sync --dev --locked - name: Check Python formatting + if: matrix.suite == 'deterministic' run: uv run ruff format --check . - name: Lint Python + if: matrix.suite == 'deterministic' run: uv run ruff check . - name: Enforce quality ratchets + if: matrix.suite == 'deterministic' run: uv run python scripts/quality_ratchet.py - name: Type-check protected core modules + if: matrix.suite == 'deterministic' run: uv run pyright --project pyright-core.json # Device, cloud, manual, and end-to-end suites require dedicated @@ -83,12 +93,14 @@ jobs: git cat-file -e 096411113522abc37964256833fecbbac4778af4^{commit} - name: Run deterministic Python tests + if: matrix.suite == 'deterministic' run: >- uv run pytest tests/unit tests/tools packages/artemis-client/tests -q + --durations=20 --cov=artemis --cov=mcp_server --cov=apps/admin_console @@ -96,16 +108,30 @@ jobs: --cov-fail-under=60 - name: Run unit tests in reverse file order + if: matrix.suite == 'reverse' shell: bash run: | mapfile -d '' -t test_files < <(find tests/unit -type f \( -name 'test_*.py' -o -name '*_test.py' -o -name '*.test.py' \) -print0 | LC_ALL=C sort -zr) - uv run pytest "${test_files[@]}" -q + uv run pytest "${test_files[@]}" -q --durations=20 - name: Enforce B2 ADB allowlist and tunnel fuzz merge gate + if: matrix.suite == 'deterministic' run: >- uv run pytest tests/unit/runtime/test_host_tunnel.py tests/unit/admin_console/test_host_tunnel_service.py -q + python-quality: + name: Python 3.12 + needs: python-tests + if: ${{ always() && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }} + runs-on: ${{ github.repository_owner == 'cheese-work' && fromJSON('["self-hosted","Linux","X64","cheese-x99"]') || fromJSON('["ubuntu-latest"]') }} + timeout-minutes: 5 + steps: + - name: Require both Python test passes + env: + PYTHON_TEST_RESULT: ${{ needs.python-tests.result }} + run: test "$PYTHON_TEST_RESULT" = success + frontend: name: Frontend tests and production build if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }} diff --git a/tests/unit/test_workflow_runner_policy.py b/tests/unit/test_workflow_runner_policy.py index 9a5487061..160e4211f 100644 --- a/tests/unit/test_workflow_runner_policy.py +++ b/tests/unit/test_workflow_runner_policy.py @@ -1,8 +1,10 @@ """CI runs on the cheese-work X99 runner pool, and never on a fork pull request.""" import json +import os from pathlib import Path import re +import subprocess import yaml @@ -68,7 +70,7 @@ def test_frontend_job_provisions_chrome_without_disabling_its_sandbox(): def test_python_jobs_install_the_opencv_system_libraries(): workflow = yaml.safe_load((WORKFLOWS / "ci.yml").read_text(encoding="utf-8")) - for name in ("python-quality", "package"): + for name in ("python-tests", "package"): steps = workflow["jobs"][name]["steps"] install = next( (i for i, step in enumerate(steps) if "apt-get install" in step.get("run", "")), None @@ -83,7 +85,59 @@ def test_python_jobs_install_the_opencv_system_libraries(): def test_python_job_timeout_allows_the_slower_x99_container(): workflow = yaml.safe_load((WORKFLOWS / "ci.yml").read_text(encoding="utf-8")) - assert workflow["jobs"]["python-quality"]["timeout-minutes"] == 60 + assert workflow["jobs"]["python-tests"]["timeout-minutes"] == 60 + + +def test_ci_does_not_duplicate_pull_request_runs_on_branch_pushes(): + workflow = yaml.safe_load((WORKFLOWS / "ci.yml").read_text(encoding="utf-8")) + triggers = workflow[True] if True in workflow else workflow["on"] + assert triggers["push"] == {"branches": ["main"]} + assert "pull_request" in triggers + assert "workflow_dispatch" in triggers + + +def test_python_passes_have_independent_budgets_without_extra_runner_contention(): + workflow = yaml.safe_load((WORKFLOWS / "ci.yml").read_text(encoding="utf-8")) + tests = workflow["jobs"]["python-tests"] + assert tests["timeout-minutes"] == 60 + assert tests["strategy"] == { + "fail-fast": False, + "max-parallel": 1, + "matrix": {"suite": ["deterministic", "reverse"]}, + } + steps = {step["name"]: step for step in tests["steps"]} + normal = steps["Run deterministic Python tests"] + reverse = steps["Run unit tests in reverse file order"] + assert normal["if"] == "matrix.suite == 'deterministic'" + assert reverse["if"] == "matrix.suite == 'reverse'" + for path in ("tests/unit", "tests/tools", "packages/artemis-client/tests"): + assert path in normal["run"] + assert "--cov-fail-under=60" in normal["run"] + assert "sort -zr" in reverse["run"] + assert 'pytest "${test_files[@]}"' in reverse["run"] + for step in (normal, reverse): + assert "--durations=20" in step["run"] + assert "Fetch CHE-844 receipt sources" in steps + + +def test_required_python_check_fails_unless_both_matrix_passes_succeed(): + workflow = yaml.safe_load((WORKFLOWS / "ci.yml").read_text(encoding="utf-8")) + gate = workflow["jobs"]["python-quality"] + assert gate["name"] == "Python 3.12" + assert gate["needs"] == "python-tests" + assert "always()" in gate["if"] + assert gate["timeout-minutes"] == 5 + assert len(gate["steps"]) == 1 + step = gate["steps"][0] + assert step["env"]["PYTHON_TEST_RESULT"] == "${{ needs.python-tests.result }}" + for result in ("success", "failure", "cancelled", "skipped", ""): + completed = subprocess.run( + ["bash", "-e", "-c", step["run"]], + env={**os.environ, "PYTHON_TEST_RESULT": result}, + capture_output=True, + text=True, + ) + assert (completed.returncode == 0) == (result == "success"), result def test_karma_tolerates_a_browser_stall_on_a_shared_x99_host(): From d8c4a4d60b68eadfe93a7dcd82515d6a4b7a2848 Mon Sep 17 00:00:00 2001 From: "congvc-bot[bot]" <3634010+congvc-bot[bot]@users.noreply.github.com> Date: Fri, 30 Oct 2026 03:18:28 +0700 Subject: [PATCH 2/2] ci: raise Python test leg timeout to 90 minutes (CHE-2461) --- .github/workflows/ci.yml | 4 +++- tests/unit/test_workflow_runner_policy.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96ea33a75..0854dca5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,9 @@ jobs: name: Python 3.12 (${{ matrix.suite }}) if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }} runs-on: ${{ github.repository_owner == 'cheese-work' && fromJSON('["self-hosted","Linux","X64","cheese-x99"]') || fromJSON('["ubuntu-latest"]') }} - timeout-minutes: 60 + # Each matrix leg gets its own budget. The deterministic suite grew from ~21 to + # ~42 min between 28 and 29 Oct and swings up to 2.6x under shared-runner load. + timeout-minutes: 90 strategy: fail-fast: false max-parallel: 1 diff --git a/tests/unit/test_workflow_runner_policy.py b/tests/unit/test_workflow_runner_policy.py index 160e4211f..be6f7f111 100644 --- a/tests/unit/test_workflow_runner_policy.py +++ b/tests/unit/test_workflow_runner_policy.py @@ -85,7 +85,7 @@ def test_python_jobs_install_the_opencv_system_libraries(): def test_python_job_timeout_allows_the_slower_x99_container(): workflow = yaml.safe_load((WORKFLOWS / "ci.yml").read_text(encoding="utf-8")) - assert workflow["jobs"]["python-tests"]["timeout-minutes"] == 60 + assert workflow["jobs"]["python-tests"]["timeout-minutes"] == 90 def test_ci_does_not_duplicate_pull_request_runs_on_branch_pushes(): @@ -99,7 +99,7 @@ def test_ci_does_not_duplicate_pull_request_runs_on_branch_pushes(): def test_python_passes_have_independent_budgets_without_extra_runner_contention(): workflow = yaml.safe_load((WORKFLOWS / "ci.yml").read_text(encoding="utf-8")) tests = workflow["jobs"]["python-tests"] - assert tests["timeout-minutes"] == 60 + assert tests["timeout-minutes"] == 90 assert tests["strategy"] == { "fail-fast": False, "max-parallel": 1,