agentleFS
idavidov13idavidov13/agentic-playwright/.cursor/skills/refactor-values/SKILL.md

refactor-values

Skill222 starsChanged 4 months agoMITView on GitHub

Safe refactoring workflow for enum values, enum keys, and static test data in test-data/static/*.ts — mandatory impact analysis, cascading updates, and verification. Use BEFORE changing any enum member's string value (ApiEndpoints.*, Messages.*, Roles, StorageStatePaths), renaming any enum key, or editing any existing file under test-data/static/. Running this workflow prevents silent test failures, TypeScript errors from stale imports, and assertion drift from hardcoded strings that bypass the enum. For defining NEW enums see the enums skill; for adding NEW static data see the data-strategy skill (three-tier rule).

The file

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 8 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    ALWAYS: run Phase 1 (find all consumers) before making any edit.

    line 11
  2. Very specific:

    ALWAYS: search for both the enum key (Messages.LOGIN_ERROR) and the raw string value ('Invalid email or password').

    line 12
  3. Distinctive:

    NEVER: update an enum value, rename a key, or edit a static-data file without updating every consumer in the same commit (atomicity — no …

    line 13
  4. Very specific:

    ALWAYS: run npx tsc --noEmit + npx eslint .

    line 15
  5. Distinctive:

    NEVER: use a single global find-and-replace — it misses case variants, hardcoded copies, and references inside comments, documentation, and …

    line 16
  6. Distinctive:

    Search the entire codebase for every occurrence of both:

    line 22
  7. Very specific:

    Use rg (ripgrep) when available — faster and more ergonomic — or grep -r as a universal fallback:

    line 27
  8. Distinctive:

    Update the source (enum or static-data file) and all consumers in one pass.

    line 78
  9. Distinctive:

    Update every consumer identified in Phase 1.

    line 83
  10. Distinctive:

    Run TypeScript compile check.

    line 84
  11. Very specific:

    If the change touches a single spec file, run that file directly instead of --grep.

    line 104
  12. Distinctive:

    If any test fails, trace the failure back to a missed consumer from Phase 1 and update it.

    line 106

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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

Refactoring Enum Values and Static Test Data

Critical

  • ALWAYS run Phase 1 (find all consumers) before making any edit. Enum values and static data feed into tests, page objects, schemas, and assertions — the blast radius must be known up front.
  • ALWAYS search for both the enum key (Messages.LOGIN_ERROR) and the raw string value ('Invalid email or password'). Some consumers may have bypassed the enum and hardcoded the string — they won't update when you change the enum.
  • NEVER update an enum value, rename a key, or edit a static-data file without updating every consumer in the same commit (atomicity — no intermediate broken state).
  • NEVER loosen a Zod schema (z.literal / z.enum) to make an updated value pass. Update the schema to match the new value; the schema is the contract.
  • ALWAYS run npx tsc --noEmit + npx eslint . + the affected tests before concluding the refactor. TypeScript catches key renames; eslint catches stale patterns; tests catch assertion drift.
  • NEVER use a single global find-and-replace — it misses case variants, hardcoded copies, and references inside comments, documentation, and sibling skill files. Inspect each match.

Instructions

Phase 1: Find all consumers before touching anything

Search the entire codebase for every occurrence of both:

  1. The enum key (the import reference consumers use).
  2. The current string value (the raw string — catches hardcoded usages that bypass the enum).

Use rg (ripgrep) when available — faster and more ergonomic — or grep -r as a universal fallback:

# Find all usages of the enum key
rg "Messages.LOGIN_ERROR" .
grep -r "Messages.LOGIN_ERROR" .

# Find all usages of the raw string value
rg "Invalid email or password" .
grep -r "Invalid email or password" .

# For endpoint changes, search both
rg "ApiEndpoints.LOGIN" .
rg "'/api/users/login'" .

Do this before making any edits. Understand the full blast radius first. Expect matches in .ts, .tsx, .md (skill files, README, CHANGELOG), .json (Playwright reports — ignore), and .cursor/rules/*.

Phase 2: Categorize impact using the right table

Pick the table that matches the change you are making.

For enum string-value changes (changing what the member resolves to):

Consumer TypeWhat to CheckAction Required
Tests with toHaveText() / toBeVisible() using the old raw valueWill fail if hardcodedUpdate to use enum or new value
Page object locators using getByText(Messages.X)Auto-updated via enumNo change needed — enum reference already correct
Zod schemas with z.literal('old-value') or z.enum([..., 'old-value'])Will reject new valueUpdate literal/enum to new value
API endpoint paths in apiRequest callsWill call wrong URLUpdate enum reference or hardcoded path
Static data in test-data/static/*.ts using the old string as expected valueTest data mismatchUpdate the as const entry
Other enum members that derive from this valueIndirect breakageAudit and update

For enum key renames (e.g., LOGIN_ERROR → AUTH_FAILURE):

Consumer TypeWhat to CheckAction Required
Every file importing and using the old keyTypeScript compile errorRename key reference in every file
Re-exports or barrel filesMay silently pass at runtimeCheck index.ts files
Documentation / skill files referring to the old nameReader confusionUpdate .md files too

For static data value changes (editing a file in test-data/static/*.ts):

Consumer TypeWhat to CheckAction Required
Tests importing the named as const export and looping over itMay use the changed value in an assertionVerify test assertions still match new data
Tests asserting against a specific value from the file directlyWill failUpdate hardcoded expected value in the test
Enum members mirroring the static-data stringOut of syncUpdate the matching enum member

Phase 3: Make all changes atomically

Update the source (enum or static-data file) and all consumers in one pass. Never leave an intermediate broken state where the value is changed but consumers still reference the old value.

Recommended order:

  1. Change the enum value / rename the key / update the as const entry in the static-data file.
  2. Update every consumer identified in Phase 1.
  3. Run TypeScript compile check.
  4. Lint.
  5. Run affected tests.

Phase 4: Verify no breakage

# 1. TypeScript -- catches key renames and type mismatches
npx tsc --noEmit

# 2. Lint
npx eslint .

# 3. Run tests that use the changed value (adjust grep pattern)
npx playwright test --grep "@api"

Notes on npx playwright test --grep:

  • Matches against tag names (@smoke, @api, etc.) and against test titles. Use the most specific filter.
  • If the change touches a single spec file, run that file directly instead of --grep.

If any test fails, trace the failure back to a missed consumer from Phase 1 and update it.

Anti-Patterns

// ANTI-PATTERN 1 -- string value changed but test still hardcodes old value
export enum Messages {
    LOGIN_ERROR = 'Incorrect credentials. Please try again.', // updated
}

// This test now fails silently -- old string no longer matches the UI:
await expect(page.getByText('Invalid email or password')).toBeVisible(); // STALE
// ANTI-PATTERN 2 -- enum key renamed but not all usages updated
// File A: updated ✅
Messages.AUTH_FAILURE;

// File B: still using old key -- TypeScript error (caught by tsc --noEmit)
Messages.LOGIN_ERROR; // ❌ Property 'LOGIN_ERROR' does not exist
// ANTI-PATTERN 3 -- static data changed but assertion not updated
// test-data/static/app/invalidCredentials.ts was updated with a new password
// but the test still asserts the old password is present in the response
expect(response.password).toBe('WrongPassword123!'); // ❌ stale assertion
// ANTI-PATTERN 4 -- Zod schema loosened to "fix" a drift
// BEFORE
role: z.literal('admin'),

// WRONG -- hides future drift instead of tracking the contract
role: z.string(),

// CORRECT -- update the literal to the new value (or switch to z.enum([...])
// if multiple values are valid)
role: z.literal('administrator'),

See Also

  • enums skill — enum conventions, organization, and how to define NEW enums (this skill covers CHANGING existing ones).
  • data-strategy skill — static data file structure (.ts with as const exports, three-tier rule) and how to ADD new static data.
  • test-standards skill — how data-driven tests import and use static TS modules.
  • type-safety skill — Zod schema patterns; z.literal() and z.enum() that may reference enum values.
  • api-testing skill — consumers of ApiEndpoints.* and how schema drift is handled via test.skip + // FIXME:.
  • debugging skill — Phase 4 verification failures during a refactor (text mismatch, ZodError, strict-mode violation) — classify the failure and use the right tool before assuming the refactor itself is wrong.
  • references/examples.md — four worked refactors (endpoint URL change, UI message wording change, enum key rename, static-data value change).
  • references/troubleshooting.md — common refactor pitfalls (hardcoded-old-string failure, missed consumer, --grep confusion, Zod literal drift, find-and-replace gaps in docs/mirrors).

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.