Files
VoiceStudio/tests/test_ci_pytest_parallel.py
debpalash 44420960c3 ci: skip jobs whose inputs already passed; scope merge-queue runs
- .github/actions/ci-pass: hashes the git index entries (mode, blob, path)
  of a job's inputs plus its workflow file; a green job saves an empty cache
  marker last, and a later pull-request or merge-queue run with the same
  inputs skips every remaining step and still passes. Pushes, manual runs and
  releases never skip; main's runs save the markers PRs reuse.
- ci.yml: pass cache on Tests (Python), Tests (Electron), renderer smokes,
  UI crawler shards, Linux native package, Desktop UI and the smoke matrix.
  mobile.yml: on iOS, Android and both inference jobs.
- ci.yml changes job: merge_group runs compare the queue commit with its
  base for the Electron scope (300-file cap). uv.lock leaves the Electron
  allowlist: the main process bundles it and its tests read the real lock.
- tests/test_ci_pass_cache.py pins the events, key sensitivity (content,
  rename, deletion, mode) and step gating; detection tests cover merge groups.
2026-11-09 17:33:37 +05:30

45 lines
2.0 KiB
Python

"""CI runs tests/ in parallel (pytest-xdist); the plugin must be a declared dev dependency-group member.
`-n auto` fails with "unrecognized arguments" when the plugin is missing, which
would break every CI run, so the workflow flag and the dependency move together.
"""
from __future__ import annotations
import re
import tomllib
from pathlib import Path
import yaml
PASS_GATE = "steps.pass.outputs.hit != 'true'" # .github/actions/ci-pass skips the whole job
ROOT = Path(__file__).resolve().parents[1]
def test_parallel_flag_requires_the_declared_plugin():
workflow = (ROOT / ".github/workflows/ci.yml").read_text(encoding="utf-8")
uses_parallel = re.search(r"pytest tests/ [^\n]*-n (auto|\d+)", workflow) is not None
dev = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))[
"dependency-groups"
]["dev"]
declared = any(dep.lower().startswith("pytest-xdist") for dep in dev)
assert declared or not uses_parallel, "ci.yml uses -n but pytest-xdist is not in the dev dependency group"
def test_backend_suite_stays_serial_until_its_order_dependence_is_fixed():
workflow = (ROOT / ".github/workflows/ci.yml").read_text(encoding="utf-8")
line = next(l for l in workflow.splitlines() if "pytest backend/tests/" in l)
assert " -n " not in line
def test_python_suite_installs_electron_dependencies_before_packaging_tests():
workflow = yaml.safe_load((ROOT / ".github/workflows/ci.yml").read_text(encoding="utf-8"))
steps = workflow["jobs"]["test-python"]["steps"]
install = next(i for i, step in enumerate(steps)
if step.get("run") == "bun install --frozen-lockfile")
pytest = next(i for i, step in enumerate(steps)
if "pytest tests/" in step.get("run", ""))
assert install < pytest, "Packaging regressions load the installed electron-builder during pytest"
# Only the pass cache, which skips the whole job, may gate it.
assert steps[install].get("if") in (None, PASS_GATE), "A clean runner must always install Electron dependencies"