Skip to content

Run every Linux test shard nightly in shuffled order - #7727

Closed
ymichael wants to merge 4 commits into
mainfrom
bb/nightly-shuffled-test-order
Closed

ymichael wants to merge 4 commits into
mainfrom
bb/nightly-shuffled-test-order

Conversation

@ymichael

@ymichael ymichael commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Test-order leaks are fixed one at a time because nothing checks order independence. #4773 added --sequence.shuffle to the blocking Linux test jobs. #4909 removed it the same day, because existing leaks failed unrelated PRs. Since then, leaks have been found only by ad hoc shuffled sweeps whose seeds are quoted in PR bodies (3638, 4721, 7674, 8821), and each was fixed in its own PR. In the flake-fix history (Aug 13 – Nov 17), 21 commits are classified as order or shared-state leaks (test-shared-state-leak 13, test-environment-leak 8). Background: the C16 section of the ui-label verification report.

A single nightly seed only samples the orders: main's ProjectPathDialog.test.tsx fails for 5 of seeds 1–10. And nothing stopped a PR from adding a new order-dependent test, or from silently opting a suite out of shuffling.

docs/debugging-and-qa.md still said "CI's test shards shuffle test files", which has been false since #4909.

What changed

  • Blocking, on every pull request: a new Changed tests in shuffled order (seed N) job in ci.yml.
    • It reruns only the test files the PR adds or changes, once per fixed seed (1, 3 and 8), as a 3-job matrix so a failure names its seed.
    • scripts/plan-shuffled-tests.mjs does the selection in the plan job. It diffs against the same comparison base as plan-ci.mjs, groups the files by owning workspace package, and keeps only packages whose test script runs Vitest.
    • Each package runs through Turbo with -- <files> --sequence.shuffle --sequence.seed=N --passWithNoTests.
    • The job is skipped when no test file changed. A failing package prints its exact reproduction command, also to the step summary.
    • Cost: wall-clock is about one run of the changed files, since the seeds run in parallel; the Turbo cache is restored read-only.
  • Guarded opt-out.
    • A suite that must run in a fixed order declares { shuffle: false } and needs an entry with a non-empty reason in scripts/test-shuffle-opt-outs.json.
    • scripts/check-test-shuffle-opt-outs.mjs runs dependency-free in the plan job. It rejects unlisted opt-outs (suite option, quoted key, config field, assignment, and the --sequence.shuffle=false / --no-sequence.shuffle CLI forms), entries without a reason, duplicate entries, and stale entries.
    • The only entry is apps/server/test/perf/request-path-statements.test.ts, with its reason.
  • Nightly: .github/workflows/test-order.yml ("Shuffled test order") runs on main and can be started by hand with an optional seed.
    • It runs every Linux test shard from scripts/plan-ci.mjs --full with --sequence.shuffle --sequence.seed=<seed>, using --continue and a read-only Turbo cache restore.
    • It finds the leaks older files still have without failing unrelated PRs, and those get fixed in batches.
  • docs/debugging-and-qa.md describes both checks, the allowlist, and reproduction from a seed.
  • Fixes for the leaks the pre-merge runs found (below).

No per-test budgets, counts or thresholds.

How the nightly picks its seed

  • The seed is the workflow's run number, unless a manual run supplies a seed input.
  • Reproducible: a rerun keeps its run number, so it repeats the same order. The seed appears in the job title, the step summary and Vitest's Running tests with seed line.
  • Run numbers used so far: runs 1–4 were this PR's temporary pull_request verification runs, with seeds 1, 3, 4 and 5; that trigger is removed. The first scheduled run on main is therefore run 5, which uses seed 5.
  • Caveat: each manual dispatch also consumes a run number.

Leaks found so far, by seed

