Repository navigation
fix(cli): swizzle finds gh on PATH instead of running gh auth status - #8626
Conversation
Every successful swizzle ran `gh auth status` with no timeout, only to decide whether to print a ready `gh issue create` line: about 400 ms locally (it calls GitHub), and on a saturated CI runner one first start of gh blocked write-failure.test.mjs's case for 34 s while the other workers kept finishing files (meta#8374's test-node). checkGhCli now looks for an executable gh on PATH (PATHEXT on Windows) without running anything, which is what the receipt's type already promises ("when gh is available").
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
…e adapter The PATH lookup reads the filesystem, which architecture:cli-surface INV21 keeps in a subject's adapter and the helpers only it imports. The copy leaf now takes checkGhCli from _adapter.mjs, so _github.mjs is an adapter-only helper and leaves the INV21 known-gap list, which only shrinks. It runs no process now, so doc-loads.test.mjs no longer lists it.
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
Recommended for approval: astryx swizzle now offers its gh issue create line when gh is on PATH instead of running gh auth status, so a copy no longer waits on gh or GitHub, and the new tests fail without the fix and pass with it. One visible difference to keep in mind: when gh is installed but not logged in, the text receipt now shows the gh command where it used to show the issues URL, while the JSON receipt keeps both. The CI run for this commit was cancelled before its test-node jobs finished, so it needs a re-run before merging.
[Automated review]
The PATH search read any error from statting a candidate as "not here". It now reads only ENOENT, ENOTDIR and EACCES that way, as `which` does, and throws any other: a symlink loop named gh, for one, now fails instead of reading as no gh. Red first: that loop case fails before this change and passes after.
There was a problem hiding this comment.
Incremental review of c3ebc8f..97dff80; prior findings carried: user_impact
Changes requested: the latest commit makes checkGhCli rethrow every stat error other than ENOENT, ENOTDIR and EACCES, and because buildFeedback runs it after the copy loop, a swizzle with a looped gh or an over-long entry on PATH now exits 1 (ERR_UNKNOWN) with every file already written, after which a plain retry stops at ERR_FILE_EXISTS and --overwrite fails the same way. Please read any stat error as "no gh" again, as which does, or catch it in buildFeedback and leave out ghCommand, and swap the ELOOP test for one showing the swizzle still returns its receipt. The rest holds up: the PATH lookup never starts gh, its tests fail on the base and pass here, and the Changeset discloses the logged-out difference. The CI test jobs for this commit had not finished yet.
[Automated review]
| if (code !== 'ENOENT' && code !== 'ENOTDIR' && code !== 'EACCES') { | ||
| throw error; | ||
| } |
There was a problem hiding this comment.
This rethrow escapes swizzleCopy after every file is written: buildFeedback calls checkGhCli() at copy/copy.mjs:386, after the copy loop and outside its undo. With a self-looped gh (or a 300-character entry) first on PATH, astryx --json swizzle Button exits 1 with ERR_UNKNOWN while all three Button files sit on disk; a plain retry then stops at ERR_FILE_EXISTS, and --overwrite fails again. Reading every stat error as "not here", as GNU which and npm's which both do, or catching around checkGhCli() in buildFeedback and leaving out ghCommand, keeps the optional hint from failing the copy.
…gh, and runs before the swizzle writes Review follow-up. The lookup threw on a gh symlink loop or a PATH entry too long to resolve, and it ran after the copy loop, so such a PATH failed the swizzle with every file written, and a retry stopped at ERR_FILE_EXISTS. It now reads every stat error that means no usable gh at a candidate as execvp and which do (ENOENT, ENOTDIR, EACCES, ELOOP, ENAMETOOLONG) and throws any other, and the swizzle runs it before it writes anything. Red first: a looped gh and an over-long entry read as no gh; a swizzle whose only gh is a loop returns its receipt without the gh line; a lookup that throws fails the swizzle before any file is written. Each fails before this change and passes after.
There was a problem hiding this comment.
Incremental review of 97dff80..9c2bf92; prior findings carried: user_impact
Changes requested: the looped and over-long PATH cases now return their receipt, and looking for gh before the copy means a failed lookup no longer leaves files behind, but checkGhCli still rethrows every other stat error, so a PATH entry on a stale NFS or disconnected FUSE mount (ESTALE, ENOTCONN, EIO, …) makes every astryx swizzle exit 1 with ERR_UNKNOWN, even when a working gh comes later on PATH, where the base returns the receipt. Please read any stat error as "no gh here", as npm's which does with ignoreErrors: true, or catch around checkGhCli() in buildFeedback and leave out ghCommand, and replace the two tests that pin the throw with ones where an unlisted error still returns the receipt without the gh line. The rest holds up: the new tests fail on the previous commit and pass here, and the CI test shards for this commit had not finished yet.
[Automated review]
| if (!NOT_HERE.has(code ?? '')) { | ||
| throw error; | ||
| } |
There was a problem hiding this comment.
This still rethrows every stat code outside NOT_HERE. buildFeedback now runs before the copy, so nothing is written, but a PATH entry on a stale NFS or disconnected FUSE mount (ESTALE, ENOTCONN, EIO, …) fails every astryx swizzle with ERR_UNKNOWN and no receipt, even when a working gh comes later on PATH; the base returned the receipt there. npm's which 4.0.0 passes ignoreErrors: true to isexe, reading any error as not found. Reading any error here as "no gh here" (or catching around checkGhCli() in buildFeedback) keeps the optional hint from failing the command.
…at as no gh there Review follow-up. A PATH entry on a stale or disconnected mount (ESTALE, ENOTCONN, EIO) still made every swizzle fail, even with a working gh later on PATH. The lookup's contract is now the one which and execvp read PATH by: a candidate the system cannot stat is not a usable gh, and the lookup goes on to the next one. An error that is not the system's answer about a candidate (no error code) is still thrown, and the lookup still runs before the swizzle writes. Red first: a working gh after a stale-mount entry is found now; before, the lookup threw.
There was a problem hiding this comment.
Incremental review of 9c2bf92..15b18c9; prior findings carried: user_impact
Recommended for approval: checkGhCli now reads any stat error on a PATH entry as "no gh here", so an entry on a stale NFS or disconnected FUSE mount (ESTALE, ENOTCONN, EIO, EPERM) no longer fails astryx swizzle, and the new stale-mount test fails on the previous commit and passes here. One visible difference remains to accept when merging: with gh installed but logged out, the text receipt shows the gh issue create command where it used to show the issues URL, while the JSON receipt keeps both. The test-node and test-ui CI jobs for this commit had not finished yet.
[Automated review]
…e the package (#9190) ## Exact decision needed What `astryx swizzle` promises about the copy it writes. Today a product team that swizzles a component to own its source gets a copy that often does not build: the copy imports Core helpers Core does not export. No current record says the copy must build, keep theme targets, or behave like the package component. This PR adds `spec:AST-110` (Swizzle output) only. Core approved the record on 2026-10-31. It stays `draft` until its co-owner, the CLI owner, agrees. A draft does not govern, so the `spec:AST-080` FR5 and FR7 swizzle cases and the `architecture:cli-surface` pointer land in the same pull request that makes AST-110 current; the record's Known gaps say so. ## Existing authority searched - `architecture:cli-surface` INV28: what `swizzle --list` reports. Says nothing about the copy's contents. - `spec:AST-035` FR11–FR12: which component an unqualified or Core-scoped `swizzle <Name>` copies. - `spec:AST-081` FR3: swizzle refuses to run outside a project. - `spec:AST-080` FR7: product rules stay outside `astryx-base`, which puts a swizzled copy above the theme layer. Its swizzle exception lands when AST-110 becomes current. - `@astryxdesign/build`: it sorts modules into its library pass (`astryx-base`) or product pass by path (`node_modules/@astryxdesign/`), so a copy in the product tree lands in the product layer. - `spec:AST-017` FR21: modules without a public contract stay internal; `./internal/*` is limited to Core and Lab. - `architecture:public-component-api` INV12 (anything reachable is public) and INV23 (each private data attribute has one owner module). - `architecture:layer-runtime`: the layer stack, modal outlet, and layer contexts that FR3 keeps single. - `spec:AST-030` FR11 and FR14: one test lane per surface; allowlisted triggers. - Searched `docs/**` and the CLI's command docs for swizzle, eject, and copy. The command doc only says imports that escape the component folder are rewritten. - Overlapping open work: #5101 (copy nested component subfolders) implements part of FR2; #8626 (gh lookup) affects how fast the copy runs. Neither decides what the copy promises. ## Decision - **FR1, builds on its own:** with the same Core version and a StyleX compiler, the copy type-checks and bundles with no edits. It imports only paths its owner package exports, never `./internal/*`. Swizzle reports the owner package's npm dependencies the copy imports (with their declared ranges); the copy builds once the product installs them. - **FR2, helpers come with it:** non-public modules the component reaches are copied with it and imported by relative path. Nested folders come too. Tests, stories, specs and docs stay behind. If an earlier swizzle already wrote a helper, an identical file is reused. A different file is never overwritten (not even with `--overwrite`): the new one is written alongside under a version-suffixed name, and only the new copy's imports point at it. - **FR3, shared runtime state stays single:** coordinating state (layer stack, modal outlet, interaction modality, bottom-sheet stack, and the one announcement channel per document of `spec:AST-086` FR9) and the contexts that connect providers to consumers live under registered, versioned keys. A copy and the package on the same version share them, so stacking, Escape and focus return work as one, a copied `useToast` reaches the package's `LayerProvider`, and identity symbols (brands, context keys) agree between copy and package. It holds in both directions: package components inside a copied Dialog deliver announcements inside that modal (`spec:AST-086` FR14), and package group context stops at the copy's layer boundary (`spec:AST-038` FR7). A copy on another version keeps its own store and never reads a different shape. - **FR4:** each private data attribute's owner module (INV23) that the component imports is copied whole, so callers, the copy included, still never write the attribute by hand. - **FR5:** theme targets, documented classes, data attributes and custom properties are unchanged. Swizzle marks its output directory with an `astryx-swizzle.json` file (owner package and version). `@astryxdesign/build` compiles modules under a marked directory in its library pass into `astryx-base`, below `astryx-theme`, so a theme's component overrides still apply. This holds for products on `@astryxdesign/build`. The stock StyleX plugins have no library-pass setting, so on them a copy's rules land above `astryx-theme`; the record lists that as a known gap. - **FR6:** keyboard, focus, roles, names, states, announcements and events match the package until the product edits the copy. - **FR7:** before a change to component source or the swizzle copy merges, every component swizzle can copy (Core's `--list` per `spec:AST-035` FR12, plus each integration package's components through `--package`) is ejected, type-checked, bundled with StyleX, and server-rendered, and a failure blocks the merge. Release checks add a real-browser render. CI impact of FR7, shaped with the CI and release owners: one step in the existing required test job, selected by the shared change-scope classification, with results in the single PR report. It uses standard runners and adds about +3 job-minutes on pull requests that change component source or swizzle code (≈ +2–3% of pull-request runner time). It adds no wall-clock time to green and no new runs or checks. These numbers are estimates until the first real run measures them. ## Rejected alternatives - Export the helpers copies need: anything reachable from a package path becomes public API (INV12), so internals would turn into permanent API to make a copy build. - Never copy stateful modules; import a contained package instance instead. That needs a public runtime entry with a compatibility promise only copies need, and it leaves a copy on another version without the state it needs. Core already keeps modality and the bottom-sheet stack in versioned per-document stores so duplicate bundles share state; FR3 makes that the rule. - Run the proof in the CLI smoke workflow: that workflow is not a required check, so a failure could not block, and it is already close to its time budget. ## Claim scope and non-goals The record governs only what a swizzled copy contains and promises, and the proof that keeps it true. It leaves out: - which component a name copies; - where the command runs; - how a product compiles StyleX; - keeping an edited copy in step with later Core releases; - making internal helpers public. ## Evidence and implementation relationship - Published 0.7.5 was built for real, covering all 112 names `swizzle --list` offers: 12 build and render, 89 fail to build, 9 build but render wrong, and 2 build with nothing to render. - Causes: - The import rewrite collapses `../X/file` to the public `@astryxdesign/core/X` entry, which lacks internal helpers (87 components). - Deep StyleX modules are missing from the exports map (12). - Copied styles land in the app's cascade layer above the theme's, so theme component overrides stop applying (9 today, 38 once imports resolve). FR5 now states the cascade rule. - Spec records and tests get copied (104), and nested folders are left out. - `--list` offers 6 folders that are not components. - On `main`, a full ledger of 154 components (Core, Lab, Charts, RichText, Vega) finds: - 32 pass every check, 96 don't bundle, 17 lose theme component overrides, and 1 behaves differently (Escape doesn't close a copied Lab MobilePowerSearch). - Copying every helper Core doesn't export raises passes to 48. What remains: - copied shared-state modules (a second live region; focus misses the combobox in a copied CommandPalette); - the cascade layer; - Core's private type additions and a unique-symbol identity split; - 16 copies that need the owner package's npm dependencies (d3, vega-util). - FR1, FR3 and FR5 cover each of these. - Running 112 separate CLI processes took 654 s locally, almost all of it start-up, so the proof copies in-process. - Response and file changes: - `swizzle.copy` lists each helper as written, reused or versioned, and each npm dependency with its range. - An existing component file still fails with `ERR_FILE_EXISTS` unless `--overwrite` is passed. - An existing helper never fails the command and is never replaced. - No implementation is in this PR. The CLI owner implements the copy changes (FR1, FR2, FR4, FR7). Core implements FR3's stores and contexts. The build package reads the FR5 marker, and the styling overview documents where a copy's rules land with and without it. ## Writing rubric results - R1 narration: none found. Intent, requirements, current-state impact and known gaps are in the present tense. - R2 research in the record: one finding, fixed. Ledger counts and CI estimates moved out of the record into this description; Known gaps keeps the causes only. - R3 evidence naming a change: none. Verification cells name checks and states. - R4 rejected alternatives over one line or outside a decision: two, in DEC-1 and DEC-2, one line each. - R5 pull request or issue references remaining: none in the record. - R6 ruled open questions still listing options: none. The record has no open questions; DEC-1 and DEC-2 carry Core's approval. ## Scope - [x] This PR contains specification records only. - [x] It records observable behavior and preserves equivalent internal implementations. - [x] Any named internal mechanism is intentionally public, names its dependent caller/system, and explains why an equivalent implementation would not satisfy the contract. - [x] Verification states the evidence layer and failure signal without prescribing CI job/workflow topology. - [x] It records one intentional durable decision, not a rescue for a separable tagalong. - [x] The canonical knowledge owner, affected current claims, and overlapping open work are named; any ownership collision is resolved or called out for human decision. - [x] Adjacent API, visual, accessibility, composition, and implementation facts remain outside scope unless this exact decision depends on them. - [x] Public text and artifacts contain no internal Meta context. ## Validation - `pnpm check:knowledge`: Knowledge templates and records are aligned. - Prettier: AST-110 clean. - `git diff --check`: clean.
There was a problem hiding this comment.
Approval waits on an engineering-owner decision, and one change is needed after it.
- Newly live check: no current spec decides when
astryx swizzleoffers itsgh issue createline, and with this change a logged-outghgets it too, printed in place of the issues URL, so an engineering owner needs to approve that condition (or name the record that states it) by commenting/approve-specwith the full head commit SHA, which the author may do as an engineering owner. - Newly live check:
checkGhCliinpackages/cli/api/swizzle/_github.mjsre-implements thePATHwalk thatpackages/cli/foundation/env/search-path.mjsalready owns, and the two already differ on the execute check,staterrors and Windows names, so please export a name-parameterized walk fromsearch-path.mjs, call it from the swizzle adapter and fromastryxCommandsOnSearchPath, and delete the copy.
The rest holds up: the lookup never starts gh, a swizzle no longer waits on it, the tests that pin the lookup fail against the base and pass here, and CI is green on this head.
[Automated review]
| .map(extension => `gh${extension.toLowerCase()}`) | ||
| : ['gh']; | ||
| const delimiter = windows ? ';' : path.delimiter; | ||
| for (const dir of (env.PATH ?? env.Path ?? '').split(delimiter)) { |
There was a problem hiding this comment.
This walk duplicates astryxCommandsOnSearchPath in packages/cli/foundation/env/search-path.mjs (the same PATH ?? Path split, empty-entry skip, stat and executable check), and the two already differ: that one checks fs.accessSync(file, X_OK) and skips every stat error, this one checks any mode bit and rethrows an error with no code, and on Windows they try different names. Exporting a name-parameterized walk from search-path.mjs and calling it from the swizzle adapter (as api/doctor/_adapter.mjs already calls that module) keeps one walk for every command.
The swizzle adapter's gh lookup repeated the PATH walk that foundation/env/search-path.mjs owns, and the two differed on the execute check, on stat errors and on Windows names. search-path.mjs now exports executablesOnSearchPath, a walk over the names a command may have. The astryx command rows build on it, and checkGhCli in the swizzle adapter calls it with gh's names. The walk keeps the module's own checks: a file this user may run, and any error about a candidate read as no command there. _github.mjs is gone. spec:AST-031 FR8 now says that the offer depends on gh being on PATH, not on its login state, and what each receipt shows.
|
/approve-spec 02e7e64 |
There was a problem hiding this comment.
Changes requested: one spec sentence needs to say which command it governs; the code change looks good.
- The lines added to
spec:AST-031FR8 (docs/specs/AST-031/spec.md:184-186) describeastryx swizzle's receipt but name no command, so they read as a rule forastryx gap-report's zero-handler fallback, which still offers to file with noghonPATH, carries no command in either receipt, and reportsfailedfor a logged-outgh; nameastryx swizzle's receipt in those lines (or move them to the record that governs it), then re-approve the new head with/approve-spec <full head SHA>.
The gh lookup now goes through the shared executablesOnSearchPath walk, swizzle no longer waits on gh (5,238 ms down to 227 ms with a gh that takes 5 s to answer), and the new tests fail on the old code and pass here.
[Automated review]
| The offer depends on `gh` being on PATH, not on its login state; a logged-out | ||
| `gh` asks for its own login when the line runs. The text receipt shows the | ||
| command; the JSON receipt keeps the command and the issues URL. |
There was a problem hiding this comment.
These lines describe astryx swizzle's receipt, but they name no command, so they read as part of the gap-report fallback that FR8 governs. On this head, astryx gap-report still returns its consent_required offer with no gh on PATH, puts no command in its text or JSON receipt, and returns failed ("Install and authenticate gh, then retry.") for a logged-out gh. FR12 also says the gap-report response shape "is the same in --json and human output modes". Swizzle's feedback never reads the handler set, so FR8's handler suppression does not describe it either.
Smallest fix: name the surface, for example "astryx swizzle's receipt offers its gh issue create line when gh is on PATH, whatever its login state; the text receipt shows the command, and the JSON receipt keeps the command and the issues URL." Or move the lines to the record that governs swizzle's receipt. Then approve the new head.
The lines FR8 gained name the command they describe: astryx swizzle's receipt. FR8's gap-report fallback keeps its own rules.
|
/approve-spec 09b1b98 |
There was a problem hiding this comment.
Approved pending CI: the required checks are still running on this head.
The reworded spec:AST-031 FR8 lines now name astryx swizzle's receipt, which resolves the earlier scope concern, and an engineering owner approved them on this head. The receipt matches those lines with no gh, a signed-in gh, a logged-out gh and a slow gh, and a swizzle no longer waits on gh (about 5.2 s down to about 0.2 s with a gh that takes 5 s to answer).
[Automated review]
Why
Every successful
astryx swizzlewaited on GitHub before it reported what it copied. It rangh auth status, with no timeout, only to decide whether its receipt offers a readygh issue createline. Where gh is logged in, that call takes about 400 ms. On a slow network, or on gh's slow first start, it holds the whole command. In CI it held a swizzle test for 34 s, past its 30 s timeout (#8374'stest-node).What led to it
It showed up as an unrelated red on another pull request's CI (#8374) while we kept the touch-component work's runs green. The twin of the timed-out case ran in 129 ms once gh had started.
Options and tradeoffs
gh auth status, with a timeout: still a network call on every swizzle, and the timeout picks between waiting and dropping the line.ghonPATHwithout running anything (this pull request): instant. The visible tradeoff is for a gh that is installed but logged out. Its text receipt now shows thegh issue createline where it showed the issues link. Running the line, gh asks the user to log in. The JSON receipt always carries the issues link.Why this choice
The receipt promises the line "when
ghis available" (swizzle.type.mjs), which is a question aboutPATH, not about the login. The lookup is the CLI's shared search-path walk infoundation/env/search-path.mjs, whichdoctoralso uses to findastryxcommands. It readsPATHthe waywhichand the shell do. The search goes on past a candidate the system cannot read: missing, not a directory, no permission, a symlink loop, a stale network mount. The lookup runs before the swizzle writes anything.The owners of
spec:AST-031confirmed that FR8 already decides this: the offer depends on handlers and a GitHubissuesUrl, not on gh's login state. FR8 now says so in one added line, together with what each receipt shows.How to check it
ghthat sleeps 31 s first onPATHand runpnpm exec vitest run --project node packages/cli/clients/cli/commands/write-failure.test.mjs. On main, both swizzle cases time out at 30 s. Now the file passes, and the swizzle cases take about 20 ms.pnpm exec vitest run --project node packages/cli/api/swizzle packages/cli/foundation/env/search-path.test.mjs. Theghlookup is checked over temporaryPATHfolders with process spawning mocked, so nothing runs. A swizzle with a recordingghonPATHoffers the line and never runs it. A looped or stale-mount entry before a working gh still finds it. A swizzle whose feedback step throws stops before it writes any file. The shared walk's own tests cover search-path order and skipped candidates.Evidence
Writing rubric results
R1 narration: none; the added FR8 sentences state what the CLI does, in the present tense.
R2 research: none in the record.
R3 evidence: no evidence cell changed.
R4 rejected alternatives: none added.
R5 change references: none.
R6 open questions: none touched.