Repository navigation
test(cli): fix concurrent core-build race in build-theme suites - #3562
Merged
Merged
Conversation
The build-theme.prose, build-theme.import-path, and build-theme.watch
suites each need a compiled @astryxdesign/core (theme build imports the
built theme entry; there is no in-CLI fallback generator). The CI test
job runs the suite without a prior core build, and Vitest runs test
files in parallel worker forks. Each suite's beforeAll independently ran
`if (!exists) pnpm -F @astryxdesign/core build`, so multiple workers saw
dist missing and launched concurrent builds that collided on the shared
packages/core/dist (core's build starts with `rimraf dist`): one worker
wiped dist while another was mid-write, failing nondeterministically
("Could not resolve dist/index.js" or "ENOTEMPTY rmdir dist/hooks").
Extract a shared ensureCoreBuilt() helper that serializes the build
behind an atomic lock directory, so exactly one worker builds and the
rest wait for it to finish before reading dist. Includes stale-lock
recovery for a crashed/killed builder. Route all three build-theme
suites through it so none can build core directly.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
cixzhang
marked this pull request as ready for review
July 4, 2026 13:06
cixzhang
requested review from
ejhammond,
imdreamrunner,
josephfarina,
marie-lucas,
nynexman4464 and
thedjpetersen
as code owners
July 4, 2026 13:06
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
josephfarina
approved these changes
Jul 4, 2026
This branch was successfully deployed
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.
Problem
The
testCI job fails nondeterministically for unrelated PRs. Three CLI suites each need a compiled@astryxdesign/core—astryx theme buildimports the built theme entrypackages/core/dist/theme/index.jsand there is no in-CLI fallback generator:build-theme.prose.test.mjsbuild-theme.import-path.test.mjsbuild-theme.watch.test.mjsThe
testjob runspnpm testwith no prior core build, and Vitest runs test files in parallel worker forks. Each suite'sbeforeAllindependently ranif (!exists) pnpm -F @astryxdesign/core build. Core's build starts withrimraf dist, so multiple workers that all sawdistmissing launched concurrent builds that collided on the sharedpackages/core/dist— one worker wipeddistwhile another was mid-write. This surfaced as errors likeENOTEMPTY: directory not empty, rmdir '.../packages/core/dist/PowerSearch'andCould not resolve "./AppShell/index.js".Fix
Extract a shared
ensureCoreBuilt()helper (packages/cli/src/commands/ensure-core-built.mjs) that serializes the build behind an atomic lock directory (mkdiris atomic across processes): exactly one worker builds core and the rest wait for the built entry to appear before proceeding. Includes stale-lock recovery so a crashed/killed builder can't deadlock the others.All three
build-theme.*suites now callensureCoreBuilt()inbeforeAllinstead of building core directly, so no suite can trigger a concurrentrimraf dist.Why this supersedes #3518
An earlier iteration (#3518) routed the prose and import-path suites through this helper, but the watch suite (added later in #3478) still had the old racy
beforeAlland kept racing against the other two. This change re-applies that helper and additionally routes the watch suite through it, so the fix now covers all three suites.Verification
Deleted
packages/core/distto force the cold-build race, then ran all three suites together in parallel forks. All 8 tests pass, repeated across multiple cold-dist runs — the winner builds core once (~24s) and the other two wait on the lock and finish immediately. No changeset: this is test-infra only and not consumer-visible.Scope
Intentionally scoped to just the test-suite race. Core is still built redundantly across CI jobs (
build,docsite-test, and lazily insidetest); building it once and sharing it via cache/artifact is a separate follow-up.