Skip to content

fix(vitest): stage a directory output's files from the test's runfiles - #262

Merged
mikn merged 1 commit into
mainfrom
mikn/vitest-runfiles-realpath
Oct 6, 2026
Merged

mikn merged 1 commit into
mainfrom
mikn/vitest-runfiles-realpath

Conversation

@mikn

@mikn mikn commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

When runfiles are materialized as files, as they are under remote execution, a realpath taken inside ts_test's private tree resolves into the launcher's runfiles tree under bazel-out/<cfg>/bin. That path is outside Vite's fs.allow list, and runfilesPath cannot map it back. Tests that import a file inside a directory output, or load an npm asset by URL, then fail with Vite's "Denied ID" error. The same tests pass where runfiles are symlinks, so the failure appears only under remote execution.

What changes

  • tools/launcher/vitest.go exports the resolved runfiles directory as TS_TEST_RUNFILES_ORIGIN.

  • ts/private/actions/vitest.bzl adds it to fs.allow, and runfilesPath maps paths under it back onto the private tree.

  • New tests/codegen_tree/tree_import_test (a ts_test importing a file from a directory output and an npm asset by URL) and materialized_runfiles_test (a Go test that re-materializes the runfiles as remote execution does and runs the launcher from there). The Go test fails without the fix.

  • tests/integration/harness/harness.go: the nested Bazel's generated bazelrc sets --remote_download_outputs=all. Its --disk_cache counts as a remote cache, so once CI's shared disk cache is warm, a cache hit left outputs unmaterialized, and tests that read files back from bazel-out failed with "cannot read …". This is what made Integration Tests (core) and (npm) fail on main and on every open PR.

Verification

All 88 tests in codegen_tree and vitest pass on remote execution (BuildBuddy invocation 029b2236), including the new regression test.

Disk-cache fix: lsp_test, gazelle_roundtrip_roots_test and gazelle_roundtrip_packages_test were run twice in one invocation with a shared scratch directory, so the second pass sees a warm disk cache. Without the change, the second pass failed all three with the CI error (88a81ef4). With it, both passes pass (fc6fbd55).

🤖 Generated with Claude Code

Where runfiles are materialized as files, as under remote execution, a realpath taken inside ts_test's private tree lands in the launcher's runfiles tree. The launcher now exports that directory as TS_TEST_RUNFILES_ORIGIN; runfilesPath maps paths under it back onto the private tree, and Vite's fs.allow includes it. A materialized-runfiles test reproduces the failure without the fix.

The integration harness's nested Bazel sets --remote_download_outputs=all: its --disk_cache counts as a remote cache, so once CI's shared disk cache is warm a cache hit left outputs the tests read back unmaterialized.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mikn
mikn force-pushed the mikn/vitest-runfiles-realpath branch from 5dd4e84 to 1714415 Compare October 6, 2026 19:02
@mikn
mikn merged commit 9bcaad2 into main Oct 6, 2026
11 checks passed
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