Skip to content

fix(cli): skip non-codemod files during integration codemod discovery - #4980

Open
abu-abdullah22 wants to merge 1 commit into
meta:mainfrom
abu-abdullah22:fix/codemod-discovery-skip-non-codemods-4975
Open

abu-abdullah22 wants to merge 1 commit into
meta:mainfrom
abu-abdullah22:fix/codemod-discovery-skip-non-codemods-4975

Conversation

@abu-abdullah22

Copy link
Copy Markdown

Fixes #4975

Summary

astryx upgrade's integration-codemod discovery threw a hard error — silently
dropping an entire integration's codemods for that run — whenever a
codemods/<version>/ directory contained conventional test files or shared
helper modules alongside real codemods. Confirmed two distinct failure modes:

  1. __tests__/*.test.mjs files import vitest, which fails at module-load
    time since vitest isn't a dependency of consumer apps.
  2. Shared helper modules (e.g. *.transform.mjs, named exports only) load
    fine but have no default export, so parseCodemod receives undefined
    and Zod rejects it.

The core codemods still ran, so astryx upgrade reported success while
silently skipping the integration's real migrations.

Approach

Chose the most conservative of the options discussed in the issue — does NOT
introduce any new file-naming convention or manifest format:

  • Skip (don't attempt to load) files under conventional test paths
    (__tests__/, *.test.*, *.spec.*) during file collection.
  • Skip (don't throw) any loaded module that has no default export at all —
    per this file's own doc comment, every codemod module must default-export
    an envelope, so a module with zero default export was never attempting to
    be one.
  • A module that DOES have a default export but fails schema validation still
    throws exactly as before — the "fail loudly on genuinely broken codemod"
    contract is fully preserved.

Changes

  • packages/cli/assets/codemods/integration-discovery.mjs: updated
    collectCodemodFiles() to skip conventional test paths, and updated the
    loading loop to skip modules with no default export before calling
    parseCodemod.
  • packages/cli/assets/codemods/integration-discovery.test.mjs: added two
    tests covering both skip cases, and confirmed the existing
    "malformed codemod still throws" test continues to pass.
  • Added a changeset (patch, @astryxdesign/cli).

Testing

Ran the full test file directly via vitest — all 8 tests pass, including
the two new ones and the pre-existing "fails discovery when default export
is not a codemod envelope" test (confirming genuinely broken codemods still
fail loudly).

@vercel

vercel Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 13, 2026 9:07am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 13, 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 13, 2026
github-actions Bot added a commit that referenced this pull request Sep 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

Current run: The current CI run concluded failure. Current analysis and preview links are unavailable.


Generated by PR Enrichment workflow | View current CI run

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

Approval is waiting on a maintainer decision for the codemod classification in this change.

This patch would treat conventional test paths (__tests__/, *.test.*, *.spec.*) and every module with no default export as non-codemods, while a present but invalid default export still fails. That direction needs a maintainer to provide or identify the governing spec for it — in particular whether a codemod that forgets its default export should be silently ignored, and whether non-codemods are excluded from all codemod identity bookkeeping. I have asked for that decision; please do not treat the current behaviour as approved until it is settled.

Independent fixes are also needed regardless of that decision:

  • Modules with no default export are currently entered into duplicate-ID bookkeeping before they are skipped, so the same helper stem in two versions (or shared with a real codemod) can still throw and drop the whole integration. Move that registration after the skip and add a cross-version regression test, or narrow the claimed scope.
  • The file header still describes the old loader and says a missing default export is a hard error, and the changeset claims all shared helpers are excluded even though a helper that fails to import is not. Align both with the behaviour that is actually adopted and implemented.
  • The new tests cover the common single-version test-file and helper cases, and malformed present defaults correctly still throw.

[Automated review]

@cixzhang

Copy link
Copy Markdown
Contributor

(Posted by Cindy's agent.) Hi @abu-abdullah22, thanks for this PR. main has moved, and this branch now conflicts with it in 1 file (packages/cli/assets/codemods/integration-discovery.mjs). Could you merge or rebase onto current main? CodeBunny reviews again automatically after you push.

This branch was successfully deployed

1 active deployment
Preview — 8c5d680c Deployed Aug 13, 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.

astryx upgrade: integration-codemod discovery throws (drops the whole integration) when codemods/ contains test or helper modules

2 participants