Skip to content

Commit 4cbef41

Browse files
authored
Run a pull request's touched nightly test modules in CI (#340)
The everyday suite `ci` runs on a pull request deselects every nightly-marked module, so a pull request whose whole diff is one of those modules goes green having exercised none of it. That is how #336 landed a rewrite of `tests/test_render_margin.py` and `tests/test_render_anchors.py` under a green gate and reddened `main` the moment it merged — #339 is the repair — and #338 is in the same position right now with `tests/test_render_margin.py` and `tests/test_render_navigation.py`. This names the touched modules back. A new pull-request step diffs the merge commit against its base parent, collects the `tests/test_*.py` files the diff touches, and runs them with `-m nightly`: `conftest.py` already runs what an explicit file selection names, `-m nightly` leaves a mixed module's everyday cases to the step above rather than running them twice, and pytest's exit 5 is what a pull request that touches no nightly case gets. The cost is the touched files, not the 22–41 minute nightly suite, and a pull request that touches no test module pays nothing. A change to the runtime those modules drive is still the nightly run's to catch; this reaches the modules themselves. <details><summary>Verification</summary> The step's shell was run locally against real commit ranges, with `uv run pytest` swapped for the same invocation: - `83f69563..d10463f` (#339's two nightly modules) — selects both, 155 nightly cases collected. - `ff580ecb..867c526` (touches `tests/test_render_mcp.py`, which carries no nightly mark) — selects it, `no tests ran`, exit 5 tolerated, step exits 0. - An empty range — `No test module touched.`, exit 0. - `d10463fd..83f6956` (the same diff reversed, so the range reads as deletions) — the `[ -f ]` filter drops what is not on disk and the step still selects correctly. End-to-end, `uv run pytest tests/test_render_drawing.py -m nightly -q` is 21 passed, so the invocation drives real browser cases rather than only collecting them. Suite and lint on this branch: - `uv run pytest tests` — 891 passed, 6 skipped. - `uv run pytest tests/test_interact_layer.py` — 157 passed, 6 skipped (this is the module that reads `ci.yaml`; the new step declares no `working-directory`, so the gate-naming test is unaffected). - `pre-commit run --files .github/workflows/ci.yaml CLAUDE.md tests/CLAUDE.md` — passed, including actionlint's shellcheck pass over the new `run:` block. `fetch-depth: 2` on the `test` job's checkout is what gives the merge commit its base parent; the default depth of 1 has no `HEAD^1` to diff against. </details> Co-authored-by: leaf-agent <[email protected]>
1 parent ac3342a commit 4cbef41

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ jobs:
2323
timeout-minutes: 105
2424

2525
steps:
26+
# Two commits, so a pull request's merge commit has its base parent and
27+
# the touched-module step below can diff against it.
2628
- name: 📂 Checkout code
2729
uses: actions/checkout@v7
30+
with:
31+
fetch-depth: 2
2832

2933
- uses: astral-sh/setup-uv@v7
3034

@@ -38,6 +42,32 @@ jobs:
3842
timeout-minutes: 45
3943
run: uv run pytest tests -v
4044

45+
# The everyday suite deselects the nightly-marked modules, so a pull request
46+
# whose whole diff is one of them goes green having run none of it: that is
47+
# how #336 rewrote two render modules under a green gate and reddened main
48+
# on the next push. Name the touched ones back. An explicit file selection
49+
# runs what it names, `-m nightly` leaves the everyday cases in a mixed
50+
# module to the step above rather than running them twice, and pytest's
51+
# exit 5 is what a pull request that touches no nightly case gets. A change
52+
# to the runtime the modules drive is still the nightly run's to catch;
53+
# this reaches the modules themselves.
54+
- name: 🧪 Nightly cases this pull request touches
55+
if: github.event_name == 'pull_request'
56+
timeout-minutes: 45
57+
run: |
58+
touched=()
59+
while IFS= read -r module; do
60+
if [ -f "$module" ]; then
61+
touched+=("$module")
62+
fi
63+
done < <(git diff --name-only HEAD^1 HEAD -- 'tests/test_*.py')
64+
if [ ${#touched[@]} -eq 0 ]; then
65+
echo "No test module touched."
66+
exit 0
67+
fi
68+
echo "Touched test modules: ${touched[*]}"
69+
uv run pytest "${touched[@]}" -m nightly -v || [ $? -eq 5 ]
70+
4171
# `-v` names a stalled test. The step timeout makes a wedge a failure that
4272
# `tend-ci-fix` can act on.
4373
- name: 🧪 Nightly suite

‎CLAUDE.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ uv run pytest tests
184184

185185
`tests/CLAUDE.md` owns environment setup, focused runs, nightly selection, and
186186
the Linux suite. `wt merge` runs pre-commit and the everyday suite on the rebased
187-
tree. Pull requests run the same gate in CI. CI adds the complete nightly suite
188-
after main moves.
187+
tree. Pull requests run the same gate in CI, and add the nightly cases in the
188+
test modules the pull request touches. CI adds the complete nightly suite after
189+
main moves.
189190

190191
That suite never reads `worker/`, and neither does pre-commit, whose prettier and
191192
eslint hooks take JavaScript and HTML rather than TypeScript. So a worker change

‎tests/CLAUDE.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ uv run pytest --lf --lfnf=none -x -n0
4747

4848
Before handing over a browser-facing change, run its complete browser file and
4949
the everyday suite. `wt merge` runs pre-commit and the everyday suite after
50-
rebasing. CI adds `--run-nightly` after main moves.
50+
rebasing. CI runs the everyday suite on a pull request and, after it, the nightly
51+
cases in the test modules that pull request touches, so a change confined to a
52+
nightly module is gated before it lands rather than by the run after it. A change
53+
to the runtime those modules drive is still the nightly run's to catch: CI adds
54+
`--run-nightly` after main moves.
5155

5256
`scripts/linux-suite.sh` supplies the pinned headless shell, installed Chrome,
5357
and CI fonts. It accepts pytest arguments and needs a Docker daemon that can run

0 commit comments

Comments
 (0)