vasiuuu/DGX_AI
0
1from __future__ import annotations2 3from dataclasses import dataclass4 5 6@dataclass(frozen=True)7class Task:8 task_id: str9 task_level: str10 brief: str11 initial_files: dict[str, str]12 target_score: float13 max_budget: int14 tools: tuple[str, ...]15 hidden_tests: dict[str, str] = () # type: ignore[assignment]16 """Hidden correctness tests injected by the environment during grading.17 18 The agent never sees these. They are written into the sandbox temp dir19 alongside the agent's submitted files so pytest runs them automatically.20 This prevents "clean garbage" exploits where syntactically valid but21 semantically wrong code scores perfectly.22 """23 24 25# -- Hidden test suites (agent never sees these) ----------------------------26 27_HIDDEN_EASY = {28 "test_hidden_greet.py": (29 "from __future__ import annotations\n"30 "from main import greet\n\n"31 "def test_greet_alice() -> None:\n"32 ' assert greet("Alice") == "Hello, Alice!"\n\n'33 "def test_greet_bob() -> None:\n"34 ' assert greet("Bob") == "Hello, Bob!"\n\n'35 "def test_greet_empty() -> None:\n"36 ' assert greet("") == "Hello, !"\n'37 ),38}39 40_HIDDEN_MEDIUM = {41 "test_hidden_greet.py": (42 "from __future__ import annotations\n"43 "import pytest\n"44 "from main import greet\n\n"45 "def test_greet_alice() -> None:\n"46 ' assert greet("Alice") == "Hello, Alice!"\n\n'47 "def test_greet_none_raises() -> None:\n"48 " with pytest.raises(ValueError):\n"49 " greet(None) # type: ignore[arg-type]\n\n"50 "def test_greet_returns_str() -> None:\n"51 ' assert isinstance(greet("X"), str)\n'52 ),53}54 55_HIDDEN_HARD = {56 "test_hidden_core.py": (57 "from __future__ import annotations\n"58 "import pytest\n"59 "from core import greet\n\n"60 "def test_greet_alice() -> None:\n"61 ' assert greet("Alice") == "Hello, Alice!"\n\n'62 "def test_greet_bob() -> None:\n"63 ' assert greet("Bob") == "Hello, Bob!"\n\n'64 "def test_greet_returns_str() -> None:\n"65 ' assert isinstance(greet("X"), str)\n\n'66 "def test_greet_empty() -> None:\n"67 ' assert greet("") == "Hello, !"\n'68 ),69}70 71 72TASKS: tuple[Task, ...] = (73 Task(74 task_id="greet_single_file",75 task_level="easy",76 brief=(77 "Implement `greet(name)` in `main.py` so that `greet(\"Alice\")` returns "78 '`"Hello, Alice!"`. Use type hints. Keep the module under 15 lines.'79 ),80 initial_files={"main.py": "def greet(name):\n pass\n"},81 target_score=0.90,82 max_budget=4,83 tools=("ruff", "imports", "mypy", "pytest"),84 hidden_tests=_HIDDEN_EASY,85 ),86 Task(87 task_id="greet_with_tests",88 task_level="medium",89 brief=(90 "Extend `main.py` so that `greet(None)` raises `ValueError`, "91 "and add a `test_main.py` with pytest assertions. Keep `ruff` and "92 "`mypy --strict` clean."93 ),94 initial_files={95 "main.py": (96 "from __future__ import annotations\n\n\n"97 "def greet(name: str) -> str:\n"98 ' return f"Hello, {name}!"\n'99 ),100 "test_main.py": "",101 },102 target_score=0.80,103 max_budget=6,104 tools=("ruff", "imports", "mypy", "pytest"),105 hidden_tests=_HIDDEN_MEDIUM,106 ),107 Task(108 task_id="multi_file_module",109 task_level="hard",110 brief=(111 "Split into three files: `main.py` (entry), `core.py` (the greet "112 "function), `test_core.py` (tests). Every function must be type-hinted. "113 "All tests pass. `mypy --strict` clean."114 ),115 initial_files={116 "main.py": (117 "from __future__ import annotations\n\nfrom core import greet\n\n\n"118 'if __name__ == "__main__":\n'119 ' print(greet("World"))\n'120 ),121 "core.py": "",122 "test_core.py": "",123 },124 target_score=0.70,125 max_budget=10,126 tools=("ruff", "imports", "mypy", "pytest"),127 hidden_tests=_HIDDEN_HARD,128 ),129)130 131 132def get_task(task_level: str) -> Task:133 for t in TASKS:134 if t.task_level == task_level:135 return t136 msg = f"unknown task_level: {task_level!r} (expected easy|medium|hard)"137 raise ValueError(msg)138 