From e1186f03ec10790cb95eaa82e46617fff607c5ad Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Mon, 16 Nov 2026 20:21:57 +0800 Subject: [PATCH 1/3] Hold mutation shards until the gates pass A mutation shard rebuilds and runs the whole suite in an unmutated tree, so when the Rust lane fails the shards fail the same way and each pays several minutes of setup to learn it. The mutants job needed only the plan, so it started beside the gates. Make it need the gates as well, and start only when both the plan and the gates succeeded and the plan found mutants. The plan result is checked explicitly because the plan is skipped on a push or a merge group, where its empty count would otherwise pass the zero guard. Shards now start after the slowest gates lane. The aggregate check job already accepts a skipped mutants job after a successful plan, and a failed gates lane fails it first. A new suite pins the job's needs and condition. Change-Id: I994815975efcce27629c6fcfd4a44ae4acb98ebd --- .github/workflows/check.yml | 17 ++++++++-- scripts/test.sh | 1 + tests/test_check_workflow.py | 61 ++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 tests/test_check_workflow.py diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 2cf880325..f3258080d 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -673,10 +673,21 @@ jobs: # asks is what a change failed to test, and that is worth answering while the # change can still be edited. mutants: - needs: plan-mutants - # No mutants means no runners. A docs-only or JS-only pull request should + needs: [plan-mutants, gates] + # A shard rebuilds and runs the whole suite in an unmutated tree, so it + # fails the same way the Rust lane does, and pays several minutes of setup + # per shard to learn it. Waiting for the gates avoids that; the trade-off + # is that shards start after the slowest gates lane rather than beside it. + # + # `plan-mutants.result` is explicit because the plan is skipped on a push + # or a merge group, where its count is empty and `'' != '0'` would pass. + # No mutants means no runners: a docs-only or JS-only pull request should # not start a job to discover it has nothing to do. - if: needs.plan-mutants.outputs.count != '0' + if: >- + ${{ !cancelled() + && needs.plan-mutants.result == 'success' + && needs.gates.result == 'success' + && needs.plan-mutants.outputs.count != '0' }} runs-on: ubuntu-24.04 timeout-minutes: 45 strategy: diff --git a/scripts/test.sh b/scripts/test.sh index d663e04ab..62660fb12 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -747,6 +747,7 @@ gate git-hooks "$ROOT/scripts/test-git-hooks.sh" gate commit-reflow-tests unittest_gate "$ROOT/tests/test_commit_reflow.py" gate commit-draft-tests unittest_gate "$ROOT/tests/test_commit_draft.py" gate pr-text-tests unittest_gate "$ROOT/tests/test_check_pr_text.py" +gate check-workflow-tests unittest_gate "$ROOT/tests/test_check_workflow.py" gate shell-syntax shell_syntax gate browser-check-env env BROWSER_CHECK_VALIDATE_ENV_ONLY=1 sh "$ROOT/scripts/browser-check.sh" diff --git a/tests/test_check_workflow.py b/tests/test_check_workflow.py new file mode 100644 index 000000000..d2244f416 --- /dev/null +++ b/tests/test_check_workflow.py @@ -0,0 +1,61 @@ +"""The shape of the mutation job and the aggregate status in check.yml.""" + +import importlib.util +from pathlib import Path +import re +import unittest + +ROOT = Path(__file__).resolve().parents[1] +SPEC = importlib.util.spec_from_file_location( + "check_workflow_support", ROOT / "tests/support.py" +) +support = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(support) + + +def header(body, key): + """The value of a job-level key, with a folded scalar joined to one line.""" + found = re.search(rf"^ {key}: (.*(?:\n .*)*)", body, re.M) + if found is None: + raise AssertionError(f"job no longer sets {key}") + return " ".join(found[1].replace(">-", "").split()) + + +class MutantsJobTests(unittest.TestCase): + def setUp(self): + self.body = support.job("mutants") + + def test_waits_for_the_gates_and_the_plan(self): + needs = set(re.findall(r"[a-z][a-z-]*", header(self.body, "needs"))) + self.assertLessEqual({"gates", "plan-mutants"}, needs) + + def test_starts_only_after_both_succeed_with_work_to_do(self): + condition = header(self.body, "if").strip("${} ") + # Exactly these terms, all required. `!cancelled()` replaces the + # implicit success() that would otherwise skip the job. plan-mutants + # is skipped on push and merge_group, where its count output is empty + # and would pass the != '0' guard on its own. + self.assertEqual( + [ + "!cancelled()", + "needs.plan-mutants.result == 'success'", + "needs.gates.result == 'success'", + "needs.plan-mutants.outputs.count != '0'", + ], + [term.strip() for term in condition.split("&&")], + ) + + +class AggregateStatusTests(unittest.TestCase): + def test_check_accepts_mutants_skipped_after_a_plan(self): + body = support.job("check") + self.assertRegex(body, r"success/success \| skipped/success[^)]*\) ;;") + # A failed gates lane fails the job before the mutants table is read. + self.assertLess(body.index('"$GATES" != success'), body.index("case ")) + + def test_release_does_not_wait_for_mutants(self): + self.assertNotIn("mutants", header(support.job("release"), "needs")) + + +if __name__ == "__main__": + unittest.main() From c502b1e8eb0ddb62898e0f1eb0a9c9ec90a13c1f Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Mon, 16 Nov 2026 21:12:23 +0800 Subject: [PATCH 2/3] Hold CI mutation runs to the lockfile The Makefile mutants target passes --cargo-arg=--locked so a mutant is never judged against a lockfile cargo quietly updated, but the plan's --list and the shard's --list and run did not, so CI tested against whatever lock cargo produced and the local and CI answers could differ. Pass the flag on all three commands and assert in the workflow suite that each carries it and that the plan and the shard list select with the same flags and values, so the shard count matches what runs. Change-Id: I32c942cb8c272fef31dff6829ab6f1419083f54e --- .github/workflows/check.yml | 7 +++-- tests/test_check_workflow.py | 55 ++++++++++++++++++++++++++++++++++++ tests/test_mutants_plan.py | 2 +- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index f3258080d..c5dcd0464 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -629,7 +629,8 @@ jobs: set -o pipefail count=0 if [ -s "$RUNNER_TEMP/pr.diff" ]; then - cargo mutants --list --in-diff "$RUNNER_TEMP/pr.diff" >"$RUNNER_TEMP/list.txt" + cargo mutants --list --cargo-arg=--locked \ + --in-diff "$RUNNER_TEMP/pr.diff" >"$RUNNER_TEMP/list.txt" count=$(wc -l <"$RUNNER_TEMP/list.txt" | tr -d ' ') fi width=$(( (count + 14) / 15 )) @@ -750,7 +751,7 @@ jobs: run: | git diff "origin/$BASE_REF...HEAD" -- '*.rs' >"$RUNNER_TEMP/pr.diff" echo "::group::Mutants in shard $SHARD" - cargo mutants --list --in-diff "$RUNNER_TEMP/pr.diff" \ + cargo mutants --list --cargo-arg=--locked --in-diff "$RUNNER_TEMP/pr.diff" \ --shard "$SHARD" \ | tee "$RUNNER_TEMP/shard.txt" echo "::endgroup::" @@ -769,7 +770,7 @@ jobs: # overrun would be swallowed by the construct meant to report it. status=0 timeout --signal=INT --kill-after=60s 35m \ - cargo mutants --in-place --in-diff "$RUNNER_TEMP/pr.diff" \ + cargo mutants --in-place --cargo-arg=--locked --in-diff "$RUNNER_TEMP/pr.diff" \ --shard "$SHARD" \ || status=$? if [ "$status" -eq 124 ]; then diff --git a/tests/test_check_workflow.py b/tests/test_check_workflow.py index d2244f416..fadc4843f 100644 --- a/tests/test_check_workflow.py +++ b/tests/test_check_workflow.py @@ -3,6 +3,7 @@ import importlib.util from pathlib import Path import re +import shlex import unittest ROOT = Path(__file__).resolve().parents[1] @@ -46,6 +47,60 @@ def test_starts_only_after_both_succeed_with_work_to_do(self): ) +def mutants_invocations(body): + """The argument words of every `cargo mutants` command. + + Continuation lines are joined, comments dropped, and the words end at the + first redirection, pipe or `||`, so a flag only counts when the shell would + pass it. + """ + found = [] + for command in re.findall( + r"^[^#\n]*?cargo mutants\b((?:[^\n]*\\\n)*[^\n]*)", body, re.M + ): + words = [] + for word in shlex.split(command.replace("\\\n", " "), comments=True): + if word[0] in "|>": + break + words.append(word) + found.append(words) + return found + + +class MutantsLockfileTests(unittest.TestCase): + def setUp(self): + self.plan = mutants_invocations(support.job("plan-mutants")) + self.shard = mutants_invocations(support.job("mutants")) + + def test_every_selecting_or_running_command_holds_the_lockfile(self): + # cargo-mutants forwards the flag to every cargo it runs; without it + # a mutant can be judged against a lockfile cargo quietly updated. + commands = self.plan + self.shard + self.assertEqual(3, len(commands)) + for words in commands: + self.assertIn("--cargo-arg=--locked", words, words) + + def test_plan_and_shard_select_the_same_mutants(self): + # The shard count comes from the plan's list, so what is listed has to + # match on both sides: the same flags with the same values. + def selection(words): + kept, skip = [], False + for word in words: + if skip: + skip = False + elif word == "--shard": + skip = True + elif word not in ("--list", "--in-place"): + kept.append(word) + return sorted(kept) + + listings = [w for w in self.plan + self.shard if "--list" in w] + self.assertEqual(2, len(listings)) + self.assertEqual(selection(listings[0]), selection(listings[1])) + run = next(w for w in self.shard if "--list" not in w) + self.assertEqual(selection(listings[1]), selection(run)) + + class AggregateStatusTests(unittest.TestCase): def test_check_accepts_mutants_skipped_after_a_plan(self): body = support.job("check") diff --git a/tests/test_mutants_plan.py b/tests/test_mutants_plan.py index ff9b26e47..019fb2438 100644 --- a/tests/test_mutants_plan.py +++ b/tests/test_mutants_plan.py @@ -42,7 +42,7 @@ def setUp(self): set -eu echo "$*" >>"$RUNNER_TEMP/cargo.log" [ "$FAKE_FAIL" = 0 ] || exit 7 -[ "$*" = "mutants --list --in-diff $RUNNER_TEMP/pr.diff" ] || exit 9 +[ "$*" = "mutants --list --cargo-arg=--locked --in-diff $RUNNER_TEMP/pr.diff" ] || exit 9 i=0 while [ "$i" -lt "$FAKE_COUNT" ]; do echo "mutant $i" From 4e582429a284e0e399470b27e850d77c9cc69aab Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Tue, 17 Nov 2026 02:08:02 +0800 Subject: [PATCH 3/3] Scratch change: own the OAuth state token Temporary fixture for verifying the CI mutation condition. It rewrites one conversion in unexpired_state so the mutants planner finds code to mutate. It must not be merged. Change-Id: Ia91144b0010fe0e19d497be36196adcdc409a8e6 --- src/web/auth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/auth.rs b/src/web/auth.rs index 6decca8ce..2c668d338 100644 --- a/src/web/auth.rs +++ b/src/web/auth.rs @@ -937,7 +937,7 @@ fn unexpired_state(payload: &str, now: i64) -> Option { let age = now.checked_sub(issued.parse::().ok()?)?; (0..=OAUTH_STATE_TTL_SECONDS) .contains(&age) - .then(|| token.to_string()) + .then(|| token.to_owned()) } /// The payload of cookie `name`, if it is present and signed for that name.