Seed Shard Test Cause Fix
1 app-3 ProjectPathDialog.test.tsx › preserves the direct single-machine folder flow LazyRemotePathBrowser is a lazy split. The test queried its button synchronously, so it passed only after a sibling had loaded the module (main: fails for seeds 1, 3, 8, 9 and 10) Here: await the button with findByRole, as the sibling does
3 server-1 test/perf/request-path-statements.test.ts › 'send while a retry is queued' (both axes) The suite replays scripted requests (send, edit, stop, …) against one shared fixture per axis, so each request's statement count depends on which mutations ran first Here: { shuffle: false } on the suite, listed with its reason in the new allowlist
3 app-3, app-5 plugin-frontend-boot-catch-up.test.ts, plugin-frontend-boot.test.ts The first test pays the ~8.5 s cold ./plugin-frontend import inside its 15 s deadline #7736 (collection-time import); dropped from this PR to avoid duplicating it
4 plugins-2 browser-automation app.test.tsx › streams frames by resuming from the last sequence The second preview frame was released immediately, so under load it replaced the first before the first was asserted Here: gate the second frame like the first. This also deletes the 3 s findBy override.
4 plugins-1 connect app.test.tsx › keeps the sign-in code behind Show pairing code (and 4 siblings) Connect ignores a Set up click made before the status RPC has loaded Here: one shared clickSetUpOnceStatusLoaded helper, which waits for the status call and flushes before clicking (the pattern 3 sibling tests already used). The product change is #7713's and is dropped from this PR.
5 — — All 16 shards passed —

The seed-5 pass was measured with the two dropped changes included. Until #7736 lands, the plugin-boot timeout can still appear on a loaded runner.

How you verified

  • The nightly guard fails on a known past case. I restored the four test files from before Restore UI test state between shuffled cases #7674 (ad80a9df576^):
    • stable order: 4 files, 95 passed;
    • --sequence.shuffle --sequence.seed=7674: 4 failed, 91 passed.
  • The PR step fails on a known past case. I restored main's ProjectPathDialog.test.tsx and ran node scripts/plan-shuffled-tests.mjs --run … --seed 3. It exits 1, reports Changed tests failed in shuffled order (seed 3), and prints the reproduction command. With this PR's fix, all four changed packages pass under seed 3.
  • The opt-out guard passes on the repo (one allowlisted opt-out). Its fixture tests cover every rejected form and every allowlist error (21 tests).
  • The selection tests (11) and the existing ci-workflow / ci-selection tests pass, 67 in total. The connect suite passes under seeds 1–5 and 8821.
  • A connect status RPC delayed by 50 ms reproduces the dropped-click race with the naive click. The helper relies on the harness's synchronous status mock, as the 3 existing tests do; Wait for initial Connect status before enabling setup #7713 removes the dependency.
  • actionlint passes apart from custom runner labels, and //#lint:type-aware passes.

Decisions for review

  • Windows shards are not shuffled. windows-tests depends on the windows-dependency-cache job and about 100 lines of Windows-only setup (dependency disk image, per-shard install filters, Bun, the plugin SDK runtime). Copying that into test-order.yml would fork the Windows setup. The clean route is extracting ci.yml's Windows test job into a reusable workflow, which renames its required checks, so it is left for a follow-up. The PR step is Linux-only for the same reason. Every leak found so far was platform-independent.
  • Alerting. The PR step blocks merges, so new leaks are caught at the author. Nightly failures surface as a red scheduled run plus its step summary, and GitHub emails whoever last edited test-order.yml. Nothing files issues automatically, because an auto-filed issue would not meet docs/filing-issues.md. The alternative is a job that opens or updates one tracking issue per failing seed.
  • Three fixed PR seeds sample orders without making a PR's result depend on its run number. Seeds 1, 3 and 8 are three of the five that fail main's ProjectPathDialog.

AGENT GENERATED

🤖 Generated with Claude Code

@ymichael
ymichael force-pushed the bb/nightly-shuffled-test-order branch from 58c8298 to 79e7f3d Compare November 17, 2026 20:08
@ymichael
ymichael marked this pull request as ready for review November 17, 2026 20:45
ymichael and others added 2 commits November 17, 2026 13:02
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ymichael
ymichael force-pushed the bb/nightly-shuffled-test-order branch from 79e7f3d to a9207d2 Compare November 17, 2026 21:05
…shuffle

The request-path statement suite replays scripted requests against one
shared fixture per axis, so declare its order. The plugin frontend boot
tests load the frontend module at collection time instead of inside the
first test's deadline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ymichael
ymichael force-pushed the bb/nightly-shuffled-test-order branch from a9207d2 to 3ecda54 Compare November 17, 2026 21:13
The browser preview test released its second frame immediately, so under
load it could replace the first before the first was asserted. The
connect Set up button ignored clicks until the status had loaded; keep it
disabled until then so a click is never dropped, and let the tests wait
for it to enable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ymichael
ymichael force-pushed the bb/nightly-shuffled-test-order branch 2 times, most recently from bacccaa to 00134ab Compare November 17, 2026 21:32
@ymichael ymichael closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant