From 499f50b5c424461cb239245f3b79067775feec06 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 16:28:26 -0600 Subject: [PATCH 1/5] CI: the ubuntu repo harness tier runs as 3 test shards, as windows-2025 does The ubuntu-latest leg of `repo harness tests` ran the whole tier in one job and was killed at its 48-minute step cap with no test failing. It now runs as the same 3 shards windows-2025 uses, on every arm: code PR, docs-only PR, push, dispatch and forks. The partition guard runs on ubuntu shard 1 only, so it still runs once. Caps, worker counts, the test selection and the CI gate are unchanged. Verified-by: tests --- .github/workflows/ci.yml | 34 ++++++++++++++----------- scripts/quality/shard_tests.py | 5 ++-- tests/test_ci_tooling_gate.py | 42 ++++++++++++++++++------------- tests/test_quality_shard_tests.py | 2 +- 4 files changed, 48 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 715461e0e7..9764cccd4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2214,10 +2214,12 @@ jobs: # # NOT a required context of its own: it rides the `ci-gate` roll-up, exactly as `webconsole` does and # for the same reason recorded there -- a new required context needs a branch-protection change, and - # until that lands every PR carries a check it can never satisfy. Each windows-2025 test shard + # until that lands every PR carries a check it can never satisfy. Each test shard # below is one more leg of this job, so each rides the roll-up the same way. # - # windows-2025 RUNS THE TIER AS 3 TEST SHARDS, ubuntu-latest as one leg, under an owner ruling of + # EACH OS RUNS THE TIER AS THE SAME 3 TEST SHARDS. ubuntu-latest was one leg until 2026-12-02, when + # its step was killed at the 48-minute cap with no test failing (job 143796847829, among others). + # windows-2025 was split first, under an owner ruling of # 2026-11-24 in the Manager's session: asked "Approve the split?", the owner answered "Shard into 3 # (Recommended)". It reverses the 2026-11-14 ruling quoted below for this leg. The windows-2025 # junit of run 45415735678 (job 138521635567) held 11,506 testcases and 15,414 s of test time at @@ -2515,7 +2517,8 @@ jobs: # 100-minute cap divided by the 1.30 floor scripts/ci/step_margin.py applies to the steps it # gates -- or if any shard is killed at the 100-minute step cap, or if TOOLING_WORKERS or the # shard count changes. Both caps are unchanged by the split and apply per shard; a shard is - # predicted to run about a third of the 86 minutes above, so re-sizing them is its own change. The + # predicted to run about a third of the 86 minutes above, so re-sizing them is its own change. + # ubuntu's 60/48 were sized on the whole tier and also apply per shard, unchanged. The # earlier triggers, at 51:32, 36:55 and 29 minutes, are in this file's git history. # `pytest_workers` is NOT this tier's knob and never was -- see the TOOLING_WORKERS note on the # step below. @@ -2544,7 +2547,7 @@ jobs: # # That is also why the install line below cannot be trimmed to a harness-only set: collection # imports the whole suite regardless of what this job intends to execute. Since the test - # shards, the harness step names only its shard's files; the partition guard, ubuntu only, + # shards, the harness step names only its shard's files; the partition guard, ubuntu shard 1, # is what still collects the whole suite and needs both. - name: Install Qt offscreen system libraries if: runner.os == 'Linux' @@ -2664,7 +2667,7 @@ jobs: # `PYTEST_WORKERS`. TOOLING_WORKERS: "${{ matrix.os == 'windows-2025' && '3' || '4' }}" # The leg's test shard of the manifest files, as an `@file` argument the way the engine test - # shards pass theirs; ubuntu's one shard is the whole tier. `--ignore-glob` prunes nothing + # shards pass theirs. `--ignore-glob` prunes nothing # from a named file, and stays so this selection and the guard's below are one. run: | mkdir -p out/tooling-shard @@ -2686,7 +2689,7 @@ jobs: # # The floor is deliberately loose (1,000 against ~1,545 executing on ubuntu and ~1,882 on # Windows when this was written), and `--shards` divides it by the leg's shard count, rounding - # up, so each windows-2025 test shard is held to its third. It is a DEAD-MARKER backstop, not a coverage assertion: a tight floor would go red + # up, so each test shard is held to its third. It is a DEAD-MARKER backstop, not a coverage assertion: a tight floor would go red # every time the tier legitimately grows or a platform gate moves, and a gate that cries wolf gets # deleted. Coverage drift is tests/test_tooling_partition.py's job, on evidence, not this one's. # A SCRIPT, NOT AN INLINE HEREDOC. The logic and its reasoning live in the script, where they can @@ -2702,11 +2705,11 @@ jobs: # THE PARTITION GUARD, the `test-shards` job's for the engine suite applied to this tier. It # runs pytest's own collection under the tier's selection and fails if a collected file is in - # no test shard or a file is in two. The split is a pure function of the tree, so the ubuntu - # leg answers for the windows-2025 shards, and it runs on docs-only PRs too. Only after a + # no test shard or a file is in two. The split is a pure function of the tree, so ubuntu shard 1 + # answers for every shard on both OSes, and it runs on docs-only PRs too. Only after a # passing suite, for the job-cap reason the engine guard states. - name: Tooling shards partition pytest's collection - if: ${{ !cancelled() && steps.tests.outcome == 'success' && runner.os == 'Linux' }} + if: ${{ !cancelled() && steps.tests.outcome == 'success' && runner.os == 'Linux' && matrix.shard == '1' }} timeout-minutes: 6 env: QT_QPA_PLATFORM: offscreen @@ -3005,7 +3008,7 @@ jobs: # output above is untouched: `docs/` is a GENUINE trigger for this tier, because 22 of the 130 # files in tests/tooling_manifest.txt read documents and tests/test_ci_tooling_gate.py asserts # `docs/security/THREAT-MODEL.md -> True` outright. Skip the tier on docs and those 22 files stop - # guarding anything. This keeps every one of them running, on one leg. + # guarding anything. This keeps every one of them running, on ubuntu. tooling_matrix: ${{ steps.f.outputs.tooling_matrix }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -3144,12 +3147,13 @@ jobs: # because unlike the two matrices above it depends on `code`, which is not known until the PR # arm at the bottom of this step. Every arm that writes `code` also writes this. A fork gets # ubuntu only either way, for the same reason the other two matrices do. - # A leg's `shard` and `of` go to shard_tests.py `--suite tooling`: windows-2025 in 3 test - # shards, ubuntu in 1 (the `tooling` job's note says why). - TU='{"os":"ubuntu-latest","shard":"1","of":"1"}' - TW='{"os":"windows-2025","of":"3","shard":' + # A leg's `shard` and `of` go to shard_tests.py `--suite tooling`: each OS in 3 test shards + # (the `tooling` job's note says why). + TU='{"os":"ubuntu-latest","of":"3","shard":' + TU="$TU\"1\"},$TU\"2\"},$TU\"3\"}" + TW="${TU//ubuntu-latest/windows-2025}" if [ "${GITHUB_REPOSITORY:-}" = "MEFORORG/MessageFoundry" ]; then - TOOLING_FULL="{\"include\":[$TU,$TW\"1\"},$TW\"2\"},$TW\"3\"}]}" + TOOLING_FULL="{\"include\":[$TU,$TW]}" else TOOLING_FULL="{\"include\":[$TU]}" fi diff --git a/scripts/quality/shard_tests.py b/scripts/quality/shard_tests.py index 80a8d057ea..c11d962fdc 100644 --- a/scripts/quality/shard_tests.py +++ b/scripts/quality/shard_tests.py @@ -28,8 +28,9 @@ it twice. And it holds the connscale smoke in shard 1, because scripts/connscale_harvest.py joins the smoke's readings to the `test (...)` jobs, and the herd floor is armed only there. -`--suite tooling` IS ci.yml's `tooling` JOB, THE REPO HARNESS TIER, split across its windows-2025 -legs (owner ruling 2026-11-24). It is the complement of the other two: exactly the files +`--suite tooling` IS ci.yml's `tooling` JOB, THE REPO HARNESS TIER, split across its legs, the +same 3 shards on each OS (windows-2025 by owner ruling 2026-11-24). +It is the complement of the other two: exactly the files tests/tooling_manifest.txt names, and nothing else. Its hash is SALTED, `crc32(":")`, because the unsalted hash split the measured tier badly; `TOOLING_SALT` below holds the measurement, how the salt was chosen and when to choose again. A salt is still a pure function of diff --git a/tests/test_ci_tooling_gate.py b/tests/test_ci_tooling_gate.py index 2c8ea5bfd2..38f3c7fe9a 100644 --- a/tests/test_ci_tooling_gate.py +++ b/tests/test_ci_tooling_gate.py @@ -223,7 +223,7 @@ def test_the_regex_is_read_not_copied() -> None: # LEGS", which is a separate decision with a separate failure mode. # # `tooling_matrix` narrows the tier to ubuntu on a docs-only PR. That is safe only because the tier -# still RUNS -- the 22 document-reading files in the manifest keep their coverage, on one leg instead +# still RUNS -- the 22 document-reading files in the manifest keep their coverage, on one OS instead # of two. If a future edit ever narrows the FILTER instead, the tests above go red. That is the # division of labour between the two blocks, and neither can cover for the other. # @@ -236,6 +236,10 @@ def test_the_regex_is_read_not_copied() -> None: _SOURCE_REPO = "MEFORORG/MessageFoundry" +#: The ubuntu half of every `tooling_matrix`: the whole tier, one leg per test shard. A docs-only PR +#: and a fork run exactly these, so a missing shard there would drop files with no other leg to run them. +_UBUNTU_LEGS = [{"os": "ubuntu-latest", "of": "3", "shard": str(n)} for n in (1, 2, 3)] + def _changes_step_script() -> str: """The `changes` job's detector step, read out of the workflow rather than restated here.""" @@ -330,7 +334,7 @@ def test_the_tooling_job_reads_the_matrix_and_does_not_carry_a_literal() -> None matrix = doc["jobs"]["tooling"]["strategy"]["matrix"] assert isinstance(matrix, str) and "tooling_matrix" in matrix, ( "the tooling job's matrix is no longer the `changes` output -- a literal list here restores " - "the full two-leg tier on every docs-only PR, with nothing to say so" + "the full two-OS tier on every docs-only PR, with nothing to say so" ) @@ -346,11 +350,11 @@ def test_every_non_pr_arm_emits_a_matrix(tmp_path: Path, event: str) -> None: assert _legs(outputs["tooling_matrix"]), f"the `{event}` arm emitted an empty leg list" -def test_a_docs_only_pr_gets_one_leg_and_a_code_pr_gets_both(tmp_path: Path) -> None: +def test_a_docs_only_pr_gets_the_ubuntu_legs_and_a_code_pr_gets_both(tmp_path: Path) -> None: """The narrowing itself, end to end, through the step's own git diff. Both halves in one test on purpose: the property worth asserting is the DIFFERENCE. A docs-only - assertion that passed because the full matrix had also collapsed to one leg would be a green + assertion that passed because the full matrix had also collapsed to ubuntu would be a green proving nothing. """ bash = require_bash(tmp_path) @@ -373,8 +377,8 @@ def test_a_docs_only_pr_gets_one_leg_and_a_code_pr_gets_both(tmp_path: Path) -> assert code_out["code"] == "true" code_legs = _legs(code_out["tooling_matrix"]) - assert docs_legs == ["ubuntu-latest"], ( - f"docs-only PR should run one ubuntu leg, got {docs_legs}" + assert json.loads(docs_out["tooling_matrix"])["include"] == _UBUNTU_LEGS, ( + f"docs-only PR should run every ubuntu shard and nothing else, got {docs_legs}" ) assert len(code_legs) > len(docs_legs), ( f"a code PR must run MORE legs than a docs-only one ({code_legs} vs {docs_legs}); equal " @@ -390,16 +394,17 @@ def test_a_fork_never_pays_for_the_windows_leg(tmp_path: Path) -> None: """The rule the `matrix` and `ide_matrix` outputs already follow, asserted for this one too.""" bash = require_bash(tmp_path) outputs = _run_detector(bash, tmp_path, "push", repo="someone/MessageFoundry") - legs = _legs(outputs["tooling_matrix"]) - assert legs == ["ubuntu-latest"], ( + legs = json.loads(outputs["tooling_matrix"])["include"] + assert legs == _UBUNTU_LEGS, ( f"a fork should build this tier on ubuntu only, got {legs} -- the 2x-billed Windows leg " "would be spending a contributor's own minutes" ) # --------------------------------------------------------------------------------------------- -# THE TEST SHARDS (owner ruling 2026-11-24): windows-2025 runs the tier as 3 test shards, ubuntu as -# one leg. A leg's `shard` and `of` reach scripts/quality/shard_tests.py `--suite tooling`; that +# THE TEST SHARDS (windows-2025 by owner ruling 2026-11-24, ubuntu since 2026-12-02): each OS runs the +# tier as the same 3 test shards. A leg's `shard` and `of` reach +# scripts/quality/shard_tests.py `--suite tooling`; that # script's own tests hold the split, these hold the wiring. A leg whose shards had a gap, a second # `of`, a shared check name or a shared artifact name would drop files, fail the upload, or hide a # red leg behind its sibling's name, each with every other check here green. @@ -434,13 +439,13 @@ def full_matrix(tmp_path_factory: pytest.TempPathFactory) -> list[dict[str, str] return list(json.loads(outputs["tooling_matrix"])["include"]) -def test_windows_2025_runs_the_tier_in_three_test_shards_and_ubuntu_in_one( +def test_each_os_runs_the_tier_in_the_same_three_test_shards( full_matrix: list[dict[str, str]], ) -> None: - """Falsified by dropping `$TW"3"}` from TOOLING_FULL in ci.yml: RED. Restored.""" + """Falsified by dropping shard 3 from TU in ci.yml: RED. Restored.""" legs = full_matrix assert legs == [ - {"os": "ubuntu-latest", "shard": "1", "of": "1"}, + *_UBUNTU_LEGS, *({"os": "windows-2025", "of": "3", "shard": str(n)} for n in (1, 2, 3)), ], legs @@ -461,7 +466,6 @@ def test_every_tooling_leg_has_its_own_check_name_and_junit_artifact( leg["os"] if leg["of"] == "1" else f"{leg['os']}, shard {leg['shard']} of {leg['of']}" for leg in legs ] - assert "ubuntu-latest" in names, "the ubuntu leg's check name changed" assert len(set(names)) == len(names), names upload = _tooling_step("Upload the tier's junit") template = str(dict(upload["with"])["name"]) # type: ignore[call-overload] @@ -502,15 +506,19 @@ def test_the_partition_guard_reads_the_tier_s_selection_on_one_leg( pytest_line = next(line for line in harness.splitlines() if line.startswith("pytest ")) guard = _tooling_step(_GUARD_STEP) condition = str(guard["if"]) - for needle in ("!cancelled()", "steps.tests.outcome == 'success'", "runner.os == 'Linux'"): - assert needle in condition, condition + # Pinned whole: without the shard clause the guard runs three times, and a shard number no ubuntu + # leg has would run it never. `_UBUNTU_LEGS` holds shard 1 on every arm that runs the tier. + assert condition == ( + "${{ !cancelled() && steps.tests.outcome == 'success' && runner.os == 'Linux'" + " && matrix.shard == '1' }}" + ) match = re.fullmatch( r"python scripts/quality/shard_tests\.py --suite tooling --of (\d+) --check-collection" r" -- (.+)", str(guard["run"]).strip(), ) assert match, guard["run"] - shard_counts = {leg["of"] for leg in full_matrix if leg["of"] != "1"} + shard_counts = {leg["of"] for leg in full_matrix} assert shard_counts == {match.group(1)}, (shard_counts, match.group(1)) # The selection is every `-m` and every `--ignore-glob` the harness line carries, and the # guard's tail must be exactly that: a narrower or broader guard compares the wrong collection. diff --git a/tests/test_quality_shard_tests.py b/tests/test_quality_shard_tests.py index d2b818009b..f48ef6b158 100644 --- a/tests/test_quality_shard_tests.py +++ b/tests/test_quality_shard_tests.py @@ -239,7 +239,7 @@ def run(*_a: object, **_k: object) -> subprocess.CompletedProcess[str]: @pytest.fixture(scope="module") def tooling_shards() -> int: """ci.yml's tooling shard count, read from its partition guard, which - tests/test_ci_tooling_gate.py holds to the windows-2025 legs' `of`. A fixture, so a drifted + tests/test_ci_tooling_gate.py holds to every leg's `of`. A fixture, so a drifted guard line fails these tests rather than this module's collection.""" text = (_ROOT / ".github" / "workflows" / "ci.yml").read_text(encoding="utf-8") counts = set(re.findall(r"shard_tests\.py --suite tooling --of (\d+) --check-collection", text)) From dfddfd729f62a0567caf3f6402396e6a1d0a1918 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 16:36:41 -0600 Subject: [PATCH 2/5] CI: review repairs for the ubuntu test shards of the repo harness tier The tooling gate tests now pin the whole six-leg matrix on every arm that runs the tier on code, and tie the partition guard's test shard to the matrix. The re-derive trigger names ubuntu. Notes that the split made false are corrected. Verified-by: tests --- .github/workflows/ci.yml | 12 ++++++------ scripts/quality/shard_tests.py | 7 ++++--- tests/conftest.py | 4 ++-- tests/test_ci_tooling_gate.py | 29 ++++++++++++++++------------- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9764cccd4c..7b7a504bde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2515,10 +2515,10 @@ jobs: # # RE-DERIVE IF a GREEN windows-2025 test shard of this tier is observed above 76:55 -- the # 100-minute cap divided by the 1.30 floor scripts/ci/step_margin.py applies to the steps it - # gates -- or if any shard is killed at the 100-minute step cap, or if TOOLING_WORKERS or the - # shard count changes. Both caps are unchanged by the split and apply per shard; a shard is + # gates -- or a GREEN ubuntu one above 36:55, the same rule on its 48, or if any test shard is + # killed at its step cap, or if TOOLING_WORKERS or the test shard count changes. Both caps are unchanged by the split and apply per shard; a shard is # predicted to run about a third of the 86 minutes above, so re-sizing them is its own change. - # ubuntu's 60/48 were sized on the whole tier and also apply per shard, unchanged. The + # ubuntu's 60/48 also apply per test shard, unchanged. The # earlier triggers, at 51:32, 36:55 and 29 minutes, are in this file's git history. # `pytest_workers` is NOT this tier's knob and never was -- see the TOOLING_WORKERS note on the # step below. @@ -2547,7 +2547,7 @@ jobs: # # That is also why the install line below cannot be trimmed to a harness-only set: collection # imports the whole suite regardless of what this job intends to execute. Since the test - # shards, the harness step names only its shard's files; the partition guard, ubuntu shard 1, + # shards, the harness step names only its shard's files; the partition guard, ubuntu test shard 1, # is what still collects the whole suite and needs both. - name: Install Qt offscreen system libraries if: runner.os == 'Linux' @@ -2705,8 +2705,8 @@ jobs: # THE PARTITION GUARD, the `test-shards` job's for the engine suite applied to this tier. It # runs pytest's own collection under the tier's selection and fails if a collected file is in - # no test shard or a file is in two. The split is a pure function of the tree, so ubuntu shard 1 - # answers for every shard on both OSes, and it runs on docs-only PRs too. Only after a + # no test shard or a file is in two. The split is a pure function of the tree, so ubuntu test + # shard 1 answers for every test shard on both OSes, and it runs on docs-only PRs too. Only after a # passing suite, for the job-cap reason the engine guard states. - name: Tooling shards partition pytest's collection if: ${{ !cancelled() && steps.tests.outcome == 'success' && runner.os == 'Linux' && matrix.shard == '1' }} diff --git a/scripts/quality/shard_tests.py b/scripts/quality/shard_tests.py index c11d962fdc..93f9b035ec 100644 --- a/scripts/quality/shard_tests.py +++ b/scripts/quality/shard_tests.py @@ -29,7 +29,7 @@ the smoke's readings to the `test (...)` jobs, and the herd floor is armed only there. `--suite tooling` IS ci.yml's `tooling` JOB, THE REPO HARNESS TIER, split across its legs, the -same 3 shards on each OS (windows-2025 by owner ruling 2026-11-24). +same 3 test shards on each OS (windows-2025 by owner ruling 2026-11-24). It is the complement of the other two: exactly the files tests/tooling_manifest.txt names, and nothing else. Its hash is SALTED, `crc32(":")`, because the unsalted hash split the measured tier badly; `TOOLING_SALT` below holds the @@ -76,8 +76,9 @@ #: non-negative integer that puts every shard within 5 percent of the mean there: 4883 / 5208 / 5323 #: against 5138. About a quarter of salts land within 15 percent on that junit, so the unsalted #: split was not unlucky, only ordinary. A file added later lands by its own hash and moves nothing, so the balance drifts -#: as the tier grows rather than jumping. RE-PICK IT when a shard's junit test-time sum is observed -#: more than 15 percent off the mean of the three, by the same search over a fresh junit; a re-pick +#: as the tier grows rather than jumping. RE-PICK IT when a windows-2025 test shard's +#: junit test-time sum is observed more than 15 percent off the mean of that OS's three (ubuntu +#: uses the same split, and its balance was not what chose the salt), by the same search over a fresh junit; a re-pick #: moves files between shards, which costs nothing but a cold read of the next run's balance. TOOLING_SALT = "9" diff --git a/tests/conftest.py b/tests/conftest.py index d3af97038e..24966a71fd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -580,8 +580,8 @@ def _private_pwsh_startup_cache(tmp_path_factory: pytest.TempPathFactory) -> Ite folder instead, which is just as private to the test. The cost: every pwsh in the suite now starts with no startup profile and no module analysis - cache, so each start is slower. That is unmeasured on Linux. The duration of the ubuntu leg of - ``repo harness tests`` will show it. The pytest process and every other child that reads + cache, so each start is slower. That is unmeasured on Linux. The summed durations of + the ubuntu test shards of ``repo harness tests`` will show it. The pytest process and every other child that reads ``XDG_CACHE_HOME`` (at least pip, uv and pre-commit) also start each test with an empty cache. A test that runs a real installer would fetch afresh. diff --git a/tests/test_ci_tooling_gate.py b/tests/test_ci_tooling_gate.py index 38f3c7fe9a..b6a12d3837 100644 --- a/tests/test_ci_tooling_gate.py +++ b/tests/test_ci_tooling_gate.py @@ -236,9 +236,11 @@ def test_the_regex_is_read_not_copied() -> None: _SOURCE_REPO = "MEFORORG/MessageFoundry" -#: The ubuntu half of every `tooling_matrix`: the whole tier, one leg per test shard. A docs-only PR -#: and a fork run exactly these, so a missing shard there would drop files with no other leg to run them. +#: The ubuntu half of `tooling_matrix`: the whole tier, one leg per test shard. A docs-only PR and a +#: fork run exactly these, so a missing one would drop files with no other leg to run them. _UBUNTU_LEGS = [{"os": "ubuntu-latest", "of": "3", "shard": str(n)} for n in (1, 2, 3)] +#: The whole matrix, on this repository, for every arm that runs the tier on code. +_FULL_LEGS = _UBUNTU_LEGS + [{**leg, "os": "windows-2025"} for leg in _UBUNTU_LEGS] def _changes_step_script() -> str: @@ -348,6 +350,8 @@ def test_every_non_pr_arm_emits_a_matrix(tmp_path: Path, event: str) -> None: "the job -- it does not fall back to a full matrix" ) assert _legs(outputs["tooling_matrix"]), f"the `{event}` arm emitted an empty leg list" + if outputs["tooling"] == "true": + assert json.loads(outputs["tooling_matrix"])["include"] == _FULL_LEGS def test_a_docs_only_pr_gets_the_ubuntu_legs_and_a_code_pr_gets_both(tmp_path: Path) -> None: @@ -376,9 +380,10 @@ def test_a_docs_only_pr_gets_the_ubuntu_legs_and_a_code_pr_gets_both(tmp_path: P code_out = _run_detector(bash, code, "pull_request", base_sha=base) assert code_out["code"] == "true" code_legs = _legs(code_out["tooling_matrix"]) + assert json.loads(code_out["tooling_matrix"])["include"] == _FULL_LEGS assert json.loads(docs_out["tooling_matrix"])["include"] == _UBUNTU_LEGS, ( - f"docs-only PR should run every ubuntu shard and nothing else, got {docs_legs}" + f"docs-only PR should run every ubuntu test shard and nothing else, got {docs_legs}" ) assert len(code_legs) > len(docs_legs), ( f"a code PR must run MORE legs than a docs-only one ({code_legs} vs {docs_legs}); equal " @@ -444,10 +449,7 @@ def test_each_os_runs_the_tier_in_the_same_three_test_shards( ) -> None: """Falsified by dropping shard 3 from TU in ci.yml: RED. Restored.""" legs = full_matrix - assert legs == [ - *_UBUNTU_LEGS, - *({"os": "windows-2025", "of": "3", "shard": str(n)} for n in (1, 2, 3)), - ], legs + assert legs == _FULL_LEGS, legs def test_every_tooling_leg_has_its_own_check_name_and_junit_artifact( @@ -501,16 +503,17 @@ def test_each_leg_runs_its_own_shard_of_the_tier() -> None: def test_the_partition_guard_reads_the_tier_s_selection_on_one_leg( full_matrix: list[dict[str, str]], ) -> None: - """Falsified by `--of 2` on the guard line: RED on the count. Restored.""" + """Falsified by `--of 2` on the guard line: RED on the count. Restored. And by dropping the + `matrix.shard` clause from its `if:`: RED on the condition. Restored.""" harness = str(_tooling_step(_HARNESS_STEP)["run"]) pytest_line = next(line for line in harness.splitlines() if line.startswith("pytest ")) guard = _tooling_step(_GUARD_STEP) condition = str(guard["if"]) - # Pinned whole: without the shard clause the guard runs three times, and a shard number no ubuntu - # leg has would run it never. `_UBUNTU_LEGS` holds shard 1 on every arm that runs the tier. + # Pinned whole: without the `matrix.shard` clause the guard runs three times, and with a number + # no ubuntu leg has it never runs. assert condition == ( "${{ !cancelled() && steps.tests.outcome == 'success' && runner.os == 'Linux'" - " && matrix.shard == '1' }}" + f" && matrix.shard == '{_UBUNTU_LEGS[0]['shard']}' }}}}" ) match = re.fullmatch( r"python scripts/quality/shard_tests\.py --suite tooling --of (\d+) --check-collection" @@ -569,8 +572,8 @@ def receipt(executed: int, skipped: int, shards: int) -> int: # # The damage shape is what makes it worth an arm of its own. Without the utilities the detector's # `grep -qE` cannot run, the `if` takes its else branch, the step writes `tooling=false`, and -# `test_a_docs_only_pr_gets_one_leg_and_a_code_pr_gets_both` fails saying THE FILTER MUST NOT -# NARROW -- a sentence about ci.yml, produced by a box that never read ci.yml's answer. A reader +# `test_a_docs_only_pr_gets_the_ubuntu_legs_and_a_code_pr_gets_both` fails saying THE FILTER MUST +# NOT NARROW -- a sentence about ci.yml, produced by a box that never read ci.yml's answer. A reader # acting on it edits a workflow that was never wrong. Measured on one variable before the fix: this # module was 27 passed with coreutils on PATH and 1 failed without. # --------------------------------------------------------------------------------------------- From 7a18d94fbf6b919cb6649a127f1b704f075f67f6 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 17:12:58 -0600 Subject: [PATCH 3/5] tests: the engine legs check every leg of the tooling matrix The tests that checked the tooling legs all ran inside one shard of that tier, so dropping a shard could drop its own check. The new tests run ci.yml's changes step on the engine legs, and a control drops each leg in turn. The conftest note on the pwsh cache cost no longer says the shard durations will show it. Verified-by: tests --- tests/conftest.py | 3 +- tests/test_tooling_partition.py | 132 ++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 24966a71fd..26a86637b7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -581,7 +581,8 @@ def _private_pwsh_startup_cache(tmp_path_factory: pytest.TempPathFactory) -> Ite The cost: every pwsh in the suite now starts with no startup profile and no module analysis cache, so each start is slower. That is unmeasured on Linux. The summed durations of - the ubuntu test shards of ``repo harness tests`` will show it. The pytest process and every other child that reads + the ubuntu test shards of ``repo harness tests`` are not comparable with the old single ubuntu + leg's, so they do not show it. The pytest process and every other child that reads ``XDG_CACHE_HOME`` (at least pip, uv and pre-commit) also start each test with an empty cache. A test that runs a real installer would fetch afresh. diff --git a/tests/test_tooling_partition.py b/tests/test_tooling_partition.py index f6c5385305..756d67b230 100644 --- a/tests/test_tooling_partition.py +++ b/tests/test_tooling_partition.py @@ -27,13 +27,20 @@ from __future__ import annotations import ast +import functools +import json +import os import re +import subprocess import tomllib from pathlib import Path import pytest +import yaml from tests import _tooling_manifest as tooling_manifest +from tests._bash_resolver import explain_returncode, probe_env, require_bash +from tests._ci_paths import plant_lists _ROOT = Path(__file__).resolve().parents[1] _TESTS = _ROOT / "tests" @@ -773,6 +780,131 @@ def test_ci_wires_both_halves(needle: str, why: str) -> None: assert needle in _CI.read_text(encoding="utf-8"), f"{needle!r} missing from ci.yml: {why}" +# --------------------------------------------------------------------------------------------------- +# THE TIER'S LEGS, CHECKED FROM OUTSIDE THE TIER. ci.yml's `changes` job builds `tooling_matrix` from +# the ubuntu list `TU`, and derives the windows list `TW` from it, so a shard dropped from `TU` is +# dropped on both systems. tests/test_ci_tooling_gate.py checks the legs too, but that file runs in +# one shard of the tier, so the edit that drops its own shard drops the check. These run on the +# engine legs, which a ci.yml edit always sets `code=true` for. +# +# THE LEGS ARE SPELLED OUT HERE, not imported from that file, so one edit cannot move both. +# --------------------------------------------------------------------------------------------------- + +_UBUNTU_LEGS = [("ubuntu-latest", shard, "3") for shard in ("1", "2", "3")] +_WINDOWS_LEGS = [("windows-2025", shard, "3") for shard in ("1", "2", "3")] +_SOURCE_REPO = "MEFORORG/MessageFoundry" + + +@pytest.fixture(scope="module") +def bash_path(tmp_path_factory: pytest.TempPathFactory) -> str: + return require_bash(tmp_path_factory.mktemp("resolve-bash")) + + +@functools.cache +def _changes_step() -> str: + """The `changes` job's detector step, read from the workflow once per process.""" + steps = yaml.safe_load(_CI.read_text(encoding="utf-8"))["jobs"]["changes"]["steps"] + return str(next(step["run"] for step in steps if step.get("id") == "f")) + + +def _tooling_legs( + bash: str, cwd: Path, script: str, *, event: str, repo: str = _SOURCE_REPO, changed: str = "" +) -> list[tuple[str, str, str]]: + """Run the step and return its `tooling_matrix` legs as sorted (os, shard, of). + + ``git`` is a shell function printing ``changed``, the only answer the step asks git for. + """ + path = cwd / "changes.sh" + stub = "git() { printf '%s\\n' \"$CHANGED_PATH\"; }\n" + path.write_text(stub + script, encoding="utf-8", newline="\n") + plant_lists(cwd) + out = cwd / "gh_output" + env = probe_env(Path(bash), dict(os.environ)) + env.update( + EVENT_NAME=event, + BASE_SHA="base", + CHANGED_PATH=changed, + GITHUB_REPOSITORY=repo, + GITHUB_OUTPUT=str(out), + ) + proc = subprocess.run( # noqa: S603 # nosec B603 - resolved interpreter, fixed argv, tmp paths + [bash, "-e", str(path)], + cwd=str(cwd), + env=env, + capture_output=True, + # Under pytest-timeout's 60 seconds, so this error fires before that one ends the process. + timeout=45, + check=False, + ) + assert proc.returncode == 0, ( + explain_returncode(proc.returncode, "the `changes` step") + + "\n" + + proc.stderr.decode("utf-8", "replace") + ) + lines = out.read_text(encoding="utf-8").splitlines() + found = [line.partition("=")[2] for line in lines if line.startswith("tooling_matrix=")] + assert len(found) == 1, f"expected one tooling_matrix line, found {found}" + matrix = json.loads(found[0]) + # Another key (`exclude`, an axis) would change the legs without changing `include`. + assert list(matrix) == ["include"], matrix + return sorted((leg["os"], leg["shard"], leg["of"]) for leg in matrix["include"]) + + +@pytest.mark.parametrize( + ("event", "repo", "changed", "expected"), + [ + ("push", _SOURCE_REPO, "", _UBUNTU_LEGS + _WINDOWS_LEGS), + ("workflow_dispatch", _SOURCE_REPO, "", _UBUNTU_LEGS + _WINDOWS_LEGS), + ("pull_request", _SOURCE_REPO, "scripts/x.py", _UBUNTU_LEGS + _WINDOWS_LEGS), + ("pull_request", _SOURCE_REPO, "docs/ARCHITECTURE.md", _UBUNTU_LEGS), + ("push", "someone/fork", "", _UBUNTU_LEGS), + ], + ids=["push", "dispatch", "code-pr", "docs-only-pr", "fork"], +) +def test_the_tooling_matrix_has_every_leg( + event: str, + repo: str, + changed: str, + expected: list[tuple[str, str, str]], + tmp_path: Path, + bash_path: str, +) -> None: + """A missing leg drops a third of the tier on that system, with every leg that did run green.""" + legs = _tooling_legs( + bash_path, tmp_path, _changes_step(), event=event, repo=repo, changed=changed + ) + assert legs == expected, ( + f"ci.yml's `tooling_matrix` is not the whole tier on {event}: {legs}. If the shard count " + "moved on purpose, move these legs with it" + ) + + +@pytest.mark.parametrize("leg", _UBUNTU_LEGS + _WINDOWS_LEGS, ids=lambda leg: f"{leg[0]}-{leg[1]}") +def test_a_dropped_tooling_leg_is_seen( + leg: tuple[str, str, str], tmp_path: Path, bash_path: str +) -> None: + """The control: drop one leg from an in-memory copy of the step, and the check above must red. + + An ubuntu leg is cut out of ``TU`` before ``TW`` is derived, so it goes on both systems. + """ + system, shard, of = leg + name = "TU" if system == "ubuntu-latest" else "TW" + text = json.dumps({"os": system, "of": of, "shard": shard}, separators=(",", ":")) + cut = f",{text}" if shard == "3" else f"{text}," + script, count = re.subn( + rf'^{name}="\$.*$', + lambda m: f"{m[0]}\n{name}=${{{name}/'{cut}'/}}", + _changes_step(), + flags=re.M, + ) + assert count == 1, f"expected one line building {name} in the `changes` step, found {count}" + legs = _tooling_legs(bash_path, tmp_path, script, event="push") + gone = {leg, ("windows-2025", shard, of)} + whole = _UBUNTU_LEGS + _WINDOWS_LEGS + assert legs == [kept for kept in whole if kept not in gone], "the cut did not take as planted" + assert legs != whole + + # --------------------------------------------------------------------------------------------------- # ONE READER (BACKLOG #1434). The manifest used to be parsed three times -- in tests/conftest.py (the # copy that applies the marker), in this file, and in tests/test_ci_tooling_gate.py -- and nothing From 65eb6a018c562262019e5c09704b1bb356476b78 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 17:22:42 -0600 Subject: [PATCH 4/5] tests: the tooling leg control now calls the check it controls Review repairs: one shared assertion, a git stub that refuses any other call, a lower child timeout, test shard wording, and a shorter conftest sentence. Verified-by: tests --- tests/conftest.py | 4 ++-- tests/test_tooling_partition.py | 41 ++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 26a86637b7..b2858d7e49 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -581,8 +581,8 @@ def _private_pwsh_startup_cache(tmp_path_factory: pytest.TempPathFactory) -> Ite The cost: every pwsh in the suite now starts with no startup profile and no module analysis cache, so each start is slower. That is unmeasured on Linux. The summed durations of - the ubuntu test shards of ``repo harness tests`` are not comparable with the old single ubuntu - leg's, so they do not show it. The pytest process and every other child that reads + the ubuntu test shards of ``repo harness tests`` are not comparable with those of the old + single ubuntu leg. The pytest process and every other child that reads ``XDG_CACHE_HOME`` (at least pip, uv and pre-commit) also start each test with an empty cache. A test that runs a real installer would fetch afresh. diff --git a/tests/test_tooling_partition.py b/tests/test_tooling_partition.py index 756d67b230..76af324fd8 100644 --- a/tests/test_tooling_partition.py +++ b/tests/test_tooling_partition.py @@ -782,10 +782,11 @@ def test_ci_wires_both_halves(needle: str, why: str) -> None: # --------------------------------------------------------------------------------------------------- # THE TIER'S LEGS, CHECKED FROM OUTSIDE THE TIER. ci.yml's `changes` job builds `tooling_matrix` from -# the ubuntu list `TU`, and derives the windows list `TW` from it, so a shard dropped from `TU` is -# dropped on both systems. tests/test_ci_tooling_gate.py checks the legs too, but that file runs in -# one shard of the tier, so the edit that drops its own shard drops the check. These run on the -# engine legs, which a ci.yml edit always sets `code=true` for. +# the ubuntu list `TU`, and derives the windows list `TW` from it, so a test shard dropped from `TU` +# is dropped on both systems. tests/test_ci_tooling_gate.py checks the legs too, but that file runs +# in one test shard of the tier, so an edit that drops that test shard drops the check. These run on +# the engine legs, which a ci.yml edit always sets `code=true` for. They check the matrix the step +# emits, and not the `tooling` output or how the `tooling` job uses the matrix. # # THE LEGS ARE SPELLED OUT HERE, not imported from that file, so one edit cannot move both. # --------------------------------------------------------------------------------------------------- @@ -804,7 +805,17 @@ def bash_path(tmp_path_factory: pytest.TempPathFactory) -> str: def _changes_step() -> str: """The `changes` job's detector step, read from the workflow once per process.""" steps = yaml.safe_load(_CI.read_text(encoding="utf-8"))["jobs"]["changes"]["steps"] - return str(next(step["run"] for step in steps if step.get("id") == "f")) + found = [str(step["run"]) for step in steps if step.get("id") == "f"] + assert len(found) == 1, f"expected one `changes` step with id `f`, found {len(found)}" + return found[0] + + +def _assert_legs(legs: list[tuple[str, str, str]], expected: list[tuple[str, str, str]]) -> None: + """The check itself, shared with its control so that the control cannot pass without it.""" + assert legs == expected, ( + f"ci.yml's `tooling_matrix` is not the legs the tier needs: {legs}, expected {expected}. If " + "the test shard count moved on purpose, move the legs in this file with it" + ) def _tooling_legs( @@ -812,10 +823,14 @@ def _tooling_legs( ) -> list[tuple[str, str, str]]: """Run the step and return its `tooling_matrix` legs as sorted (os, shard, of). - ``git`` is a shell function printing ``changed``, the only answer the step asks git for. + ``git`` is a shell function that answers the step's one diff with ``changed`` and fails on any + other call. """ path = cwd / "changes.sh" - stub = "git() { printf '%s\\n' \"$CHANGED_PATH\"; }\n" + stub = ( + 'git() { [ "$*" = "diff --name-only --no-renames base...HEAD" ] || ' + '{ echo "unexpected: git $*" >&2; return 1; }; printf \'%s\\n\' "$CHANGED_PATH"; }\n' + ) path.write_text(stub + script, encoding="utf-8", newline="\n") plant_lists(cwd) out = cwd / "gh_output" @@ -832,8 +847,8 @@ def _tooling_legs( cwd=str(cwd), env=env, capture_output=True, - # Under pytest-timeout's 60 seconds, so this error fires before that one ends the process. - timeout=45, + # Under the lowest per-test cap a leg sets (60 seconds), which also covers fixture setup. + timeout=30, check=False, ) assert proc.returncode == 0, ( @@ -873,10 +888,7 @@ def test_the_tooling_matrix_has_every_leg( legs = _tooling_legs( bash_path, tmp_path, _changes_step(), event=event, repo=repo, changed=changed ) - assert legs == expected, ( - f"ci.yml's `tooling_matrix` is not the whole tier on {event}: {legs}. If the shard count " - "moved on purpose, move these legs with it" - ) + _assert_legs(legs, expected) @pytest.mark.parametrize("leg", _UBUNTU_LEGS + _WINDOWS_LEGS, ids=lambda leg: f"{leg[0]}-{leg[1]}") @@ -902,7 +914,8 @@ def test_a_dropped_tooling_leg_is_seen( gone = {leg, ("windows-2025", shard, of)} whole = _UBUNTU_LEGS + _WINDOWS_LEGS assert legs == [kept for kept in whole if kept not in gone], "the cut did not take as planted" - assert legs != whole + with pytest.raises(AssertionError, match="is not the legs the tier needs"): + _assert_legs(legs, whole) # --------------------------------------------------------------------------------------------------- From 0aef401484b87dd82da55189a0d55621a750edc0 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 17:46:07 -0600 Subject: [PATCH 5/5] tests: the engine legs pin how the tooling job uses its matrix test_ci_wires_both_halves also requires the job's matrix line, its TOOLING_SHARD env line and the selector call, with a control that cuts each one. The child timeout in the matrix tests is now 120 seconds. Verified-by: tests --- tests/test_tooling_partition.py | 36 +++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tests/test_tooling_partition.py b/tests/test_tooling_partition.py index 76af324fd8..6a7fb2fd60 100644 --- a/tests/test_tooling_partition.py +++ b/tests/test_tooling_partition.py @@ -759,6 +759,25 @@ def test_marker_is_registered() -> None: ) +#: How the `tooling` job uses the matrix. Pinned here because the tests that read these steps run +#: inside the tier, and a leg that ran the wrong test shard could drop them. +_TOOLING_JOB_WIRING = [ + ("TOOLING_SHARD: ${{ matrix.shard }}", "each leg must run its own test shard"), + ( + '--suite tooling --shard "$TOOLING_SHARD"', + "the selector must be given the leg's own test shard", + ), + ( + "matrix: ${{ fromJSON(needs.changes.outputs.tooling_matrix) }}", + "the job must take its legs from the `changes` job", + ), +] + + +def _assert_wired(ci_text: str, needle: str, why: str) -> None: + assert needle in ci_text, f"{needle!r} missing from ci.yml: {why}" + + @pytest.mark.parametrize( ("needle", "why"), [ @@ -773,11 +792,20 @@ def test_marker_is_registered() -> None: "-m tooling", "the tooling job must SELECT it -- without it the tier stops running anywhere", ), + *_TOOLING_JOB_WIRING, ], ) def test_ci_wires_both_halves(needle: str, why: str) -> None: - """Both spellings must appear. Either one alone is a silent half-failure.""" - assert needle in _CI.read_text(encoding="utf-8"), f"{needle!r} missing from ci.yml: {why}" + """Every spelling must appear. One missing is a silent half-failure.""" + _assert_wired(_CI.read_text(encoding="utf-8"), needle, why) + + +@pytest.mark.parametrize(("needle", "why"), _TOOLING_JOB_WIRING) +def test_removed_tooling_job_wiring_is_seen(needle: str, why: str) -> None: + """The control: cut the text once from an in-memory ci.yml, and the check above must red.""" + text = _CI.read_text(encoding="utf-8").replace(needle, "", 1) + with pytest.raises(AssertionError, match="missing from ci.yml"): + _assert_wired(text, needle, why) # --------------------------------------------------------------------------------------------------- @@ -847,8 +875,8 @@ def _tooling_legs( cwd=str(cwd), env=env, capture_output=True, - # Under the lowest per-test cap a leg sets (60 seconds), which also covers fixture setup. - timeout=30, + # A hang backstop. A leg whose per-test cap is lower (60 seconds on ubuntu) ends first. + timeout=120, check=False, ) assert proc.returncode == 0, (