Skip to content

test(cli): fix concurrent core-build race in build-theme suites - #3562

Merged
cixzhang merged 1 commit into
mainfrom
navi/fix/core-build-race-all-suites
Jul 4, 2026
Merged

cixzhang merged 1 commit into
mainfrom
navi/fix/core-build-race-all-suites

Conversation

@cixzhang

@cixzhang cixzhang commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Problem

The test CI job fails nondeterministically for unrelated PRs. Three CLI suites each need a compiled @astryxdesign/core — astryx theme build imports the built theme entry packages/core/dist/theme/index.js and there is no in-CLI fallback generator:

  • build-theme.prose.test.mjs
  • build-theme.import-path.test.mjs
  • build-theme.watch.test.mjs

The test job runs pnpm test with no 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. Core's build starts with rimraf dist, so multiple workers that all saw dist missing launched concurrent builds that collided on the shared packages/core/dist — one worker wiped dist while another was mid-write. This surfaced as errors like ENOTEMPTY: directory not empty, rmdir '.../packages/core/dist/PowerSearch' and Could 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 (mkdir is 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 call ensureCoreBuilt() in beforeAll instead of building core directly, so no suite can trigger a concurrent rimraf 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 beforeAll and 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/dist to 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 inside test); building it once and sharing it via cache/artifact is a separate follow-up.

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.
@vercel

vercel Bot commented Jul 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 4, 2026 1:03pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 4, 2026
@cixzhang
cixzhang marked this pull request as ready for review July 4, 2026 13:06
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.6KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Jul 4, 2026
@cixzhang
cixzhang merged commit 90d2a8c into main Jul 4, 2026
16 checks passed
@github-actions
github-actions Bot deleted the navi/fix/core-build-race-all-suites branch July 12, 2026 06:58

This branch was successfully deployed

1 active deployment
Preview — 3d004a12 Deployed Jul 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants