Main/WordPress Fullstack/Blueprints/AI & Agents/Self-Healing CI/CD in GitHub Actions with Automated Bug Fixes
Back to «AI & Agents» cards
AI & Agents(ТЗ 46 из 54)
Spec: Self-Healing CI/CD in GitHub Actions with Automated Bug Fixes
AI & Agents5 шагов • +25 XP

Spec: Self-Healing CI/CD in GitHub Actions with Automated Bug Fixes

Designing an autonomous Self-Healing pipeline in GitHub Actions: intercepting test failures (Vitest/PHPUnit), extracting stack traces and AST context, calling LLM agents for minimal patch generation, and creating automated Pull Requests.

~10 ч работыУровень: SeniorGitHub Actions WorkflowDocker Isolated RunnerVitest / PlaywrightAnthropic Claude 3.7 / Claude Code@octokit/rest (GitHub API)Node.js 22 LTS
+5 XP за шаг
Выполнено 0 из 5 шагов (0%)
Трудозатраты~10 рабочих часов
Фриланс вилка~$450 – $750 (€400 – €700)
Оценка веб-студии~$950 – $1,600 (€900 – €1500)

ТЗ заказчика (исходный бриф):

“The bot must fix the code, NOT weaken or disable the failing unit tests.”
Ключевые требования:
  • •Trigger conditionally on workflow step failure (if: failure())
  • •Parse test report logs (Vitest / PHPUnit) into structured JSON format
  • •AST extraction of related source files and line ranges for LLM context
  • •Prompt engineering for generating minimal, targeted Unified Diff patches
  • •Safety guard: automated verification that no test files (*.test.*, *Test.php) were modified
Ограничения проекта:
  • •Budget cap: maximum 3 LLM correction attempts per build run
  • •Patch size limited to 100 lines of diff
Критерии приёмки (KPI):
  • ≥ 60% successful automatic resolution of broken builds
  • Mean time to fix < 3 minutes
  • Zero manual modifications required on generated PRs

Пошаговое практическое руководство по ТЗ

Подробный разбор архитектуры, код реализации и советы эксперта по каждому этапу:

1
Этап 1 из 5

Step 1: GitHub Actions Configuration with if: failure() Trigger

~45 минСредний

Практическое руководство:

Configure a dedicated self-healing job in .github/workflows/ci.yml with if: failure() condition. Ensure it pulls GitHub repository secrets for AI API keys.

План и контрольные точки реализации:
1Настроить вывод тестов в формат JSON
2Сконфигурировать upload/download артефактов
3Выдать необходимые permissions для GITHUB_TOKEN
Важные технические нюансы и подводные камни:

Grant contents: write and pull-requests: write permissions in job permissions block.

Ожидаемый артефакт этапа:

GitHub Actions пайплайн с изолированной джобой авто-исправления.

YAML
name: Continuous Integration & Self-Healing

on:
  push:
    branches: [main, develop]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v3
        with:
          version: 9
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: 'pnpm'

      - run: pnpm install --frozen-lockfile
      - name: Run Test Suite
        id: run_tests
        run: pnpm test --reporter=json --outputFile=test-results.json

      - name: Upload Test Results on Failure
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: vitest-failure-report
          path: test-results.json

  auto-heal:
    needs: test
    if: failure()
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - uses: actions/checkout@v4
      - uses: actions/download-artifact@v4
        with:
          name: vitest-failure-report
      - name: Run Self-Healing Agent
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: node scripts/self-heal/agent-fix-runner.mjs
2
Этап 2 из 5

Step 2: Error Log Parsing & Problem Context Localization

~45 минСредний
3
Этап 3 из 5

Step 3: Agentic Generation & Patch Application Cycle

~60 минСложный
4
Этап 4 из 5

Step 4: Safety Guard: Assert No Modification to Test Files

~30 минЛегкий
5
Этап 5 из 5

Step 5: Verification Run & Automated Pull Request Dispatch

~45 минСредний

Типичные грабли на этом ТЗ

3 антипаттерна

Что сдаём клиенту (Deliverables)

Чек-лист сдачи
Файл GitHub Actions workflow (.github/workflows/self-heal-ci.yml)
Скрипт парсинга логов Vitest/Jest (extract-failure-context.mjs)
Изолированный агентский скрипт исправления (agent-fix-runner.mjs)
Автоматическое открытие Pull Request через Octokit с детальным описанием
Защитный валидатор (test-tampering-detector.mjs) против изменения файлов тестов

Инструменты экосистемы Fullstack AI Lab для этого ТЗ

Интеграция