File size: 4,475 Bytes
0e239c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Verify released task, dataset, and image metadata without running containers."""
from pathlib import Path
import argparse, hashlib, json
from statement_text import read_problem_statement

ROOT = Path(__file__).resolve().parents[1]


def checksum(path):
    h = hashlib.sha256()
    with path.open('rb') as source:
        for data in iter(lambda:source.read(1024**2), b''):
            h.update(data)
    return h.hexdigest()


def validate(root, all_files=False):
    tasks = [json.loads(line) for line in (root / 'data/instances.jsonl').read_text().splitlines()]
    flat = [json.loads(line) for line in (root / 'data/crossswe-bench.jsonl').read_text().splitlines()]
    images = [json.loads(line) for line in (root / 'data/images.jsonl').read_text().splitlines()]
    registry = json.loads((root / 'data/reusable-agent-images.json').read_text())['instances']
    ids = [x['instance_id'] for x in tasks]
    assert len(ids) == len(set(ids)) == len(flat) == len(images) == len(registry) == 171
    assert ids == [x['instance_id'] for x in flat] == [x['instance_id'] for x in images]
    assert set(ids) == {x['instance_id'] for x in registry}
    assert {p.name for p in (root / 'instances').iterdir() if p.is_dir()} == set(ids)
    registry = {x['instance_id']:x['image'] for x in registry}
    bindings = {item['instance_id']:item for item in map(json.loads, (root / 'data/task-bindings.jsonl').read_text().splitlines())}
    assert set(bindings) == set(ids)
    checked = 0
    for task, record, image in zip(tasks, flat, images):
        prefix = root / 'instances' / task['instance_id']
        assert task == json.loads((prefix / 'task.json').read_text())
        binding = bindings[task['instance_id']]
        assert binding['task_sha256'] == checksum(prefix / 'task.json')
        assert binding['source_task_sha256'] == record['original_task_sha256']
        assert binding['contract_sha256'] == task['evaluation']['sha256']
        assert record['problem_statement'] == read_problem_statement(task, root)
        assert record['problem_statement'] == (root / 'statements' / (task['instance_id'] + '.md')).read_text(encoding='utf-8')
        assert record['PASS_TO_PASS_count'] == len(json.loads(record['PASS_TO_PASS']))
        assert record['FAIL_TO_PASS_count'] == len(json.loads(record['FAIL_TO_PASS']))
        assert record['image_ref'] == image['image_ref']
        assert image['image_descriptor_sha256'] == checksum(root / image['image_descriptor']), (task['instance_id'], 'image_descriptor_sha256')
        for field in ['PASS_TO_PASS', 'FAIL_TO_PASS']:
            values = json.loads(record[field])
            assert values and len(values) == len(set(values)) and all(isinstance(v, str) for v in values)
        assert not set(json.loads(record['PASS_TO_PASS'])) & set(json.loads(record['FAIL_TO_PASS']))
        for ref in task['artifacts']:
            path = prefix / ref['path']
            assert path.is_file() and path.stat().st_size == ref['bytes'] and checksum(path) == ref['sha256'], path
            checked += 1
        ref = registry[task['instance_id']]
        assert checksum(root / ref['path']) == ref['sha256']
        for patch in record['gold_patches'] + record['test_patches']:
            assert checksum(root / patch['path']) == patch['sha256']
    release = json.loads((root / 'release.json').read_text())
    logo = root / 'assets/crossswe-logo.png'
    assert checksum(logo) == release['logo_sha256'] == '217cd244582fa3bfb5a7cf2954caa1baf76de4ad824be79f481fdcad959deca1'
    total = 0
    if all_files:
        for line in (root / 'CHECKSUMS.sha256').read_text().splitlines():
            digest, relative = line.split('  ', 1)
            path = root / relative
            assert not Path(relative).is_absolute() and '..' not in Path(relative).parts
            assert checksum(path) == digest, relative
            total += 1
    return dict(state='RELEASE_METADATA_VERIFIED', tasks=171, repository_entries=sum(len(t['repositories']) for t in tasks),
                images=171, task_artifacts_checked=checked,
                all_file_checks=total, logo_unchanged=True, container_or_test_executions=0)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--root', type=Path, default=ROOT)
    parser.add_argument('--all-files', action='store_true')
    args = parser.parse_args()
    print(json.dumps(validate(args.root.resolve(), args.all_files), indent=2))