Closed-Loop Self-Healing
CI Test Runners
Intercept failing Playwright and unit test steps in CI, parse stack traces, and allow agents to open targeted auto-fix pull requests
On Day 11, you configure a closed-loop self-healing mechanism that intercepts Playwright CI test failures, extracts the failing selector from stack traces, generates a targeted remediation patch, and validates the repair locally.
Playwright JSON Reporter & Failure Artifacts
Configure Playwright to output structured JSON execution artifacts to enable automated error extraction.
playwright.config.ts includes the JSON reporter:export default {
reporter: [
['json', { outputFile: 'test-results/results.json' }],
['list']
]
};Closed-Loop Self-Repair Prompt & Sample Response
Instruct your AI assistant to generate the self-healing runner script that parses test failures and synthesizes patch files.
@workspace Create a closed-loop self-healing mechanism for Playwright CI test failures.
Please write a utility scripts/qe-part2/self-heal-runner.js that:
1. Intercepts failed test runs from Playwright test output (test-results/results.json).
2. Extracts the exact failure error message, expected vs actual locator, and stack trace.
3. Invokes an agent prompt to suggest a target code patch for the failing selector or state wait.
4. Saves the proposed fix into a patch file fixes/auto-repair.patch.
Demonstrate how to run this script conditionally when npx playwright test exits with code 1.I have created `scripts/qe-part2/self-heal-runner.js`.
Self-Healing Pipeline Flow:
1. Intercepts Exit Code 1 from Playwright.
2. Locates error stack trace in `test-results/results.json`.
3. Isolates broken locator: page.getByRole("button", { name: "Submit Login" }).
4. Synthesizes regex-resilient selector: page.getByRole("button", { name: /Sign In|Submit Login/i }).
5. Emits Unified Git Diff to `fixes/auto-repair.patch`.
β
Execute locally via: node scripts/qe-part2/self-heal-runner.jsLocal Self-Healing Execution & Patch Application
Run the self-heal runner locally, inspect the generated patch, and apply the repair to your project.
node scripts/qe-part2/self-heal-runner.jscat fixes/auto-repair.patch
git apply fixes/auto-repair.patch- name: Run Playwright Tests
id: playwright-tests
run: npx playwright test
continue-on-error: true
- name: Closed-Loop Self-Healing (On Failure Only)
if: steps.playwright-tests.outcome == 'failure'
run: |
echo "[WARNING] Tests failed. Intercepting failure traces..."
node scripts/qe-part2/self-heal-runner.jsVerification Loop, Troubleshooting & Done Checklist
Verify your self-healing loop operates deterministically without masking application bugs.
- β
Test failure traces in
test-results/are parsed accurately. - β
fixes/auto-repair.patchis generated as a unified Git diff. - β
Running
git apply fixes/auto-repair.patchresolves the locator mismatch.
β’ Single Retry Limit: Always constrain self-healing to **1 retry attempt** per pipeline run to avoid runaway agent cost and timeouts.
β’ Guard Business Logic: Self-healing agents should only adjust test locators and wait conditions. Reject any automated patch that alters core application business logic.