Skip to content

refactor: Split App component into focused modules (#173) - #194

Merged
will-lamerton merged 1 commit into
mainfrom
refactor/app-split
Dec 21, 2025
Merged

will-lamerton merged 1 commit into
mainfrom
refactor/app-split

Conversation

@will-lamerton

Copy link
Copy Markdown
Member

Summary

Splits source/app.tsx (938 lines) into focused modules following the established codebase pattern. This is PR #5 of 5 in the refactoring series for issue #173.

Structure

source/app/
├── App.tsx                      # Main component (557 lines)
├── types.ts                     # AppProps and internal types
├── components/
│   ├── AppContainer.tsx         # Layout wrapper with welcome message
│   ├── ChatInterface.tsx        # Main chat UI section
│   └── ModalSelectors.tsx       # Model/Provider/Theme selection modals
├── hooks/
│   ├── useAppHandlers.tsx       # Handler consolidation
│   └── useNonInteractiveMode.ts # Non-interactive execution logic
├── helpers.ts                   # Utility functions for app state
└── index.ts                     # Re-exports App

Test Coverage

All new modules include comprehensive test coverage:

  • ✅ App.spec.tsx - Type safety tests
  • ✅ components/AppContainer.spec.tsx - Rendering + content verification
  • ✅ components/ChatInterface.spec.tsx - UI state + rendering tests (9 tests)
  • ✅ components/ModalSelectors.spec.tsx - Modal rendering tests (9 tests)
  • ✅ helpers.spec.ts - Utility function tests

Test Improvements

  • Enhanced tests use ink-testing-library for actual component rendering
  • All tests verify both component structure AND rendered output
  • Proper cleanup with unmount() to prevent test timeouts
  • Fixed theme preset values (tokyo-night, dracula vs invalid monokai, default)
  • All 30 tests in source/app passing ✅

Benefits

  • Reduced complexity by extracting components, hooks, and utilities
  • Improved testability and maintainability
  • Clear separation of concerns (UI components, state helpers, handlers)
  • Easier to navigate and understand
  • Comprehensive test coverage with actual rendering verification

Breaking Changes

  • Import path changed: '@/app' instead of '@/app.tsx'
  • Only affects source/cli.tsx (already updated)

Testing

pnpm run test:ava source/app
# ✔ 30 tests passed

Closes #173

Splits source/app.tsx (938 lines) into focused modules following the established codebase pattern.

Structure:
- source/app/
  ├── App.tsx (main component, ~200 lines)
  ├── types.ts (AppProps and internal types)
  ├── components/
  │   ├── AppContainer.tsx (layout wrapper with welcome message)
  │   ├── ChatInterface.tsx (main chat UI section)
  │   └── ModalSelectors.tsx (model/provider/theme selection modals)
  ├── hooks/
  │   ├── useAppHandlers.tsx (handler consolidation)
  │   └── useNonInteractiveMode.ts (non-interactive execution logic)
  ├── helpers.ts (utility functions for app state)
  └── index.ts (re-exports App)

All new modules include comprehensive test coverage:
- App.spec.tsx (type safety tests)
- components/AppContainer.spec.tsx (rendering + content verification)
- components/ChatInterface.spec.tsx (UI state + rendering tests)
- components/ModalSelectors.spec.tsx (modal rendering tests)
- helpers.spec.ts (utility function tests)

Test improvements:
- Enhanced tests use ink-testing-library for actual component rendering
- All tests verify both component structure AND rendered output
- Proper cleanup with unmount() to prevent test timeouts
- Fixed theme preset values (tokyo-night, dracula vs invalid monokai, default)

Benefits:
- Each module <500 lines with single responsibility
- Improved testability and maintainability
- Clear separation of concerns (UI, state, handlers)
- Easier to navigate and understand

Breaking changes:
- Import path changed: '@/app' instead of '@/app.tsx'
- Only affects source/cli.tsx

Part of 5-PR refactoring series (#173) - PR #5 of 5
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.

Split large files into focused modules

2 participants