CrossSWE-Bench / scripts /test_batch05_runtime_resource.py
Silin-Chen's picture
CrossSWE-Bench: current 171-instance release
0e239c6
Raw History Blame Contribute Delete
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)