Datasets:
Download scripts/validate_release.py from CrossSWE/CrossSWE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 10.2 kB
-
https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/validate_release.py
- Command line
-
hf download hf://datasets/CrossSWE/CrossSWE-Bench/scripts/validate_release.py
-
curl -L -o validate_release.py https://huggingface.co/datasets/CrossSWE/CrossSWE-Bench/resolve/main/scripts/validate_release.py
10.2 kB
| """Validate task indexes, artifact bytes and the release checksum inventory.""" | |
| import argparse | |
| import csv | |
| import json | |
| import re | |
| from pathlib import Path | |
| import sys | |
| from common import ROOT, contained, sha256 | |
| from source_construction import object_id | |
| def validate(root): | |
| root = Path(root).resolve() | |
| rows = [json.loads(line) for line in (root / "data/instances.jsonl").read_text().splitlines()] | |
| with (root / "release171.tsv").open() as stream: | |
| index = list(csv.DictReader(stream, delimiter="\t")) | |
| assert len(rows) == len(index) == 171, "Expected exactly 171 tasks" | |
| ids = [row["instance_id"] for row in rows] | |
| assert len(set(ids)) == 171, "Duplicate task IDs" | |
| assert ids == [row["instance_id"] for row in index], "TSV order differs" | |
| assert set(ids) == {p.name for p in (root / "instances").iterdir() if p.is_dir()}, "Directory set differs" | |
| with (root / "data/instance-id-map.tsv").open() as stream: | |
| aliases = list(csv.DictReader(stream, delimiter="\t")) | |
| assert len(aliases) == 171 and ids == [row["instance_id"] for row in aliases], "ID mapping differs" | |
| originals = [row["original_instance_id"] for row in aliases] | |
| assert len(set(originals)) == 171, "Original IDs must be unique" | |
| for row in aliases: | |
| assert row["original_instance_id"] not in ids or row["original_instance_id"] == row["instance_id"], "Ambiguous legacy ID" | |
| mapping = {row["instance_id"]: row for row in aliases} | |
| labels = {row['instance_id']:row for row in map(json.loads, (root / 'data/crossswe-bench.jsonl').read_text().splitlines())} | |
| assert set(labels) == set(ids), 'Annotation IDs differ' | |
| artifact_count = 0 | |
| for ordinal, (task, item) in enumerate(zip(rows, index), 1): | |
| instance_id = task["instance_id"] | |
| directory = contained(root / "instances", instance_id) | |
| assert task["ordinal"] == ordinal == int(item["ordinal"]), instance_id | |
| assert json.loads((directory / "task.json").read_text()) == task, instance_id | |
| assert item["task_path"] == f"instances/{instance_id}/task.json", instance_id | |
| assert json.loads((directory / "repos.json").read_text()) == task["repositories"], instance_id | |
| assert task["repositories"], instance_id | |
| identity = mapping[instance_id] | |
| naming = task["naming"] | |
| assert task["original_instance_id"] == identity["original_instance_id"] == item["original_instance_id"], instance_id | |
| assert naming["category"] == identity["category"], instance_id | |
| assert item["language"] == labels[instance_id]["language"] and item["task"] == labels[instance_id]["task"], instance_id | |
| assert identity["ordinal"] == str(ordinal), instance_id | |
| for field in ("primary_repository", "primary_pr_url"): | |
| assert naming[field] == identity[field], instance_id | |
| assert naming["primary_pr_number"] == int(identity["primary_pr_number"]), instance_id | |
| assert re.fullmatch(r"[a-z]+-[a-z0-9]+(?:-[a-z0-9]+)*-[1-9][0-9]*", instance_id), instance_id | |
| assert instance_id.startswith(naming["category"] + "-") and instance_id.endswith("-" + str(naming["primary_pr_number"])), instance_id | |
| assert naming["primary_repository"] in {r["repo"] for r in task["repositories"]}, instance_id | |
| provenance = json.loads((directory / task["provenance"]["path"]).read_text()) | |
| matches = [pr for pr in provenance["pull_requests"] if pr.get("repo", "").lower() == naming["primary_repository"].lower()] | |
| assert any(pr.get("url", "").removesuffix(".patch") == naming["primary_pr_url"] for pr in matches), instance_id | |
| refs = {ref["path"]: ref for ref in task["artifacts"]} | |
| assert len(refs) == len(task["artifacts"]), f"Duplicate paths: {instance_id}" | |
| actual = {str(p.relative_to(directory)) for p in directory.rglob("*") if p.is_file() and p != directory / "task.json"} | |
| assert actual == set(refs), f"Unindexed or missing files: {instance_id}: {actual ^ set(refs)}" | |
| for ref in refs.values(): | |
| path = contained(directory, ref["path"]) | |
| assert path.is_file() and path.stat().st_size == ref["bytes"], str(path) | |
| assert sha256(path) == ref["sha256"], f"Hash mismatch: {path}" | |
| artifact_count += 1 | |
| assert (directory / task["problem_statement"]["path"]).read_text().strip(), instance_id | |
| for repo in task["repositories"]: | |
| assert repo["gold_patch"]["path"] in refs, instance_id | |
| assert repo["url"].startswith("https://github.com/"), instance_id | |
| assert repo["base_commit"] and repo["fixed_commit"], instance_id | |
| # Source and dependency records carry nested artifact references. | |
| def verify_reference(ref): | |
| assert ref["path"] in refs, f"Unindexed reference: {instance_id}: {ref['path']}" | |
| for field in ("sha256", "bytes"): | |
| if field in ref: | |
| assert refs[ref["path"]][field] == ref[field], f"Reference differs: {instance_id}: {ref['path']}" | |
| by_key = {r["key"]: r for r in task["repositories"]} | |
| assert len(by_key) == len(task["repositories"]), instance_id | |
| dependencies = json.loads((directory / "environment/source-dependencies.json").read_text()) | |
| assert dependencies["instance_id"] == instance_id | |
| assert [r["repository"] for r in dependencies["repositories"]] == list(by_key), instance_id | |
| for dependency in dependencies["repositories"]: | |
| repo = by_key[dependency["repository"]] | |
| assert dependency["source_commit"] == repo["base_commit"], instance_id | |
| for ref in dependency["files"]: | |
| verify_reference(ref) | |
| assert ref["source_commit"] == repo["base_commit"], instance_id | |
| assert ref["repository"] == repo["key"], instance_id | |
| if ref.get("source_construction"): | |
| verify_reference(ref["source_construction"]) | |
| for repo in task["repositories"]: | |
| policy = repo["source_policy"] | |
| if policy.get("construction_recipe"): | |
| verify_reference(policy["construction_recipe"]) | |
| recipe = json.loads(contained(directory, policy["construction_recipe"]["path"]).read_text()) | |
| assert recipe["schema_version"] == 1 and recipe["kind"] == "git-tree-transform-v1", instance_id | |
| assert recipe["expected_commit"] == repo["base_commit"], instance_id | |
| verify_reference(recipe["commit_object"]) | |
| commit = contained(directory, recipe["commit_object"]["path"]).read_bytes() | |
| assert object_id("commit", commit) == repo["base_commit"], instance_id | |
| header = commit.split(b"\n\n", 1)[0].splitlines() | |
| assert b"tree " + recipe["expected_tree"].encode() in header, instance_id | |
| parents = [line[7:].decode() for line in header if line.startswith(b"parent ")] | |
| assert parents == recipe.get("parents", []), instance_id | |
| assert parents in ([], [recipe["upstream_base_commit"]]), instance_id | |
| for operation in recipe["operations"]: | |
| if operation["kind"] == "reverse_patch": | |
| verify_reference(operation["patch"]) | |
| for link in policy.get("workspace_links", []): | |
| provider = by_key[link["target_repository"]] | |
| assert provider["key"] != repo["key"], instance_id | |
| assert provider["container_path"] == link["original_target"], instance_id | |
| assert object_id("blob", link["original_target"].encode()) == link["expected_blob"], instance_id | |
| compatibility = directory / "evaluation/test-preparation.json" | |
| if compatibility.is_file(): | |
| configuration = json.loads(compatibility.read_text()) | |
| assert configuration["schema_version"] == 1 and configuration["instance_id"] == instance_id | |
| for variant in configuration["patch_variants"]: | |
| assert variant["original"] in by_key[variant["repository"]]["test_patches"], instance_id | |
| verify_reference(variant["original"]) | |
| for alternative in variant["alternatives"]: | |
| verify_reference(alternative) | |
| contract = json.loads((directory / task["evaluation"]["path"]).read_text()) | |
| assert contract["instance_id"] == instance_id | |
| for ref in contract["test_files"]: | |
| assert refs[ref["path"]]["sha256"] == ref["sha256"], instance_id | |
| assert any(r["test_patches"] for r in task["repositories"]) or contract["test_files"], f"Missing tests: {instance_id}" | |
| checks = root / "CHECKSUMS.sha256" | |
| if checks.exists(): | |
| inventory = {} | |
| for line in checks.read_text().splitlines(): | |
| digest, relative = line.split(" ", 1) | |
| assert relative not in inventory, relative | |
| inventory[relative] = digest | |
| assert sha256(contained(root, relative)) == digest, relative | |
| actual = {str(p.relative_to(root)) for p in root.rglob("*") if p.is_file() | |
| and not any(x in p.relative_to(root).parts for x in [".git", ".cache", "workspaces", "results", "__pycache__"]) | |
| and p.name != "CHECKSUMS.sha256"} | |
| assert actual == set(inventory), f"Checksum inventory differs: {actual ^ set(inventory)}" | |
| return {"tasks": len(rows), "repositories": sum(len(t["repositories"]) for t in rows), "artifacts": artifact_count} | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--root", type=Path, default=ROOT) | |
| parser.add_argument("--list", action="store_true") | |
| args = parser.parse_args() | |
| if args.list: | |
| for row in map(json.loads, (args.root / "data/instances.jsonl").read_text().splitlines()): | |
| print(row["instance_id"]) | |
| else: | |
| try: | |
| print(json.dumps(validate(args.root), sort_keys=True)) | |
| except (AssertionError, ValueError, OSError, KeyError) as error: | |
| print(f"Invalid release: {error}", file=sys.stderr) | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() | |