skills/testing/tdd-refactor-guard/SKILL.md
Pre-refactor safety checklist. Verifies test coverage exists before AI modifies existing code. Use before asking AI to refactor anything.
npx skillsauth add rshankras/claude-code-apple-skills tdd-refactor-guardInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A safety gate that runs before any AI-assisted refactoring. Ensures tests exist to catch regressions. If coverage is insufficient, generates characterization tests first.
Use this skill when the user:
Without guard: With guard:
"Claude, refactor this" "Claude, refactor this"
→ AI rewrites code → Guard checks for tests
→ Something breaks → Tests missing → generate them
→ You don't know what → Tests pass → proceed with refactor
→ Debugging nightmare → Tests fail → exact regression found
What code is being refactored?
Ask user: "Which files/classes are you planning to refactor?"
Or detect from context:
Glob: [files mentioned in conversation]
Read: each file to understand scope
Determine:
Grep: "class.*Tests.*XCTestCase|@Suite.*Tests|struct.*Tests" in test targets
Grep: "@Test|func test" that reference the classes being refactored
| Level | Criteria | Action | |-------|----------|--------| | Good (> 80%) | Most public methods have tests for happy + error paths | Proceed with refactoring | | Partial (40-80%) | Some methods tested, missing edge cases | Add characterization tests for uncovered methods | | Minimal (< 40%) | Few or no tests | Generate full characterization test suite first | | None (0%) | No test file exists | STOP — create characterization tests before any refactoring |
Even if tests exist, check quality:
// ❌ Low-quality test — doesn't actually verify behavior
@Test("test items")
func testItems() {
let vm = ViewModel()
vm.loadItems()
#expect(true) // Always passes, tests nothing
}
// ❌ Tests implementation, not behavior
@Test("calls repository")
func testCallsRepo() {
let vm = ViewModel()
vm.loadItems()
#expect(mockRepo.fetchCallCount == 1) // Brittle
}
// ✅ Tests observable behavior
@Test("loads items into published array")
func testLoadsItems() async {
let vm = ViewModel(repo: MockRepo(items: [.sample]))
await vm.loadItems()
#expect(vm.items.count == 1)
#expect(vm.items.first?.title == "Sample")
}
Quality checklist:
#expect(true) or always-passing assertionsIf coverage is insufficient, use characterization-test-generator/:
Before refactoring [ClassName], generate characterization tests:
1. Read the source file
2. Identify all public methods
3. Generate tests that capture CURRENT behavior
4. Run and verify all pass
## Refactor Guard: ✅ PROCEED
**Files**: ItemManager.swift, ItemRepository.swift
**Test coverage**: Good (12 tests covering 8/9 public methods)
**Test quality**: Adequate — tests verify behavior, not implementation
Safe to refactor. Run tests after each change:
`xcodebuild test -scheme YourApp`
## Refactor Guard: ⚠️ NEEDS TESTS
**Files**: ItemManager.swift, ItemRepository.swift
**Test coverage**: Partial (5 tests covering 4/9 public methods)
**Missing coverage**:
- `ItemManager.sort()` — no test
- `ItemManager.filter(by:)` — no test
- `ItemRepository.sync()` — no test
- Error paths for `save()` and `delete()` — not tested
**Action**: Generate characterization tests for uncovered methods before refactoring.
Use `characterization-test-generator` skill.
## Refactor Guard: 🔴 STOP
**Files**: ItemManager.swift, ItemRepository.swift
**Test coverage**: None (0 tests found)
**Action**: Do NOT refactor until characterization tests exist.
Refactoring without tests is like surgery without monitoring —
you won't know if you killed the patient.
Run `characterization-test-generator` on:
1. ItemManager (7 public methods)
2. ItemRepository (5 public methods)
Then re-run this guard.
After refactoring is complete:
# Run all tests
xcodebuild test -scheme YourApp
# Check specifically for regressions
xcodebuild test -scheme YourApp \
-only-testing "YourAppTests/ItemManagerCharacterizationTests"
These typically don't change behavior:
These can change behavior:
Full contract tests recommended:
## Refactor Guard Report
**Scope**: [Files/classes to be refactored]
**Verdict**: ✅ PROCEED / ⚠️ NEEDS TESTS / 🔴 STOP
### Coverage Summary
| Class | Public Methods | Tests | Coverage | Verdict |
|-------|---------------|-------|----------|---------|
| ItemManager | 9 | 12 | 89% | ✅ |
| ItemRepository | 5 | 2 | 40% | ⚠️ |
### Missing Coverage
- [ ] `ItemRepository.sync()` — needs characterization test
- [ ] Error path for `ItemRepository.delete()` — untested
### Recommendations
1. [Action item]
2. [Action item]
testing/characterization-test-generator/ — generates tests this guard may requiretesting/tdd-feature/ — for building new code during refactordevelopment
US web checkout via the StoreKit External Purchase Link entitlement — currently 0% Apple commission (litigation ongoing), how to ship it safely, and how to architect for a commission flip so a future ruling is a config change, not a rewrite. Use when adding external purchase links, weighing web checkout vs IAP, or planning US-storefront pricing strategy.
tools
Revenue beyond the single-app price tag — own-app bundles, Family Sharing as a conversion lever, cross-developer bundles & suites, and institutional licensing via Group Purchases / Apple School & Business Manager. Use when a developer has multiple apps, a subscription worth sharing, complementary indie partners, or school/clinic/business buyers.
testing
Run a structured accessibility audit on an iOS/macOS app — automated XCUITest audits, Accessibility Inspector, manual VoiceOver/Dynamic Type passes, and App Store Accessibility Nutrition Label evaluation. Use before release, when preparing Nutrition Label declarations, or for EU Accessibility Act compliance.
tools
Stage-by-stage audit of an app's App Store growth machinery against a 54-item P0–P9 playbook — every item scored from an App Store Connect MCP call, a codebase check, or an explicit question to the user, then routed to the skill or command that fixes it. Read-only on App Store Connect. Use for a growth audit or scorecard, a pre-launch growth plan, a quarterly re-audit, or "which growth levers am I missing."