Datasets:
Download scripts/validate_reusable_images.py from CrossSWE/CrossSWE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.86 kB
-
https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/validate_reusable_images.py
- Command line
-
hf download hf://datasets/CrossSWE/CrossSWE-Bench/scripts/validate_reusable_images.py
-
curl -L -o validate_reusable_images.py https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/validate_reusable_images.py
2.86 kB
| """Validate reusable-image references, frozen inputs and closed context archives offline.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import re | |
| from common import ROOT,contained,sha256 | |
| from materialize_agent_context import archive_stream, current_context, verify_manifest | |
| def check(root,reference): | |
| path=contained(root,reference['path']) | |
| if path.is_symlink() or not path.is_file() or path.stat().st_size!=reference['bytes'] or sha256(path)!=reference['sha256']: | |
| raise ValueError('Artifact reference mismatch: '+reference['path']) | |
| return path | |
| def validate(root): | |
| rows=json.loads((root/'data/reusable-agent-images.json').read_text())['instances'] | |
| ids=[row['instance_id'] for row in rows] | |
| if not rows or len(ids)!=len(set(ids)):raise ValueError('Empty/duplicate image index') | |
| for row in rows: | |
| image_path=check(root,row['image']);image=json.loads(image_path.read_text());folder=image_path.parent | |
| if image['instance_id']!=row['instance_id'] or image['platform']!='linux/amd64' or image['model_independent'] is not True: | |
| raise ValueError('Image identity/platform differs') | |
| for name in ['registry_digest','amd64_manifest_digest','config_digest']: | |
| if not re.fullmatch(r'sha256:[0-9a-f]{64}',image[name]):raise ValueError('Mutable/invalid image digest') | |
| if image['image_ref']!=image['tag'].split(':',1)[0]+'@'+image['registry_digest']:raise ValueError('Image reference differs') | |
| task_root=contained(root/'instances',row['instance_id']);task=json.loads((task_root/'task.json').read_text()) | |
| if sha256(task_root/'task.json')!=image['task_sha256'] or sha256(task_root/task['evaluation']['path'])!=image['contract_sha256']: | |
| raise ValueError('Frozen task/contract hash differs') | |
| source=json.loads(check(folder,image['source_manifest']).read_text()) | |
| actual={r['key']:(r['repo'],r['base_commit'],r['path']) for r in source['repositories']} | |
| expected={r['key']:(r['repo'],r['base_commit'],r['container_path']) for r in task['repositories']} | |
| if actual!=expected:raise ValueError('Agent source manifest differs from task') | |
| check(folder,image['dockerfile']) | |
| context_path,recipe=current_context(root,row['instance_id']);context=json.loads(context_path.read_text()) | |
| with archive_stream(context_path.parent,context['archive']) as stream: | |
| if stream.read(2)!=b'\x1f\x8b':raise ValueError('Invalid context gzip header') | |
| verify_manifest(context_path) | |
| return {'state':'VERIFIED','reusable_images':len(rows),'instance_ids':ids,'runtime_or_model_calls':0} | |
| if __name__=='__main__': | |
| parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--root',type=Path,default=ROOT) | |
| print(json.dumps(validate(parser.parse_args().root.resolve()),sort_keys=True)) | |