Download tests/test_bench.py from fahadhafeezofficial/clsa-code: direct link, hf CLI and curl.
- Browser
- Download file 2.08 kB
-
https://huggingface.co/datasets/fahadhafeezofficial/clsa-code/resolve/main/tests/test_bench.py
- Command line
-
hf download hf://datasets/fahadhafeezofficial/clsa-code/tests/test_bench.py
-
curl -L -o test_bench.py https://huggingface.co/datasets/fahadhafeezofficial/clsa-code/resolve/main/tests/test_bench.py
2.08 kB
| # Copyright (c) 2026 CLSA contributors | |
| # SPDX-License-Identifier: MIT | |
| """Benchmark integrity: schema, episode-disjoint splits, fork replay.""" | |
| from __future__ import annotations | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) | |
| import pytest # noqa: E402 | |
| from clsa.envs.bench_io import load_preact_bench, task_index, validator, verify_fork # noqa: E402 | |
| from clsa.util import load_config # noqa: E402 | |
| def items(): | |
| return load_preact_bench() | |
| def test_item_ids_unique(items): | |
| ids = [i["item_id"] for i in items] | |
| assert len(ids) == len(set(ids)) | |
| def test_splits_are_episode_disjoint(items): | |
| by_split: dict[str, set[str]] = {} | |
| for i in items: | |
| by_split.setdefault(i["split"], set()).add(i["episode_id"]) | |
| assert set(by_split) == {"train", "calib", "test", "heldout"} | |
| names = sorted(by_split) | |
| for a in range(len(names)): | |
| for b in range(a + 1, len(names)): | |
| shared = by_split[names[a]] & by_split[names[b]] | |
| assert not shared, f"episodes shared by {names[a]}/{names[b]}: {list(shared)[:3]}" | |
| def test_every_item_validates(items): | |
| v = validator() | |
| for item in items: | |
| v.validate(item) | |
| def test_fork_replay_reproduces_labels(items): | |
| task_by_id = task_index(int(load_config("bench").get("seed", 0))) | |
| checked = 0 | |
| for item in items: | |
| if item["split"] not in ("test", "heldout"): | |
| continue | |
| assert verify_fork(item, task_by_id), f"fork replay disagreed at {item['item_id']}" | |
| checked += 1 | |
| if checked >= 40: | |
| break | |
| assert checked > 0 | |
| def test_candidates_and_labels_agree_in_length(items): | |
| for item in items: | |
| cands = item["candidate_set"] | |
| assert cands | |
| for c in cands: | |
| assert "name" in c and "args" in c | |
| lab = item["labels"] | |
| for key in ("harmful", "irreversible_harm", "reversible", "executed", "committed"): | |
| assert key in lab, f"{item['item_id']} missing labels.{key}" | |