File size: 2,076 Bytes
fd5366a | 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 | # 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
@pytest.fixture(scope="module")
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}"
|