Skip to content

test(cli): the node suites rebuild a Core build older than its sources - #8567

Merged
cixzhang merged 1 commit into
meta:mainfrom
vjeux:uikit/core-build-freshness
Nov 5, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
vjeux:uikit/core-build-freshness

Conversation

@vjeux

@vjeux vjeux commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

A contributor who switches branches can see the CLI's theme-build tests fail, or pass, against an old Core. The suites test the compiled @astryxdesign/core/theme. The helper that builds it returned as soon as a build existed, however old. A second failure came when a Core file changed during a run: a suite rebuilt Core mid-run and deleted the build other suites were reading. CI builds fresh, so this hits local runs.

Intended invariant

The node test project tests the CLI against a Core build as new as Core's sources. No run rebuilds Core under another run.

Change

  • The node project's global setup rebuilds Core when its build is older than any input of Core's build. Those inputs are its sources, locales, package.json, and the build's scripts and configs. The rebuild comes before any test worker forks.
  • A suite's beforeAll builds only a missing Core, so no suite rebuilds Core mid-run.
  • Each node run holds a lease in the checkout. A stale rebuild waits for the runs that started before it, for at most two minutes. Past that, the run stops with an error naming each live run and its lease file.
  • Each checkout has its own build lock, so one worktree's build never holds up another's tests.
  • The global setup still packs the CLI once for every suite, as on main.

Evidence

  • Failure before the change: on main 54166ff, a Core source was made newer than the build. The setup kept the stale build, whose last output kept its time, and the suites ran against it.
  • Success after the change: in the same checkout, the same source change made this setup rebuild Core first. Its last output moved from before the source change to after it.
  • The guard tests catch inputs that main adds later. The rebase without this head's updates (NOT-FOR-LANDING commit 0c99a74) fails 3 of them on today's main. They name the new generated i18n/generated-english output, two new build inputs, and the setup's new shape. This head adds all three.
  • Product/runtime behavior verified unchanged: test setup only.
  • CI impact: none; no workflow changes.

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

At 838d6d3, on main 54166ff:

  • the node project (pnpm exec vitest run --project node): 901 files passed, 7 skipped; 16,525 tests;
  • scripts/ensure-core-built.test.mjs: 33 of 33;
  • the theme-build suites (packages/cli/api/theme/build and the build-theme command suites): 36 files, 406 tests;
  • CI=true pnpm lint: no errors;
  • pnpm review:pre: no findings.

@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 4, 2026 8:16pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 4, 2026, 8:25 PM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 26, 2026

@astracat-bot astracat-bot 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.

Thanks, the freshness check closes a real gap for reused checkouts, but it needs two changes before it can merge.

  • The walk counts the locale modules in packages/core/src/i18n/generated-locales/, which the root Vitest global setup regenerates after the node setup when the CLI suites run on their own (as pnpm -F @astryxdesign/cli test does), so a translation edit makes one suite rebuild Core inside its worker while the waiting suites continue before Core's declarations exist and three tsc --noEmit assertions fail in build.family.test.mjs and build-theme.variants.test.mjs: please skip generated output in the walk and have waiting workers return only after the lock is released.
  • ensure-core-built.test.mjs tests a non-command helper inside clients/cli/commands/, which architecture:cli-surface INV22 reserves for command handlers, their CommandDocs, and their tests, so please move it out of that directory.

[Automated review]

