Download release/manipulationarena/validation.py from AI45Research/ManipulationArena: direct link, hf CLI and curl.
- Browser
- Download file 4.27 kB
-
https://huggingface.co/datasets/AI45Research/ManipulationArena/resolve/main/release/manipulationarena/validation.py
- Command line
-
hf download hf://datasets/AI45Research/ManipulationArena/release/manipulationarena/validation.py
-
curl -L -o validation.py https://huggingface.co/datasets/AI45Research/ManipulationArena/resolve/main/release/manipulationarena/validation.py
4.27 kB
| """Offline release validation. No task, model, or container is started.""" | |
| from __future__ import annotations | |
| import ast | |
| import collections | |
| from pathlib import Path | |
| import re | |
| from .dataset import Dataset | |
| from .io import digest, inside, read_json, sha256 | |
| from .task_start import validate_frozen_start | |
| def validate(root: Path, require_checksums: bool = False) -> dict: | |
| errors = [] | |
| dataset = Dataset(root) | |
| inventory = read_json(root / 'index/inventory.json') | |
| actual = collections.Counter(u.family for u in dataset.units.values()) | |
| if len(dataset.units) != inventory['total_units']: | |
| errors.append('Inventory total differs from the index') | |
| for family, entry in inventory['families'].items(): | |
| selected = dataset.select(family=family) | |
| if actual[family] != entry['units'] or sorted(u.key for u in selected) != entry['unit_keys']: | |
| errors.append('Inventory unit set differs: ' + family) | |
| if sorted({u.metadata['task_id'] for u in selected}) != entry['task_ids']: | |
| errors.append('Inventory task set differs: ' + family) | |
| for unit in dataset.units.values(): | |
| try: | |
| if sha256(inside(root, unit.metadata['unit_path'])) != unit.metadata['unit_sha256']: | |
| raise ValueError('Unit descriptor checksum mismatch') | |
| plan = unit.load_plan() | |
| if unit.family == 'obstruction-attack': | |
| folder = inside(root, unit.metadata['unit_path']).parent | |
| init = read_json(folder / 'initialization.json') | |
| if init['plan'] != plan or init['initialization_id'] != digest({k: v for k, v in init.items() if k != 'initialization_id'}): | |
| raise ValueError('Initialization identity mismatch') | |
| validate_frozen_start(read_json(folder / 'attack_start.json'), init, plan) | |
| except (ValueError, KeyError, OSError) as exc: | |
| errors.append(unit.key + ': ' + str(exc)) | |
| engines = read_json(root / 'engine/profiles.json') | |
| for name, engine in engines['profiles'].items(): | |
| if ('harness/prompts/tool_catalog.py' in engine['files'] | |
| and 'harness/reference/mcp_tool_catalog.json' not in engine['files']): | |
| errors.append(name + ': Required MCP tool catalog is missing') | |
| for relative, entry in engine['files'].items(): | |
| try: | |
| inside(Path('/engine'), relative) | |
| path = inside(root, entry['path']) | |
| if sha256(path) != entry['sha256']: | |
| raise ValueError('Module checksum mismatch') | |
| if path.suffix == '.py': ast.parse(path.read_text()) | |
| except (ValueError, SyntaxError, OSError) as exc: | |
| errors.append(name + '/' + relative + ': ' + str(exc)) | |
| expected_paths = set() | |
| checksums = root / 'SHA256SUMS' | |
| if checksums.is_file(): | |
| for line in checksums.read_text().splitlines(): | |
| try: | |
| expected, relative = line.split(' ', 1) | |
| if not re.fullmatch(r'[0-9a-f]{64}', expected) or relative in expected_paths: | |
| raise ValueError('Invalid or repeated checksum') | |
| path = inside(root, relative) | |
| expected_paths.add(relative) | |
| if sha256(path) != expected: errors.append('File checksum mismatch: ' + relative) | |
| except (ValueError, OSError): errors.append('Invalid checksum entry') | |
| actual_paths = {p.relative_to(root).as_posix() for p in root.rglob('*') if p.is_file() and p != checksums} | |
| if actual_paths != expected_paths: | |
| errors.append('Checksum inventory does not cover the exact file set') | |
| elif require_checksums: | |
| errors.append('SHA256SUMS is required') | |
| for path in root.rglob('*'): | |
| if path.is_symlink(): errors.append('Symbolic link in release: ' + str(path.relative_to(root))) | |
| if path.name in {'__pycache__', '.env', '.DS_Store', 'results', 'runs', 'outcomes'} or path.name.startswith('._'): | |
| errors.append('Runtime or local state in release: ' + str(path.relative_to(root))) | |
| return {'valid': not errors, 'units': len(dataset.units), 'families': dict(actual), | |
| 'engine_profiles': len(engines['profiles']), 'errors': errors} | |