cloudnative-devops-debug-env / server /tasks /task_3_workflow_syntax.py
Krishna1107's picture
fixing old codes
a7caaff
"""Task 3: Workflow Syntax and Structure — EASY.
Agent fixes GitHub Actions YAML syntax and job structure issues:
step ordering, missing runs-on, invalid triggers, duplicate job IDs,
and missing 'on' trigger.
"""
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 = [
# Scenario 1: Checkout happens after build (wrong step order)
{
"id": "checkout_after_build",
"files": [
{
"path": ".github/workflows/build.yml",
"type": "workflow",
"content": (
"name: Build\n"
"on: push\n"
"\n"
"jobs:\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\n"
" - name: Run tests\n"
" run: docker run myapp pytest"
),
},
{
"path": "Dockerfile",
"type": "dockerfile",
"content": (
"FROM python:3.11-slim\n"
"WORKDIR /app\n"
"COPY . .\n"
'CMD ["python", "app.py"]'
),
},
],
"error": {
"phase": "workflow_parse",
"message": (
"unable to prepare context: unable to evaluate symlinks "
"in Dockerfile path: lstat /home/runner/work/repo/repo/Dockerfile: "
"no such file or directory"
),
"exit_code": 1,
"failed_step": "Build Docker image",
},
"expected_fixes": [
{
"file": ".github/workflows/build.yml",
"type": "contains",
"expected": "- uses: actions/checkout@v4",
"hint": "Checkout must happen before any build commands",
}
],
},
# Scenario 2: Missing runs-on field in job
{
"id": "missing_runs_on",
"files": [
{
"path": ".github/workflows/ci.yml",
"type": "workflow",
"content": (
"name: CI Pipeline\n"
"on: [push, pull_request]\n"
"\n"
"jobs:\n"
" test:\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
" - name: Run tests\n"
" run: npm test"
),
},
],
"error": {
"phase": "workflow_parse",
"message": "Job 'test' is missing required field 'runs-on'",
"exit_code": 1,
},
"expected_fixes": [
{
"file": ".github/workflows/ci.yml",
"type": "contains",
"expected": "runs-on:",
"hint": "Every job must specify a 'runs-on' field (e.g. runs-on: ubuntu-latest)",
}
],
},
# Scenario 3: Invalid event trigger syntax
{
"id": "invalid_trigger_syntax",
"files": [
{
"path": ".github/workflows/deploy.yml",
"type": "workflow",
"content": (
"name: Deploy\n"
"on:\n"
" push:\n"
" branches: main\n"
"\n"
"jobs:\n"
" deploy:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
" - name: Deploy\n"
" run: echo 'deploying...'"
),
},
],
"error": {
"phase": "workflow_parse",
"message": (
"Unexpected value 'main' for 'on.push.branches'. "
"Expected a sequence (list) value."
),
"exit_code": 1,
},
"expected_fixes": [
{
"file": ".github/workflows/deploy.yml",
"type": "contains",
"expected": "branches: [main]",
"hint": "branches must be a list: branches: [main] or branches:\\n - main",
}
],
},
# Scenario 4: Duplicate step IDs / missing step name
{
"id": "missing_step_uses_or_run",
"files": [
{
"path": ".github/workflows/lint.yml",
"type": "workflow",
"content": (
"name: Lint\n"
"on: push\n"
"\n"
"jobs:\n"
" lint:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
" - name: Install dependencies\n"
" run: npm ci\n"
" - name: Run linter\n"
),
},
],
"error": {
"phase": "workflow_parse",
"message": "Every step must define a 'uses' or 'run' key. Step 'Run linter' has neither.",
"exit_code": 1,
},
"expected_fixes": [
{
"file": ".github/workflows/lint.yml",
"type": "contains",
"expected": "run:",
"hint": "The 'Run linter' step is missing a 'run' command — add e.g. run: npm run lint",
}
],
},
# Scenario 5: Missing 'on' trigger entirely
{
"id": "missing_on_trigger",
"files": [
{
"path": ".github/workflows/test.yml",
"type": "workflow",
"content": (
"name: Test Suite\n"
"\n"
"jobs:\n"
" test:\n"
" runs-on: ubuntu-latest\n"
" steps:\n"
" - uses: actions/checkout@v4\n"
" - name: Run tests\n"
" run: pytest tests/ -v"
),
},
],
"error": {
"phase": "workflow_parse",
"message": "Workflow must define an 'on' trigger event",
"exit_code": 1,
},
"expected_fixes": [
{
"file": ".github/workflows/test.yml",
"type": "contains",
"expected": "on:",
"hint": "Workflow is missing the required 'on' trigger — add e.g. on: push",
}
],
},
]