// What the build compiles: a file here newer than the built entry means dist
// is stale. A checkout rewrites the files it changes, so they read as newer.
const CORE_SOURCES = [
path.join(REPO_ROOT, 'packages/core/src'),

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.

This root also takes in src/i18n/generated-locales/, which the root Vitest global setup (internal/test-utils/src/globalSetup.ts) regenerates after the node project's setup has called ensureCoreBuilt() whenever only CLI suites run (as pnpm -F @astryxdesign/cli test does). After a translation edit with a fresh build, the build turns stale only once workers have forked, so the first suite rebuilds Core in its worker (deleting dist) and the others return at line 151 as soon as dist/theme/index.js reappears, about 11 s before tsc writes declarations; three tsc --noEmit assertions in build.family.test.mjs and build-theme.variants.test.mjs then fail. Skipping generated output here, and letting waiters wait for the lock to clear, keeps the staleness decision in the global setup.

@@ -0,0 +1,80 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

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.

architecture:cli-surface INV22: "Only command handlers, their CommandDoc files, and their tests live in that directory." This file tests a non-command helper, so it belongs outside clients/cli/commands/, for example in scripts/ beside the build-css.* suites that already import the helper by path.

@vjeux

vjeux commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

The walk now skips the generated output: src/i18n/generated-locales and locales/pseudo.json, which the Vitest global setup rewrites after a build, so a regeneration no longer makes a fresh build read as stale. It counts the translations they come from (packages/core/locales, outside src), so the first call after a translation edit rebuilds before any worker forks, and a test checks that the skip list matches .gitignore. A waiting caller now returns only once the lock is released, not when dist/theme/index.js reappears. In your scenario (a fresh build, a translation edit, the setup's call, the regeneration, then four workers at once), the previous head had one worker rebuild while three returned after 13.5 s with Core's declarations missing; this head rebuilds in the setup's call and all four return in about 20 ms with them. The helper's test moved to scripts/ensure-core-built.test.mjs, outside the command directory.

@astracat-bot astracat-bot 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.

The generated-output skip, the lock wait and the test's move to scripts/ address the earlier review, but one race introduced by the freshness check needs a change before this can merge. When any Core file changes while the CLI suites run, the next suite's beforeAll finds the build stale and rebuilds Core in its worker, and that build deletes packages/core/dist under suites still reading it, so unrelated build-theme tests fail where the base passes. Please rebuild a stale Core only in the node global setup, before workers fork, and keep the in-suite calls on the missing-build check; keying the lock to the checkout instead of one os.tmpdir() path would also stop one worktree's rebuild from stalling another worktree's suites.

[Automated review]

* build-theme suite's beforeAll.
*/
export function ensureCoreBuilt() {
ensureBuiltOnce({isBuilt: coreIsBuilt, build: buildCore, lockDir: LOCK_DIR});

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.

A suite's beforeAll reaches this with a stale build whenever a Core file changes after the global setup's check, so the rebuild runs in that worker: pnpm -F @astryxdesign/core build deletes packages/core/dist first, and suites that already returned fail mid-test (Could not resolve "@astryxdesign/core/theme", tsc --noEmit). Touching packages/core/src/Button/Button.spec.md 9 s into a run of the theme-build suites failed 6 tests; the base passes the same sequence. Rebuilding a stale build only from vitest.global-setup.node.mjs, with the in-suite calls kept on the missing-build check, closes this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 841ce23. A stale Core is now rebuilt only by the node global setup (ensureCoreBuilt({rebuildStale: true}), before the workers fork), and a suite's beforeAll builds only a missing one. Your sequence (touching Button.spec.md 9 s into the build-theme suites) failed 6 tests in 4 files before and passes 104/104 now.

const deadline = Date.now() + staleLockMs;
while (Date.now() < deadline) {
if (fs.existsSync(CORE_THEME_ENTRY)) {
if (!lockIsHeld(lockDir, staleLockMs) && isBuilt()) {

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.

LOCK_DIR (line 56) is one os.tmpdir() path shared by every checkout on the machine, so this condition makes a checkout with a current build wait for any other checkout's Core rebuild (32 s measured, where the base returns at once), and a lock left by a killed holder blocks every call until it is 200 s old. Keying the lock to REPO_ROOT keeps the wait to this checkout's own build.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 841ce23. The lock is now coreBuildLockDir(REPO_ROOT), one per checkout under os.tmpdir(), so a checkout with a current build no longer waits on another checkout's rebuild, and a lock a killed holder leaves blocks only its own checkout. The tests check that two checkouts get different locks, and that a lock held for another checkout returns a current build at once.

@astracat-bot astracat-bot 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.

The setup-only rebuild and the per-checkout lock address the earlier review, and a Core edit during a run no longer breaks running suites, but one gap needs a change before this can merge. If the global setup's rebuild is interrupted or fails after Babel writes dist/theme/index.js, the next run treats that half-built Core as current, because coreBuildIsStale dates the build by a file the build writes before its declarations and CSS; the type-check tests then fail as if the CLI had regressed. Please date the build by a marker that only a finished build writes, such as a stamp written after buildCore() returns or dist/astryx.css. Adding the build's own scripts and config (for example scripts/build-css.mjs) to CORE_SOURCES would also let the build-css.* suites see changes to the script they test.

[Automated review]

export function coreBuildIsStale(entry, roots, generated = []) {
let built;
try {
built = fs.statSync(entry).mtimeMs;

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.

This dates the build by dist/theme/index.js, which Core's build:esm writes about 11 s into a 38 s build, before tsc and build:css. If the global setup's rebuild is interrupted (Ctrl-C while the run shows only Vitest's header) or a later step fails, the next run finds this entry newer than every source and skips the rebuild, so the suites test a dist with no declarations or astryx.css. Reproduced here, the rerun failed three tsc --noEmit assertions in build.family and build-theme.variants. Dating the build by a stamp the helper writes after buildCore() returns, or by dist/astryx.css, makes an incomplete rebuild read as stale.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ca95141: a build is now dated by dist/astryx.css, which build:css writes after the modules, declarations and declaration extensions, so a rebuild interrupted or failed before it reads as missing and is rebuilt. With astryx.css removed, as an interrupted rebuild leaves it, the old check called the build current and this one rebuilds; a test pins that the marker is the build's last output step.

Comment on lines +48 to +52
export const CORE_SOURCES = [
path.join(REPO_ROOT, 'packages/core/src'),
path.join(REPO_ROOT, 'packages/core/locales'),
path.join(REPO_ROOT, 'packages/core/package.json'),
];

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.

Core's build also runs scripts/build-css.mjs, scripts/generate-i18n-runtime.mjs, scripts/add-declaration-extensions.mjs and packages/core/scripts/build-pseudo-locale.mjs, and reads packages/core/babel.config.json and tsconfig.build.json; this list covers none of them. After scripts/build-css.mjs is touched, the helper still calls the build current, so the scripts/build-css.* suites, which read dist/astryx.css, keep testing the old stylesheet after a change to the script they test. Adding those files here closes it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ca95141: the sources now include scripts/build-css.mjs, scripts/generate-i18n-runtime.mjs, scripts/add-declaration-extensions.mjs, packages/core/scripts/build-pseudo-locale.mjs, babel.config.json, tsconfig.build.json and the root tsconfig.json it extends. A test reads Core's build* scripts and fails when a script or config they write output with is missing from the list.

@astracat-bot astracat-bot 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.

The last-output marker and the build-script inputs address the earlier review, and an interrupted rebuild now heals, but two gaps need a change before this can merge.

  • A second node run started after a Core edit rebuilds Core under a run already in progress: with the 15 build-theme test files running, 6 of 104 tests failed where the base passes, so please let a stale rebuild wait while another run in the checkout is live, or narrow the "never under a running suite" guarantee to a single run.
  • CORE_SOURCES misses packages/core/babel-plugin-add-extensions.cjs, which babel.config.json runs on every compiled module, and scripts/stylex-module-resolution.cjs, which build-css.mjs hands to StyleX, so please add both and extend the inputs test to the files those configs and scripts load.

[Automated review]

Comment on lines +55 to +66
export const CORE_SOURCES = [
path.join(REPO_ROOT, 'packages/core/src'),
path.join(REPO_ROOT, 'packages/core/locales'),
path.join(REPO_ROOT, 'packages/core/package.json'),
path.join(REPO_ROOT, 'packages/core/babel.config.json'),
path.join(REPO_ROOT, 'packages/core/tsconfig.build.json'),
path.join(REPO_ROOT, 'tsconfig.json'),
path.join(REPO_ROOT, 'packages/core/scripts/build-pseudo-locale.mjs'),
path.join(REPO_ROOT, 'scripts/generate-i18n-runtime.mjs'),
path.join(REPO_ROOT, 'scripts/add-declaration-extensions.mjs'),
path.join(REPO_ROOT, 'scripts/build-css.mjs'),
];

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.

packages/core/babel.config.json runs the local plugin ./babel-plugin-add-extensions.cjs on every module build:esm compiles, and scripts/build-css.mjs imports ./stylex-module-resolution.cjs and passes it to StyleX when it writes astryx.css. Neither is listed here, so after a build, touching either leaves coreBuildIsStale false and the setup keeps the old build. Adding both paths closes it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 0a24e46: CORE_SOURCES now lists packages/core/babel-plugin-add-extensions.cjs and scripts/stylex-module-resolution.cjs.

Comment on lines +268 to +269
* setup passes `rebuildStale`, so a build older than Core's sources is rebuilt
* there, before any worker forks, and never under a running suite.

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.

This holds within one run only. With the 15 build-theme test files running, a Core edit followed by a second node run made that run's setup rebuild Core under the first run, which failed 6 of 104 tests; the base passes the same sequence. A run lease that each setup registers and its teardown removes, checked before a stale rebuild, would keep the guarantee; otherwise this sentence should say it covers a single run.

Comment on lines +364 to +372
for (const [, file] of command.matchAll(/\bnode\s+(\S+\.m?js)/g)) {
// Checks read the build; they write nothing it depends on.
if (!/\/(check-|clean-dist)/.test(file)) inputs.add(file);
}
for (const [, file] of command.matchAll(
/--(?:config-file|project)\s+(\S+)/g,
)) {
inputs.add(file);
}

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.

This collects only node <file> and --config-file/--project arguments, so it passes while the plugin babel.config.json names and the ./stylex-module-resolution.cjs import of build-css.mjs are missing from CORE_SOURCES. Following the configs' local plugins and the listed scripts' relative imports would make the check match its name.

@astracat-bot astracat-bot 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.

Thanks: the run leases fix the overlapping-run failure from the last round (the 15 build-theme files now pass 104/104 while a second run waits, then rebuilds), and the two missing build inputs are covered, but the new wait needs one change before this can merge. The stale-rebuild loop in ensure-core-built.mjs polls synchronously with no deadline, so after a Core edit a node run waits for as long as an idle watch-mode run (such as pnpm test:watch) stays open, and Ctrl-C ends only the pnpm wrapper while Vitest keeps waiting and later rebuilds Core in the background. Please make that wait asynchronous and bounded (after a limit, skip the rebuild with a warning or fail naming the live run), and end each lease on process exit as well as in the teardown, since a vitest run stopped with Ctrl-C currently leaves its lease behind.

[Automated review]

Comment on lines +346 to +361
if (rebuildStale && runLeaseDir) {
let announced = false;
while (
fs.existsSync(entry) &&
coreBuildIsStale(entry, roots, generated) &&
earlierLiveRuns(runLeaseDir, {isAlive}).length > 0
) {
if (!announced) {
console.warn(
'[ensure-core-built] Core changed; waiting for the test run already running in this checkout to end before rebuilding it.',
);
announced = true;
}
sleepSync(pollMs);
}
}

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.

This wait has no deadline and blocks the main thread (sleepSync is Atomics.wait), so Vitest's SIGINT and SIGTERM handlers cannot run while it polls. Behind an idle watch-mode node run, a run started after a Core edit sat here 93 s until the watcher was stopped, and Ctrl-C ended only the pnpm wrapper while Vitest kept waiting and later rebuilt Core in the background. Awaiting a timer instead (Vitest awaits an async global setup) and giving up after a limit, with a warning that the run tests the existing build or an error naming the live run, would keep the run stoppable and bounded.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3e5ac0d: the node global setup now awaits ensureCoreBuiltForRun, which waits on a timer, so the event loop stays free and Ctrl-C stops the run, and gives up after two minutes: past that, the run tests the build already in dist, with a warning naming the live run. Behind an idle watch-mode run, Ctrl-C now ends every process of the waiting run within about 50 ms, and nothing rebuilds afterwards.

ensureCoreBuilt();
// This run holds a lease for its whole length, so a later run's setup does
// not rebuild Core under it; the returned teardown ends the lease.
const endRun = registerTestRun();

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.

If ensureCoreBuilt or the template sync below throws, this lease is never ended, and a vitest run stopped with Ctrl-C exits without calling the returned teardown, so its lease stays too. A later stale rebuild waits on any live process that has that pid, so ending the lease in a finally and on process.once('exit', endRun) would keep leftover leases from holding future runs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3e5ac0d: the setup ends its lease on process.once('exit', endRun) and in a catch before rethrowing, besides the returned teardown. A test spawns a process with that pattern, stops it with SIGINT, and checks that its lease is gone.

@astracat-bot astracat-bot 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.

Thanks: the earlier-run wait is now an awaited timer bounded at two minutes, and each run's lease ends on exit and on a setup error, which resolves the last round's request; nothing else blocks this change. Two trade-offs remain by design: behind a node run that outlives the two-minute wait (an idle watch-mode run, say) a later run still tests the old Core build with a warning, and while Core's sources do not compile every node run fails in setup with the TypeScript error visible only as bytes in Vitest's serialized error, because buildCore pipes the build's output. Neither needs a change here, though surfacing that output when the setup's rebuild fails would make the second case easier to diagnose.

[Automated review]

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 838d6d3

Storybook · Sandbox · built from this PR's head

Package size: @astryxdesign/cli 3.35 MB packed (+3.0 kB); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 8 rows, core 2 rows; run pnpm api:report.

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot 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.

Incremental review of 3e5ac0d..4bcac44; prior findings carried: user_impact

Thanks: a run that cannot rebuild a stale Core now stops with an error instead of testing the old build, and the narrowed error handling comes with tests; nothing blocks this change. Two small follow-ups would help: the header of ensure-core-built.mjs (lines 31-32) still says that past the limit the run tests the build it has with a warning, and the new error names any live process that holds a leftover lease's pid as a test run (a run killed by SIGHUP, as closing its terminal does, leaves its lease), so naming the lease file in the message would let someone clear it. The pull request description also still describes the earlier fallback and 28 test cases.

[Automated review]

Comment on lines +31 to +32
* already in progress; past the limit it tests the build it has, with a
* warning naming the live run.

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.

This clause still describes the fallback the latest push removed: past the limit the setup now throws an error naming the live run (lines 464-468), as ensureCoreBuiltForRunAt's comment and the Changeset say. Updating it keeps the header in step with the code, as the documentation standard in AGENTS.md asks.

});
if (stillLive.length > 0) {
throw new Error(
`[ensure-core-built] Core's sources changed since packages/core/dist was built, and test run ${stillLive.join(', ')} in this checkout still uses that build after ${Math.round((limitMs ?? EARLIER_RUN_WAIT_MS) / 1000)} s: rebuilding would delete dist under it, and this run would test old code. Run again once it ends.`,

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.

processIsAlive counts any live process with the lease's pid as this run, and a run killed by SIGHUP (closing its terminal) or SIGKILL leaves its lease behind. Once another process holds that pid, this error names a test run that does not exist on every run after a Core edit, and nothing in it points at the lease. Naming the lease file here (path.join(leaseDir, String(pid))) would let someone who finds no such run delete it.

@astracat-bot astracat-bot 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.

Incremental review of 4bcac44..688f1a1; prior findings carried: user_impact

Thanks: the stop-with-error now names each live run's lease file and the helper's header describes the stop, which resolves both follow-ups from the last round; nothing blocks this change. With a live non-test process holding an earlier lease, a node run failed after 120 s naming that lease file, and once the file was deleted the next run rebuilt Core and passed. No further changes are needed.

[Automated review]

@vjeux
vjeux marked this pull request as draft October 29, 2026 22:37

@astracat-bot astracat-bot 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.

Thanks: the freshness rule, the setup-only rebuild and the run leases still work on this branch (the helper's 33 tests pass here, and a stale Core is rebuilt once in setup), but main has moved under it, and one change is needed before this can merge.

  • Regression: CORE_SOURCES and CORE_GENERATED in packages/cli/clients/cli/commands/ensure-core-built.mjs miss scripts/i18n-english-fallback.mjs, scripts/lib/stylex-generated-variable.mjs and packages/core/src/i18n/generated-english/, which main has added since, so once merged an edit to either script leaves a stale Core reading as current, 2 of the 33 tests in scripts/ensure-core-built.test.mjs fail, and vitest.global-setup.node.mjs conflicts with main's new CLI pack step.

Merging main, keeping its pack step beside the lease, and adding those three paths should clear it. Optional: the helper's file header is now 32 lines, where architecture:knowledge-contracts INV29 asks for about 12 with @input, @output and @position; an inline comment suggests one.

[Automated review]

Comment on lines +61 to +81
export const CORE_SOURCES = [
path.join(REPO_ROOT, 'packages/core/src'),
path.join(REPO_ROOT, 'packages/core/locales'),
path.join(REPO_ROOT, 'packages/core/package.json'),
path.join(REPO_ROOT, 'packages/core/babel.config.json'),
path.join(REPO_ROOT, 'packages/core/babel-plugin-add-extensions.cjs'),
path.join(REPO_ROOT, 'packages/core/tsconfig.build.json'),
path.join(REPO_ROOT, 'tsconfig.json'),
path.join(REPO_ROOT, 'packages/core/scripts/build-pseudo-locale.mjs'),
path.join(REPO_ROOT, 'scripts/generate-i18n-runtime.mjs'),
path.join(REPO_ROOT, 'scripts/add-declaration-extensions.mjs'),
path.join(REPO_ROOT, 'scripts/build-css.mjs'),
path.join(REPO_ROOT, 'scripts/stylex-module-resolution.cjs'),
];
// Git-ignored output generated from those sources, by the build and again by
// the Vitest global setup (internal/test-utils/src/globalSetup.ts): rewritten
// after a build, it would read as newer than that build.
export const CORE_GENERATED = [
path.join(REPO_ROOT, 'packages/core/src/i18n/generated-locales'),
path.join(REPO_ROOT, 'packages/core/locales/pseudo.json'),
];

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.

Regression: main has added build inputs these lists miss. scripts/generate-i18n-runtime.mjs now imports ./i18n-english-fallback.mjs, scripts/build-css.mjs imports ./lib/stylex-generated-variable.mjs, and .gitignore adds packages/core/src/i18n/generated-english/. Merged into main, an edit to either script leaves a stale Core reading as current, and scripts/ensure-core-built.test.mjs fails 2 of 33 ("skip exactly the git-ignored output under them" and "cover every script and config file Core's build scripts write output with"). Adding scripts/i18n-english-fallback.mjs and scripts/lib/stylex-generated-variable.mjs to CORE_SOURCES, and packages/core/src/i18n/generated-english to CORE_GENERATED, should clear both.

Comment thread vitest.global-setup.node.mjs Outdated
maxBuffer: 32 * 1024 * 1024,
},
);
export default async function setup() {

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.

Regression: main rewrote this setup to pack the CLI once for the node project (setup(project), project.provide('astryxPackedCliTarball', …), project.onTestsRerun), so merging main conflicts here. The lease and await ensureCoreBuiltForRun() can sit before the pack step, and the unit test's regex over this file will need to accept the project parameter.

Comment on lines +20 to +33
* The node project's global setup also rebuilds a build older than Core's
* sources, before any test worker forks: a reused worktree checked out to a
* new head keeps its old dist, and the suites would otherwise test the new CLI
* against the old theme build. The files the build and the test setup
* generate from those sources are not sources. A suite's beforeAll builds
* only a missing Core: rebuilding a stale one mid-run would delete dist under
* suites still reading it. Each checkout has its own lock, so one worktree's
* rebuild never holds up another's suites. Each node run also holds a lease in
* the checkout while it runs (ended by its teardown or its exit), and a stale
* rebuild waits, on a timer and for at most two minutes, until every run that
* started before it has ended, so a second run never rebuilds Core under a run
* already in progress; past the limit it stops with an error naming each
* live run and its lease file (a run killed by SIGHUP leaves its lease, and
* another process can take its pid).

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.

Non-blocking (architecture:knowledge-contracts INV29): the file header is now 32 lines, where INV29 asks for @input, @output and @position in about 12 lines, and the sentence on lines 27-33 runs past 80 words. A shorter header that keeps the reasons:

/**
 * @file Shared test helper: builds @astryxdesign/core once per run, race-free.
 * @input Core's sources, translations and build scripts; this checkout's lock
 *   and run leases in the system temp directory.
 * @output A packages/core/dist whose last output is newer than every source.
 * @position Called by the node global setup and the build-theme suites.
 *
 * A Core build deletes dist first. Only the global setup rebuilds a stale
 * build, before the workers start, and only after earlier runs end.
 */

@vjeux
vjeux force-pushed the uikit/core-build-freshness branch from 688f1a1 to 8a3b916 Compare November 4, 2026 20:04
@vjeux vjeux changed the title test(cli): the theme build suites rebuild Core when its build is older than its sources test(cli): the node suites rebuild a Core build older than its sources Nov 4, 2026
A reused checkout keeps its old Core build. The CLI's theme-build
suites then test the new CLI against an old Core. A suite that rebuilt
Core mid-run deleted dist under suites still reading it.

The node project's global setup now rebuilds a Core build older than
Core's sources, before any test worker forks. A suite's beforeAll
builds only a missing Core. Each node run holds a lease in the
checkout, and a stale rebuild waits for the runs that started before
it, for at most two minutes. Each checkout has its own build lock.

The global setup still packs the CLI once for every suite.
@vjeux
vjeux force-pushed the uikit/core-build-freshness branch from 8a3b916 to 838d6d3 Compare November 4, 2026 20:08

@astracat-bot astracat-bot 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.

Approved pending CI: CI has not run on this head yet.

The input lists now cover the build scripts and generated output that main added, and the setup keeps main's CLI pack step. On this head, a changed build input rebuilds Core once in setup, and the helper's tests and the theme-build and build-css suites pass. Next: mark the pull request ready for review, and because the branch is in a fork, a maintainer adds the ci:run label so CI runs.

[Automated review]

@vjeux
vjeux marked this pull request as ready for review November 4, 2026 20:27
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 4, 2026
@cixzhang
cixzhang marked this pull request as draft November 4, 2026 20:35
@cixzhang
cixzhang marked this pull request as ready for review November 4, 2026 20:35
@cixzhang
cixzhang merged commit 3139560 into meta:main Nov 5, 2026
144 of 149 checks passed
@vjeux
vjeux deleted the uikit/core-build-freshness branch November 5, 2026 02:24
prath47 added a commit to prath47/astryx that referenced this pull request Nov 11, 2026
ensure-core-built.mjs ships in the @astryxdesign/cli tarball, so the
change needs a CLI patch changeset, as meta#8567's did for this helper.
cixzhang pushed a commit that referenced this pull request Nov 11, 2026
* test(cli): run the Core rebuild through cmd.exe on Windows

The node global setup rebuilds a stale Core with execFileSync('pnpm').
On Windows pnpm is a pnpm.cmd batch file, which execFileSync can't start
without a shell, so the setup dies with "spawnSync pnpm ENOENT" and no CLI
test runs whenever Core's sources are newer than its build.

Route the call through cmd.exe /d /s /c on win32, the same way the
vibe-tests helpers do since #5841 and #5843. Every argument is a literal,
so this avoids shell: true and its DEP0190 warning. Other platforms are
unchanged.

* test(cli): keep the Core rebuild to one execFileSync call

doc-loads.test.mjs lists each file's child_process sites, and the
platform branch had made two. Pick the executable and its arguments by
platform and keep the single call.

* chore(changeset): note the Windows Core rebuild in the CLI release

ensure-core-built.mjs ships in the @astryxdesign/cli tarball, so the
change needs a CLI patch changeset, as #8567's did for this helper.

This branch was successfully deployed

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

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) 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