Skip to content

🤖 refactor(stories): split Storybook helper monoliths into feature-scoped modules#3080

Open
jaaydenh wants to merge 8 commits intomainfrom
storybook-tests-kws9
Open

🤖 refactor(stories): split Storybook helper monoliths into feature-scoped modules#3080
jaaydenh wants to merge 8 commits intomainfrom
storybook-tests-kws9

Conversation

@jaaydenh
Copy link
Copy Markdown
Contributor

Summary

Split the monolithic mockFactory.ts (~1134 LoC) and storyHelpers.ts (~646 LoC) Storybook helper files into feature-scoped modules to reduce TurboSnap invalidation scope and improve Chromatic build efficiency.

Background

Both files were imported by 20+ story files each, meaning any edit to an unrelated helper (e.g., adding a new tool factory) would invalidate every dependent story in Chromatic's TurboSnap. This broad dependency fan-out undermined onlyChanged: true effectiveness — a single-line change in mockFactory.ts could trigger re-snapshots of 20+ stories.

Implementation

New module structure

src/browser/stories/mocks/ (from mockFactory.ts):

Module Contents
workspaces.ts Workspace/project factories, NOW, STABLE_TIMESTAMP
messages.ts createUserMessage, createAssistantMessage, etc.
tools.ts All create*Tool helpers, withHookOutput
chatHandlers.ts Static/streaming chat handler builders
git.ts Git status fixtures

src/browser/stories/helpers/ (from storyHelpers.ts):

Module Contents
uiState.ts localStorage helpers (selection, sidebar, model)
reviews.ts Review/hunk state helpers, createReview
drafts.ts Draft fixture/persistence
chatSetup.ts setup*ChatStory adapters
git.ts Git diff/executor helpers

Migration approach

  1. Extracted code into 10 feature modules (pure move, no logic changes)
  2. Migrated all ~35 story files + 3 test files to import from feature modules directly
  3. Removed the original monolith files entirely (no compatibility shims remain)

TurboSnap impact

Previously, editing mockFactory.ts invalidated all 20 dependent stories. Now editing mocks/tools.ts only invalidates the ~15 stories that use tool factories, helpers/reviews.ts only invalidates ~3 review stories, etc.

Validation

  • make typecheck
  • make lint
  • bun x storybook build --stats-json
  • Zero remaining imports from deleted mockFactory.ts / storyHelpers.ts

Risks

Low — pure structural refactoring with no logic changes. All exports preserved with identical signatures. The only risk is if external tooling hard-codes paths to the deleted files, but grep confirms no such references exist outside generated content strings.


Generated with mux • Model: anthropic:claude-opus-4-6 • Thinking: xhigh • Cost: $10.78

@jaaydenh
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jaaydenh jaaydenh self-assigned this Mar 30, 2026
@jaaydenh jaaydenh force-pushed the storybook-tests-kws9 branch from 06a93e7 to d62b1c5 Compare March 30, 2026 05:36
@jaaydenh
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

https://github.com/coder/mux/blob/d62b1c5534f2e98f857601eb0d635c0d5b75ea82/src/browser/stories/mockFactory.ts#L1
P2 Badge Keep a compatibility shim for removed story helper imports

Removing src/browser/stories/mockFactory.ts (and storyHelpers.ts) without a compatibility re-export breaks internal guidance that still imports those paths, including docs/reference/storybook.mdx and the runtime-loaded built-in skill snapshot in src/node/services/agentSkills/builtInSkillContent.generated.ts. In practice, users/agents following those instructions now hit module-resolution failures when creating stories. Please either add temporary shim files that re-export from the new modules or update+regenerate the docs/skill content in the same change.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant