Skip to content

[vitest-plugin] Fix filesystem module caching - #16163

Merged
petebacondarwin merged 14 commits into
mainfrom
edmundhung/fix-vitest-fs-module-cache
Oct 15, 2026
Merged

petebacondarwin merged 14 commits into
mainfrom
edmundhung/fix-vitest-fs-module-cache

Conversation

@edmundhung

@edmundhung edmundhung commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #16132 and the fsModuleCache report.

Vitest 5 returns paths to transformed modules when fsModuleCache: true, but workerd cannot read the host filesystem. Read those cache files in the Node pool before forwarding RPC responses to the runner, including the warm-module snapshot. No change to the default cache setting or module-registry selection.

Keep the adapter file-backed: reuse file contents within each RPC response so aliases do not trigger duplicate reads, without retaining a persistent content cache or looking up the module graph. Omit unavailable warm entries so Vitest falls back to fetching them normally.

The regressions cover cold and populated caches and hoisted mocks with both legacy and new module registries. A focused unit test checks warm-cache aliases and the missing-file fallback.


  • 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: this restores existing opt-in test behavior without changing the configuration API.

Local checks on Node.js 22.22.1: plugin build; Vitest 5 cache, module-registry, watch, coverage, and module-fallback tests; Vitest 4.1.0 registry tests; plugin typecheck; type-aware lint and formatting for the changed files.

@changeset-bot

changeset-bot Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b5359e8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/vitest-plugin Patch

Not sure what this means? Click here to learn what changesets are.

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

@ask-bonk

ask-bonk Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@pkg-pr-new

pkg-pr-new Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

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

@cloudflare/build-output-utils

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

@cloudflare/codemods

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

@cloudflare/config

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

@cloudflare/containers-shared

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

create-cloudflare

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

@cloudflare/deploy-helpers

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-functions

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

@cloudflare/pages-shared

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

@cloudflare/runtime-types

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-plugin

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

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 164e02d

@bigmac44

Copy link
Copy Markdown

This may deserve more priority as the latest vitest version enabled fsModuleCache by default. I now get failures with vitest-plugin by default (without explicitly disabling fsModuleCache).

vitest-dev/vitest#11435

LordCoughmann added a commit to LordCoughmann/effect-libs-browser that referenced this pull request Oct 13, 2026
Effect moves from 4.0.0-rc.115 to the stable 4.0.0 release, with
@effect/platform-node, @effect/platform-bun and @effect/vitest in lockstep.

Migrate off the `effect/unstable/*` export paths that 4.0.0 removed
(32 imports across 27 files): unstable/http -> effect/http,
unstable/httpapi -> effect/http-api, unstable/process -> effect/process
and unstable/cli -> effect/cli. Docs, READMEs and the "Effect v4 RC
required" notices drop the now-stale RC wording.

Vitest moves 4.1.11 -> 5.0.4 with @vitest/coverage-v8 5.0.4 (its peer
matches the vitest version exactly) and @cloudflare/vitest-plugin
1.1.13 -> 1.4.0, the first plugin release supporting Vitest 5. That
finally satisfies @effect/vitest's `vitest >=5` peer.

Vitest 5 enables `fsModuleCache` by default, and plugin 1.4.0 cannot
read those host-FS cache entries from workerd, so every workerd test
file failed before running. Set `fsModuleCache: false` in the four
workerd configs until cloudflare/workers-sdk#16163 ships; the removal
follow-up is recorded in CONTRIBUTING.md.

BREAKING CHANGE: consumers must migrate to Effect 4.0.0.
@mattjohnsonpint

mattjohnsonpint commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

FYI, this just became more urgent because Vitest 5.0.4 enables fsModuleCache by default. All workers tests will fail after updating, unless they set fsModuleCache: false or run with --no-fsModuleCache. @edmundhung - please prioritize accordingly. Thanks.

mattjohnsonpint added a commit that referenced this pull request Oct 13, 2026
Set fsModuleCache to false in both coverage fixtures so Vitest 5.0.4 can exercise coverage independently of the filesystem-cache incompatibility.

This workaround is temporary until PR #16163 is merged; remove the overrides once the cache fix is available.

Validation: both coverage tests passed with Vitest 5.0.4 in the fixture processes; type-aware lint and formatting passed.
@mattjohnsonpint

Copy link
Copy Markdown
Contributor

I tested this locally and found some issues, which I've resolved in #16249 which targets this branch, not main. So you can merge it here to have one PR for the feature. I also expanded the test coverage based on AI feedback.

