Official agent skill

Behavior Preserving Refactor

by microsoft in microsoft/testfx

Preserve observable behavior when splitting files, moving members, consolidating helpers, or simplifying TestFx code.

OfficialMITAuto-check passedDevelopment

Install Behavior Preserving Refactor

skills CLI
$ npx skills add microsoft/testfx --skill behavior-preserving-refactor -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install microsoft/testfx behavior-preserving-refactor --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/microsoft/testfx.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.github/skills/behavior-preserving-refactor .claude/skills/behavior-preserving-refactor && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
behavior-preserving-refactor
GitHub stars
1k
Token cost
~2k tokens
SKILL.md length
1,009 words
Files
1
Skills in repo
50
Repo updated
First seen
Licence
MIT

At a glance

Preserve observable behavior when splitting files, moving members, consolidating helpers, or simplifying TestFx code.

  • Works in 5 steps: Establish the baseline before editing → Trace the actual consumers and constraints → Make the structural change, not adjacent… → …
  • Structural refactors and file-diet implementation
  • SKILL.md covers 1. Establish the baseline…, 2. Trace the actual consumers…, 3. Make the structural change,… and 4. Use distinguishing…, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Behavior Preserving Refactor is an agent skill from microsoft/testfx, published by the product's own GitHub organization. Preserve observable behavior when splitting files, moving members, consolidating helpers, or simplifying TestFx code. Use for structural refactors and file-diet implementation; inventory baseline semantics and consumers, then run focused equivalence checks.

Its SKILL.md is about 2k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Refactoring. The repository describes itself as: This repository holds the source code of Microsoft.Testing.Platform (MTP), a lightweight alternative to VSTest, as well as MSTest adapter and framework. The licence is MIT.

When your agent uses it

  • Structural refactors and file-diet implementation
  • Inventory baseline semantics and consumers
  • Then run focused equivalence checks

Example prompts

  • “/behavior-preserving-refactor”

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Establish the baseline before editing
  2. Trace the actual consumers and constraints
  3. Make the structural change, not adjacent cleanup
  4. Use distinguishing equivalence cases
  5. Validate the smallest relevant surface

What it can do on your machine

Read from SKILL.md and the folder at commit 19d717a. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Behavior Preserving Refactor loads about 2k tokens when it runs. Until then it costs about 72 tokens; SKILL.md has 1,009 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~72
When it runs · the whole SKILL.md, loaded when a task matches
~2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from microsoft/testfx at commit 19d717a, republished under its MIT licence (© microsoft). 1,009 words, ~1,959 tokens.

