From e99b027c949b3a4d8e81841bf70ce5427919aeb5 Mon Sep 17 00:00:00 2001 From: Etienne Filhol Date: Tue, 1 Dec 2026 18:56:39 +0100 Subject: [PATCH 1/6] feat(catalogue): label HealthAgentBench's tasks for the Leaderboard --- .../benchmarks/healthagentbench/labels.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/nullius/catalogue/benchmarks/healthagentbench/labels.json diff --git a/app/nullius/catalogue/benchmarks/healthagentbench/labels.json b/app/nullius/catalogue/benchmarks/healthagentbench/labels.json new file mode 100644 index 000000000..92349d4ce --- /dev/null +++ b/app/nullius/catalogue/benchmarks/healthagentbench/labels.json @@ -0,0 +1,16 @@ +{ + "schema": 1, + "labels": [ + { + "axes": [ + "Health" + ] + }, + { + "dataset": "ehr-to-meds", + "axes": [ + "Coding" + ] + } + ] +} From 9e2cfef597081d695dd6a0e12a851d03136f3b8e Mon Sep 17 00:00:00 2001 From: Etienne Filhol Date: Tue, 1 Dec 2026 21:42:30 +0100 Subject: [PATCH 2/6] feat(standard): name tasks in labels whose ids the upstream publishes while their data stays unshared --- .agents/skills/label-benchmark/SKILL.md | 15 +++- .../label-benchmark/scripts/public_ids.py | 82 +++++++++++++++++++ app/nullius/leaderboard/labels.py | 5 +- app/nullius/standard/contract/definitions.py | 6 ++ app/tests/test_leaderboard_labels.py | 4 + app/tests/test_standard_controls.py | 11 +++ docs/standard.md | 1 + 7 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 .agents/skills/label-benchmark/scripts/public_ids.py diff --git a/.agents/skills/label-benchmark/SKILL.md b/.agents/skills/label-benchmark/SKILL.md index f0f444756..6990eef48 100644 --- a/.agents/skills/label-benchmark/SKILL.md +++ b/.agents/skills/label-benchmark/SKILL.md @@ -63,6 +63,15 @@ benchmark's own statement in its README, paper or dataset description: the one d capability it says every task of the dataset is graded on. Never your reading of what a dataset is about. Such a rule labels the dataset in every release the second command lists it in: the statement must hold for each. Then hand over. +Unless the upstream repository itself publishes every task id (task files or folders, an id list, tracked at the +pinned commit, not a gated download): then propose `units.public_ids` too, the path where it does, in the same diff. +With it, both steps run and `labels.json` may name tasks, but a state holds only what that repository tracks at the +pinned commit (instructions, graders, tool names), never a record fetched behind a gate or a credential. Before the +proposal is shown, this must exit 0; it prints counts, never an id: +```bash +PYTHONPATH=REPO/app python3 SKILL/scripts/public_ids.py ENTRY +``` + ## The format `ENTRY/labels.json`: @@ -73,7 +82,8 @@ labels the dataset in every release the second command lists it in: the statemen ]} ``` -- Under `units.redistribute: false`, dataset rules instead, never both: `{"dataset": "retail", "axes": ["Shopping"]}`. +- Under `units.redistribute: false` with no `units.public_ids`, dataset rules instead, never both: + `{"dataset": "retail", "axes": ["Shopping"]}`. - A rule selects the whole benchmark (no `dataset`), one dataset, or the listed `tasks` of one dataset. A task's axes are the union of its rules' `axes`, minus their `not`. No other key, no prefix, no pattern. - `dataset` is a dataset of the definition, never a cut of another (`subset_of`): name the dataset it is cut from. @@ -211,7 +221,8 @@ PYTHONPATH=REPO/app python3 -c 'import json; from nullius.standard.contract impo Then report in a few lines, in `WORK/report.md` and to the user: -- the terms read, and `units.redistribute` as proposed; calls and cost, every run counted; +- the terms read, `units.redistribute` and `units.public_ids` as proposed, and `public_ids.py`'s counts; calls and + cost, every run counted; - per rule: the step or statement that gave it, and for step 2 the models and how many pairs agreed; - per axis: tasks labelled, disagreements left unlabelled, conflicts with a rule kept; the option values left out; labels proposed outside `labels.AXES`, written nowhere. diff --git a/.agents/skills/label-benchmark/scripts/public_ids.py b/.agents/skills/label-benchmark/scripts/public_ids.py new file mode 100644 index 000000000..c9bf1d6ce --- /dev/null +++ b/.agents/skills/label-benchmark/scripts/public_ids.py @@ -0,0 +1,82 @@ +"""Check that every task id ENTRY/labels.json names is one the upstream publishes, before it is written. + + PYTHONPATH=REPO/app python3 SKILL/scripts/public_ids.py ENTRY + +For a benchmark whose data may not be redistributed (``units.redistribute: false``), ``labels.json`` may name +tasks only under ``units.public_ids``: the path in the upstream repository where it publishes the ids. For each +version a ``tasks`` rule is ``checked`` at, this fetches the upstream at its pinned commit over HTTPS with no +credentials (a private repository fails here), and finds each id there, under that path, as a tracked file or +folder name or a whole word of a tracked file. Untracked files, a gated download among them, prove nothing. + +Prints counts, never an id. Exit 0: every id found; 1: not; 2: usage. +""" +import json +import os +import re +import subprocess +import sys +import tempfile + +from nullius.standard.contract import definitions + +WORD = re.compile(rb"[A-Za-z0-9_.\-]+") +QUIET = {**os.environ, "GIT_TERMINAL_PROMPT": "0", "GIT_ASKPASS": "true", "SSH_ASKPASS": "true", + "GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_NOSYSTEM": "1"} + + +def git(*args, cwd): + return subprocess.run(["git", "-c", "credential.helper=", *args], cwd=cwd, env=QUIET, capture_output=True, + timeout=900, check=True).stdout + + +def published(repository, commit, path): + """Every name and word the repository tracks under ``path`` at ``commit``, fetched with no credentials.""" + if not repository.startswith("https://"): + sys.exit(f"{repository}: an https repository is needed, so that no credential is used") + with tempfile.TemporaryDirectory() as here: + git("init", "--quiet", cwd=here) + try: + git("fetch", "--quiet", "--depth", "1", repository, commit, cwd=here) + except subprocess.CalledProcessError: + sys.exit(f"{repository} at {commit}: not fetched without credentials, so not public") + files = git("ls-tree", "-r", "-z", "--name-only", "FETCH_HEAD", "--", path, cwd=here).split(b"\0") + files = [f for f in files if f] + if not files: + sys.exit(f"units.public_ids: {path} is not tracked at {commit}") + found = {part for f in files for part in f.split(b"/")} + for f in files: + found |= set(WORD.findall(git("show", f"FETCH_HEAD:{f.decode()}", cwd=here))) + return {w.decode(errors="replace") for w in found} + + +def main(): + if len(sys.argv) != 2: + sys.exit(2) + entry = os.path.abspath(sys.argv[1]) + key = os.path.basename(entry) + versions = {definitions.version_identity(b): b for b in definitions.load("benchmark", os.path.dirname(os.path.dirname(entry)), every=True)[0] + if b["key"] == key} + with open(os.path.join(entry, "labels.json"), encoding="utf-8") as f: + rules = [r for r in json.load(f)["labels"] if isinstance(r, dict) and "tasks" in r] + wanted = {} + for r in rules: + for v in r.get("checked") or []: + wanted.setdefault(v, set()).update(r["tasks"]) + missing, checked = 0, 0 + for v, ids in sorted(wanted.items()): + b = versions.get(v) + units = (b or {}).get("units") or {} + if units.get("redistribute") is not False: + continue # ids of such a version may be named anyway + if not units.get("public_ids"): + sys.exit(f"{v}: units.redistribute is false and no units.public_ids: no task id may be named") + there = published(b["upstream"]["repository"], b["upstream"]["tested"], units["public_ids"]) + lost = len(ids - there) + print(f"{v}: {len(ids)} ids, {len(ids) - lost} found under {units['public_ids']} at {b['upstream']['tested'][:12]}") + missing += lost + checked += len(ids) + print(f"{checked} ids checked, {missing} not published") + sys.exit(1 if missing else 0) + + +main() diff --git a/app/nullius/leaderboard/labels.py b/app/nullius/leaderboard/labels.py index 90f842122..ba36f36fa 100644 --- a/app/nullius/leaderboard/labels.py +++ b/app/nullius/leaderboard/labels.py @@ -93,7 +93,7 @@ def _rule(rule, shapes, task_ids): if "tasks" not in rule: return "checked: only with tasks" if "checked" in rule else Rule(frozenset(rule.get("axes", [])), frozenset(rule.get("not", [])), dataset) if not task_ids: - return "tasks: this benchmark's ids may not be redistributed (units.redistribute); dataset rules only" + return "tasks: this benchmark's ids may not be redistributed (units.redistribute, no units.public_ids); dataset rules only" if not _names(rule["tasks"]): return "tasks: a list of task ids, never empty" if not dataset: @@ -118,7 +118,8 @@ def check(document, versions) -> Labels: for b in versions: cuts = {d["id"]: d["subset_of"] for d in b.get("datasets") or [] if d.get("subset_of")} shapes[definitions.version_identity(b)] = ({d["id"] for d in b.get("datasets") or []} - set(cuts), cuts) - task_ids = all((b.get("units") or {}).get("redistribute") is not False for b in versions) + task_ids = all((b.get("units") or {}).get("redistribute") is not False or (b.get("units") or {}).get("public_ids") + for b in versions) rules, problems = [], [] for i, rule in enumerate(document["labels"]): got = _rule(rule, shapes, task_ids) diff --git a/app/nullius/standard/contract/definitions.py b/app/nullius/standard/contract/definitions.py index 434a3fa2a..2b14e32a2 100644 --- a/app/nullius/standard/contract/definitions.py +++ b/app/nullius/standard/contract/definitions.py @@ -1742,6 +1742,12 @@ def problems(d: dict, kind: str) -> List[str]: bad.append("units: {noun, nouns}") if "redistribute" in u and not isinstance(u["redistribute"], bool): bad.append("units.redistribute: false when the data may not be redistributed") + if "public_ids" in u: + p = u["public_ids"] + if not (isinstance(p, str) and p and not os.path.isabs(p) and ".." not in p.split("/")): + bad.append("units.public_ids: the path in the upstream repository where it publishes the task ids") + elif u.get("redistribute") is not False or not (d.get("upstream") or {}).get("repository"): + bad.append("units.public_ids: only with units.redistribute: false and an upstream repository") cats = u.get("categories", {}) if not isinstance(cats, dict) or not all( isinstance(c, dict) and set(c) <= {"label", "names"} and isinstance(c.get("label", ""), str) diff --git a/app/tests/test_leaderboard_labels.py b/app/tests/test_leaderboard_labels.py index 08e61658a..2932bbfbc 100644 --- a/app/tests/test_leaderboard_labels.py +++ b/app/tests/test_leaderboard_labels.py @@ -67,6 +67,10 @@ def test_ids_that_may_not_ship_get_dataset_rules_only(self): closed = [dict(b, units=dict(b["units"], redistribute=False)) for b in BENCH] got = labels.check({"schema": 1, "labels": RULES}, closed) self.assertEqual((got.rules, len(got.problems)), (GOOD.rules[:2], 2)) + public = [dict(b, units=dict(b["units"], public_ids="tasks")) for b in closed] + self.assertEqual(labels.check({"schema": 1, "labels": RULES}, public), GOOD) + one = [public[0], closed[1]] # a version without it still names none + self.assertEqual(len(labels.check({"schema": 1, "labels": RULES}, one).problems), 2) def test_a_file_that_does_not_read_labels_nothing(self): import tempfile diff --git a/app/tests/test_standard_controls.py b/app/tests/test_standard_controls.py index 15d12060d..f59b890cf 100644 --- a/app/tests/test_standard_controls.py +++ b/app/tests/test_standard_controls.py @@ -57,6 +57,17 @@ def test_units_that_may_not_be_redistributed_say_so_with_a_boolean(self): self.assertIn("units.redistribute: false when the data may not be redistributed", definitions.problems(dict(self.b, units=dict(units, redistribute="no")), "benchmark")) + def test_public_ids_name_a_path_of_a_repository_whose_data_may_not_be_redistributed(self): + b = dict(self.b, upstream={"repository": "https://example.org/up", "tested": "a" * 40, "license": "MIT"}) + named = lambda **u: definitions.problems(dict(b, units=dict(self.b["units"], **u)), "benchmark") + self.assertEqual(named(redistribute=False, public_ids="data/tasks.json"), []) + for path in ("", "/etc/tasks", "../tasks", True): + self.assertIn("units.public_ids: the path in the upstream repository where it publishes the task ids", + named(redistribute=False, public_ids=path)) + held = "units.public_ids: only with units.redistribute: false and an upstream repository" + self.assertIn(held, named(public_ids="tasks")) + self.assertIn(held, definitions.problems(dict(self.b, units=dict(self.b["units"], redistribute=False, public_ids="tasks")), "benchmark")) + def test_an_agent_cannot_take_a_controls_name(self): a = definitions.get("agent", "fake", FIX) self.assertIn("key: nop is the word for a benchmark's control", definitions.problems(dict(a, key="nop"), "agent")) diff --git a/docs/standard.md b/docs/standard.md index c69f2e7fc..8b8bd39d3 100644 --- a/docs/standard.md +++ b/docs/standard.md @@ -464,6 +464,7 @@ An `answer` or `score` error that begins `EnvironmentSetupError: `, `VerifierErr | `limits.retries` | The upstream's own retries of a failed unit (0 to 9): a run's `--retries` when none is given | | `limits.scored_cuts` | The cuts after which an agent's unit is still scored: `time`, `calls`, `end` ([a unit cut at a limit](cli/run.md#a-unit-cut-at-a-limit)) | | `units.redistribute` | `false` when the data may not be redistributed: `cli prove` then records no unit id | +| `units.public_ids` | With `redistribute: false`: the path in the upstream repository where it publishes the unit ids. `labels.json` may then name units; the data stays unshared | | `units.categories` | `{FIELD: {label, names: {VALUE: name}}}`: how `describe`'s categories read on a listing; `--category` still takes the value | !!! note "Call the upstream, never copy it" From bb506d66ffc26b1a5ea4358131510bad4d4f31b7 Mon Sep 17 00:00:00 2001 From: Etienne Filhol Date: Tue, 1 Dec 2026 21:43:22 +0100 Subject: [PATCH 3/6] feat(catalogue): name HealthAgentBench's tasks in its labels --- .../benchmarks/healthagentbench/labels.json | 30 +++++++++++++++++++ .../benchmarks/healthagentbench/standard.json | 3 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/nullius/catalogue/benchmarks/healthagentbench/labels.json b/app/nullius/catalogue/benchmarks/healthagentbench/labels.json index 92349d4ce..05109d9dd 100644 --- a/app/nullius/catalogue/benchmarks/healthagentbench/labels.json +++ b/app/nullius/catalogue/benchmarks/healthagentbench/labels.json @@ -6,8 +6,38 @@ "Health" ] }, + { + "dataset": "full", + "checked": [ + "v1" + ], + "tasks": [ + "ehr_to_meds_etl" + ], + "axes": [ + "Coding" + ] + }, + { + "dataset": "public", + "checked": [ + "v1" + ], + "tasks": [ + "ehr_to_meds_etl" + ], + "axes": [ + "Coding" + ] + }, { "dataset": "ehr-to-meds", + "checked": [ + "v1" + ], + "tasks": [ + "ehr_to_meds_etl" + ], "axes": [ "Coding" ] diff --git a/app/nullius/catalogue/benchmarks/healthagentbench/standard.json b/app/nullius/catalogue/benchmarks/healthagentbench/standard.json index a2018d8c9..29359aaa9 100644 --- a/app/nullius/catalogue/benchmarks/healthagentbench/standard.json +++ b/app/nullius/catalogue/benchmarks/healthagentbench/standard.json @@ -89,7 +89,8 @@ "units": { "noun": "task", "nouns": "tasks", - "redistribute": false + "redistribute": false, + "public_ids": "tasks" }, "environments": { "task": { From 32ea78b811ddb0739afdb3b9a3c202be8f110cdb Mon Sep 17 00:00:00 2001 From: Etienne Filhol Date: Tue, 1 Dec 2026 23:01:37 +0100 Subject: [PATCH 4/6] feat(catalogue): label HealthAgentBench's full list alone, the others holding its tasks --- .../benchmarks/healthagentbench/labels.json | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/app/nullius/catalogue/benchmarks/healthagentbench/labels.json b/app/nullius/catalogue/benchmarks/healthagentbench/labels.json index 05109d9dd..968f887f5 100644 --- a/app/nullius/catalogue/benchmarks/healthagentbench/labels.json +++ b/app/nullius/catalogue/benchmarks/healthagentbench/labels.json @@ -2,6 +2,7 @@ "schema": 1, "labels": [ { + "dataset": "full", "axes": [ "Health" ] @@ -17,30 +18,6 @@ "axes": [ "Coding" ] - }, - { - "dataset": "public", - "checked": [ - "v1" - ], - "tasks": [ - "ehr_to_meds_etl" - ], - "axes": [ - "Coding" - ] - }, - { - "dataset": "ehr-to-meds", - "checked": [ - "v1" - ], - "tasks": [ - "ehr_to_meds_etl" - ], - "axes": [ - "Coding" - ] } ] } From 0270ff1879e33d08c9c784400753040a7be6f303 Mon Sep 17 00:00:00 2001 From: Etienne Filhol Date: Tue, 1 Dec 2026 23:12:25 +0100 Subject: [PATCH 5/6] Revert "feat(catalogue): label HealthAgentBench's full list alone, the others holding its tasks" This reverts commit 32ea78b811ddb0739afdb3b9a3c202be8f110cdb. --- .../benchmarks/healthagentbench/labels.json | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/nullius/catalogue/benchmarks/healthagentbench/labels.json b/app/nullius/catalogue/benchmarks/healthagentbench/labels.json index 968f887f5..05109d9dd 100644 --- a/app/nullius/catalogue/benchmarks/healthagentbench/labels.json +++ b/app/nullius/catalogue/benchmarks/healthagentbench/labels.json @@ -2,7 +2,6 @@ "schema": 1, "labels": [ { - "dataset": "full", "axes": [ "Health" ] @@ -18,6 +17,30 @@ "axes": [ "Coding" ] + }, + { + "dataset": "public", + "checked": [ + "v1" + ], + "tasks": [ + "ehr_to_meds_etl" + ], + "axes": [ + "Coding" + ] + }, + { + "dataset": "ehr-to-meds", + "checked": [ + "v1" + ], + "tasks": [ + "ehr_to_meds_etl" + ], + "axes": [ + "Coding" + ] } ] } From 77ed5073edb85690d247f4767d39cfbc875c0219 Mon Sep 17 00:00:00 2001 From: Etienne Filhol Date: Tue, 1 Dec 2026 23:30:46 +0100 Subject: [PATCH 6/6] fix(standard): refuse a task id in labels unless listed and published, fetched with no credential --- .agents/skills/label-benchmark/SKILL.md | 30 ++-- .../label-benchmark/scripts/public_ids.py | 151 ++++++++++++------ app/nullius/standard/contract/definitions.py | 3 +- app/tests/test_leaderboard_labels.py | 25 +++ app/tests/test_standard_controls.py | 2 +- 5 files changed, 145 insertions(+), 66 deletions(-) diff --git a/.agents/skills/label-benchmark/SKILL.md b/.agents/skills/label-benchmark/SKILL.md index 61990a5a7..fbf4a73b1 100644 --- a/.agents/skills/label-benchmark/SKILL.md +++ b/.agents/skills/label-benchmark/SKILL.md @@ -58,20 +58,22 @@ Read the terms before the first `units` listing: it writes task text. A canary o reported and changes nothing below: task ids and labels are not the data. Gated data, data its authors ask not to reshare, or records about real people (patients, clients): propose -`units.redistribute: false` in the benchmark's definition, as a ```diff block for the user. With it, proposed or already set, no task id goes anywhere: -not into `labels.json`, the report or a model. Skip both steps. Write dataset rules alone (no `tasks`), each from the -benchmark's own statement in its README, paper or dataset description: the one domain it defines the dataset as, or a -capability it says every task of the dataset is graded on. Never your reading of what a dataset is about. Such a rule -labels the dataset in every release the second command lists it in: the statement must hold for each. Then hand over. - -Unless the upstream repository itself publishes every task id (task files or folders, an id list, tracked at the -pinned commit, not a gated download): then propose `units.public_ids` too, the path where it does, in the same diff. -With it, both steps run and `labels.json` may name tasks, but a state holds only what that repository tracks at the -pinned commit (instructions, graders, tool names), never a record fetched behind a gate or a credential. Before the -proposal is shown, this must exit 0; it prints counts, never an id: -```bash -PYTHONPATH=REPO/app python3 SKILL/scripts/public_ids.py ENTRY -``` +`units.redistribute: false` in the benchmark's definition, as a ```diff block for the user. Where the upstream +repository itself publishes every task id (task files or folders, an id list, tracked at the pinned commit, not a +gated download), propose `units.public_ids` in the same diff: the path where it does. + +- With `public_ids`: both steps run and `labels.json` may name tasks, but a state holds only what the upstream + publishes openly: what its repository tracks at the pinned commit, or a file its README links that downloads with + no login and that the definition pins by `sha256`. Never a record fetched behind a gate or a credential. Apply the + diff in the checkout, then, before the proposal is shown, this must exit 0; it prints counts, never an id: + ```bash + PYTHONPATH=REPO/app python3 SKILL/scripts/public_ids.py ENTRY + ``` +- Without it, proposed or already set: no task id goes anywhere, not into `labels.json`, the report or a model. Skip + both steps. Write dataset rules alone (no `tasks`), each from the benchmark's own statement in its README, paper or + dataset description: the one domain it defines the dataset as, or a capability it says every task of the dataset is + graded on. Never your reading of what a dataset is about. Such a rule labels the dataset in every release the + second command lists it in: the statement must hold for each. Then hand over. ## The format diff --git a/.agents/skills/label-benchmark/scripts/public_ids.py b/.agents/skills/label-benchmark/scripts/public_ids.py index c9bf1d6ce..43d78d3b9 100644 --- a/.agents/skills/label-benchmark/scripts/public_ids.py +++ b/.agents/skills/label-benchmark/scripts/public_ids.py @@ -1,82 +1,135 @@ -"""Check that every task id ENTRY/labels.json names is one the upstream publishes, before it is written. +"""Check every task id ENTRY/labels.json names, before the file is committed, for a benchmark whose data may not be +redistributed (``units.redistribute: false``). PYTHONPATH=REPO/app python3 SKILL/scripts/public_ids.py ENTRY -For a benchmark whose data may not be redistributed (``units.redistribute: false``), ``labels.json`` may name -tasks only under ``units.public_ids``: the path in the upstream repository where it publishes the ids. For each -version a ``tasks`` rule is ``checked`` at, this fetches the upstream at its pinned commit over HTTPS with no -credentials (a private repository fails here), and finds each id there, under that path, as a tracked file or -folder name or a whole word of a tracked file. Untracked files, a gated download among them, prove nothing. +Such a benchmark's labels may name tasks only under ``units.public_ids``, the path in the upstream repository where +it publishes the ids, and only ids that are, at each version a rule is ``checked`` at: +- listed by ``units`` for that dataset (the listing Nullius cached when the skill listed it); +- published: the upstream fetched at its pinned commit over HTTPS, with no credential, no user configuration and an + empty home (a private repository fails here), and the id found under that path as a tracked file or folder name + or a whole string value of a tracked ``.json`` or ``.jsonl`` file. Untracked files, a gated download among them, + prove nothing. +The file must also have no ``labels.check`` problem, and the definition on disk must be the one proposed. -Prints counts, never an id. Exit 0: every id found; 1: not; 2: usage. +Prints counts, never an id. Exit 0: every id passes, or the benchmark's ids may be named anyway; 1: refused. """ import json import os -import re import subprocess import sys import tempfile +from nullius.leaderboard import labels from nullius.standard.contract import definitions +from nullius.standard.runner import units -WORD = re.compile(rb"[A-Za-z0-9_.\-]+") -QUIET = {**os.environ, "GIT_TERMINAL_PROMPT": "0", "GIT_ASKPASS": "true", "SSH_ASKPASS": "true", - "GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_NOSYSTEM": "1"} +def refusals(document, versions, listed, published) -> list: + """Why the ids of ``document`` may not be named; [] when they may. ``versions``: the benchmark at each version; + ``listed``: {(version, dataset): ids or None}; ``published``: {version: ids}. Counts, never an id.""" + if not versions: + return ["the benchmark: no version of it loads from ENTRY"] + problems = list(labels.check(document, versions).problems) + if problems: + return [f"labels.check: {len(problems)} problems; run the hand-over check"] + unit = versions[0].get("units") or {} + if unit.get("redistribute") is not False: + return [] + rules = [r for r in document["labels"] if "tasks" in r] + if rules and not unit.get("public_ids"): + return ["units.public_ids: not set, so no task id may be named"] + out = [] + for v in sorted({v for r in rules for v in r["checked"]}): + for ds in sorted({r["dataset"] for r in rules if v in r["checked"]}): + ids = {t for r in rules if v in r["checked"] and r["dataset"] == ds for t in r["tasks"]} + there = listed.get((v, ds)) + if there is None: + out.append(f"{v} {ds}: no cached listing; list its units first") + continue + if ids - set(there): + out.append(f"{v} {ds}: {len(ids - set(there))} of {len(ids)} ids not listed") + if ids - published.get(v, set()): + out.append(f"{v} {ds}: {len(ids - published.get(v, set()))} of {len(ids)} ids not published under {unit['public_ids']}") + return out -def git(*args, cwd): - return subprocess.run(["git", "-c", "credential.helper=", *args], cwd=cwd, env=QUIET, capture_output=True, - timeout=900, check=True).stdout +def _strings(value): + if isinstance(value, str): + yield value + elif isinstance(value, dict): + for k, x in value.items(): + yield k + yield from _strings(x) + elif isinstance(value, list): + for x in value: + yield from _strings(x) -def published(repository, commit, path): - """Every name and word the repository tracks under ``path`` at ``commit``, fetched with no credentials.""" + +def published(repository, commit, path) -> set: + """Every name and JSON string the repository tracks under ``path`` at ``commit``, fetched with no credential.""" if not repository.startswith("https://"): sys.exit(f"{repository}: an https repository is needed, so that no credential is used") - with tempfile.TemporaryDirectory() as here: - git("init", "--quiet", cwd=here) + with tempfile.TemporaryDirectory() as here, tempfile.TemporaryDirectory() as home: + env = {"PATH": os.environ.get("PATH", "/usr/bin:/bin"), "HOME": home, "XDG_CONFIG_HOME": home, + "GIT_CONFIG_NOSYSTEM": "1", "GIT_CONFIG_GLOBAL": os.devnull, "GIT_TERMINAL_PROMPT": "0", + "GIT_ASKPASS": "true", "SSH_ASKPASS": "true", "GIT_LFS_SKIP_SMUDGE": "1"} + git = lambda *a: subprocess.run(["git", "-c", "credential.helper=", *a], cwd=here, env=env, + capture_output=True, timeout=900, check=True).stdout + git("init", "--quiet") try: - git("fetch", "--quiet", "--depth", "1", repository, commit, cwd=here) + git("fetch", "--quiet", "--depth", "1", "--no-recurse-submodules", repository, commit) except subprocess.CalledProcessError: sys.exit(f"{repository} at {commit}: not fetched without credentials, so not public") - files = git("ls-tree", "-r", "-z", "--name-only", "FETCH_HEAD", "--", path, cwd=here).split(b"\0") - files = [f for f in files if f] + entries = [e.split(b"\t", 1) for e in git("ls-tree", "-r", "-z", "FETCH_HEAD", "--", path).split(b"\0") if e] + files = [name.decode() for meta, name in entries if meta.split()[1] == b"blob"] if not files: - sys.exit(f"units.public_ids: {path} is not tracked at {commit}") - found = {part for f in files for part in f.split(b"/")} + sys.exit(f"units.public_ids: {path} tracks no file at {commit}") + found = {part for f in files for part in f.split("/")} for f in files: - found |= set(WORD.findall(git("show", f"FETCH_HEAD:{f.decode()}", cwd=here))) - return {w.decode(errors="replace") for w in found} + if f.endswith((".json", ".jsonl")): + text = git("show", f"FETCH_HEAD:{f}").decode("utf-8", errors="replace") + try: + docs = [json.loads(text)] if f.endswith(".json") else [json.loads(x) for x in text.splitlines() if x.strip()] + except ValueError: + continue + for doc in docs: + found.update(_strings(doc)) + return found def main(): if len(sys.argv) != 2: - sys.exit(2) + sys.exit("usage: public_ids.py ENTRY") entry = os.path.abspath(sys.argv[1]) key = os.path.basename(entry) - versions = {definitions.version_identity(b): b for b in definitions.load("benchmark", os.path.dirname(os.path.dirname(entry)), every=True)[0] - if b["key"] == key} + versions = [b for b in definitions.load("benchmark", os.path.dirname(os.path.dirname(entry)), every=True)[0] if b["key"] == key] with open(os.path.join(entry, "labels.json"), encoding="utf-8") as f: - rules = [r for r in json.load(f)["labels"] if isinstance(r, dict) and "tasks" in r] - wanted = {} - for r in rules: - for v in r.get("checked") or []: - wanted.setdefault(v, set()).update(r["tasks"]) - missing, checked = 0, 0 - for v, ids in sorted(wanted.items()): - b = versions.get(v) - units = (b or {}).get("units") or {} - if units.get("redistribute") is not False: - continue # ids of such a version may be named anyway - if not units.get("public_ids"): - sys.exit(f"{v}: units.redistribute is false and no units.public_ids: no task id may be named") - there = published(b["upstream"]["repository"], b["upstream"]["tested"], units["public_ids"]) - lost = len(ids - there) - print(f"{v}: {len(ids)} ids, {len(ids) - lost} found under {units['public_ids']} at {b['upstream']['tested'][:12]}") - missing += lost - checked += len(ids) - print(f"{checked} ids checked, {missing} not published") - sys.exit(1 if missing else 0) + document = json.load(f) + by = {definitions.version_identity(b): b for b in versions} + rules = [r for r in document.get("labels") or [] if isinstance(r, dict) and "tasks" in r] + unit = (versions[0].get("units") or {}) if versions else {} + listed, seen = {}, {} + if versions and not labels.check(document, versions).problems and unit.get("redistribute") is False and unit.get("public_ids"): + for v in {v for r in rules for v in r["checked"]}: + b = by[v] + for ds in {r["dataset"] for r in rules if v in r["checked"]}: + d = next(x for x in b["datasets"] if x["id"] == ds) + try: + with open(units.cache_path(b, d, units.option_values(b, ds)), encoding="utf-8") as f: + listed[v, ds] = [t["id"] for t in json.load(f)["tasks"]] + except (OSError, ValueError, KeyError, TypeError, units.Refused): + listed[v, ds] = None + where = (b["upstream"]["repository"], b["upstream"]["tested"], unit["public_ids"]) + seen[v] = published(*where) + out = refusals(document, versions, listed, seen) + ids = sum(len(r["tasks"]) for r in rules if isinstance(r.get("tasks"), list)) + if not out and unit.get("redistribute") is not False: + print("units.redistribute is not false in ENTRY: its ids may be named; apply a proposed change first") + else: + print("\n".join(out) or f"{ids} named ids: every one listed and published") + sys.exit(1 if out else 0) -main() +if __name__ == "__main__": + main() diff --git a/app/nullius/standard/contract/definitions.py b/app/nullius/standard/contract/definitions.py index 6788dfee1..bdff8ea59 100644 --- a/app/nullius/standard/contract/definitions.py +++ b/app/nullius/standard/contract/definitions.py @@ -1743,8 +1743,7 @@ def problems(d: dict, kind: str) -> List[str]: if "redistribute" in u and not isinstance(u["redistribute"], bool): bad.append("units.redistribute: false when the data may not be redistributed") if "public_ids" in u: - p = u["public_ids"] - if not (isinstance(p, str) and p and not os.path.isabs(p) and ".." not in p.split("/")): + if not (isinstance(u["public_ids"], str) and _RELATIVE.match(u["public_ids"])): bad.append("units.public_ids: the path in the upstream repository where it publishes the task ids") elif u.get("redistribute") is not False or not (d.get("upstream") or {}).get("repository"): bad.append("units.public_ids: only with units.redistribute: false and an upstream repository") diff --git a/app/tests/test_leaderboard_labels.py b/app/tests/test_leaderboard_labels.py index a2420d237..26c97be50 100644 --- a/app/tests/test_leaderboard_labels.py +++ b/app/tests/test_leaderboard_labels.py @@ -72,6 +72,31 @@ def test_ids_that_may_not_ship_get_dataset_rules_only(self): one = [public[0], closed[1]] # a version without it still names none self.assertEqual(len(labels.check({"schema": 1, "labels": RULES}, one).problems), 2) + def test_the_label_skill_names_only_ids_listed_and_published(self): + """``public_ids.py``'s verdict, the fetch aside: every named id listed and published, or a refusal that + names none of them.""" + import importlib.util + path = os.path.join(os.path.dirname(__file__), "..", "..", ".agents", "skills", "label-benchmark", "scripts", "public_ids.py") + if not os.path.isfile(path): + self.skipTest("no label skill in this checkout") + spec = importlib.util.spec_from_file_location("public_ids", path) + script = importlib.util.module_from_spec(spec) + spec.loader.exec_module(script) + public = [dict(b, units=dict(b["units"], redistribute=False, public_ids="tasks")) for b in BENCH] + doc = {"schema": 1, "labels": RULES} + listed, seen = {("v1", "retail"): ["a", "b", "c"]}, {"v1": {"a", "b", "README.md"}} + self.assertEqual(script.refusals(doc, public, listed, seen), []) + self.assertEqual(script.refusals(doc, BENCH, {}, {}), []) # ids that may ship need nothing + refused = [script.refusals(doc, public, listed, {"v1": {"a"}}), # b unpublished + script.refusals(doc, public, {("v1", "retail"): ["a"]}, seen), # b unlisted + script.refusals(doc, public, {("v1", "retail"): None}, seen), + script.refusals(doc, [dict(b, units=dict(b["units"], redistribute=False)) for b in BENCH], listed, seen), + script.refusals({"schema": 1, "labels": [dict(RULES[2], tasks="ab")]}, public, listed, seen), + script.refusals(doc, [], listed, seen)] + for got in refused: + self.assertTrue(got) + self.assertFalse(any(f"'{t}'" in g or f" {t} " in g for g in got for t in "ab"), got) + def test_a_file_that_does_not_read_labels_nothing(self): import tempfile with tempfile.TemporaryDirectory() as here: diff --git a/app/tests/test_standard_controls.py b/app/tests/test_standard_controls.py index f59b890cf..9db96271a 100644 --- a/app/tests/test_standard_controls.py +++ b/app/tests/test_standard_controls.py @@ -61,7 +61,7 @@ def test_public_ids_name_a_path_of_a_repository_whose_data_may_not_be_redistribu b = dict(self.b, upstream={"repository": "https://example.org/up", "tested": "a" * 40, "license": "MIT"}) named = lambda **u: definitions.problems(dict(b, units=dict(self.b["units"], **u)), "benchmark") self.assertEqual(named(redistribute=False, public_ids="data/tasks.json"), []) - for path in ("", "/etc/tasks", "../tasks", True): + for path in ("", "/etc/tasks", "../tasks", ".", "./tasks", ":/", "a b", True): self.assertIn("units.public_ids: the path in the upstream repository where it publishes the task ids", named(redistribute=False, public_ids=path)) held = "units.public_ids: only with units.redistribute: false and an upstream repository"