スキル一覧に戻る
vasilyu1983

qa-refactoring

by vasilyu1983

25🍴 6📅 2026年1月23日
GitHubで見るManusで実行

SKILL.md


name: qa-refactoring description: "Safe refactoring for quality engineering: characterization tests, seam creation, incremental steps, contracts, and CI quality gates to preserve behavior while changing structure."

QA Refactoring Safety (Dec 2025) — Quick Reference

This skill provides execution-ready patterns for improving code quality and refactoring safely (preserve behavior, reduce risk, keep CI green).

Core references: Michael Feathers on characterization testing (https://michaelfeathers.silvrback.com/characterization-testing) and Martin Fowler’s Strangler Fig application pattern (https://martinfowler.com/bliki/StranglerFigApplication.html).


Core QA (Default)

Safe Refactor Loop (Behavior First)

  • Baseline: tests green on main; reproduce the behavior you must preserve.
  • Characterize: add characterization tests around current behavior before changing structure (Feathers: https://michaelfeathers.silvrback.com/characterization-testing).
  • Create seams: introduce injection points/adapters to isolate dependencies.
  • Refactor in small steps: one behavior-preserving change at a time, with CI staying green.
  • Verify: run the smallest relevant suite locally, then full CI; monitor for regressions after merge.

Test Strategy for Refactors

  • Prefer contract and integration tests around boundaries to preserve behavior.
  • Use snapshots/golden masters only when:
    • Output is stable and meaningful, and
    • You have a plan to review diffs and prevent “approve everything”.

CI Economics and Debugging Ergonomics

  • Keep refactor PRs small and reviewable; avoid refactor + feature in one PR.
  • REQUIRED: failure artifacts for tests that guard refactors (logs/trace IDs, deterministic seeds).

Do / Avoid

Do:

  • Add missing tests before refactoring high-risk areas.
  • Add guardrails (linters, type checks, contract checks) so refactors don’t silently break interfaces.

Avoid:

  • Combining large structural refactors with behavior changes.
  • Using flaky E2E as the primary safety net for refactors.

Quick Reference

TaskTool/PatternCommand/ApproachWhen to Use
Long method (>50 lines)Extract MethodSplit into smaller functionsSingle method does too much
Large class (>300 lines)Split ClassCreate focused single-responsibility classesGod object doing too much
Duplicated codeExtract Function/ClassDRY principleSame logic in multiple places
Complex conditionalsReplace Conditional with PolymorphismUse inheritance/strategy patternSwitch statements on type
Long parameter listIntroduce Parameter ObjectCreate DTO/config objectFunctions with >3 parameters
Legacy code modernizationCharacterization Tests + Strangler FigWrite tests first, migrate incrementallyNo tests, old codebase
Automated quality gatesESLint, SonarQube, Prettiernpm run lint, CI/CD pipelinePrevent quality regression
Technical debt trackingSonarQube, CodeClimateDebt ratio < 10% targetPrioritize refactoring work

Decision Tree: Refactoring Strategy

Code issue: [Refactoring Scenario]
    ├─ Code Smells Detected?
    │   ├─ Duplicated code? → Extract method/function
    │   ├─ Long method (>50 lines)? → Extract smaller methods
    │   ├─ Large class (>300 lines)? → Split into focused classes
    │   ├─ Long parameter list? → Parameter object
    │   └─ Feature envy? → Move method closer to data
    │
    ├─ Legacy Code (No Tests)?
    │   ├─ High risk? → Write characterization tests first
    │   ├─ Large rewrite needed? → Strangler Fig (incremental migration)
    │   ├─ Unknown behavior? → Characterization tests + small refactors
    │   └─ Production system? → Canary deployments + monitoring
    │
    ├─ Quality Standards?
    │   ├─ New project? → Setup linter + formatter + quality gates
    │   ├─ Existing project? → Add pre-commit hooks + CI checks
    │   ├─ Complexity issues? → Set cyclomatic complexity limits (<10)
    │   └─ Technical debt? → Track in register, 20% sprint capacity

When to Use This Skill

Use this skill when a user requests:

  • Refactoring code to improve readability/maintainability
  • Identifying and fixing code smells
  • Managing technical debt
  • Establishing code quality standards
  • Setting up automated quality gates (linters, formatters)
  • Modernizing legacy codebases
  • Reducing code complexity
  • Improving test coverage
  • Code review automation
  • Establishing refactoring strategies

Operational Deep Dives

Shared Foundation

Skill-Specific

See references/operational-patterns.md for detailed refactoring catalogs, automated quality gates, technical debt playbooks, and legacy modernization steps.


Templates

See assets/ for copy-paste ready examples organized by domain:

Refactoring Process

Checklists and workflows for systematic code improvement:

Technical Debt Tracking

Tools for managing and prioritizing technical debt:

Quality Gates Configuration

Automated quality enforcement by tech stack:

JavaScript/TypeScript

Platform-Agnostic

  • SonarQube Setup - Static analysis and quality gates for 20+ languages (Docker, Cloud, Server)

Resources

See references/ for deep-dive guides:


Optional: AI / Automation

Do:

  • Use AI to propose mechanical refactors (rename/extract/move) only when you can prove behavior preservation via tests and contracts.
  • Use AI to summarize diffs and risk hotspots; verify by running targeted characterization tests.

Avoid:

  • Accepting refactors that change behavior without an explicit requirement and regression tests.
  • Letting AI “fix tests” by weakening assertions to make CI green.

Resources

Templates

Data


スコア

総合スコア

60/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です