Download SKILL.mdSave it as .claude/skills/behavior-preserving-refactor/SKILL.md (or your agent's skills folder).
name
behavior-preserving-refactor
description
Preserve observable behavior when splitting files, moving members, consolidating helpers, or simplifying TestFx code. Use for structural refactors and file-diet implementation; inventory baseline semantics and consumers, then run focused equivalence checks.

Behavior-Preserving Refactors

Use this recipe for the specific code being refactored, not a repository-wide audit. Read .github/copilot-instructions.md and applicable directory rules. Preserve existing behavior, including surprising reachable cases; a bug fix or modernization needs separate authorization and validation.

An issue-generation workflow's bounded inspection is not implementation preflight. For example, Daily File Diet inspects only the first 100 lines and up to 50 declaration lines of one file. Keep that budget when proposing work, label unverified assumptions, and include this recipe for the later implementer. Do not claim equivalence, tested behavior, or complete consumer coverage from that sample.

1. Establish the baseline before editing

Identify the exact methods or declarations to move or extract, their callers, existing focused tests, and owning projects. Read the complete affected bodies and relevant context, not just signatures or similar-looking helpers. For each existing implementation that might share a helper, record:

BoundaryWhat must remain unchanged
SelectionIteration order, first versus last match, first matching name versus first matching typed value, exact type tests, casts, defaults, and missing-value handling.
EvaluationShort-circuit operand order, which callbacks run and how often, enumeration count, laziness, mutation, and side effects before return or failure.
Results and failuresReturn values, diagnostics and locations, output ordering, exception type and timing, cancellation, and cleanup/disposal order where affected.
CompilationNamespaces, accessibility, attributes, overload binding, target-framework guards, and native interop signatures and marshalling.
CostAllocations, materialization, boxing, repeated scans, and algorithmic complexity on affected hot paths.

Inventory reachable empty, duplicate, malformed, null, and wrong-type inputs. Do not add support for impossible states, but do not assume compiler or user input is always valid: analyzer inputs can be incomplete or contain errors. Name the existing guard that makes a case unreachable if excluding it. Use existing behavior as the oracle, not the intended behavior of a new helper.

2. Trace the actual consumers and constraints

  • Find all partial declarations and call sites of the affected type or member. Check initialization order if moving fields between partial files.
  • Inspect owning project files and imports for linked Compile items, shared source, globs, explicit includes, and packaging rules. Find every consuming project, including source-only packages; a build of the original owner does not prove that a new file is included by another consumer.
  • Keep target frameworks, conditional compilation, supported platforms, and package layout intact. A native interop file move is not permission to replace DllImport, change marshalling, or adopt APIs unavailable on older targets.
  • Check applicable PublicAPI and InternalAPI shipped/unshipped baselines. Prefer unchanged signatures and accessibility; do not expose a helper just to share it. Record required newly tracked declarations without rewriting shipped API history.

3. Make the structural change, not adjacent cleanup

Move existing bodies unchanged first, preserving attributes, guards, resource access, and file encoding. Keep unrelated renaming, formatting, LINQ rewrites, interop modernization, new validation, and behavior fixes out of the change.

Before consolidating helpers, compare every caller's baseline. Similar names or happy-path outputs do not establish equivalence. If callers differ in selection, evaluation, or failure behavior, keep separate implementations or use the smallest explicit helper that preserves each contract; do not invent a configurable abstraction merely to eliminate duplication.

Do not replace a loop with a dictionary, eager projection, sort, or single-match operator without proving duplicate handling, enumeration, and failure behavior. On hot paths, preserve allocation and complexity characteristics. Use existing allocation/performance checks when the extraction could change them; do not introduce a benchmark project for a pure move.

If the size target requires behavior changes or unsafe fragmentation, stop that part of the refactor and report the remaining line count and concrete constraint. Do not alter semantics just to meet a file-size goal.

Show full SKILL.md (402 more words)Show less

4. Use distinguishing equivalence cases

These are examples to adapt to the actual baseline, not new product semantics:

BaselineFocused caseRequired observation
A loop overwrites its result for every matching name.Matching values 1, then 2.Result remains 2; returning the first match is not equivalent.
A loop returns the first matching name whose value is an int.Same-name string "bad", integer 7, then integer 9.Result remains 7; taking the first name then casting, or taking the last integer, is not equivalent.
Exact int type matching.Same-name long value 7L, followed by int value 8.Result remains 8; numeric conversion changes type selection.
ShouldRun() && Execute().ShouldRun returns false; Execute records a call or throws.Only ShouldRun runs; reordering operands or evaluating both eagerly is not equivalent.
A guarded interop declaration moves to another file.Build every source-linked consumer and affected supported TFM/platform path.Declaration, guards, accessibility, and marshalling remain unchanged; no new runtime API requirement.

Also cover the actual missing/empty and malformed-only outcomes, not just malformed input followed by a valid value. Assert observable values, diagnostic locations, exception behavior, and ordered side-effect traces where applicable. Pin expectations to the baseline; comparing two paths that both call the new helper is not an equivalence test.

5. Validate the smallest relevant surface

Before editing, run the existing focused checks when feasible and add any necessary distinguishing cases against the original implementation. After the change, rerun the same checks. Explain pre-existing failures or unavailable checks; do not report unrun checks as passed.

Use the repo-local toolchain and documented filtered build/test commands from .github/copilot-instructions.md. Build the owning and linked consuming projects for affected target frameworks. Run directly related tests, escalating only when dependencies or failures justify it. A pure file move needs inclusion and compilation checks plus relevant existing tests, not the full solution. If shipping package/source inclusion changes, validate the packed consumer layout using existing acceptance infrastructure.

Review the final diff for changed expressions, ordering, signatures, attributes, guards, includes, tracked APIs, and unintended adjacent edits. Measure resulting file sizes rather than assuming the split meets its target.

Completion evidence

Report the moved/extracted responsibility, baseline invariants and distinguishing cases, affected consumers/TFMs and API surfaces, exact checks and outcomes, and resulting line counts when size is the goal. Identify any remaining uncertainty or blocked target explicitly. Compilation alone does not prove runtime equivalence, and passing happy-path tests does not settle first/last selection or short-circuit behavior.

© microsoft, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .github/skills/behavior-preserving-refactor of microsoft/testfx.

Open the folder on GitHubat commit 19d717a

Compare with similar skills

Behavior Preserving Refactor next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Behavior Preserving Refactor compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Behavior Preserving Refactor this skillmicrosoft/testfx1k—~2kAutomated safety check: PassMIT
Guidelinesakash-network/node1.1k20 repos~577Automated safety check: PassMIT
Component Refactoringlangflow-ai/langflow155k—~3.5kAutomated safety check: PassMIT
Migrate Core Code to Submodulestinyhumansai/openhuman42k—~2.6kAutomated safety check: PassGPL-3.0
ast-grep Structural Searchcode-yeongyu/oh-my-openagent70k—~3.3kAutomated safety check: PassMIT
Systematic Code Refactoringluongnv89/claude-howto42k—~3kAutomated safety check: PassMIT

Similar skills

  • Guidelines

    akash-network/node

    Behavioral guidelines to reduce common LLM coding mistakes. An agent skill from akash-network/node.

    1.1k GitHub starsUsed in 20 repos~577 tokens
    DevelopmentAuto-check passed
  • Component Refactoring

    langflow-ai/langflow

    Refactor high-complexity React components in Langflow frontend.

    155k GitHub stars~3.5k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Migrate Core Code to Submodules

    tinyhumansai/openhuman

    Plans and carries out moving non-host-specific code and its tests from the OpenHuman core into vendored tiny submodule libraries, then releases the submodule and re-pins the host.

    42k GitHub stars~2.6k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • ast-grep Structural Search

    code-yeongyu/oh-my-openagent

    Searches and rewrites code by syntax-tree shape across 25 languages with ast-grep, for codemods, structural queries and YAML lint rules, using a Python wrapper script.

    70k GitHub stars~3.3k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Systematic Code Refactoring

    luongnv89/claude-howto

    Guides refactoring in phases based on Martin Fowler's method: research, test coverage check, planning and small tested steps, with your approval at each phase.

    42k GitHub stars~3k tokensUpdated 9 days ago
    DevelopmentAuto-check passed
  • Codex

    skills-directory/skill-codex

    A skill your agent uses when the user asks to run Codex CLI (codex exec, codex resume) or references OpenAI Codex for code analysis, refactoring, or automated editing

    1.5k GitHub starsUsed in 3 repos~1.8k tokens
    DevelopmentAuto-check passed

More from microsoft/testfx

All 50 skills in this repo
  • Official

    Guide for organizing MSBuild infrastructure with Directory.Build.props, Directory.Build.targets, Directory.Packages.props, and Directory.Build.rsp.

    1k GitHub starsUsed in 1 repo~2.5k tokens
    Auto-check passed
  • Coverage Analysis

    microsoft/testfx

    Official

    Project-wide code coverage and CRAP (Change Risk Anti-Patterns) score analysis for .NET projects.

    1k GitHub stars~7.3k tokensUpdated yesterday
    Auto-check passed
  • Incremental Build

    microsoft/testfx

    Official

    Guide for optimizing MSBuild incremental builds. An agent skill from microsoft/testfx.

    1k GitHub starsUsed in 3 repos~3.7k tokens
    Auto-check passed
  • Official

    Validate TestFx shipping paths and capable CI execution using packed consumers, package/cache provenance, exact exits and artifacts, and selected-versus-executed test evidence.

    1k GitHub stars~4.7k tokensUpdated yesterday
    Auto-check passed
  • Msbuild Modernization

    microsoft/testfx

    Official

    Guide for modernizing and migrating MSBuild project files to SDK-style format.

    1k GitHub starsUsed in 3 repos~4.3k tokens
    Auto-check passed
  • Official

    Guide for interpreting ResolveProjectReferences time in MSBuild performance summaries.

    1k GitHub starsUsed in 3 repos~743 tokens
    Auto-check passed

Categories

Questions about Behavior Preserving Refactor

What does Behavior Preserving Refactor do?

Preserve observable behavior when splitting files, moving members, consolidating helpers, or simplifying TestFx code. Behavior Preserving Refactor is an agent skill from microsoft/testfx, published by the product's own GitHub organization. Preserve observable behavior when splitting files, moving members, consolidating helpers, or simplifying TestFx code.

When should I use Behavior Preserving Refactor?

Behavior Preserving Refactor fits situations like: structural refactors and file-diet implementation; inventory baseline semantics and consumers; then run focused equivalence checks.

How do I install Behavior Preserving Refactor in Claude Code?

Run `npx skills add microsoft/testfx --skill behavior-preserving-refactor -a claude-code`. Or copy the skill folder (.github/skills/behavior-preserving-refactor in microsoft/testfx) into .claude/skills/behavior-preserving-refactor in your project. Claude Code loads it when a task matches its description.

How do I install Behavior Preserving Refactor in Codex?

Run `npx skills add microsoft/testfx --skill behavior-preserving-refactor -a codex`. Or copy the skill folder (.github/skills/behavior-preserving-refactor in microsoft/testfx) into .agents/skills/behavior-preserving-refactor in your project. Codex loads it when a task matches its description.

Can I use Behavior Preserving Refactor in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add microsoft/testfx --skill behavior-preserving-refactor -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/behavior-preserving-refactor, .gemini/skills/behavior-preserving-refactor, .github/skills/behavior-preserving-refactor and .opencode/skills/behavior-preserving-refactor in your project.

What does Behavior Preserving Refactor need to run?

SKILL.md names no scripts, command-line tools or credentials: Behavior Preserving Refactor is instructions for the agent only.

Does Behavior Preserving Refactor access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Behavior Preserving Refactor safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Behavior Preserving Refactor use?

Behavior Preserving Refactor is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Behavior Preserving Refactor use?

About 2k tokens (SKILL.md is roughly 7.8k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Behavior Preserving Refactor?

Skills that share tags, products or a category with Behavior Preserving Refactor: Guidelines (akash-network/node, 1.1k stars), Component Refactoring (langflow-ai/langflow, 155k stars), Migrate Core Code to Submodules (tinyhumansai/openhuman, 42k stars) and ast-grep Structural Search (code-yeongyu/oh-my-openagent, 70k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Behavior Preserving Refactor?

microsoft (a GitHub organization, an official publisher) maintains it in microsoft/testfx, which has 1,047 GitHub stars. The repository holds 50 skills in this directory. The repository was last updated on October 9, 2026.

Source: microsoft/testfx on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.