Skip to content

Run changed test files 5 times at once in CI - #17184

Draft
danlapid wants to merge 6 commits into
mainfrom
dlapid/repeat-changed-tests
Draft

danlapid wants to merge 6 commits into
mainfrom
dlapid/repeat-changed-tests

Conversation

@danlapid

@danlapid danlapid commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Nothing in CI runs a new or edited test more than once before it lands. The Miniflare and Wrangler suites run without retries, but each test still gets one attempt per OS. A test that fails only a few percent of the time passes that, and the flake shows up afterwards on other PRs. The local Artifacts port race fixed in #17182 is an example: it failed about 8% of runs on workerd's "Run workers-sdk tests" check, which runs five suites at once on one runner, but rarely here.

This adds a Repeat changed tests job to test-and-check.yml. On each PR it:

  1. Lists the *.test.* / *.spec.* files the PR adds or edits (git diff HEAD^1 HEAD on the PR's merge commit). If none, it stops after checkout, before installing dependencies.
  2. Groups them by workspace package. Each file runs from its package root, as test:ci does, with the package's own vitest.config.*, so its projects and their platform exclusions apply. A package without one, such as workers-shared, uses the subdirectory's config with --dir, as its scripts do.
  3. Builds those packages with Turbo, as test:ci does, and runs their pretest:ci hooks once, for example to install Playwright's Chromium.
  4. Starts five Vitest processes at once on the files with --retry=0, so the tests also run under CPU and port contention, like workerd's check. Fixtures run their five runs one after another instead. They start wrangler dev against their own directory, so concurrent copies share its .wrangler/state (one SPA fixture run failed with SQLITE_BUSY this way) and its dev registry entries, which a single run never does. The job fails if any run fails.

The job summary lists every skipped file and why:

  • files the package's config doesn't run on that platform;
  • packages the test partitions leave out on that platform (Browser Run fixtures on Linux, @cloudflare/vitest-plugin on Windows);
  • end-to-end tests, which run in their own workflows and need credentials;
  • packages that don't use Vitest;
  • packages that run Vitest only through custom-named configs in their own scripts (the remote-bindings fixtures, the Vite plugin playground);
  • files outside workspace packages, such as C3 templates.

The job summary has a table of passing runs per file, with the names of the tests that failed, and each failing file gets an error annotation. Each run's log and Vitest JSON report are uploaded as the repeat-changed-tests-<os> artifact. The script is tools/test/repeat-changed-tests.ts. To run it locally: pnpm run test:ci:repeat-changed --base=origin/main.

Choices for reviewers to weigh in on:

  • The Tests gate requires it. Otherwise a red run is easy to ignore. If you'd rather start with it advisory, drop it from the gate's needs.
  • It runs on all three OSes. Windows is the slowest. On this PR's own run the whole job took 2m32s on Windows, 1m04s on Linux and 3m14s on macOS (install, build and five runs of one tools test file). With a Miniflare file it took 2m01s on Windows, 1m22s on Linux and 3m34s on macOS. That is well inside the 30-minute timeout and shorter than the test partitions, so I kept all three OSes. Restricting the matrix to ubuntu-latest is a one-line change if it proves too slow.
  • It is skipped in the merge queue, since the PR already ran it.
  • Concurrent package runs share the package directory. A test that writes to a fixed path or listens on a fixed port can fail here because its copies collide, which a single run never shows. The README says to give each run its own temporary directory and port 0. Retries a test sets on itself, such as it("…", { retry: 2 }), still apply.

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: CI-only change. It is documented in .github/workflows/README.md, next to the retry diagnostics.

Testing:

  • Unit tests for file selection and grouping are in tools/test/__tests__/repeat-changed-tests.test.ts. Being a changed test file, it is what this PR's own job runs five times: 5/5 on Linux, macOS and Windows (run).
  • A throwaway commit added a Miniflare spec that fails 70% of the time. The job built Miniflare and failed on every OS: 2/5 passing runs on Linux, 1/5 on macOS, 0/5 on Windows, each naming the failing test in the summary and an annotation (run). The commit was then dropped.
  • Locally on macOS, after the review fixes: 5/5 on each of workers-shared/asset-worker/tests/analytics.test.ts (subdirectory config), vitest-plugin-examples/durable-objects/test/sqlite-in-do.test.ts (root projects), workers-with-assets-spa/tests/index.test.ts (Chromium pretest:ci, sequential runs) and the new tools test. playground/worker-♫/…/worker.spec.ts is reported by name as skipped.
  • Locally on macOS, before them: 5/5 on the new test file. With a throwaway flaky test it exited 1, reported 1/5 with the failing test's name, and wrote the annotation.
  • The full tools suite (358 tests), tsc, oxfmt --check, oxlint --deny-warnings --type-aware, and the action-pinning check pass.

🤖 Generated with Claude Code

A test that fails a few percent of the time usually passes the one CI
run it gets before landing. Add a "Repeat changed tests" job that runs
every Vitest file a PR adds or edits in five Vitest processes started
together, with retries disabled, on Linux, macOS and Windows. It fails
if any run fails, and the Tests gate requires it.

tools/test/repeat-changed-tests.ts picks the test files from the PR's
diff, groups them by the closest vitest.config.* in their workspace
package, builds those packages, and keeps only the files each config
really runs. The job summary lists how many runs each file passed and
which tests failed; logs and JSON reports are uploaded as artifacts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1415a76

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@17184

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@17184

@cloudflare/cli-shared-helpers

npm i https://pkg.pr.new/@cloudflare/cli-shared-helpers@17184

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@17184

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@17184

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@17184

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@17184

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@17184

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@17184

miniflare

npm i https://pkg.pr.new/miniflare@17184

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@17184

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@17184

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@17184

@cloudflare/test-server

npm i https://pkg.pr.new/@cloudflare/test-server@17184

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@17184

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@17184

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@17184

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@17184

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@17184

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@17184

wrangler

npm i https://pkg.pr.new/wrangler@17184

commit: 1415a76

devin-ai-integration[bot]

This comment was marked as resolved.

ask-bonk[bot]

This comment was marked as resolved.

@ask-bonk

ask-bonk Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

Adds a required cross-platform job that repeats changed Vitest files concurrently.

  1. P1: Direct Vitest execution bypasses pretest:ci, causing browser-dependent fixture edits to fail. Suggestion posted inline.
  2. P1: The new job re-enables existing Linux/Windows platform exclusions. Suggestion posted inline.

github run

devin-ai-integration[bot]

This comment was marked as resolved.

@danlapid
danlapid force-pushed the dlapid/repeat-changed-tests branch from b0e7976 to 8983dc8 Compare November 25, 2026 22:54
Address review findings on the repeat job:

- Start Vitest from the package root with the package's own config,
  so projects and their platform exclusions apply. Packages without
  one, such as workers-shared, use the subdirectory's config with
  --dir, as their scripts do.
- Run each package's pretest:ci hook first, e.g. to install
  Playwright's Chromium, via a new test:ci:repeat-changed script.
- Skip packages the test partitions leave out on the platform:
  Browser Run fixtures on Linux, vitest-plugin on Windows.
- Run fixture repeats one after another. Concurrent copies of a
  `wrangler dev` fixture share its .wrangler/state (SQLITE_BUSY) and
  dev registry entries, which a single run never does.
- Drop `vitest list`, which never exited in vitest-plugin-examples;
  runs pass --passWithNoTests and report unrun files as skipped.
- Read `git diff -z` so non-ASCII paths are not quoted, and list
  end-to-end tests as skipped. Drop --out-dir, so the runner only
  ever clears its own .turbo/repeat-tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

pnpm runs scripts through cmd.exe on Windows, which treats `^` as an
escape character, so `--base=HEAD^1` reached git as `HEAD1`. Use
`HEAD~1`, the same commit.

Skip packages that have no default Vitest config for a file but do
have a custom-named one, such as vitest.workers.config.ts: only their
own scripts know how to run those files. This covers the two remote
bindings fixtures and the Vite plugin playground's e2e config.

A file that several projects run is reported once per project; merge
the failures instead of keeping the last report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

readWorkspace's directory scan decides which packages run Vitest,
need a pretest:ci hook, or use custom-named configs. Check it on real
packages, including the remote bindings fixture and a non-ASCII
playground directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

The previous test read the real repository, which the tools suite's
Turbo cache key does not cover, so a cached pass could hide a
regression. Build a small workspace in a temporary directory instead.

Its CRLF pnpm-workspace.yaml found a bug: `.` in a JavaScript regular
expression does not match `\r`, so a CRLF checkout of the workspace
manifest failed to parse. Match `[^\n]` instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

Mirror the real manifest's shapes: a nested playground glob, the
playground directory itself, and a plain `tools` entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

1 participant