Datasets:
Skills Desk v2: 36 screened training tasks (pre-registered rule), ev_contracts on CC0 USAspending data; reserved set unchanged
8685f4e verified Download source/tests/test_contracts.py from Syndicate604/skills-desk: direct link, hf CLI and curl.
- Browser
- Download file 3.4 kB
-
https://huggingface.co/datasets/Syndicate604/skills-desk/resolve/main/source/tests/test_contracts.py
- Command line
-
hf download hf://datasets/Syndicate604/skills-desk/source/tests/test_contracts.py
-
curl -L -o test_contracts.py https://huggingface.co/datasets/Syndicate604/skills-desk/resolve/main/source/tests/test_contracts.py
3.4 kB
| """ev_contracts: every v2 candidate id catches the shortcuts its level is meant to teach, and the grader | |
| accepts harmless spelling differences but nothing else.""" | |
| import json | |
| import os | |
| import tempfile | |
| import pytest | |
| os.environ.setdefault("TERMINAL_DESK_APP", tempfile.mkdtemp(prefix="td-contracts-")) | |
| from test_solvers import play, solver # noqa: E402 | |
| from terminal_desk.models import Tbench2Action # noqa: E402 | |
| from terminal_desk.server.environment import TerminalDeskEnvironment # noqa: E402 | |
| CANDIDATES = ["ev_contracts-L1", "ev_contracts-L1-i1", "ev_contracts-L2", "ev_contracts-L2-i1", | |
| "ev_contracts-L3", "ev_contracts-L3-i1", "ev_contracts-L4", "ev_contracts-L4-i2", | |
| "ev_contracts-L5", "ev_contracts-L5-i2", "ev_contracts-L6", "ev_contracts-L6-i1"] | |
| REFS = ''' if "/" in d: | |
| a, _, m = d.rpartition("/") | |
| else: | |
| a, _, m = d.rpartition("-")''' | |
| SHORTCUTS = { | |
| "slash_only": (REFS, ' a, _, m = d.rpartition("/") if "/" in d else (d, "", "0")'), | |
| "dash_only": (REFS, ' a, _, m = d.rpartition("-")'), | |
| "ignore_deob": ('-amt if et == "DEOB" else amt', "amt"), | |
| } | |
| LIVE = {1: ["slash_only"], 2: ["dash_only"], 3: ["slash_only", "dash_only", "ignore_deob"], | |
| 4: ["dash_only", "ignore_deob"], 5: ["slash_only", "dash_only"], 6: ["dash_only"]} | |
| def test_candidates_use_distinct_sources(): | |
| from terminal_desk.families import FAMILIES, instance_seed, parse_task_id | |
| import random | |
| src = [FAMILIES["ev_contracts"].build(parse_task_id(t)[1], random.Random(instance_seed(t))).notes["source"] | |
| for t in CANDIDATES] | |
| assert len(set(src)) == len(src) | |
| def test_level_shortcuts_score_zero(task_id): | |
| level = int(task_id.split("-L")[1][0]) | |
| for name in LIVE[level]: | |
| old, new = SHORTCUTS[name] | |
| src = solver("ev_contracts") | |
| assert old in src | |
| assert play(task_id, src.replace(old, new)) == 0.0, name | |
| def _grade(task_id: str, rows) -> float: | |
| env = TerminalDeskEnvironment() | |
| env.reset(task_id=task_id) | |
| env.step(Tbench2Action(action_type="write_file", file_path="discrepancies.json", content=json.dumps(rows))) | |
| return env.step(Tbench2Action(action_type="evaluate")).reward | |
| def _expected(task_id: str) -> list: | |
| env = TerminalDeskEnvironment() | |
| env.reset(task_id=task_id) | |
| return env._ep["built"].notes["expected"] | |
| def test_harmless_spellings_pass(): | |
| want = _expected("ev_contracts-L3") | |
| alt = [{"award": w["award"].lower(), "mod": ("BASE" if w["mod"] == "0" else "M" + str(int(w["mod"].lstrip("P")))) | |
| , "difference": w["difference"] + 0.004} for w in reversed(want)] | |
| assert _grade("ev_contracts-L3", alt) == 1.0 | |
| def test_wrong_lists_fail(change): | |
| want = _expected("ev_contracts-L3") | |
| rows = [dict(w) for w in want] | |
| if change == "drop": | |
| rows = rows[1:] | |
| elif change == "extra_key": | |
| rows[0]["note"] = "x" | |
| elif change == "duplicate": | |
| rows.append(dict(rows[0])) | |
| elif change == "off_by_cent": | |
| rows[0]["difference"] += 0.01 | |
| elif change == "string_amount": | |
| rows[0]["difference"] = str(rows[0]["difference"]) | |
| elif change == "empty": | |
| rows = [] | |
| assert _grade("ev_contracts-L3", rows) == 0.0 | |