tdd-refactor-guard — community tdd-refactor-guard, snapgrid, community, ide skills, Claude Code, Cursor, Windsurf

v1.0.0
GitHub

About this Skill

Perfect for Code Refactoring Agents needing automated test-driven development and code quality assurance. SnapGrid is an open-source Mac app for collecting, organizing, and analyzing UI screenshots. It uses AI to automatically detect UI components and patterns, making it a powerful tool for designers and

gustavscirulis gustavscirulis
[108]
[8]
Updated: 3/22/2026

Agent Capability Analysis

The tdd-refactor-guard skill by gustavscirulis is an open-source community AI agent skill for Claude Code and other IDE workflows, helping agents execute tasks with better context, repeatability, and domain-specific guidance.

Ideal Agent Persona

Perfect for Code Refactoring Agents needing automated test-driven development and code quality assurance.

Core Value

Empowers agents to ensure code reliability and stability by enforcing test coverage and quality checks using XCTest and characterization tests, thereby preventing regressions and debugging nightmares.

Capabilities Granted for tdd-refactor-guard

Automating test coverage checks for refactored code
Generating characterization tests for uncovered methods
Evaluating test quality to prevent brittle or low-quality tests

! Prerequisites & Limits

  • Requires existing test targets and XCTest framework
  • Limited to Swift and iOS development environments
  • Needs user input or context detection to identify refactoring scope
Labs Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

tdd-refactor-guard

Install tdd-refactor-guard, an AI agent skill for AI agent workflows and automation. Works with Claude Code, Cursor, and Windsurf with one-command setup.

SKILL.md
Readonly

TDD Refactor Guard

A safety gate that runs before any AI-assisted refactoring. Ensures tests exist to catch regressions. If coverage is insufficient, generates characterization tests first.

When This Skill Activates

Use this skill when the user:

  • Says "refactor this" or "clean this up"
  • Wants AI to "restructure" or "reorganize" code
  • Asks to "extract", "inline", "rename", or "simplify" existing code
  • Plans to migrate between patterns (e.g., MVC → MVVM, CoreData → SwiftData)
  • Wants AI to "improve" or "modernize" existing code

Why This Guard Exists

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

Process

Step 1: Identify Scope

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:

  • Files involved
  • Public API surface (methods, properties)
  • Dependencies (what calls this code, what it calls)
  • Side effects (network, disk, notifications, UI updates)

Step 2: Check Existing Test Coverage

Grep: "class.*Tests.*XCTestCase|@Suite.*Tests|struct.*Tests" in test targets
Grep: "@Test|func test" that reference the classes being refactored

Coverage Assessment

LevelCriteriaAction
Good (> 80%)Most public methods have tests for happy + error pathsProceed with refactoring
Partial (40-80%)Some methods tested, missing edge casesAdd characterization tests for uncovered methods
Minimal (< 40%)Few or no testsGenerate full characterization test suite first
None (0%)No test file existsSTOP — create characterization tests before any refactoring

Step 3: Evaluate Test Quality

Even if tests exist, check quality:

swift
1// ❌ Low-quality test — doesn't actually verify behavior 2@Test("test items") 3func testItems() { 4 let vm = ViewModel() 5 vm.loadItems() 6 #expect(true) // Always passes, tests nothing 7} 8 9// ❌ Tests implementation, not behavior 10@Test("calls repository") 11func testCallsRepo() { 12 let vm = ViewModel() 13 vm.loadItems() 14 #expect(mockRepo.fetchCallCount == 1) // Brittle 15} 16 17// ✅ Tests observable behavior 18@Test("loads items into published array") 19func testLoadsItems() async { 20 let vm = ViewModel(repo: MockRepo(items: [.sample])) 21 await vm.loadItems() 22 #expect(vm.items.count == 1) 23 #expect(vm.items.first?.title == "Sample") 24}

Quality checklist:

  • Tests verify outputs/state, not implementation details
  • Both happy path and error paths covered
  • Edge cases (empty, nil, boundary) tested
  • Async behavior properly awaited
  • No #expect(true) or always-passing assertions

Step 4: Generate Missing Tests

If coverage is insufficient, use characterization-test-generator/:

markdown
1Before refactoring [ClassName], generate characterization tests: 21. Read the source file 32. Identify all public methods 43. Generate tests that capture CURRENT behavior 54. Run and verify all pass

Step 5: Green Light / Red Light

Green Light — Proceed

markdown
1## Refactor Guard: ✅ PROCEED 2 3**Files**: ItemManager.swift, ItemRepository.swift 4**Test coverage**: Good (12 tests covering 8/9 public methods) 5**Test quality**: Adequate — tests verify behavior, not implementation 6 7Safe to refactor. Run tests after each change: 8`xcodebuild test -scheme YourApp`

Yellow Light — Needs Work

