Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/tests/test_runner_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 32 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: CI

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

Expand All @@ -23,11 +24,18 @@ 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
# 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
matrix:
suite: [deterministic, reverse]

steps:
- name: Check out repository
Expand Down Expand Up @@ -61,15 +69,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
Expand All @@ -83,29 +95,45 @@ 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
--cov=third_party
--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 }}
Expand Down
58 changes: 56 additions & 2 deletions tests/unit/test_workflow_runner_policy.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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"] == 90


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"] == 90
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():
Expand Down
Loading