Spaces:
Sleeping
Sleeping
| """ | |
| Level 1 Scenarios — Single-step fixes. | |
| These are the simplest scenarios requiring exactly one command to resolve. | |
| Used as the starting point for curriculum learning. | |
| """ | |
| from __future__ import annotations | |
| import re | |
| from typing import List | |
| from scenarios.registry import Scenario | |
| def _success_flask_installed(output: str) -> bool: | |
| """Check if flask was successfully installed or is available.""" | |
| output_lower = output.lower() | |
| return ( | |
| "successfully installed flask" in output_lower | |
| or "requirement already satisfied: flask" in output_lower | |
| or "already satisfied" in output_lower | |
| ) | |
| def _success_numpy_installed(output: str) -> bool: | |
| """Check if numpy was successfully installed or is available.""" | |
| output_lower = output.lower() | |
| return ( | |
| "successfully installed numpy" in output_lower | |
| or "requirement already satisfied: numpy" in output_lower | |
| or "already satisfied" in output_lower | |
| ) | |
| def _success_python3_used(output: str) -> bool: | |
| """Check if the script ran successfully with python3.""" | |
| output_lower = output.lower() | |
| return ( | |
| "server running" in output_lower | |
| or "hello world" in output_lower | |
| or "success" in output_lower | |
| or "exit code: 0" in output_lower | |
| ) | |
| def _success_requests_installed(output: str) -> bool: | |
| """Check if requests was successfully installed.""" | |
| output_lower = output.lower() | |
| return ( | |
| "successfully installed requests" in output_lower | |
| or "requirement already satisfied: requests" in output_lower | |
| ) | |
| def get_level1_scenarios() -> List[Scenario]: | |
| """Return all Level 1 (single-step fix) scenarios. | |
| Returns: | |
| List of Level 1 Scenario objects. | |
| """ | |
| return [ | |
| Scenario( | |
| id="missing_flask", | |
| level=1, | |
| description="Flask module is not installed. Python app fails with ModuleNotFoundError.", | |
| initial_state={ | |
| "files": { | |
| "/app/server.py": ( | |
| "from flask import Flask\n" | |
| "app = Flask(__name__)\n" | |
| "\n" | |
| "@app.route('/')\n" | |
| "def hello():\n" | |
| " return 'Hello World'\n" | |
| "\n" | |
| "if __name__ == '__main__':\n" | |
| " app.run(host='0.0.0.0', port=5000)\n" | |
| ) | |
| }, | |
| "env_vars": {}, | |
| "processes": [], | |
| }, | |
| success_condition=_success_flask_installed, | |
| hint_commands=["pip install flask"], | |
| error_fingerprint=r"ModuleNotFoundError.*flask", | |
| setup_commands=[ | |
| "mkdir -p /app", | |
| "cat > /app/server.py << 'EOF'\n" | |
| "from flask import Flask\n" | |
| "app = Flask(__name__)\n" | |
| "@app.route('/')\n" | |
| "def hello():\n" | |
| " return 'Hello World'\n" | |
| "if __name__ == '__main__':\n" | |
| " app.run(host='0.0.0.0', port=5000)\n" | |
| "EOF", | |
| "pip uninstall flask -y 2>/dev/null; true", | |
| ], | |
| initial_error_log=( | |
| "$ python /app/server.py\n" | |
| "Traceback (most recent call last):\n" | |
| " File \"/app/server.py\", line 1, in <module>\n" | |
| " from flask import Flask\n" | |
| "ModuleNotFoundError: No module named 'flask'\n" | |
| ), | |
| verification_command="python -c 'import flask; print(\"flask imported successfully\")'", | |
| ), | |
| Scenario( | |
| id="missing_numpy", | |
| level=1, | |
| description="NumPy module is not installed. Data processing script fails.", | |
| initial_state={ | |
| "files": { | |
| "/app/process.py": ( | |
| "import numpy as np\n" | |
| "data = np.array([1, 2, 3, 4, 5])\n" | |
| "print(f'Mean: {np.mean(data)}')\n" | |
| "print('Success')\n" | |
| ) | |
| }, | |
| "env_vars": {}, | |
| "processes": [], | |
| }, | |
| success_condition=_success_numpy_installed, | |
| hint_commands=["pip install numpy"], | |
| error_fingerprint=r"ModuleNotFoundError.*numpy", | |
| setup_commands=[ | |
| "mkdir -p /app", | |
| "cat > /app/process.py << 'EOF'\n" | |
| "import numpy as np\n" | |
| "data = np.array([1, 2, 3, 4, 5])\n" | |
| "print(f'Mean: {np.mean(data)}')\n" | |
| "print('Success')\n" | |
| "EOF", | |
| "pip uninstall numpy -y 2>/dev/null; true", | |
| ], | |
| initial_error_log=( | |
| "$ python /app/process.py\n" | |
| "Traceback (most recent call last):\n" | |
| " File \"/app/process.py\", line 1, in <module>\n" | |
| " import numpy as np\n" | |
| "ModuleNotFoundError: No module named 'numpy'\n" | |
| ), | |
| verification_command="python -c 'import numpy; print(\"numpy imported successfully\")'", | |
| ), | |
| Scenario( | |
| id="wrong_python_version", | |
| level=1, | |
| description="Script requires Python 3 but was called with Python 2 syntax.", | |
| initial_state={ | |
| "files": { | |
| "/app/main.py": ( | |
| "#!/usr/bin/env python3\n" | |
| "print(f'Hello from Python 3')\n" | |
| "data = {'key': 'value'}\n" | |
| "result = {**data, 'extra': True}\n" | |
| "print(f'Result: {result}')\n" | |
| "print('Success')\n" | |
| ) | |
| }, | |
| "env_vars": {}, | |
| "processes": [], | |
| }, | |
| success_condition=_success_python3_used, | |
| hint_commands=["python3 /app/main.py"], | |
| error_fingerprint=r"SyntaxError|invalid syntax", | |
| setup_commands=[ | |
| "mkdir -p /app", | |
| "cat > /app/main.py << 'EOF'\n" | |
| "#!/usr/bin/env python3\n" | |
| "print(f'Hello from Python 3')\n" | |
| "data = {'key': 'value'}\n" | |
| "result = {**data, 'extra': True}\n" | |
| "print(f'Result: {result}')\n" | |
| "print('Success')\n" | |
| "EOF", | |
| ], | |
| initial_error_log=( | |
| "$ python2 /app/main.py\n" | |
| " File \"/app/main.py\", line 2\n" | |
| " print(f'Hello from Python 3')\n" | |
| " ^\n" | |
| "SyntaxError: invalid syntax\n" | |
| "\n" | |
| "Note: The script has a python3 shebang but was invoked with python2.\n" | |
| ), | |
| verification_command="python3 /app/main.py", | |
| ), | |
| Scenario( | |
| id="missing_requests", | |
| level=1, | |
| description="Requests library not installed. API client script fails.", | |
| initial_state={ | |
| "files": { | |
| "/app/client.py": ( | |
| "import requests\n" | |
| "response = requests.get('https://httpbin.org/get')\n" | |
| "print(response.status_code)\n" | |
| "print('Success')\n" | |
| ) | |
| }, | |
| "env_vars": {}, | |
| "processes": [], | |
| }, | |
| success_condition=_success_requests_installed, | |
| hint_commands=["pip install requests"], | |
| error_fingerprint=r"ModuleNotFoundError.*requests", | |
| setup_commands=[ | |
| "mkdir -p /app", | |
| "cat > /app/client.py << 'EOF'\n" | |
| "import requests\n" | |
| "response = requests.get('https://httpbin.org/get')\n" | |
| "print(response.status_code)\n" | |
| "print('Success')\n" | |
| "EOF", | |
| "pip uninstall requests -y 2>/dev/null; true", | |
| ], | |
| initial_error_log=( | |
| "$ python /app/client.py\n" | |
| "Traceback (most recent call last):\n" | |
| " File \"/app/client.py\", line 1, in <module>\n" | |
| " import requests\n" | |
| "ModuleNotFoundError: No module named 'requests'\n" | |
| ), | |
| verification_command="python -c 'import requests; print(\"requests imported successfully\")'", | |
| ), | |
| ] | |