File size: 1,819 Bytes
85b7ac8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from __future__ import annotations

import random
from typing import Dict, Optional

from server.models import TaskDifficulty
from server.tasks.base import BaseTask


class WorkflowSyntaxStructureTask(BaseTask):
    NAME = "Workflow Syntax and Structure"
    DESCRIPTION = "Fix GitHub Actions YAML syntax and job structure issues"
    DIFFICULTY = TaskDifficulty.EASY
    AVAILABLE_SECRETS = ["GITHUB_TOKEN"]
    SCENARIOS = [
        {
            "id": "checkout_after_build",
            "files": [
                {
                    "path": ".github/workflows/build.yml",
                    "type": "workflow",
                    "content": "name: Build\non: push\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Build Docker image\n        run: docker build -t myapp .\n      - uses: actions/checkout@v4",
                },
                {"path": "Dockerfile", "type": "dockerfile", "content": "FROM python:3.11-slim\nWORKDIR /app\nCOPY . ."},
            ],
            "error": {
                "phase": "workflow_parse",
                "message": "Build step runs before source checkout",
            },
            "expected_fixes": [
                {
                    "file": ".github/workflows/build.yml",
                    "type": "contains",
                    "expected": "- uses: actions/checkout@v4",
                    "hint": "Checkout should happen before build commands",
                }
            ],
        }
    ]

    def load_scenario(self, scenario_id: Optional[str] = None) -> Dict:
        if scenario_id:
            for scenario in self.SCENARIOS:
                if scenario["id"] == scenario_id:
                    return scenario
            raise ValueError(f"Unknown scenario: {scenario_id}")
        return random.choice(self.SCENARIOS)