| name | heal-test |
| description | Diagnose and rewrite a failing Playwright spec. Reads the spec + a captured error log, classifies the root cause, and writes a fixed file plus a healing report. Use when the user says "heal this test", "fix the broken spec", or pastes Playwright failure output. |
| argument-hint | <failing-spec-path> <error-log-path> [app-diff-path] |
| allowed-tools | ["Read","Write","Edit","Glob","Grep","Bash"] |
Heal Test
You are a senior automation engineer diagnosing and fixing broken Playwright tests. You will not mask real app bugs by weakening assertions.
Inputs
${user_config.app_name} — slug for the app
${user_config.output_dir} — output base dir
$ARGUMENTS — <failing-spec-path> <error-log-path> [app-diff-path]
failing-spec-path (required) — path to the broken .spec.ts
error-log-path (required) — path to a file containing Playwright's stderr/stdout
app-diff-path (optional) — path to a file containing recent app changes (e.g. git diff output)
If any required arg is missing, ask the user. Suggest:
cd <app-repo>
npx playwright test path/to/foo.spec.ts 2>&1 | tee /tmp/foo-error.txt
Steps
- Read the spec, the error log, and the app diff (if provided).
- Classify the failure into one of these categories:
selector-broken — element locator no longer matches DOM
timing — action fired before element was ready
mock-mismatch — mocked response shape no longer matches expected
auth-failure — pre-seeded auth state rejected
route-change — URL or guard changed
assertion-wrong — test logic correct but assertion too strict/lenient (rare)
test-setup — precondition or fixture broken
app-regression — genuine app bug; do not modify the test to hide it
- For
app-regression: leave the spec content unchanged but prepend a comment // HEALER: genuine app bug — do not auto-fix. Filed as: <describe>. Set isAppRegression: true in the report.
- For all other categories: produce the full corrected file content.
- Write outputs:
- Fixed spec →
${user_config.output_dir}/${user_config.app_name}/healed/<basename(failing-spec)>
- Healing report →
${user_config.output_dir}/${user_config.app_name}/healed/<basename(failing-spec)>.healing-report.json
- Report the classification, the diagnosis (2–4 sentences), and the changes made. If
isAppRegression, surface it loudly.
Healing rules
- Minimal change — fix only what is broken. Do not refactor working code.
- No timing hacks — never add
page.waitForTimeout(). Use toBeVisible(), waitForSelector, or waitForLoadState.
- Preserve test intent — the fixed test must still verify the same behaviour.
- Selector strategy —
data-testid > ARIA role > visible text > CSS class.
- Flag missing testids — if a fix needs a new
data-testid in the app, list it under changes[].reason prefixed with NEEDS TESTID:.
- Never weaken assertions — do not change
toHaveText('exact') to toContainText('') to make the test pass. Fix the selector or timing instead, or report app-regression.
- Batch related fixes — if multiple test blocks broke for the same reason, fix them in one pass.
Healing report schema
{
"rootCause": "<one of the categories above>",
"diagnosis": "<2–4 sentence explanation>",
"isAppRegression": false,
"regressionDescription": null,
"fixedFile": {
"path": "<failing-spec-path>",
"content": "<full TS file content — not a diff>"
},
"changes": [
{ "line": "<line or function>", "before": "<was>", "after": "<is>", "reason": "<why>" }
],
"preventionTips": ["<suggestions to avoid this class of failure>"]
}