Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.

fix(vitest): resolve the quarantine runner with the current build's extension - #253

Open
QuanticPotatoes wants to merge 1 commit into
Mergifyio:mainfrom
QuanticPotatoes:fix-vitest-runner-resolution
Open

fix(vitest): resolve the quarantine runner with the current build's extension#253
QuanticPotatoes wants to merge 1 commit into
Mergifyio:mainfrom
QuanticPotatoes:fix-vitest-runner-resolution

Conversation

@QuanticPotatoes

Copy link
Copy Markdown

Fixes #169.

Problem

MergifyReporter._configureRunner injects resolve(dir, 'runner.js') as the custom vitest runner, but the build (tsdown, format: ['esm', 'cjs']) only emits dist/runner.mjs and dist/runner.cjs — there is no runner.js in the published package. As soon as the quarantine list is non-empty (or flaky detection configures the runner), every worker dies with ERR_MODULE_NOT_FOUND before collecting a single test, aborting the entire suite.

We were hit by this in production CI on 2026-08-05: the first quarantine entry ever created on our repo flipped the latent path on and took down every vitest tier org-wide (0 tests collected, one collect error per file), on vitest 4.0.18 and 3.2.4 alike — not only 4.x as #169 reports. 0.3.1 is equally affected.

Why the existing tests didn't catch it

tests/runner.test.ts exercises the quarantine path end-to-end and passes — because it imports from ../src/reporter.js, so the injected path is src/runner.js, and vite-node remaps that .js specifier onto src/runner.ts. In the published package the injected dist/runner.js path goes through native node resolution in the worker, which does no such remapping.

Fix

Resolve the runner sibling with the same extension as the currently-executing module:

  • dist/index.cjsdist/runner.cjs
  • dist/index.mjsdist/runner.mjs
  • src/reporter.ts (dev/tests) → src/runner.ts

One rule, correct in all three contexts, no behavior change in dev.

Regression test

Adds tests/dist-runner.test.ts: the same quarantine scenario as runner.test.ts, but importing MergifyReporter from ../dist/index.mjs — i.e. consuming the built artifact the way a real consumer does. It fails on main (expected 'failed' to be 'passed') and passes with the fix. (It requires pnpm build to have run before tests, which the workspace setup already does.)

Also verified from a standalone external project consuming the packed tarball: with the fix, the ERR_MODULE_NOT_FOUND crash is gone on vitest 4.0.18 and 4.1.8.

Side observation (out of scope here)

While validating from the standalone consumer (vitest 4.0.18 and 4.1.8, CLI runs), failure absorption did not engage even though the runner loaded and isQuarantined matched — whereas it works in this repo's own tests (vitest 4.1.7, programmatic startVitest). Possibly a separate vitest-version-sensitivity issue worth a look; happy to open a separate issue with the repro if useful.

…xtension

_configureRunner hardcoded 'runner.js', but the build emits runner.mjs/runner.cjs
only — in the published package the injected path fails native resolution with
ERR_MODULE_NOT_FOUND in every worker, aborting the whole suite (0 tests collected)
as soon as the quarantine list is non-empty. It only worked in this repo's own
tests because vite-node remaps the .js specifier onto src/runner.ts.

Resolve the sibling with the same extension as the current module instead:
dist/index.cjs -> runner.cjs, dist/index.mjs -> runner.mjs, src (dev) -> runner.ts.

Adds a dist-mode regression test that consumes the built package the way a real
consumer does — it fails on main and passes with the fix.

Fixes Mergifyio#169
@mergify

mergify Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 2 of 6 protections blocking · waiting on 👀 reviews and 🤖 CI

Protection Waiting on
🔴 Approval 👀 reviews
🟠 Continuous Integration 🤖 CI
🟢 Enforce conventional commit
🟢 🔎 Reviews
🟢 📕 PR description
🟢 🚦 Auto-queue

🔴 Approval

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.
  • #approved-reviews-by >= 2

🟠 Continuous Integration

Waiting for

  • check-success = all-greens
Waiting checks: all-greens.
  • check-success = all-greens

Show 4 satisfied protections

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|internal|docs|style|refactor|perf|test|build|ci|chore|revert|ui)(?:\(.+\))?!?:

🟢 🔎 Reviews

  • #changes-requested-reviews-by = 0
  • #review-requested = 0
  • #review-threads-unresolved = 0

🟢 📕 PR description

  • body ~= (?ms:.{48,})

🟢 🚦 Auto-queue

When all merge protections are satisfied, this pull request will be queued automatically.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

@mergifyio/vitest@0.3.0: _configureRunner resolves dist/runner.js (ships .mjs/.cjs) → ERR_MODULE_NOT_FOUND under Vitest 4.x in CI

1 participant