Systematic Type Migration
БесплатноБез исполняемых скриптовНе проверенSafe refactoring workflow for replacing old types with new type-safe implementations through integration-test-first, file-by-file migration with incremental…
Об этом скилле
Systematic Type Migration
Overview
When refactoring components to new type-safe implementations, use this systematic workflow to prevent "works in isolation but broken integration" bugs.
Core principle: Integration test FIRST → file-by-file migration → incremental verification → cleanup
The Problem
Recurring issue during major refactoring:
- Old component definitions remain in the codebase
- Some files spawn entities with old types
- Other files query for new types
- Systems become disconnected (queries find zero entities)
- User functionality breaks despite all systems being "properly registered"
Example: After introducing type-safe MovementState enum, if setup.rs spawns entities with the old MovementState but planning.rs queries for the new MovementState, queries will silently fail.
The Workflow
Phase 1: Preparation
Step 1: Document the change
- Create work directory (e.g.,
docs/work/YYYY-MM-DD-type-safe-X) - Document scope and goals
Step 2: Identify all uses
# Find all references to the type being replaced
grep -r "ComponentName" src/
rg "OldType" --type rust
Step 3: Create integration test FIRST
- Write test that exercises full user flow (not just isolated system behavior)
- Test should verify end-to-end functionality
- This test MUST pass before starting AND after completion
Step 4: Run baseline tests
- Run project test command
- Run project check command
- Capture baseline to compare against
Phase 2: Implementation
Step 1: Create new component
- Implement in canonical location (e.g.,
src/components/movement/states.rs) - Include all required derives
Step 2: Do NOT delete old component yet
- Keep both during migration
- Enables gradual migration without breaking everything
- Allows atomic commits per file
Phase 3: Migration (Systematic, File-by-File)
For EACH file using the old component:
Step 1: Update imports
// Before
use old_module::OldType;
// After
use new_module::NewType;
Step 2: Update type usage
- Pattern matching if enum variants changed
- Entity spawning to use new type
- Queries to use new type
Step 3: Test after each file
cargo check # Or language-specific quick check
- Catch type errors immediately
- Don't accumulate errors across files
Step 4: Commit atomically
git add path/to/file.rs
git commit -m "refactor: migrate FileX to new ComponentName"
- One commit per file or logical group
- Enables easy rollback if needed
Common file locations to check:
- Entity spawning files (e.g.,
setup.rs,spawners.rs) - System logic files (business logic using the component)
- UI display files (rendering component state)
- Component definition files
- Integration test files
Phase 4: Cleanup
Step 1: Delete old component definition
- Remove from original module
- Only after ALL references migrated
Step 2: Remove obsolete imports
# Find unused imports
cargo clippy -- -W unused_imports
Step 3: Remove obsolete helper code
- Builder functions
- Conversion utilities
- Deprecated APIs
Step 4: Update exports
- Remove old type from
mod.rspublic API - Ensure new type properly exported
Phase 5: Verification
Step 1: Compile clean
cargo check --all-targets
# Or language-specific equivalent
Step 2: Run all tests
Run project test command
- All unit tests must pass
- All integration tests must pass
Step 3: Verify integration test passes
- The test created in Phase 1 MUST pass
- This verifies end-to-end functionality
Step 4: Run checks
Run project check command
- Linting, formatting, type checking
Step 5: Manual testing
- Test actual user flows
- Verify UI updates correctly
- Check edge cases
Phase 6: Documentation
Step 1: Update pattern docs
- If new pattern emerged, document it
Step 2: Document in retrospective
- Capture lessons learned in work directory
- Note any pitfalls encountered
Step 3: Update project docs
- If pattern is important, reference from CLAUDE.md or README
Key Principles
| Principle | Rationale |
|---|---|
| Integration test FIRST | Prevents "works in parts, broken as whole" |
| Keep both during migration | Enables atomic commits per file |
| File-by-file, not all-at-once | Easier debugging, clear progress |
| Incremental verification | Catch errors immediately (5 min) vs batch (30+ min) |
| Atomic commits | Easy rollback if specific change breaks something |
Prevention: Integration Tests
The best prevention is integration tests that verify the full user flow, not just isolated system behavior.
What Makes a Good Integration Test
Good integration test:
#[test]
fn test_user_can_move_vehicle() {
// Setup: Spawn entities with realistic component combinations
let world = setup_test_world();
let vehicle = spawn_vehicle_with_all_components(&mut world);
//
Установить Systematic Type Migration в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Systematic Type Migration?
Safe refactoring workflow for replacing old types with new type-safe implementations through integration-test-first, file-by-file migration with incremental verification
Как установить скилл Systematic Type Migration?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Systematic Type Migration запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic