Skip to content

fix(cli): swizzle recursively copies nested component subdirectories - #5101

Closed
jiunshinn wants to merge 3 commits into
meta:mainfrom
jiunshinn:fix/3506-swizzle-recursive-copy
Closed

jiunshinn wants to merge 3 commits into
meta:mainfrom
jiunshinn:fix/3506-swizzle-recursive-copy

Conversation

@jiunshinn

@jiunshinn jiunshinn commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3506

Clean-room provenance: implemented from the issue description and source only; no code from the prior closed PRs (#3507, #4347, #4445) was opened, read, or consulted.

astryx swizzle Table previously copied only 17 top-level files while its barrel still referenced missing plugins/* modules. It now copies all 47 source files with their directory structure intact. A single file set drives copying, overwrite checks, and the receipt. Import rewriting accounts for each file's depth, preserving intra-component relative imports while rewriting escaping imports to the owner package.

Before creating directories or writing files, swizzle checks every destination path segment below the project root and rejects symlinks, including dangling file links. --overwrite does not bypass this check. Regression tests cover output-root, component-root, nested-directory, existing-file, dangling-file, and in-project symlinks, and verify that rejection leaves no partial output.

Recursive traversal is limited to core component directories. Integration discovery identifies a same-stem entry file, not an exclusively owned directory tree, so integrations retain their previous flat copy behavior. A shared-directory regression confirms that swizzling Alpha does not newly copy unrelated nested files or overwrite consumer edits there. The pre-existing copying of top-level sibling integration files remains unchanged; this PR does not define a new integration ownership policy.

Validation:

  • Focused swizzle and routing suite: 42 passed.
  • CLI strict typechecking: passed.
  • pnpm lint:strict, including repository checks: passed.
  • pnpm build: passed.
  • Full pnpm test: 10,379 passed, 2 failed. Both failures involve case-sensitive component/hook filename expectations on this local filesystem. Their failing behaviors also reproduce on untouched head fd227184: lowercase button resolves instead of throwing, and mediaquery resolves with useMediaquery.doc.mjs casing.

Maintainer rebuild on main (merge commit on top; jiunshinn's commits unchanged)

Main's swizzle changed under this branch: since #10085 it also carries the private attribute owner modules a component imports. The recursive copy is rebuilt on that code, following the maintainers' ruling under spec:AST-017 FR1/FR5.

  • Nested source: a Core component's nested folders are copied (Table brings plugins/), and an integration's folder stays flat. One sorted file list drives the pre-flight, the copy and the receipt. The owner-module walk reads each nested file from its own folder.
  • Imports: an import that stays inside the component (../types from plugins/) stays relative; one that leaves it is rewritten to the owner package.
  • Test-only files: __tests__ and __snapshots__ folders and *.spec.ts/*.spec.tsx browser harnesses are left out at every depth. A Markdown regression checks plugins/headingLinks.a11y.chromium.spec.ts.
  • Destination symlinks: a folder linked elsewhere inside the project (for example components → src/components) is written through, as in released versions. A link out of the project, dangling or not, is still refused by the existing confinement check before anything is written. The earlier blanket refusal of every destination symlink is dropped, and a test covers the in-project case.
  • Wrong-kind destinations: a destination held by the wrong kind of entry (a file where a folder goes, or the reverse) is refused before any write, even with --overwrite. A copy that fails part-way removes the folders it created.
  • Not carried: rewriteImports' depth parameter. Main's keep predicate covers it, and the copy tests check depth end to end.

Verification: the swizzle copy, routing and path-safety suites and write-failure.test.mjs pass (78). One path-safety manifest test timed out once under M5 load and passes alone. CLI type check, strict lint and check:changesets pass.

@vercel

vercel Bot commented Aug 16, 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 6, 2026 5:54am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 16, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Aug 16, 2026
@github-actions

github-actions Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 9d55f2b

This branch's preview address cannot be known in advance; open it from Vercel's comment.

Current run: The current CI run concluded failure. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

@jiunshinn
jiunshinn marked this pull request as ready for review August 16, 2026 11:48
github-actions Bot added a commit that referenced this pull request Aug 16, 2026

@cixzhang cixzhang 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 for fixing nested component copies. Two boundaries still block this head:

  • A nested symlink already present under the destination is followed, so swizzle Table can write through Table/plugins outside the requested output tree. Please reject symlinks in every destination path segment before any write and add a regression for that case.
  • Integration components can share one source directory. Recursing from that directory means swizzling one component also copies sibling components and shared files (for example, Alpha also copies Beta.tsx). Please derive the selected component's exact owned file boundary rather than treating the containing directory as the component root, with a multi-component integration regression.

The focused and current-main synthetic-merge tests pass, but they do not cover these two cases.

@cixzhang
cixzhang dismissed their stale review September 9, 2026 10:05

Automated review posted in error while an unresolved ownership decision is still under review.

@jiunshinn

Copy link
Copy Markdown
Contributor Author

@cixzhang Could you review the updated head, 65b265b?

  • Swizzle now rejects destination symlinks at every segment below cwd, including dangling file links, before any writes; --overwrite cannot bypass the check. Regressions verify that rejection leaves no partial output.
  • Recursive copying is limited to core component directories. Integrations retain their previous flat behavior, with a regression proving that unrelated nested files and consumer edits are left alone. The pre-existing top-level sibling-copy behavior remains unchanged while the integration ownership decision is unresolved.

Validation: 42 focused tests pass, as do CLI strict typechecking, strict lint, repository checks, and the full package build. The full test suite has 10,379 passes and two filename-case failures whose behaviors also reproduce on the untouched prior head. CI is running on this update.

@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 for the clean recursive fix — copying Table's nested plugins, handling import depth, reporting nested paths, and rejecting destination symlinks (including dangling links, even with --overwrite) all look well targeted, and keeping integration copies flat avoids inventing a new ownership policy.

One destination shape still needs handling before this is ready:

  • In packages/cli/api/swizzle/copy/copy.mjs, the preflight checks each destination segment only for symlinks. If an intermediate path such as out/Table/plugins already exists as a regular file, the check itself throws a raw ENOTDIR error with an absolute path instead of a stable Astryx error. Worse, if a planned file destination such as out/Table/plugins/nested.ts already exists as a directory and --overwrite is used, earlier files are written first and the copy then fails with a raw EISDIR, leaving a partial copy in the consumer's tree.

Please extend the preflight to validate destination shape before any write — existing intermediate segments must be directories and existing leaf targets must not be directories, regardless of --overwrite — returning a stable error code, with regression tests for both shapes asserting that no file is written. After that, the rest of the change looks ready.

[Automated review]

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

Reviewed exact head 65b265b0, including the copy preflight, recursive import rewriting, receipts, and tests. Requesting changes.

packages/cli/api/swizzle/copy/copy.mjs:223-240,340-377 does not preflight destination type collisions. If a late destination such as Table/types.ts is already a directory, earlier sorted files are overwritten before writeFileSync() fails with EISDIR. That violates the stated all-paths-before-write guarantee and can leave a partially modified destination. Please validate every intermediate segment and final target type before any mkdir or write, with a regression proving no earlier file changes when a late destination has the wrong type.

Also make integration receipt ordering deterministic at copy.mjs:335-339; the current test requires exact order while production returns raw readdirSync() order.

This head currently conflicts with main. It also overlaps open #6621 in copy.mjs and swizzle.doc.mjs, and #6507 in swizzle.doc.mjs. Rebase and reconcile those changes rather than resolving the files wholesale.

@jiunshinn
jiunshinn force-pushed the fix/3506-swizzle-recursive-copy branch from 65b265b to deaaa1c Compare September 30, 2026 13:25
@jiunshinn

Copy link
Copy Markdown
Contributor Author

@humbertovirtudes Thanks. Addressed on deaaa1c0f4, rebased onto current main (d774400a9d). This also covers the same destination-shape point from the automated review.

Destination type collisions. checkDestinationPaths now validates every segment below cwd before any mkdir or write, with or without --overwrite:

  • No segment may be a symlink → ERR_PATH_TRAVERSAL (unchanged).
  • An existing directory segment (the output base, the component dir, or a nested dir such as Table/plugins) must be a directory. An existing file target must be a regular file. A violation → ERR_WRITE_FAILED, with the path relative to the project, e.g. Could not write out/Table/types.ts: it exists and is a directory. Nothing was written.
  • Parents are checked before children, so the check itself never hits a raw ENOTDIR. An lstat that fails for another reason (e.g. EACCES) is also reported as ERR_WRITE_FAILED, with its errno.

I used ERR_WRITE_FAILED rather than ERR_FILE_EXISTS because --overwrite cannot clear these. It is also the code #6621 gives the same failures at write time, so the contract stays the same when that lands.

Regression (copy.test.mjs › destination shape): a fake core Table with the sorted plan Table.tsx, plugins/nested.ts, types.ts. Consumer edits are pre-created at every destination the blocker leaves room for. The blockers are out, out/Table, and out/Table/plugins as files, and out/Table/plugins/nested.ts and out/Table/types.ts as directories. For both overwrite: false and true, each case asserts ERR_WRITE_FAILED, a relative message, and a project tree identical to the one before the call. A permission case covers the EACCES path. All 6 new cases fail on the previous head: they get a raw ENOTDIR/EACCES, or ERR_FILE_EXISTS. On the previous head, your exact scenario with overwrite: true rewrote Table.tsx and then threw a raw EISDIR.

Receipt ordering. The flat integration list is now sorted like the core walk, so the exact-order assertion in swizzle.routing.test.mjs no longer depends on readdir order.

Rebase and reconciliation

Validation

  • Focused swizzle suites (api/swizzle/**, swizzle.routing, swizzle.path-safety; 5 files): 54 passed.
  • Full packages/cli suite: 5,473 passed. The 2 failures were 60s timeouts under full-suite load (docs/index/index.test.mjs, build.text-fields.test.mjs); both pass when run on their own.
  • pnpm build, pnpm -F @astryxdesign/cli typecheck:strict, strict ESLint on the changed files, and the full check:repo chain: all passed.

@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 for the thorough fix — swizzle now copies nested core source completely (Table's plugins included), rewrites imports by depth, reports nested paths in the receipt, and keeps integration copies flat without inventing a new ownership policy.

The destination-shape gap from the previous round is addressed: existing intermediate segments must be directories and existing leaf targets must not be directories, checked before any write regardless of --overwrite, with a stable ERR_WRITE_FAILED naming the project-relative path. The new regression tests assert both shapes (and the symlink matrix) leave the destination unchanged, and receipt ordering is now deterministic for both core and integration copies.

One note: I could not independently rerun the test suite in this environment, so the passing focused tests, typecheck, lint, and build rest on your reported results, which are consistent with the code and tests as written. With that, this looks ready to approve.

[Automated review]

github-actions Bot added a commit that referenced this pull request Sep 30, 2026
@jiunshinn
jiunshinn force-pushed the fix/3506-swizzle-recursive-copy branch from deaaa1c to 5447ece Compare October 3, 2026 23:26
@jiunshinn

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (73a6506d60) and resolved the documentation conflicts while preserving main's structured feedback receipt and absolute-output path rejection.

The previous fixes remain intact: all destination segments and leaf types are checked before any write, --overwrite cannot bypass symlink or type checks, core copies recurse, integration copies retain their existing boundary, and both receipts are sorted.

Validation on this revision: 54 focused swizzle tests, CLI strict typecheck, pnpm lint:strict, and pnpm build pass. A repository-wide run during this update on the same main base passed 20,226 tests but was not green: unrelated macOS shell/copy compatibility failures and UI failures are being checked separately. This is not a claim of a green full suite on this head.

@humbertovirtudes Please re-review the rebased head. #6621 and #6507 remain separate open PRs; their unmerged behavior has not been folded into this change.

@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 for the thorough fix — swizzle now copies nested core source completely (Table's plugins included), rewrites imports by depth, reports nested paths in the receipt, keeps integration copies flat, and rejects destination symlinks and wrong-kind destination paths before any write. The focused swizzle suites also pass when rerun here.

One thing still needs handling before this is ready:

  • The recursive walk now also copies __tests__/ directories, which the old flat copy never reached. For example, swizzle Button copies 7 files, 5 of them __tests__/Button.a11y.* test-harness files, and swizzle Table includes __tests__/TableScroll.a11y.chromium.spec.ts. Those files import @playwright/test and @astryxdesign/a11y-spec, which is a private, unpublished internal package, so consumers get copied files they cannot resolve. The collector only excludes files by basename (.test., .doc.), which these harness files do not match.

Please skip test-only directories (__tests__, __snapshots__) in the recursive collector and add a regression asserting no __tests__/ path is copied or reported. After that, the rest of the change looks ready.

[Automated review]

@jiunshinn
jiunshinn requested a review from cixzhang October 3, 2026 23:34
@josephfarina

Copy link
Copy Markdown
Contributor

Thanks for sticking with this one, and sorry it has taken four attempts across three PRs to get here. This is the right fix and it reads well — the per-segment symlink checks, the depth-aware import rewriting, and driving copy, preflight and receipt from one sorted file set.

One thing to remove and then I will stamp it: the recursive walk now picks up __tests__/, which the old flat copy never reached. swizzle Button copies 5 accessibility harness files, and they import @astryxdesign/a11y-spec, which is not published, so consumers get files they cannot resolve. Skipping __tests__ and __snapshots__ in the collector, plus a test asserting that nothing under those paths is copied or reported, is all it needs.

Worth updating the comment above collectSourceFiles too: it says such a directory contributes nothing because every file matches .test., which is not true of these harness files.

It is also 526 commits behind main, so it will need a rebase. Ping me when it is up and I will approve.

Core component directories are walked recursively so nested source
(e.g. Table/plugins/*) is copied, reported and preflighted from one
sorted file set. Escaping relative imports are rewritten by depth.
Every destination segment is checked before any write: no symlinks,
existing directory segments must be directories and existing file
targets regular files, regardless of --overwrite. Integration copies
keep their flat boundary.
The recursive walk entered __tests__/ and __snapshots__/, which the old
flat copy never reached. Their harness files do not all match the
.test. basename filter (e.g. Button.a11y.harnesses.tsx,
TableScroll.a11y.chromium.spec.ts) and import dev-only packages such as
the unpublished @astryxdesign/a11y-spec, so swizzle Button copied 5
files a consumer cannot resolve. The collector now skips those
directories at any depth; tests assert nothing under them is copied or
reported, for real components and a nested fixture.
@jiunshinn
jiunshinn force-pushed the fix/3506-swizzle-recursive-copy branch from 5447ece to 89f332e Compare October 15, 2026 23:58
@jiunshinn

Copy link
Copy Markdown
Contributor Author

@josephfarina Thanks! Done on 89f332e1bf, rebased onto current main (f16dc9f438).

  • collectSourceFiles now skips __tests__/ and __snapshots__/ at any depth, and the comment above it says why: the harness files don't all match .test. and import dev-only packages such as @astryxdesign/a11y-spec.
  • New tests: swizzle Button, Table and FormLayout copy and report nothing under those directories (each first asserts the source dir is non-empty), plus a fixture with both directories at the root and under plugins/. The Button, Table and fixture cases fail with the skip removed.

Rebase note: main's rollback from #6621 met the recursive copy here. The copy loop now creates nested directories inside the guarded write and records the ones it created, so a part-way failure removes them too. Otherwise plugins/ was left behind and a new output directory could not be removed. That has its own regression test. main's write-failure.test.mjs cases still pass.

Validation: full CLI suite (394 files, 6301 tests), typecheck:strict, typecheck:json-api and the pre-commit checks pass.

@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 recursive copy, the depth-aware import rewriting and the up-front destination checks look right, and the __tests__/__snapshots__ skip works for every Core component, but this needs one fix and one maintainer decision before it can be approved. swizzle Markdown still copies plugins/headingLinks.a11y.chromium.spec.ts, which imports @playwright/test and the unpublished @astryxdesign/a11y-spec, so please also skip *.spec.ts/*.spec.tsx harness files in the recursive walk and add Markdown to the test-only regression. Refusing a destination symlink that stays inside the project (for example components → src/components) changes behavior the released CLI allows, and no current spec covers it, so approval also needs a maintainer to decide whether that setup is supported and to name the spec that governs it; that settles whether this can ship as a patch fix. The earlier change request from humbertovirtudes, which this head addresses, also needs a re-review or dismissal.

[Automated review]

Comment thread packages/cli/api/swizzle/copy/copy.mjs Outdated
if (entry.isDirectory()) {
if (TEST_ONLY_DIRS.has(entry.name)) continue;
files.push(...collectSourceFiles(path.join(dir, entry.name), rel));
} else if (entry.isFile() && !isExcludedFromCopy(entry.name)) {

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.

swizzle Markdown still copies plugins/headingLinks.a11y.chromium.spec.ts. It is not under __tests__/ and does not match .test., and it imports @playwright/test and the unpublished @astryxdesign/a11y-spec/storybook, so consumers cannot resolve it. Please also skip code harness files such as *.spec.ts/*.spec.tsx in this walk (or in isExcludedFromCopy), and add Markdown to the test-only regression.

Comment thread packages/cli/api/swizzle/copy/copy.mjs Outdated
Comment on lines +289 to +295
if (stat.isSymbolicLink()) {
throw new AstryxError(
`Refusing to write through destination symlink "${rel}".`,
[],
ERROR_CODES.ERR_PATH_TRAVERSAL,
);
}

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 also refuses links that stay inside the project (for example components → src/components), which main copies through and its docs allow. Whether that narrowing is intended, and whether it can ship as a patch fix, is a maintainer decision; no change is needed here until that is settled.

@jiunshinn

Copy link
Copy Markdown
Contributor Author

gentle ping @josephfarina sorry.

cixzhang added a commit that referenced this pull request Oct 31, 2026
…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.
Rebuilds the recursive copy on main's swizzle, which since meta#10085 also
carries the private attribute owner modules a component imports.

- A Core component's nested folders are copied (Table's plugins/), and an
  integration's folder stays flat. One sorted file list drives the
  pre-flight, the copy and the receipt; the owner-module walk reads each
  nested file from its own folder.
- Imports that stay inside the component (../types from plugins/) stay
  relative; imports that leave it are rewritten to the owner package.
- __tests__ and __snapshots__ folders and *.spec.ts(x) browser harnesses
  are left out at every depth (Markdown's headingLinks chromium spec).
- Destination symlinks follow spec:AST-017 FR1/FR5: a folder linked
  elsewhere inside the project is written through, as released; a link out
  of the project is still refused by the existing confinement check. The
  blanket refusal of every destination symlink is dropped.
- A destination held by the wrong kind of entry is refused before any
  write, even with --overwrite; a failed copy removes the folders it made.
- The rewriteImports depth parameter is not carried: main's keep predicate
  covers it, and the copy tests check the depth behaviour end to end.

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

One fix is needed before approval. Everything else checks out: Core components with nested folders now eject whole, imports inside the component stay relative, test-only files stay out, and folders linked inside the project keep working as before.

  • Newly live check: checkDestinationKinds builds its own refuse error (packages/cli/api/swizzle/copy/copy.mjs:412-417) instead of calling writeFailed from packages/cli/api/error.mjs, and the two have already drifted (the pre-flight's EACCES message drops "(no permission)"), so please throw writeFailed(segment, root, err) in the statSync catch, pass EISDIR/ENOTDIR or an optional reason for the two wrong-kind refusals, and delete refuse.

Two optional comment trims are noted inline. CI has not run on this head yet: a maintainer needs to add the ci:run label, and the earlier engineering-owner change request clears when that owner re-reviews.

[Automated review]

Comment on lines +412 to +417
const refuse = message =>
new AstryxError(
`${message} Nothing was written.`,
[],
ERROR_CODES.ERR_WRITE_FAILED,
);

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 rebuilds writeFailed from api/error.mjs, which this file already imports: the same ERR_WRITE_FAILED code, project-relative path, errno and "Nothing was written." The two have already drifted: a pre-flight EACCES reads Could not write out/Table/Table.tsx: EACCES. Nothing was written., while the same failure during the write adds (no permission). Please throw writeFailed(segment, root, err) in the statSync catch, pass EISDIR/ENOTDIR (or an optional reason added to writeFailed) for the two wrong-kind refusals, and delete refuse.

Comment on lines +8 to +12
* A Core component is copied with its nested folders (Table's `plugins/`),
* test-only folders and harness files left out; an integration component's
* folder is copied flat. Every destination is checked before anything is
* written: it stays inside the project, through any symlink, and nothing of
* the wrong kind is in its place.

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.

Optional: this paragraph takes the file header from 12 to 18 lines, and its facts already sit in the componentFilesOf and checkDestinationKinds JSDoc and the call-site comment. Consider dropping it.

Comment on lines +396 to +398
* Refuse, before anything is written and whatever `overwrite` says, a
* destination that something of the wrong kind already holds: a file where a
* folder must go, or a folder where a file must go. Symlinks are followed;

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.

Optional: this first sentence runs 34 words. Suggested: "Refuse a destination that holds the wrong kind of entry: a file where a folder goes, or a folder where a file goes. The check runs before any write, even with overwrite."

cixzhang added a commit that referenced this pull request Nov 7, 2026
* test(swizzle): cover destination symlinks

Carries the destination-symlink tests from #5101 over to the merged
swizzle code: an output folder, component folder, nested folder or file
linked outside the project is refused before anything is written, with
or without --overwrite, and a folder linked elsewhere inside the project
is written through, nested folders included. The fixtures import the
nested file, since the copy follows imports.

Refs #5101

Co-authored-by: jiunshinn <[email protected]>

* test(swizzle): keep the file's existing formatting

Only the destination-symlink block is added; the rest of the file is as
on main.
@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

(Posted by Cindy's agent.) Thank you, @jiunshinn! This landed through #10197 (swizzle copies the whole module graph a component reaches, including nested subdirectories) and #10484 (your symlink tests, with you credited as co-author), so I'm closing this as superseded.

@cixzhang cixzhang closed this Nov 8, 2026
@github-actions
github-actions Bot deleted the fix/3506-swizzle-recursive-copy branch November 9, 2026 15:25

This branch was successfully deployed

1 active deployment
Preview — 9d55f2bd Deployed Nov 6, 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. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

swizzle silently drops nested subdirectories, producing a broken partial eject (e.g. Table/plugins)

4 participants