test(vite-plugin-rails): build determinism + add to JS matrix#4
Draft
andriytyurnikov wants to merge 3 commits intochore/ci-hardening-and-node-bumpfrom
Draft
test(vite-plugin-rails): build determinism + add to JS matrix#4andriytyurnikov wants to merge 3 commits intochore/ci-hardening-and-node-bumpfrom
andriytyurnikov wants to merge 3 commits intochore/ci-hardening-and-node-bumpfrom
Conversation
build.spec.ts pinned exact 8-char content hashes (e.g. assets/main-Ddvw3iap.js) in both the file-list assertion and the snapshot. Any routine bump of Vite, Rolldown, Vue, or sass that changes a chunk by even a byte forces a manual hash regeneration even though the manifest shape is unchanged. Strip the 8-char hash from filenames before asserting, and replace the sub-resource integrity value with a `<integrity>` placeholder in the snapshot. The test now fails on structural changes (entry → file mapping, imports list, css list, etc.) but absorbs byte-level churn from upstream dependency updates.
vitest sets NODE_ENV=test by default, and build.spec.ts spawns `npm run build` inheriting that env. Vite respects an externally-set NODE_ENV — it doesn't overwrite it from --mode production — so the test-driven build was producing Vue's *development* bundle (Object.freeze, __file injection with absolute paths, prop validators, dev-only warnings). Local `npm run build` (no vitest in the loop) shipped Vue's production bundle. The two outputs diverged by ~27 KB and produced different chunk hashes — the symptom we previously misdiagnosed as cross-platform drift. Setting NODE_ENV=production in the build script makes the build match production semantics regardless of how it's invoked, so the test exercises the same code real users ship.
Now that the build snapshot strips chunk hashes and the example build
is pinned to NODE_ENV=production, vite-plugin-rails' tests are stable
enough across Node versions and dep bumps to run in CI.
- Matrix: package: [vite-plugin-ruby, vite-plugin-rails].
- name: matrix package, so each job is named for what it tests.
- fail-fast: false, so a failure in one matrix cell doesn't cancel
siblings.
- Test step uses ${{ matrix.package }}.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Slice 4 of the ElMassimo#607 split. Stacks on #3 (CI hardening + Node 22) —
baseis set to that branch so the diff stays focused on the test-stability work. When #3 merges to main, retarget this PR's base to main and the diff becomes self-contained.Drafted in fork — will retarget upstream once locally reviewed.
Why
vite-plugin-rails'tests/build.spec.tspinned exact 8-char content hashes (e.g.assets/main-Ddvw3iap.js) in both the file-list assertion and the manifest snapshot. Any routine bump of Vite, Rolldown, Vue, or sass that changes a chunk by even a byte forces a manual hash regeneration even though the manifest shape is unchanged.This brittleness is what made #3's first attempt at adding
vite-plugin-railsto the JS matrix fail: Node 22 + 24 produce different chunk bytes than whoever last regenerated the snapshot, so the test failed on hash mismatch even though nothing structural had changed.This PR fixes the brittleness, then adds
vite-plugin-railsto the matrix.Changes
Test stability — hash normalization
vite-plugin-rails/tests/build.spec.ts: introducestripHash(regex on 8-char content-hash suffixes) andnormalizehelpers. The file-list assertion now compares hash-stripped names; the snapshot is normalized recursively, replacingintegritySRI values with the literal<integrity>placeholder.vite-plugin-rails/tests/__snapshots__/build.spec.ts.snapregenerated against the new normalize pass.The test now fails on structural changes (entry → file mapping, imports list, css list, etc.) but absorbs byte-level churn from upstream dependency updates.
Build determinism — pin
NODE_ENV=productionvite-plugin-rails/example/package.json:npm run buildnow pinsNODE_ENV=production.vitest sets
NODE_ENV=testby default, andbuild.spec.tsspawnsnpm run buildinheriting that env. Vite respects an externally-setNODE_ENV— it doesn't overwrite it from--mode production— so the test-driven build was producing Vue's development bundle (withObject.freeze,__fileinjection of absolute paths, prop validators, dev-only warnings). Localnpm run build(no vitest in the loop) shipped Vue's production bundle. The two outputs diverged by ~27 KB and produced different chunk hashes — the symptom previously misdiagnosed as cross-platform drift.Pinning
NODE_ENV=productionin the build script makes the build match production semantics regardless of how it's invoked, so the test exercises the same code real users ship.Add
vite-plugin-railsto JS matrix.github/workflows/js.yml: package matrix[vite-plugin-ruby, vite-plugin-rails];fail-fast: false; jobnameand test step use${{ matrix.package }}.Commits
Test plan
vite-plugin-railson Node 22 + 24vite-plugin-rubyon Node 22 + 24