Separately, I found a different issue with Vitest 5.0.4, which I addressed in #16248. You'll need both for all tests to pass.

Hope this helps get this out the door asap. Thanks!

@edmundhung

Copy link
Copy Markdown
Member Author

I will try to get this landed tomorrow.

eve0415 added a commit to eve0415/website that referenced this pull request Oct 14, 2026
Updates the runtime, toolchain, dependencies, compatibility date and
workflows, and replaces `clsx` + `tailwind-merge` with `cn`. It also
carries two refactors already on this branch: the 404 search result
driven by `<ViewTransition>`, and a `useMemo` in the sky that React
Compiler already covers.

## Changes

- Node.js 24.21.0 and pnpm 12.11.2. Every dependency is on its newest
version that passes pnpm's minimum release age, exact-pinned.
`@cloudflare/vitest-plugin` moves from the `pkg.pr.new` preview build to
the npm release, so the workspace overrides are gone.
- `compatibility_date` moves to 2026-10-06. The two flags that flip in
that window, `spec_compliant_dispatch_exceptions` and
`durable_object_io_tasks_prevent_eviction`, touch nothing in the
Worker's server code.
- The `worker` vitest project disables vitest's file module cache, which
workerd cannot read. It can go once
cloudflare/workers-sdk#16163 ships.
- Workflows: `pnpm/setup` v3.1.1, `upload-artifact` v7.0.2,
`ubuntu-26.04-arm`, and the obsolete `update-pnpm: next-12` input
dropped.
- `cn`: the `cn/vite` plugin compiles the merge tables into
`src/lib/cn-tables.gen.ts`, which is gitignored. `pnpm generate` writes
the same file from `cn-tables.config.ts`, and CI and the update workflow
run it before lint. `pnpm generate` now types `Env` from
`.dev.vars.example` everywhere.
- `tw()` marker tests: the identity-binding assertion only ever matched
`@tanstack/react-store`'s `useSelector` default, and it was already
failing on `main`. Its replacement checks every `tw()` call and bare
`tw` reference in `src` under `stripTw`'s import rule, and requires each
marked list to ship as a bare string.

## For review

- The prerendered pages' 2,966 `class` attributes are identical before
and after the `cn` switch.
- `ubuntu-26.04-arm` is exercised for the first time by this PR's own CI
run.
- This supersedes #152 and #154.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01Qe4qPEEZguMBNMhaU8ecs6

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
@edmundhung
edmundhung force-pushed the edmundhung/fix-vitest-fs-module-cache branch from 731314b to d8b0def Compare October 14, 2026 10:31
murugu-21 added a commit to murugu-21/murugu-21.github.io that referenced this pull request Oct 14, 2026
…ettier

