Synthèse automatique
Ce skill encadre une refactorisation en imposant d'abord une suite de tests au vert, puis des étapes incrémentales qui laissent le code fonctionnel après chacune.
Points forts
- Exige une base de tests passants avant toute modification, et arrête le travail si la suite est déjà rouge
- Découpe la refactorisation en petits pas dont chacun est vérifié par les tests
- Recherche systématiquement les appelants et les dépendances d'interface avant de déplacer ou renommer quoi que ce soit
- Propose une méthode de diagnostic structurée lorsqu'un test casse en cours de route
Limites
- Suppose qu'un projet avec commandes de test identifiables existe ; sans tests, il faut d'abord en écrire
- Refuse délibérément de corriger un bug et de restructurer dans la même étape, ce qui allonge la procédure
- Le nom du skill évoque FastAPI mais les instructions restent génériques, sans conseils spécifiques au framework
À utiliser lorsqu'il faut réorganiser du code existant (extraire, déplacer, renommer) sans modifier son comportement observable.
À éviter pour ajouter des fonctionnalités, corriger des bugs ou travailler sur du code sans aucun test de référence.
Analyse de sécurité
PrudenceNo destructive commands, credential access, network exfiltration, obfuscated payloads, or safety-disabling instructions are present. The skill uses Bash/Edit/Write only for normal test-driven refactoring, so the risk is limited to executing project tests and modifying files.
- •Uses Bash to run the project test suite and git diff, which executes repository-defined commands/code.
- •Uses Edit/Write to modify source files; appropriate for refactoring but still changes the working tree.
Exemples
Refactor src/api/users.py into smaller modules — it's doing routing, validation, and database access all in one file. Behavior must stay exactly the same.Extract the order-validation logic out of app/services/orders.py into its own helper function, without changing what it returns or how it handles errors.Move the payment module from app/utils/payments to app/billing/payments and update every caller, keeping all tests green at each step.name: fastapi-refactor
description: Use when the user wants to restructure code while preserving behavior exactly. Establishes a passing test baseline first, then makes incremental moves that each leave the suite green. Refuses to change behavior and structure in the same step. Also known as klaussy-refactor.
allowed-tools: Read Grep Glob Bash Edit Write
Refactor the code the user described. The goal is to change structure while preserving behavior exactly. Do NOT change what the code does — only how it's organized.
Phase 1: Establish the Safety Net
Before changing any code, confirm you have tests that cover the current behavior.
- Read CLAUDE.md for project structure, test commands, and conventions.
- Read any
.claude/rules/*.mdwhosepaths:glob matches the area being refactored — they encode the conventions the moved code must continue to obey. - Run the existing test suite. Record the results — every test must pass before you start. If tests are failing already, stop and report that. Do not refactor code that doesn't have a passing baseline.
- Assess coverage of the code you plan to change. Read the existing tests for the modules involved. If a function you're restructuring has no tests:
- Write tests for its current behavior first.
- Run them to confirm they pass.
- These are your regression guardrails — they prove the refactor didn't break anything.
Phase 2: Understand the Current Code
Read the code you're refactoring in full. The three checks below are independent — issue them as a single batch of parallel tool calls, not sequentially:
- What it does — the inputs, outputs, side effects, and edge cases. Read the file(s) in full.
- Who calls it — grep for callers across the whole repo. Every caller is a contract you must preserve.
- What depends on its interface — function signatures, return types, exceptions thrown, event emissions. Grep for type/import references too. These are the things you cannot change without updating all consumers.
Phase 3: Plan the Refactor
Design the target structure before editing.
- Describe the structural change — what moves where, what gets renamed, what gets split or merged.
- List what must NOT change — public interfaces, return values, side effects, error behavior. Be explicit.
- Plan incremental steps. Break the refactor into the smallest possible moves that each leave the code in a working state. Never change behavior and structure in the same step. For example:
- Step 1: Extract a function (tests still pass).
- Step 2: Move the function to a new module (tests still pass).
- Step 3: Update callers to use the new location (tests still pass).
Phase 4: Refactor
Execute your plan. After EACH incremental step:
- Run the test suite. If anything fails, your last change broke something. Fix it before moving on — do not accumulate breakage across steps.
- Re-read the code to verify it looks correct.
When a test fails mid-refactor
Don't immediately edit the test or roll back the step. Diagnose:
- Did you miss a caller? Re-grep for the symbol you moved or renamed across the whole repo (not just the immediate file). Update every match in this same step.
- Did you change a signature unintentionally? Compare the new signature to the old one — argument order, default values, return type. Even a "trivial" rename of a kwarg breaks callers using keyword args.
- Did you introduce a subtle behavior change? Re-read the moved code line-by-line against the original. Refactors break in tiny ways: a list comprehension that no longer preserves order, an early-return that now runs cleanup, a class attribute that became an instance attribute.
Only after the test is green again move on to the next step.
Rules
- Never change behavior and structure in the same step. If you need to fix a bug you found, do it in a separate commit.
- Preserve all public interfaces unless the explicit goal is to change them. If you change a function signature, update every caller in the same step.
- Don't "improve" things outside the refactor scope. No drive-by style fixes, no adding types to unrelated code, no renaming things you aren't restructuring.
- Match existing conventions. If moving code to a new file, follow the naming and structure patterns already in the codebase.
- Don't add narrating comments. Restructuring is not an excuse to annotate. When you delete or move code, delete its now-stale comments too; keep only short comments that explain a non-obvious WHY, and never leave commented-out code behind.
Phase 5: Verify
- Run the full test suite one final time. Every test that passed before must pass now. No exceptions.
- Check your diff. Run
git diffand verify:- No behavioral changes snuck in.
- No unrelated files were modified.
- No debug code or commented-out code remains.
- Verify callers. Re-grep for callers of anything you moved or renamed. Confirm every reference was updated.
When NOT to use
- The user wants to add new behavior, not rearrange existing code — use implement.
- There's no passing test baseline AND the user can't accept "write tests first" — refactor without tests is just hope; flag the missing baseline and stop.
- The user wants to fix a known bug as part of the refactor — split: bug fix in one commit (debug skill), refactor in another. Mixing them hides regressions.
Du fichier au premier essai
Le téléchargement contient exactement le contenu affiché sur cette fiche. Cette copie peut différer de la dernière version du dépôt source.
Consulter la source et ses fichiers annexesCe téléchargement contient uniquement SKILL.md. Les scripts, références, modèles et dépendances éventuels ne sont pas inclus. Récupérez les fichiers nécessaires depuis la source en conservant leur arborescence avant de poursuivre.
1. Télécharger le fichier
Télécharger SKILL.mdDepuis la racine d’un projet de test, enregistrez le fichier sous .skill-downloads/safe-refactoring-with-tests-mu7w4g46/SKILL.md, ou utilisez la commande suivante. Ce dossier sert à examiner la skill avant son installation.
Commande pour macOS/Linux ou WSL : un shell POSIX et curl sont nécessaires. Sous Windows sans WSL, utilisez le bouton de téléchargement et créez le dossier manuellement.
mkdir -p '.skill-downloads/safe-refactoring-with-tests-mu7w4g46' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/safe-refactoring-with-tests-mu7w4g46/download' --output '.skill-downloads/safe-refactoring-with-tests-mu7w4g46/SKILL.md.part' && mv '.skill-downloads/safe-refactoring-with-tests-mu7w4g46/SKILL.md.part' '.skill-downloads/safe-refactoring-with-tests-mu7w4g46/SKILL.md'2. Vérifier les prérequis
Lisez SKILL.md avant de l’utiliser. Si le fichier cite des scripts ou services externes, examinez-les et préparez les accès nécessaires dans votre environnement de test.
Outils déclarés par l’auteur (à vérifier dans votre agent) : Read Grep Glob Bash Edit Write
Aucune section de prérequis reconnue dans ce fichier. Cela ne signifie pas qu’il est autonome : les bibliothèques, outils et accès peuvent être cités ailleurs dans le contenu ou dans le dépôt source.
Les plateformes de la fiche sont des indications du catalogue. Les chemins ci-dessous suivent la documentation des outils ; ils ne prouvent pas que cette skill y a été exécutée. Aucune version minimale de ces outils n’est attestée pour cette fiche.
3. Charger la skill
Après vérification, copiez le dossier complet dans le projet avec l’une des commandes ci-dessous, puis ouvrez une nouvelle session de l’outil. La commande s’arrête si un dossier du même nom existe déjà : comparez les fichiers avant de le remplacer.
Claude Code
test -f '.skill-downloads/safe-refactoring-with-tests-mu7w4g46/SKILL.md' && test -s '.skill-downloads/safe-refactoring-with-tests-mu7w4g46/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/fastapi-refactor' && cp -R '.skill-downloads/safe-refactoring-with-tests-mu7w4g46' '.claude/skills/fastapi-refactor'OpenSkills
OpenSkills doit déjà être installé. La procédure locale install/read est contrôlée avec OpenSkills 1.5.0, qui exige Node.js ≥ 20.6.0. Aucun slug du catalogue n’est résolu automatiquement.
Installation officielle d’OpenSkillsopenskills install './.skill-downloads/safe-refactoring-with-tests-mu7w4g46'openskills read 'safe-refactoring-with-tests-mu7w4g46'La lecture doit afficher le contenu du fichier installé et son dossier de base. Elle ne lance ni la skill ni ses dépendances.
Pour un agent qui lit AGENTS.md, synchronisez ensuite l’index. Cette commande modifie AGENTS.md : relisez le diff avant de l’utiliser.
openskills syncMode manuel ou autre outil : joignez SKILL.md à une conversation, ou ouvrez-le dans un agent capable de lire les fichiers. Ajoutez les ressources annexes nécessaires. Il n’existe pas de dossier universel reconnu par tous les outils.
4. Faire un premier essai
Utilisez une entrée courte et fictive : un endpoint d’API, un petit document ou un brief d’interface. Dans une nouvelle conversation, joignez le fichier ou donnez son chemin à l’agent, puis adaptez cette demande :
Lis .skill-downloads/safe-refactoring-with-tests-mu7w4g46/SKILL.md et applique ses instructions à cet exemple : [décrire une entrée de test]. Indique les fichiers, dépendances ou accès qui manquent. Produis le résultat demandé par la skill sans inventer de données ni exécuter de script non examiné.Résultat attendu : une sortie correspondant aux instructions de la skill, ou une liste précise des prérequis manquants. Une simple confirmation de lecture ne valide pas le premier usage. Si une ressource externe est indisponible, ce parcours reste à tester.
Bonnes pratiques React Hook Form
Developpement
Maîtrisez React Hook Form : évitez les anti-patterns, gérez les abonnements, et traitez correctement reset, dirty state et entrées contrôlées.
Migration Emotion vers Mantine
Developpement
Migrer les styled-components Emotion vers des composants Mantine avec style props et modules CSS. Pour convertir .styled.tsx ou supprimer les imports @emotion.
Détecteur de dérive de périmètre
Developpement
Analyse les diffs git par rapport à une intention pour détecter la dérive de périmètre, fichiers non liés et PR trop larges, puis suggère de garder, diviser ou justifier.