legacy-characterization-tests
Skill2 starsChanged 7 days agoMITView on GitHub
Write characterization tests for untested legacy code to lock current behavior before refactoring. Use when users want to safely refactor legacy controllers/models/services, add regression safety nets, or prepare code for extraction. Trigger words: characterization test, lock behavior, legacy test, safe refactor, 行為鎖定, 特徵測試, 安全重構. Not for: greenfield code, already well-tested modules, or pure bug fixes. Output: characterization test files + coverage delta report.
In this repository39 other files it gives its agents.
- AGENTS.mdAGENTS.md
- change-verdictSkill
- code-simplifySkill
- code-traceSkill
- create-prSkill
- deploy-listSkill
- doc-maintainSkill
- feature-verifySkill
- flow-driveSkill
- flow-guideSkill
- git-smart-commitSkill
- git-worktreeSkill
- harness-setupSkill
- issue-analyzeSkill
- js-static-checksSkill
- laravelSkill
- library-authorSkill
- merge-prepSkill
- module-designSkill
- nextjsSkill
- openspec-artifact-guardSkill
- opsx-apply-resumeSkill
- phpSkill
- phpunitSkill
- precommitSkill
- project-auditSkill
- project-briefSkill
- proposal-analyzeSkill
- pr-summarySkill
- pythonSkill
- reactSkill
- release-creatorSkill
- repo-intakeSkill
- repo-verifySkill
- swiftSkill
- tdd-workflowSkill
- ui-ux-verifySkill
- vue-2-notesSkill
- yii1Skill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Use test-first development for new behavior or a confirmed bug fix.
- Distinctive: line 23
Verify: Run each test independently and the affected suite.
- Distinctive: line 26
Keep external services behind test doubles where necessary while exercising real local logic.
- Distinctive: line 32
Every locked behavior has an observed passing test.
- Distinctive: line 39
Read PHP/Yii examples only for PHP or Yii projects.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Legacy characterization tests
Record observed behavior before changing an untested legacy component. The existing implementation and observed outputs own the contract; this Method does not decide whether that behavior is desirable.
When NOT to Use
Use test-first development for new behavior or a confirmed bug fix. Skip characterization when adequate regression coverage already locks the target.
Lifecycle and procedure
- Inventory. Identify public entrypoints, external dependencies, global state, existing tests and high-risk behavior. Include display, edit, print and export consumers when a previously empty value becomes populated.
- Choose a seam. Exercise the smallest public boundary that preserves the real behavior. Prefer isolated unit tests; use integration or functional tests when the behavior requires those boundaries. Use disposable fixtures and verified cleanup for persistent state.
- Observe and lock. Start with one ordinary input, run the existing implementation, then assert its observed output. Add null, empty, boundary and failure inputs one at a time. Each test must pass before proceeding. Unexpected observations require investigation before changing assertions; they do not authorize production fixes.
- Verify. Run each test independently and the affected suite. Report actual coverage when available, including untested high-risk behavior; use the consumer project's acceptance criteria rather than an invented universal threshold.
- Refactor and extract. Production edits require separate authorization. Keep the characterization suite green through a later refactor; transfer stable output contracts to focused unit tests when a pure component is extracted. Retire characterization tests only when replacement coverage demonstrably preserves the contract.
Keep external services behind test doubles where necessary while exercising real local logic. Restore replaced globals and isolate tests from execution order. Database rollback is suitable only when the storage engine supports it; otherwise use owned fixtures and explicit cleanup.
Output and verification
Deliver test files in the consumer project's existing layout, with documentation of the observed behavior, known debt and extraction exit. Report the exact commands, GREEN/FAIL/NOT_RUN evidence, coverage or its absence, and remaining gaps. Characterization alone leaves production code unchanged.
- Every locked behavior has an observed passing test.
- Tests are independent and persistent fixtures have verified cleanup.
- High-risk gaps and uncovered render consumers are explicit.
- Replacement unit coverage is verified before retiring a characterization test.
Stack-specific reference
Read PHP/Yii examples only for PHP or Yii projects. Adapt framework commands, annotations, isolation helpers and coverage options to the installed versions; the stack-neutral lifecycle above owns the Method.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

