agentleFS
hmj1026hmj1026/dhpk/skills/legacy-characterization-tests/SKILL.md

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.

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
  1. Distinctive:

    Use test-first development for new behavior or a confirmed bug fix.

    line 16
  2. Distinctive:

    Verify: Run each test independently and the affected suite.

    line 23
  3. Distinctive:

    Keep external services behind test doubles where necessary while exercising real local logic.

    line 26
  4. Distinctive:

    Every locked behavior has an observed passing test.

    line 32
  5. Distinctive:

    Read PHP/Yii examples only for PHP or Yii projects.

    line 39

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.