본문으로 건너뛰기
Skillpedia
테스트5.8k · #14632

migrate-static-to-wrapper

하는 일

이 스킬은 C# 코드가 현재 시각이나 파일을 직접 정적으로 호출하던 방식을, 주입된 래퍼나 내장 추상화로 바꿉니다. 테스트 가능하게 만드는 작업을 작은 단계로 통제하려는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓프로젝트에서 DateTime.UtcNow나 DateTime.Now를 TimeProvider로 바꾸고 싶을 때.
  • ✓직접 File 호출을 네임스페이스 전체에서 기존 파일 시스템 래퍼로 옮기고 싶을 때.
  • ✓클래스에 새 추상화를 생성자 주입으로 넣고, 그 테스트에 가짜 구현이 필요할 때.

스킬 링크

https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/migrate-static-to-wrapper/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/migrate-static-to-wrapper/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제 Orders 프로젝트의 직접 DateTime.UtcNow 호출을 TimeProvider로 바꾸고, 테스트는 가짜 시계를 쓰도록 업데이트해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트가 작업을 지정한 범위로 제한하고, 호출 지점과 생성자를 주입된 추상화를 쓰도록 바꾸며, 영향을 받는 테스트를 가짜로 업데이트합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Migrate Static to Wrapper

Perform mechanical, codemod-style replacement of static dependency call sites with calls to injected wrapper interfaces or built-in abstractions. Operates on a bounded scope (single file, project, or namespace) so migrations can be done incrementally.

When to Use

  • After wrappers have been generated (via generate-testability-wrappers) or built-in abstractions identified
  • Migrating DateTime.UtcNow → TimeProvider.GetUtcNow() across a project
  • Migrating File.* → IFileSystem.File.* across a namespace
  • Adding constructor injection for the new abstraction to affected classes
  • Making a static utility class testable by adding an ambient seam (Step 3) while its existing call sites keep compiling unchanged
  • Incremental migration: one project or namespace at a time
  • Updating affected tests with fakes when the requested migration names the replacement abstraction

When Not to Use

  • No wrapper or abstraction exists yet and one must be designed from scratch (use generate-testability-wrappers first). A built-in abstraction such as TimeProvider or IFileSystem always counts as existing.
  • The user wants to detect statics, not migrate them (use detect-static-dependencies)
  • Migrating between test frameworks (use the appropriate migration skill)
  • The user primarily asks for a deterministic behavior test and has not selected the production seam (use testability-obstacle)

A class that is static, or a project with no DI container, is not a reason to skip this skill — that is exactly what the ambient seam in Step 3 is for. Use it whenever the call sites must keep compiling unchanged.

Inputs

Input Required Description
Static pattern No Infer from the request and discovered call sites (e.g., DateTime.UtcNow, File.ReadAllText)
Replacement abstraction No Infer from the request and existing project abstractions; stop only when no named/existing abstraction is available
Scope No Infer from the requested file/project/namespace, otherwise discover the narrowest relevant workspace scope
Injection strategy No constructor (default), primary-constructor, or ambient

Workflow

Non-negotiable migration boundaries

  • Missing abstraction means stop. If the named interface/package is absent and the request only authorizes call-site replacement, do not add a package, invent a local lookalike interface, or edit production code. Report the exact missing prerequisite and the authorization needed to continue.
  • One source read stays one replacement read. Do not hoist or coalesce calls, even when sharing a captured timestamp looks cleaner.
  • The requested scope is exhaustive and exclusive. Replace every named call in scope and no adjacent member or file.
  • Repository-backed requests require repository work. Start by discovering files from the current workspace. Do not claim the repository is unavailable or ask the user for a path or file contents until workspace-relative discovery found no target. Do not say work was implemented unless the diff proves it.
  • Discovered workspace files must be completed in this turn when permitted. Use a host-native shell reader (sed/cat or Get-Content) only after a confirmed reader availability, transport, or path-normalization failure and only after verifying the canonical path remains inside the current workspace. Stop on content-exclusion, permission/policy, workspace-boundary, or unknown read failures. Use a shell edit fallback only for a confirmed editor availability, transport, or path-normalization failure, never for a stale context, concurrent change, permission/policy denial, or path-boundary error. Before fallback, resolve the canonical path inside the current workspace, freshly read the file, and require an anchored replacement with the expected old text and exact match count; abort if either changed. Then re-open the file, inspect the diff, and validate. Do not ask the user to paste a readable discovered file or report a proposed patch as completed work.

Step 1: Verify prerequisites

Before modifying any code:

  1. Confirm the wrapper/abstraction exists: Check that the interface or built-in abstraction is available in the project. For TimeProvider, verify the target framework is .NET 8+ or Microsoft.Bcl.TimeProvider is referenced. For System.IO.Abstractions, v
자주 묻는 질문

래퍼도 만드나요?

아니요. 래퍼가 없으면 먼저 테스트 가능성 래퍼 생성 스킬이 만들어야 합니다.

솔루션 전체를 한 번에 할 수 있나요?

이 스킬은 파일, 프로젝트, 네임스페이스처럼 제한된 범위에서 작업하므로 변경을 단계별로 할 수 있습니다.

정적 호출만 찾아 주나요?

아니요. 찾는 것은 별도의 탐지 스킬이 맡고, 이 스킬은 교체를 수행합니다.

상세 정보

작성자의 원본 설명

ALWAYS USE when asked to migrate, replace, or make testable existing C# static calls with a named wrapper or built-in abstraction: DateTime.UtcNow/Now or DateTimeOffset.UtcNow to TimeProvider/IClock, File.* to IFileSystem or an existing store such as ITextFileStore, and Environment.* to an existing reader such as IEnvironmentReader. Covers scoped files/projects, constructor injection, replacing temp-file or process-environment tests with fakes, "already registered" abstractions, and static classes whose callers/signatures must stay unchanged. Preserves DateTimeKind and call count. DO NOT USE f

repo: dotnet/skills

인기도

GitHub 스타
5.8k
순위
#14632
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