Repository navigation
fix(cli): theme build scans the icon import from the source it loaded - #8598
Conversation
theme build loaded the theme module, then read the file again to find its icon registry import. An in-place save truncates before it writes, so that second read could find the file empty; with a registry that holds no icons yet the scan then found no import, and the build succeeded with a module that lacked it (the watch-mode flake in build-theme.icons-specifier.test.mjs). The build now reads the theme file before and after loading it and scans those bytes; a file that changed while it loaded fails the build, and the next save builds it.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
Recommending approval. The registry scan now reads the bytes the build loaded, so a theme saved in place mid-build fails with ERR_THEME_LOAD instead of writing a module that has dropped its icon-registry import, and the new torn-read test fails against main's build.mjs and passes here. One optional hardening: the test compares a theme path built from os.tmpdir() with the path the CLI resolves from process.cwd(), so on macOS, where the temp directory sits behind the /var symlink, the torn case passes without emptying any read; wrapping fs.mkdtempSync(...) in fs.realpathSync(...) keeps it live. The CI node test shards for this head were cancelled and still need a re-run before merge.
[Automated review]
|
|
||
| let tmpDir; | ||
| beforeEach(() => { | ||
| tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-torn-theme-')); |
There was a problem hiding this comment.
This path keeps os.tmpdir() unresolved, while the CLI builds the theme path from process.cwd(), which is the physical path. Where the temp directory sits behind a symlink (macOS's /var/folders/..., with /var linking to /private/var), the preload's comparison on line 79 never matches. Nothing is emptied, so the torn case passes even against main's build.mjs; a symlinked TMPDIR shows the same on Linux. Resolving the directory keeps the case live:
tmpDir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-torn-theme-')));|
Posted by Cindy's agent on her behalf: closed and reopened only to restart this PR's CI on the current workflow after tonight's queue-wide cancel; nothing in the PR changed. |
|
Posted by Cindy's agent on her behalf: closed and reopened only to restart this PR's CI on the current workflow (the last run used a workflow without the Core build step that scoped Node tests need); nothing in the PR changed. |
There was a problem hiding this comment.
Recommending approval, pending CI: one required test shard is still running on this head.
The registry scan now uses the bytes the build loaded, so a theme saved in place mid-build fails with ERR_THEME_LOAD and writes nothing, instead of exiting 0 with a module that has dropped its icon-registry import; the new torn-read test fails against the base's build.mjs and passes here. Two optional follow-ups:
- The torn case compares a path built from
os.tmpdir()with the physical path the CLI resolves fromprocess.cwd(), so behind a symlinked temp directory (macOS's default/var/folders/...) it passes without emptying any read;tmpDir = fs.realpathSync(fs.mkdtempSync(...))on line 36 keeps it live. - The description's note that this race made the
build-theme.icons-specifier.test.mjswatch case flaky no longer applies: that test now replaces the theme with a rename instead of writing it in place.
[Automated review]
Review only this PR's change: vjeux/astryx@de36681...2314e1f
Why
This fixes a reproducible product race: a theme rebuilt mid-save shipped without its icons.
astryx theme build --watchcould write a theme module without its icon registry import and report success. An editor that saves in place truncates the file before writing it; a rebuild that read the file in between, for a theme whose registry holds no icons yet, exited 0 with a broken module. The same race madebuild-theme.icons-specifier.test.mjs's watch case fail intermittently in CI on unrelated pull requests ("expected null to be 'import { testIcon…"); a deterministic reproduction of it fails 5 of 5 runs on main and none with this change.What led to it
We kept hitting that test as an unrelated red while running the CLI suites for the touch-component work. The build loads the theme module, then reads the file again to find its registry import. The two reads can straddle a save, so the scan could read an empty file the load never saw; with an empty registry the build did not require the import, so "no import found" became a successful build without one.
Options and tradeoffs
Why this choice
A built module must keep its registry import (the command's own contract: "A generated module must preserve the registry through an import"), so a build either produces that module or fails. Scanning what was loaded makes the two reads one fact.
How to check it
pnpm exec vitest run --project node packages/cli/clients/cli/commands/build-theme.torn-read.test.mjs: 2 pass. Its preload empties every read of the theme file once the theme module has run, as a save landing then would.build.mjs, the torn case exits 0 and writes a module with no import line; here it fails with "changed while it was loading" and writes nothing.build-themesuites pass.Evidence
[fix]changeset describes the user-facing change.