Spaces:
Sleeping
Sleeping
| """ | |
| tasks/task_registry.py — Central task registry. | |
| All 9 tasks indexed by ID and difficulty. sample_task() picks randomly | |
| within a difficulty tier to prevent memorisation across episodes. | |
| """ | |
| import random | |
| from typing import Dict, Any | |
| from tasks.easy.password_validator import TASK as T1 | |
| from tasks.easy.input_sanitizer import TASK as T2 | |
| from tasks.easy.hash_generator import TASK as T3 | |
| from tasks.medium.sql_query_builder import TASK as T4 | |
| from tasks.medium.file_path_handler import TASK as T5 | |
| from tasks.medium.api_rate_limiter import TASK as T6 | |
| from tasks.hard.file_upload_handler import TASK as T7 | |
| from tasks.hard.jwt_validator import TASK as T8 | |
| from tasks.hard.auth_middleware import TASK as T9 | |
| ALL_TASKS: Dict[str, Dict[str, Any]] = { | |
| t["id"]: t for t in [T1, T2, T3, T4, T5, T6, T7, T8, T9] | |
| } | |
| BY_DIFFICULTY = { | |
| "easy": [T1, T2, T3], | |
| "medium": [T4, T5, T6], | |
| "hard": [T7, T8, T9], | |
| } | |
| def get_task(task_id: str) -> Dict[str, Any]: | |
| if task_id not in ALL_TASKS: | |
| raise ValueError(f"Unknown task_id: {task_id}. Valid: {list(ALL_TASKS.keys())}") | |
| return ALL_TASKS[task_id] | |
| def sample_task(difficulty: str = "medium") -> Dict[str, Any]: | |
| """Randomly pick a task at the given difficulty. Anti-memorisation.""" | |
| tasks = BY_DIFFICULTY.get(difficulty, BY_DIFFICULTY["medium"]) | |
| return random.choice(tasks) | |
| def list_tasks() -> list: | |
| return [ | |
| { | |
| "id": t["id"], | |
| "difficulty": t["difficulty"], | |
| "cwe_targets": t["cwe_targets"], | |
| } | |
| for t in ALL_TASKS.values() | |
| ] | |