vite-plus 1.2.0 bundles oxfmt 0.73.0, which formats .astro (oxc-project/oxc#27386)
and sorts its Tailwind classes, the resume pages against resume.css. Its output
matches Prettier's byte for byte on every template, so prettier,
prettier-plugin-astro, prettier-plugin-tailwindcss and .prettierrc go. Zed
formats .astro on save with vp fmt instead of its bundled Prettier.

vite-plus 1.2.0 pins Vitest 5.0.4, which needs two workarounds:
- The workers test project turns off fsModuleCache, which workerd can't read
  until cloudflare/workers-sdk#16163 lands.
- ListenControls.test.tsx dispatches pagehide on a stand-in target, because
  5.0.4 fails the file 5 s after a synthetic pagehide on window
  (vitest-dev/vitest#11561).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@edmundhung
edmundhung marked this pull request as ready for review October 14, 2026 12:27
@workers-devprod
workers-devprod requested review from a team and jamesopstad and removed request for a team October 14, 2026 12:28
@workers-devprod

workers-devprod commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@edmundhung

edmundhung commented Oct 14, 2026 •

Copy link
Copy Markdown
Member Author

The failed CI should be fixed once #16248 is merged and we rebase this branch on top. Meanwhile, I think this is ready for review.

devin-ai-integration[bot]

This comment was marked as resolved.

Custom artifact replies can legitimately contain cached and tmp fields. Match replies to module-fetch request IDs so unrelated data stays unchanged.
The session-disposal test bypasses the worker constructor, so its test instances must provide the request state now cleared during shutdown.
@edmundhung
edmundhung force-pushed the edmundhung/fix-vitest-fs-module-cache branch from 8c09ef4 to b5359e8 Compare October 15, 2026 12:22

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

Devin Review

just-goforward added a commit to just-goforward/Nikke-Collection-Item-Calculator that referenced this pull request Oct 15, 2026
Pin Vitest and coverage-v8 5.0.4 in all six Worker workspaces. Normalize runtime boundary lock assertions to actual resolved package locations, preserving exact manifest, installed, and locked version checks. Add a dated superseding CHANGELOG entry without changing historical entries.

Set test.fsModuleCache=false only in the six workerd configs, with removal comments for cloudflare/workers-sdk#16163. Installed Vitest 5.0.4 types confirm the boolean option/default true; upstream draft PR #16163 documents the host-filesystem incompatibility and PR #16248 uses the temporary false override. Root Vitest config stays unchanged. No prerelease fixes installed.

Verification passes: check:test-runtimes, all six worker suites, npm test (127 files / 1521 tests). The original File path must be a file: URL failure is resolved with the cache disabled. Worker coverage teardown remains an upstream limitation tracked by #16248; worker coverage was not requested or run.
@petebacondarwin
petebacondarwin merged commit 5f12934 into main Oct 15, 2026
94 checks passed
@petebacondarwin
petebacondarwin deleted the edmundhung/fix-vitest-fs-module-cache branch October 15, 2026 12:47
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in workers-sdk Oct 15, 2026
murugu-21 added a commit to murugu-21/murugu-21.github.io that referenced this pull request Oct 16, 2026
…ettier

vite-plus 1.2.0 bundles oxfmt 0.73.0, which formats .astro (oxc-project/oxc#27386)
and sorts its Tailwind classes, the resume pages against resume.css. Its output
matches Prettier's byte for byte on every template, so prettier,
prettier-plugin-astro, prettier-plugin-tailwindcss and .prettierrc go. Zed
formats .astro on save with vp fmt instead of its bundled Prettier.

vite-plus 1.2.0 pins Vitest 5.0.4, which needs two workarounds:
- The workers test project turns off fsModuleCache, which workerd can't read
  until cloudflare/workers-sdk#16163 lands.
- ListenControls.test.tsx dispatches pagehide on a stand-in target, because
  5.0.4 fails the file 5 s after a synthetic pagehide on window
  (vitest-dev/vitest#11561).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
murugu-21 added a commit to murugu-21/murugu-21.github.io that referenced this pull request Oct 16, 2026
oxfmt in vite-plus formats .astro and sorts its Tailwind classes, with
output matching Prettier byte for byte, so Prettier and its plugins go
and Zed formats .astro with vp fmt. vite-plus moves to 1.3.0 with Vitest
5.0.5. The workers test project turns off fsModuleCache, which workerd
cannot read until cloudflare/workers-sdk#16163 lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
murugu-21 added a commit to murugu-21/murugu-21.github.io that referenced this pull request Oct 16, 2026
TypeScript moves to the 7.1.0-dev.20261014.1 nightly that @effect/tsgo
0.53.1 supports. agents 0.28.1 peers on exact
@modelcontextprotocol/client and /server 2.3.1, so both are pinned and
held from Renovate. fsModuleCache stays off: @cloudflare/vitest-plugin
1.4.3 still sends the warm module cache in one 46 MB reply that workerd
closes with 1009 (cloudflare/workers-sdk#16163).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dermoumi added a commit to dermoumi/acme that referenced this pull request Oct 17, 2026
Bumps @cloudflare/vitest-plugin to 1.4.3 for vitest 5's fs module cache (cloudflare/workers-sdk#16163).
brandhaug added a commit to brandhaug/b2b-saas-starter that referenced this pull request Oct 19, 2026
## pnpm-workspace.yaml (default)

## Dependency Updates

| Package | From | To | Type |
| --- | --- | --- | --- |
| `@cloudflare/vitest-plugin` | 1.4.2 | 1.4.4 | patch |

## Release Notes

<details>
<summary><b>@<!---->cloudflare/vitest-plugin</b> (1.4.2 → 1.4.4) — 2
releases</summary>

<details>
<summary><b>1.4.4</b></summary>

### Patch Changes

- Updated dependencies
[[`e1d1b77`](cloudflare/workers-sdk@e1d1b77),
[`e13d5cc`](cloudflare/workers-sdk@e13d5cc),
[`42c6912`](cloudflare/workers-sdk@42c6912),
[`4a5377f`](cloudflare/workers-sdk@4a5377f)]:
  - miniflare@5.20261012.1-beta
  - wrangler@4.151.1

</details>

<details>
<summary><b>1.4.3</b></summary>

### Patch Changes

- [#16248](cloudflare/workers-sdk#16248)
[`ad01099`](cloudflare/workers-sdk@ad01099)
Thanks [@<!---->mattjohnsonpint](https://github.com/mattjohnsonpint)! -
Fix V8 coverage failing with Vitest 5.0.4

Tests using V8 coverage with Vitest 5.0.4 no longer fail with an
assertion error during teardown.

- [#16163](cloudflare/workers-sdk#16163)
[`5f12934`](cloudflare/workers-sdk@5f12934)
Thanks [@<!---->edmundhung](https://github.com/edmundhung)! - Fix
Workers tests failing with Vitest's filesystem module cache

This supports Vitest 4.1's `test.experimental.fsModuleCache` and Vitest
5's `test.fsModuleCache`.

</details>

</details>

---
*This PR was auto-generated by
[catalog-update-action](https://github.com/brandhaug/catalog-update-action).*

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
sds added a commit to tempoxyz/tip.bot that referenced this pull request Oct 21, 2026
## Summary

Rebased onto #102, which cleared the earlier `pnpm audit` failure. This
PR moves the dependencies #102 upgraded to their newer patch releases,
fixes a range mismatch in a pinned dependency, and clears
[GHSA-p458-7748-mcp3](GHSA-p458-7748-mcp3).
That advisory was published after #102 and also fails `main`'s audit:
Vitest servers misapply `server.fs.deny`. It needs vite-plus 1.3.0 and
Vitest 5.0.5.

| Dependency | `main` (#102) | This PR |
| --- | --- | --- |
| @tanstack/react-start | 1.168.60 | 1.169.2 |
| @tanstack/react-router | 1.170.41 | 1.170.44 |
| @tanstack/router-plugin | 1.168.42 | 1.168.46 |
| hono (direct and transitive) | 4.13.11 | 4.13.13 |
| @modelcontextprotocol/sdk | 1.32.0 | 1.32.1 |
| vite-plus / vite-plus-core | 1.1.0 | 1.3.0 |
| vitest (and `@vitest/*`) | 5.0.3 | 5.0.5 |
| @cloudflare/vitest-plugin | 1.4.0 | 1.4.2 |
| seroval | 1.6.7 | 1.6.9 |
| @babel/core | 7.29.6 | 7.29.7 |

- **@babel/core:** router-plugin requires `^7.29.7`, but `main` forces
7.29.6.
- **TanStack Start 1.169:**
- `.inputValidator()` was renamed to `.validator()`; this updates 3 call
sites.
- The lazy server-entry patch is regenerated as
`@tanstack__react-start@1.169.2.patch`. Upstream's `createServerEntry`
now adds request scoping and error handling, so the patch lazy-loads it
too.
- **Workers test cache:** Since 5.0.4, Vitest turns on `fsModuleCache`
by default. vitest-plugin 1.4.2 can't read that cache, so every Workers
test file failed with `readAll … .vitest-cache: no such file or
directory` ([fixed in vitest-plugin
1.4.3](cloudflare/workers-sdk#16163)). The cache
is disabled for the Workers project only, with a TODO to remove it once
vitest-plugin is on 1.4.3. 1.4.3 is still under Aegis's 7-day limit.
- **workerd build:** `workerd@1.20261012.1` (from vitest-plugin 1.4.2's
Miniflare) is added to `allowBuilds`.
- **Release-age excludes:** the `vite-plus@1.1.0` and
`@babel/core@7.29.6` entries are removed. The new versions are older
than the 1-day minimum release age.
- **Aegis age limit:** locally, Socket Aegis blocks npm versions less
than about 7 days old. Aegis exceptions were added for vite-plus 1.3.0 /
Vitest 5.0.5 and their pinned packages. Every other version is at least
7 days old. Transitive `srvx` is pinned to 1.0.5 in the lockfile only.
No overrides or audit suppressions are added.

## Validation

- `pnpm audit`: only the two existing image-size findings remain
(ignored).
- `pnpm check`, `pnpm check:types`, `pnpm build`: pass. The
frozen-lockfile install passes, and `pnpm install --lockfile-only`
leaves the lockfile unchanged.
- Unit tests: 57/57 pass on Vitest 5.0.5.
- E2E: 22/22 pass.
- Reproduced the Workers failure in a minimal Worker project using this
repo's installed vitest-plugin 1.4.2 and Vitest 5.0.4. CI's Workers job
passes with the workaround. With `fsModuleCache: true` it fails with
CI's exact error; with `false` it passes. The resolved config shows
`fsModuleCache` off for `workers` and on for `unit`.
- Worker tests were not run locally because the ghcr pull of the pinned
Tempo image is denied. CI covers them, as it did for #102 on
vitest-plugin 1.4.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants