Skip to content

fix(cli): theme build scans the icon import from the source it loaded - #8598

Merged
cixzhang merged 2 commits into
meta:mainfrom
vjeux:cli/theme-build-single-read
Nov 5, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
vjeux:cli/theme-build-single-read

Conversation

@vjeux

@vjeux vjeux commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

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 --watch could 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 made build-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

  • Retry the scan when it finds nothing: hides the torn read, and an empty registry legitimately has no icons to look for.
  • Always require the import, even for an empty registry: would fail themes that are correct today.
  • Scan the bytes the build actually loaded (this pull request): read the file before and after loading, scan those bytes, and fail the build with "changed while it was loading" if they differ. In watch mode, the save that changed it queues the next rebuild anyway.

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

  1. 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.
  2. On main's 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.
  3. A theme left alone still builds with its import: the theme build and build-theme suites pass.

Evidence

  • A [fix] changeset describes the user-facing change.

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.
@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:36pm 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:46 PM UTC

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 357a5e4

Storybook · Sandbox · built from this PR's head

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

API changes: none in this pull request

Committed API report behind this build: cli 8 rows, core 4 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.

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-'));

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 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-')));

@cixzhang

Copy link
Copy Markdown
Contributor

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.

@cixzhang cixzhang closed this Oct 28, 2026
@cixzhang cixzhang reopened this Oct 28, 2026
@cixzhang

Copy link
Copy Markdown
Contributor

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.

@vjeux
vjeux marked this pull request as draft October 29, 2026 22:37
@vjeux
vjeux marked this pull request as ready for review November 4, 2026 14:28
@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 19:50
@cixzhang
cixzhang marked this pull request as ready for review November 4, 2026 19:50
@cixzhang
cixzhang marked this pull request as draft November 4, 2026 20:29
@cixzhang
cixzhang marked this pull request as ready for review November 4, 2026 20:29

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

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 from process.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.mjs watch case flaky no longer applies: that test now replaces the theme with a rename instead of writing it in place.

[Automated review]

@cixzhang
cixzhang merged commit 68507bb into meta:main Nov 5, 2026
68 of 106 checks passed
@vjeux
vjeux deleted the cli/theme-build-single-read branch November 5, 2026 02:15

This branch was successfully deployed

1 active deployment
Preview — 357a5e43 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