Team Ai
Apppublic

jester1177/cloud-native-debug-env

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
task_3_workflow_syntax.py222 linesDownload Raw Back to tasks
1"""Task 3: Workflow Syntax and Structure — EASY.2 3Agent fixes GitHub Actions YAML syntax and job structure issues:4step ordering, missing runs-on, invalid triggers, duplicate job IDs,5and missing 'on' trigger.6"""7 8 9 10from server.models import TaskDifficulty11from server.tasks.base import BaseTask12 13 14class WorkflowSyntaxStructureTask(BaseTask):15    NAME = "Workflow Syntax and Structure"16    DESCRIPTION = "Fix GitHub Actions YAML syntax and job structure issues"17    DIFFICULTY = TaskDifficulty.EASY18    AVAILABLE_SECRETS = ["GITHUB_TOKEN"]19 20    SCENARIOS = [21        # Scenario 1: Checkout happens after build (wrong step order)22        {23            "id": "checkout_after_build",24            "files": [25                {26                    "path": ".github/workflows/build.yml",27                    "type": "workflow",28                    "content": (29                        "name: Build\n"30                        "on: push\n"31                        "\n"32                        "jobs:\n"33                        "  build:\n"34                        "    runs-on: ubuntu-latest\n"35                        "    steps:\n"36                        "      - name: Build Docker image\n"37                        "        run: docker build -t myapp .\n"38                        "      - uses: actions/checkout@v4\n"39                        "      - name: Run tests\n"40                        "        run: docker run myapp pytest"41                    ),42                },43                {44                    "path": "Dockerfile",45                    "type": "dockerfile",46                    "content": (47                        "FROM python:3.11-slim\n"48                        "WORKDIR /app\n"49                        "COPY . .\n"50                        'CMD ["python", "app.py"]'51                    ),52                },53            ],54            "error": {55                "phase": "workflow_parse",56                "message": (57                    "unable to prepare context: unable to evaluate symlinks "58                    "in Dockerfile path: lstat /home/runner/work/repo/repo/Dockerfile: "59                    "no such file or directory"60                ),61                "exit_code": 1,62                "failed_step": "Build Docker image",63            },64            "expected_fixes": [65                {66                    "file": ".github/workflows/build.yml",67                    "type": "contains",68                    "expected": "- uses: actions/checkout@v4",69                    "hint": "Checkout must happen before any build commands",70                }71            ],72        },73 74        # Scenario 2: Missing runs-on field in job75        {76            "id": "missing_runs_on",77            "files": [78                {79                    "path": ".github/workflows/ci.yml",80                    "type": "workflow",81                    "content": (82                        "name: CI Pipeline\n"83                        "on: [push, pull_request]\n"84                        "\n"85                        "jobs:\n"86                        "  test:\n"87                        "    steps:\n"88                        "      - uses: actions/checkout@v4\n"89                        "      - name: Run tests\n"90                        "        run: npm test"91                    ),92                },93            ],94            "error": {95                "phase": "workflow_parse",96                "message": "Job 'test' is missing required field 'runs-on'",97                "exit_code": 1,98            },99            "expected_fixes": [100                {101                    "file": ".github/workflows/ci.yml",102                    "type": "contains",103                    "expected": "runs-on:",104                    "hint": "Every job must specify a 'runs-on' field (e.g. runs-on: ubuntu-latest)",105                }106            ],107        },108 109        # Scenario 3: Invalid event trigger syntax110        {111            "id": "invalid_trigger_syntax",112            "files": [113                {114                    "path": ".github/workflows/deploy.yml",115                    "type": "workflow",116                    "content": (117                        "name: Deploy\n"118                        "on:\n"119                        "  push:\n"120                        "    branches: main\n"121                        "\n"122                        "jobs:\n"123                        "  deploy:\n"124                        "    runs-on: ubuntu-latest\n"125                        "    steps:\n"126                        "      - uses: actions/checkout@v4\n"127                        "      - name: Deploy\n"128                        "        run: echo 'deploying...'"129                    ),130                },131            ],132            "error": {133                "phase": "workflow_parse",134                "message": (135                    "Unexpected value 'main' for 'on.push.branches'. "136                    "Expected a sequence (list) value."137                ),138                "exit_code": 1,139            },140            "expected_fixes": [141                {142                    "file": ".github/workflows/deploy.yml",143                    "type": "contains",144                    "expected": "branches: [main]",145                    "hint": "branches must be a list: branches: [main] or branches:\\n  - main",146                }147            ],148        },149 150        # Scenario 4: Duplicate step IDs / missing step name151        {152            "id": "missing_step_uses_or_run",153            "files": [154                {155                    "path": ".github/workflows/lint.yml",156                    "type": "workflow",157                    "content": (158                        "name: Lint\n"159                        "on: push\n"160                        "\n"161                        "jobs:\n"162                        "  lint:\n"163                        "    runs-on: ubuntu-latest\n"164                        "    steps:\n"165                        "      - uses: actions/checkout@v4\n"166                        "      - name: Install dependencies\n"167                        "        run: npm ci\n"168                        "      - name: Run linter\n"169                    ),170                },171            ],172            "error": {173                "phase": "workflow_parse",174                "message": "Every step must define a 'uses' or 'run' key. Step 'Run linter' has neither.",175                "exit_code": 1,176            },177            "expected_fixes": [178                {179                    "file": ".github/workflows/lint.yml",180                    "type": "contains",181                    "expected": "run:",182                    "hint": "The 'Run linter' step is missing a 'run' command — add e.g. run: npm run lint",183                }184            ],185        },186 187        # Scenario 5: Missing 'on' trigger entirely188        {189            "id": "missing_on_trigger",190            "files": [191                {192                    "path": ".github/workflows/test.yml",193                    "type": "workflow",194                    "content": (195                        "name: Test Suite\n"196                        "\n"197                        "jobs:\n"198                        "  test:\n"199                        "    runs-on: ubuntu-latest\n"200                        "    steps:\n"201                        "      - uses: actions/checkout@v4\n"202                        "      - name: Run tests\n"203                        "        run: pytest tests/ -v"204                    ),205                },206            ],207            "error": {208                "phase": "workflow_parse",209                "message": "Workflow must define an 'on' trigger event",210                "exit_code": 1,211            },212            "expected_fixes": [213                {214                    "file": ".github/workflows/test.yml",215                    "type": "contains",216                    "expected": "on:",217                    "hint": "Workflow is missing the required 'on' trigger — add e.g. on: push",218                }219            ],220        },221    ]222