|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Validate AgentBench lite preset configs. |
| 3 | +
|
| 4 | +Goal: a fast smoke check that doesn't require building Docker images or running |
| 5 | +any tasks. It only validates that: |
| 6 | +- lite config files exist and are valid YAML |
| 7 | +- referenced tasks exist in configs/tasks/task_assembly.yaml |
| 8 | +- lite assignment references tasks that exist in the task assembly |
| 9 | +
|
| 10 | +Run: |
| 11 | + python scripts/validate_lite_configs.py |
| 12 | +""" |
| 13 | + |
| 14 | +from __future__ import annotations |
| 15 | + |
| 16 | +import pathlib |
| 17 | +import sys |
| 18 | +from typing import Any, Dict, Set |
| 19 | + |
| 20 | +import yaml |
| 21 | + |
| 22 | +ROOT = pathlib.Path(__file__).resolve().parents[1] |
| 23 | + |
| 24 | + |
| 25 | +def load_yaml(path: pathlib.Path) -> Dict[str, Any]: |
| 26 | + try: |
| 27 | + with path.open("r", encoding="utf-8") as f: |
| 28 | + data = yaml.safe_load(f) |
| 29 | + except Exception as e: |
| 30 | + raise RuntimeError(f"Failed to parse YAML: {path}: {e}") |
| 31 | + if data is None: |
| 32 | + return {} |
| 33 | + if not isinstance(data, dict): |
| 34 | + raise RuntimeError(f"Expected mapping at top-level in {path}, got {type(data)}") |
| 35 | + return data |
| 36 | + |
| 37 | + |
| 38 | +def main() -> int: |
| 39 | + start_lite = ROOT / "configs" / "start_task_lite.yaml" |
| 40 | + assign_lite = ROOT / "configs" / "assignments" / "lite.yaml" |
| 41 | + task_assembly = ROOT / "configs" / "tasks" / "task_assembly.yaml" |
| 42 | + |
| 43 | + for p in (start_lite, assign_lite, task_assembly): |
| 44 | + if not p.exists(): |
| 45 | + raise RuntimeError(f"Missing required file: {p}") |
| 46 | + |
| 47 | + start_cfg = load_yaml(start_lite) |
| 48 | + assign_cfg = load_yaml(assign_lite) |
| 49 | + assembly_cfg = load_yaml(task_assembly) |
| 50 | + |
| 51 | + # Collect task names from imported task configs (based on file names). |
| 52 | + imports = assembly_cfg.get("import", []) |
| 53 | + if not isinstance(imports, list) or not all(isinstance(x, str) for x in imports): |
| 54 | + raise RuntimeError("configs/tasks/task_assembly.yaml must have a list field: import") |
| 55 | + |
| 56 | + task_names: Set[str] = set() |
| 57 | + for rel in imports: |
| 58 | + # rel like "webshop.yaml" -> file stem "webshop". |
| 59 | + task_names.add(pathlib.Path(rel).stem) |
| 60 | + |
| 61 | + # start_task_lite.yaml: ensure start keys look like known tasks. |
| 62 | + start = start_cfg.get("start", {}) |
| 63 | + if not isinstance(start, dict) or not start: |
| 64 | + raise RuntimeError("configs/start_task_lite.yaml must have non-empty mapping field: start") |
| 65 | + |
| 66 | + unknown_in_start = sorted([k for k in start.keys() if str(k).split("-")[0] not in task_names]) |
| 67 | + if unknown_in_start: |
| 68 | + raise RuntimeError( |
| 69 | + "start_task_lite.yaml references tasks not present in task_assembly imports: " |
| 70 | + + ", ".join(map(str, unknown_in_start)) |
| 71 | + ) |
| 72 | + |
| 73 | + # assignments/lite.yaml: ensure tasks exist. |
| 74 | + assignments = assign_cfg.get("assignments") |
| 75 | + if not isinstance(assignments, list) or not assignments: |
| 76 | + raise RuntimeError("configs/assignments/lite.yaml must have a non-empty list field: assignments") |
| 77 | + |
| 78 | + unknown_in_assign = [] |
| 79 | + for a in assignments: |
| 80 | + if not isinstance(a, dict): |
| 81 | + raise RuntimeError("Each assignment must be a mapping") |
| 82 | + tasks = a.get("task", []) |
| 83 | + if isinstance(tasks, str): |
| 84 | + tasks = [tasks] |
| 85 | + if not isinstance(tasks, list): |
| 86 | + raise RuntimeError("assignment.task must be a string or list") |
| 87 | + for t in tasks: |
| 88 | + base = str(t).split("-")[0] |
| 89 | + if base not in task_names: |
| 90 | + unknown_in_assign.append(t) |
| 91 | + |
| 92 | + if unknown_in_assign: |
| 93 | + raise RuntimeError( |
| 94 | + "assignments/lite.yaml references tasks not present in task_assembly imports: " |
| 95 | + + ", ".join(map(str, unknown_in_assign)) |
| 96 | + ) |
| 97 | + |
| 98 | + print("OK: lite configs look valid") |
| 99 | + return 0 |
| 100 | + |
| 101 | + |
| 102 | +if __name__ == "__main__": |
| 103 | + try: |
| 104 | + raise SystemExit(main()) |
| 105 | + except Exception as e: |
| 106 | + print(f"ERROR: {e}", file=sys.stderr) |
| 107 | + raise SystemExit(1) |
0 commit comments