Datasets:
Download scripts/test_batch05_runtime_resource.py from CrossSWE/CrossSWE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.16 kB
-
https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/test_batch05_runtime_resource.py
- Command line
-
hf download hf://datasets/CrossSWE/CrossSWE-Bench/scripts/test_batch05_runtime_resource.py
-
curl -L -o test_batch05_runtime_resource.py https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/test_batch05_runtime_resource.py
2.16 kB
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import tempfile | |
| import unittest | |
| import sys | |
| sys.path.insert(0,str(Path(__file__).resolve().parent/'reusable_support')) | |
| from batch05_runtime_resources import validate_runtime_descriptor,verify_runtime_files | |
| class ResourceBindingTests(unittest.TestCase): | |
| def descriptor(self,root): | |
| data=b'{}\n';(root/'bundle-manifest.json').write_bytes(data) | |
| h=hashlib.sha256(data).hexdigest() | |
| return dict(kind='frozen-evaluator-dependencies',image_ref='example/repo@sha256:'+'1'*64,container_path='/crossswe-evaluator',manifest_sha256=h,files=[dict(path='bundle-manifest.json',kind='file',bytes=len(data),sha256=h)]) | |
| def test_rejects_tampered_or_extra_dependency_bytes(self): | |
| with tempfile.TemporaryDirectory() as d: | |
| root=Path(d);r=self.descriptor(root);verify_runtime_files(root,r) | |
| (root/'bundle-manifest.json').write_bytes(b'bad') | |
| with self.assertRaises(AssertionError):verify_runtime_files(root,r) | |
| r=self.descriptor(root);(root/'extra').write_text('x') | |
| with self.assertRaises(AssertionError):verify_runtime_files(root,r) | |
| def test_rejects_path_escape_and_mutable_reference(self): | |
| with tempfile.TemporaryDirectory() as d: | |
| r=self.descriptor(Path(d));r['files'][0]['path']='../outside' | |
| with self.assertRaises(AssertionError):validate_runtime_descriptor(r) | |
| r=self.descriptor(Path(d));r['image_ref']='example/repo:latest' | |
| with self.assertRaises(AssertionError):validate_runtime_descriptor(r) | |
| def test_checks_symlink_metadata_without_reading_target(self): | |
| with tempfile.TemporaryDirectory() as d: | |
| root=Path(d);r=self.descriptor(root);target='/not-a-host-dependency' | |
| (root/'link').symlink_to(target);r['files'].append(dict(path='link',kind='symlink',target=target,bytes=len(target),sha256=hashlib.sha256(target.encode()).hexdigest())) | |
| verify_runtime_files(root,r) | |
| (root/'link').unlink();(root/'link').symlink_to('/other') | |
| with self.assertRaises(AssertionError):verify_runtime_files(root,r) | |