markdown
1## Refactor Guard: ⚠️ NEEDS TESTS 2 3**Files**: ItemManager.swift, ItemRepository.swift 4**Test coverage**: Partial (5 tests covering 4/9 public methods) 5**Missing coverage**: 6- `ItemManager.sort()` — no test 7- `ItemManager.filter(by:)` — no test 8- `ItemRepository.sync()` — no test 9- Error paths for `save()` and `delete()` — not tested 10 11**Action**: Generate characterization tests for uncovered methods before refactoring. 12Use `characterization-test-generator` skill.

Red Light — Stop

markdown
1## Refactor Guard: 🔴 STOP 2 3**Files**: ItemManager.swift, ItemRepository.swift 4**Test coverage**: None (0 tests found) 5 6**Action**: Do NOT refactor until characterization tests exist. 7Refactoring without tests is like surgery without monitoring — 8you won't know if you killed the patient. 9 10Run `characterization-test-generator` on: 111. ItemManager (7 public methods) 122. ItemRepository (5 public methods) 13 14Then re-run this guard.

Step 6: Post-Refactor Verification

After refactoring is complete:

bash
1# Run all tests 2xcodebuild test -scheme YourApp 3 4# Check specifically for regressions 5xcodebuild test -scheme YourApp \ 6 -only-testing "YourAppTests/ItemManagerCharacterizationTests"
  • All pre-existing tests still pass
  • Characterization tests still pass
  • No new warnings or errors
  • Public API surface unchanged (unless intentionally changed)

Refactoring Safeguards

Safe Refactorings (Low Risk)

These typically don't change behavior:

  • Rename variable/method/type
  • Extract method/function
  • Inline temporary variable
  • Move method to another type (keeping same behavior)
  • Extract protocol from class

Risky Refactorings (Need Good Coverage)

These can change behavior:

  • Change method signature
  • Reorder operations
  • Replace algorithm
  • Merge/split classes
  • Change data structure
  • Introduce async/await to sync code
  • Migration between frameworks (CoreData → SwiftData)

Migration Refactorings (Need Comprehensive Coverage)

Full contract tests recommended:

  • Architecture change (MVC → MVVM)
  • Framework migration (UIKit → SwiftUI)
  • Storage migration (UserDefaults → SwiftData)
  • Concurrency model change (GCD → async/await)

Output Format

markdown
1## Refactor Guard Report 2 3**Scope**: [Files/classes to be refactored] 4**Verdict**: ✅ PROCEED / ⚠️ NEEDS TESTS / 🔴 STOP 5 6### Coverage Summary 7| Class | Public Methods | Tests | Coverage | Verdict | 8|-------|---------------|-------|----------|---------| 9| ItemManager | 9 | 12 | 89% || 10| ItemRepository | 5 | 2 | 40% | ⚠️ | 11 12### Missing Coverage 13- [ ] `ItemRepository.sync()` — needs characterization test 14- [ ] Error path for `ItemRepository.delete()` — untested 15 16### Recommendations 171. [Action item] 182. [Action item]

References

  • testing/characterization-test-generator/ — generates tests this guard may require
  • testing/tdd-feature/ — for building new code during refactor
  • Martin Fowler, Refactoring: Improving the Design of Existing Code

FAQ & Installation Steps

These questions and steps mirror the structured data on this page for better search understanding.

? Frequently Asked Questions

What is tdd-refactor-guard?

Perfect for Code Refactoring Agents needing automated test-driven development and code quality assurance. SnapGrid is an open-source Mac app for collecting, organizing, and analyzing UI screenshots. It uses AI to automatically detect UI components and patterns, making it a powerful tool for designers and

How do I install tdd-refactor-guard?

Run the command: npx killer-skills add gustavscirulis/snapgrid/tdd-refactor-guard. It works with Cursor, Windsurf, VS Code, Claude Code, and 19+ other IDEs.

What are the use cases for tdd-refactor-guard?

Key use cases include: Automating test coverage checks for refactored code, Generating characterization tests for uncovered methods, Evaluating test quality to prevent brittle or low-quality tests.

Which IDEs are compatible with tdd-refactor-guard?

This skill is compatible with Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer. Use the Killer-Skills CLI for universal one-command installation.

Are there any limitations for tdd-refactor-guard?

Requires existing test targets and XCTest framework. Limited to Swift and iOS development environments. Needs user input or context detection to identify refactoring scope.

How To Install

  1. 1. Open your terminal

    Open the terminal or command line in your project directory.

  2. 2. Run the install command

    Run: npx killer-skills add gustavscirulis/snapgrid/tdd-refactor-guard. The CLI will automatically detect your IDE or AI agent and configure the skill.

  3. 3. Start using the skill

    The skill is now active. Your AI agent can use tdd-refactor-guard immediately in the current project.

Related Skills

Looking for an alternative to tdd-refactor-guard or another community skill for your workflow? Explore these related open-source skills.

View All

widget-generator

Logo of f
f

f.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source — self-host for your organization with complete privacy.

149.6k
0
AI

flags

Logo of vercel
vercel

flags is a Next.js feature management skill that enables developers to efficiently add or modify framework feature flags, streamlining React application development.

138.4k
0
Browser

zustand

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
AI

data-fetching

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
AI