Datasets:
Download scripts/reusable_support/batch05_node_source_audit.py from CrossSWE/CrossSWE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.83 kB
-
https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/reusable_support/batch05_node_source_audit.py
- Command line
-
hf download hf://datasets/CrossSWE/CrossSWE-Bench/scripts/reusable_support/batch05_node_source_audit.py
-
curl -L -o batch05_node_source_audit.py https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/reusable_support/batch05_node_source_audit.py
2.83 kB
| """Run inside the untouched agent image; output contains no evaluator answers.""" | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import subprocess | |
| def git(path, *args, check=True): | |
| p = subprocess.run(['git', '-C', str(path), *args], text=True, capture_output=True) | |
| if check and p.returncode: | |
| raise RuntimeError(f'git {args[0]} failed: {p.returncode}') | |
| return p | |
| manifest = json.loads(Path('/opt/crossswe/instance.json').read_text()) | |
| out = {'manifest': manifest, 'repositories': []} | |
| for r in manifest['repositories']: | |
| path = Path(r['path']) | |
| base = r['base_commit'] | |
| head = git(path, 'rev-parse', 'HEAD').stdout.strip() | |
| tree = git(path, 'rev-parse', 'HEAD^{tree}').stdout.strip() | |
| status = git(path, 'status', '--porcelain=v1', '--untracked-files=all').stdout | |
| objects = git(path, 'cat-file', '--batch-all-objects', '--batch-check=%(objectname) %(objecttype)').stdout.splitlines() | |
| entries = git(path, 'ls-tree', '-r', '-t', 'HEAD').stdout.splitlines() | |
| expected = {base, tree} | {line.split()[2] for line in entries if not line.startswith('160000 ')} | |
| actual = {line.split()[0] for line in objects} | |
| assert head == base and tree == r['tree_sha1'] and not status | |
| assert actual == expected, 'Unexpected Git objects in agent image' | |
| assert [line.split()[0] for line in objects if line.endswith(' commit')] == [base] | |
| assert not (path / '.git/objects/info/alternates').exists() | |
| assert git(path, 'remote').stdout.strip() == '' | |
| gitlinks=[line for line in entries if line.startswith('160000 ')] | |
| assert len(gitlinks)==len(r.get('gitlinks',[])) | |
| for link in r.get('gitlinks',[]): | |
| assert not link['initialized'] | |
| assert any(line.split()[2]==link['commit'] and line.split('\t')[1]==link['path'] for line in gitlinks) | |
| assert (path/link['path']).is_dir() and not list((path/link['path']).iterdir()) | |
| listing = [] | |
| for file in sorted(path.rglob('*')): | |
| rel = file.relative_to(path) | |
| if '.git' in rel.parts or (not file.is_file() and not file.is_symlink()): | |
| continue | |
| if file.is_symlink(): | |
| import os | |
| listing.append((str(rel), 'symlink', os.readlink(file))) | |
| else: | |
| listing.append((str(rel), file.stat().st_mode & 0o777, hashlib.sha256(file.read_bytes()).hexdigest())) | |
| out['repositories'].append({'key': r['key'], 'head': head, 'tree': tree, | |
| 'clean': not status, 'git_object_count': len(actual), 'only_base_objects': True, | |
| 'files': len(listing), 'file_inventory_sha256': hashlib.sha256(json.dumps(listing).encode()).hexdigest()}) | |
| out['node'] = subprocess.check_output(['node', '--version'], text=True).strip() | |
| out['npm'] = subprocess.check_output(['npm', '--version'], text=True).strip() | |
| print(json.dumps(out, indent=2, sort_keys=True)) | |