diff --git a/dokimi/changelog.d/20261128_150000_readers-unlistable-dir-three.md b/dokimi/changelog.d/20261128_150000_readers-unlistable-dir-three.md new file mode 100644 index 0000000000..760b31b79a --- /dev/null +++ b/dokimi/changelog.d/20261128_150000_readers-unlistable-dir-three.md @@ -0,0 +1,10 @@ + + +### Fixed + +- **`dashboard generate` refuses a results directory with a subdirectory it cannot list** — `ResultsAggregator.aggregate` found the result files with `Path.rglob`, which skips a subdirectory it cannot list (mode `0o111`) without an error, so a `eval_*.json` file below it was missing from the dashboard and nothing said so. It now lists the tree strictly and `dashboard generate` exits 2 naming the directory. A tree that can be listed gives the same files, and an `eval` or `evaluations` that is a symlink to a directory is still read through. +- **`repo hits judge` and `repo hits sheet` refuse a batch whose exported eval content has a directory they cannot list** — the task directory was found with `Path.rglob("task.json")`, which skips a directory it cannot list, so a task below it was reported as `no directory of task ... with a task.json`, blaming a missing task. Both commands now exit 2 naming the directory and the OS reason, before any judge call. A task that is really absent is reported as before. +- **`eval inspect` reports a directory it cannot list instead of skipping it** — the tree scan listed a directory with `iterdir()` inside `except OSError: return`, so the tasks below a directory it could not list (mode `0o111`) were left out without a word. The directory is now an `unknown` item with a `cannot read:` problem, as a `task.md` the scan cannot read already was, and the rest of the tree is still reported. The exit code is unchanged (0). A tree that can be listed gives the same items. diff --git a/dokimi/docs/benchmarking-and-comparison.md b/dokimi/docs/benchmarking-and-comparison.md index 8a76dac0c7..000b1df47e 100644 --- a/dokimi/docs/benchmarking-and-comparison.md +++ b/dokimi/docs/benchmarking-and-comparison.md @@ -220,7 +220,9 @@ python cli.py dashboard generate \ ``` The dashboard reads evaluation artifacts and writes `reports/DASHBOARD.md` and -`reports/dashboard.json`. +`reports/dashboard.json`. A directory under `--results-dir` that cannot be listed +is an input error (exit 2): the command names it and writes nothing, rather than +leaving out the result files below it. ## Standalone pipeline commands diff --git a/dokimi/docs/coding-harnesses.md b/dokimi/docs/coding-harnesses.md index 95b782c32b..bd1c561c7c 100644 --- a/dokimi/docs/coding-harnesses.md +++ b/dokimi/docs/coding-harnesses.md @@ -138,7 +138,9 @@ kind, item count, which parts are present or missing (instruction, environment, oracle, verifier, metadata), lint problems, and what in dokimi can consume it today. It only reads: nothing is run or converted, a Python file is scanned as text and never imported, and a file that does not parse is -a problem on its report, not an error. A path no format claims is reported as +a problem on its report, not an error. A directory of a tree it cannot list +is an `unknown` item with a `cannot read:` problem, and the rest of the tree is +still reported. A path no format claims is reported as `unknown` with its files (or keys) and likely prompt and verifier files; when two formats claim a path about equally, the report lists the other as `ambiguous` with its evidence. `--json` prints and `--out` writes the report diff --git a/dokimi/dokimi/commands/dashboard.py b/dokimi/dokimi/commands/dashboard.py index 213c3c63e3..cd34773a8b 100644 --- a/dokimi/dokimi/commands/dashboard.py +++ b/dokimi/dokimi/commands/dashboard.py @@ -22,7 +22,10 @@ def cmd_dashboard_generate(args: argparse.Namespace) -> None: print(f"Scanning results in: {results_dir}") aggregator = ResultsAggregator(results_dir) - data = aggregator.aggregate() + try: + data = aggregator.aggregate() + except OSError as exc: # a directory under the results that cannot be listed + raise InputError(f"cannot list the results in {results_dir}: {exc}") from exc if not data.products: raise InputError("No evaluation results found. Run benchmark first.") diff --git a/dokimi/dokimi/dashboard/aggregator.py b/dokimi/dokimi/dashboard/aggregator.py index c4c876d51b..d35afb6e67 100644 --- a/dokimi/dokimi/dashboard/aggregator.py +++ b/dokimi/dokimi/dashboard/aggregator.py @@ -84,6 +84,23 @@ def sorted_by_score(self) -> List[ProductSnapshot]: ) +def _result_files(root: Path) -> List[Path]: + """The evaluation result files under ``root``: ``eval/*.json``, then ``eval_*.json``, then + ``evaluations/*.json`` at any depth, as three ``rglob`` calls list them, except that a directory + that cannot be listed raises its OSError where ``rglob`` skips it. An ``eval`` or ``evaluations`` that is a symlink + to a directory is read through, as ``rglob`` names it. A ``root`` that is not a directory has none.""" + if not root.is_dir(): + return [] + from dokimi.digest_entries import listed_entries + + rels = [(path, path.relative_to(root)) for path in listed_entries(root)] + for path, rel in list(rels): + if (rel.match("eval") or rel.match("evaluations")) and path.is_symlink() and path.is_dir(): + rels.extend((child, rel / child.name) for child in path.iterdir()) + return [path for pattern in ("eval/*.json", "eval_*.json", "evaluations/*.json") + for path, rel in rels if rel.match(pattern)] + + class ResultsAggregator: """Scan a results directory and build DashboardData.""" @@ -100,9 +117,7 @@ def aggregate(self) -> DashboardData: return DashboardData(generated_at=now, products=[]) # Find all eval JSON files matching orchestrator output pattern (eval/{product}.json) - eval_files = list(self.results_dir.rglob("eval/*.json")) + \ - list(self.results_dir.rglob("eval_*.json")) + \ - list(self.results_dir.rglob("evaluations/*.json")) + eval_files = _result_files(self.results_dir) # Deduplicate seen = set() diff --git a/dokimi/dokimi/repos/hits_judge.py b/dokimi/dokimi/repos/hits_judge.py index 3e085e9ea3..240088ac20 100644 --- a/dokimi/dokimi/repos/hits_judge.py +++ b/dokimi/dokimi/repos/hits_judge.py @@ -29,6 +29,7 @@ from dokimi import caching from dokimi.artifacts import save_artifact +from dokimi.digest_entries import listed_entries from dokimi.judged import judged_reply from dokimi.llm import LLM, Ask, Unparseable from dokimi.llm_json import extract_json_object @@ -158,9 +159,14 @@ def _once(self, kind: str, cell: str, read: Callable[[], Any]) -> Any: def task_dir(self, task: str) -> Path: """The task's directory in the batch's exported eval dir, found by its name as ``repo run`` loads it.""" if self._task_dirs is None: - self._task_dirs = defaultdict(list) - for path in sorted(self.content.rglob("task.json")): - self._task_dirs[path.parent.name].append(path.parent) + found: dict[str, list[Path]] = defaultdict(list) + try: + listed = listed_entries(self.content) if self.content.is_dir() else [] + except OSError as exc: # a directory under the content that cannot be listed: not a missing task + raise HitsInputError(f"cannot list {exc.filename}: {exc.strerror}") from exc + for path in sorted(p for p in listed if p.match("task.json")): + found[path.parent.name].append(path.parent) + self._task_dirs = found dirs = self._task_dirs.get(task, []) if len(dirs) != 1: where = "no" if not dirs else f"{len(dirs)}" diff --git a/dokimi/dokimi/task_formats/detect.py b/dokimi/dokimi/task_formats/detect.py index 96e991b98b..ac11d4c07b 100644 --- a/dokimi/dokimi/task_formats/detect.py +++ b/dokimi/dokimi/task_formats/detect.py @@ -129,7 +129,8 @@ def walk(self, directory: Path) -> None: return try: children = sorted(directory.iterdir()) - except OSError: + except OSError as exc: # a directory that cannot be listed: shown, not skipped + self.entries.append((directory, Report(directory, FORMAT_UNKNOWN, KIND_UNKNOWN, problems=[f"cannot read: {exc}"]))) return for child in children: if self.truncated: diff --git a/dokimi/tests/test_dashboard.py b/dokimi/tests/test_dashboard.py index 159034a678..82962d31d1 100644 --- a/dokimi/tests/test_dashboard.py +++ b/dokimi/tests/test_dashboard.py @@ -3,7 +3,8 @@ """Tests for dashboard aggregator and markdown renderer.""" import json -from pathlib import Path +import os +from pathlib import Path, PureWindowsPath import pytest @@ -12,6 +13,7 @@ ProductSnapshot, QuestionResult, ResultsAggregator, + _result_files, ) from dokimi.dashboard.markdown_renderer import render_dashboard, save_dashboard_markdown, save_dashboard_json from dokimi.eval.stats import paired_summary @@ -68,6 +70,72 @@ def test_aggregator_finds_eval_files(tmp_path): assert p.avg_delta == 20.0 +def test_the_result_files_of_a_listable_tree_are_the_three_rglobs(tmp_path): + names = ["eval/a.json", "x/eval/b.json", "eval/eval_c.json", "eval_d.json", "y/eval_e.json", "evaluations/f.json", + "z/evaluations/g.json", "eval/n/h.json", "evaluations/i.txt", "other/j.json", "eval/k.json/l", "m.json"] + for name in names: + (tmp_path / name).parent.mkdir(parents=True, exist_ok=True) + (tmp_path / name).write_text("{}", encoding="utf-8") + expected = [*tmp_path.rglob("eval/*.json"), *tmp_path.rglob("eval_*.json"), *tmp_path.rglob("evaluations/*.json")] + found = _result_files(tmp_path) + assert sorted(found) == sorted(expected) and len(found) == 9 # eval/eval_c.json is in two of the three lists + assert _result_files(tmp_path / "eval" / "a.json") == [] == _result_files(tmp_path / "absent") + + +def test_an_eval_or_evaluations_symlink_to_a_directory_is_read_through_as_rglob_names_it(tmp_path): + snapshots = tmp_path / "snapshots" + snapshots.mkdir() + (snapshots / "a.json").write_text("{}", encoding="utf-8") + results = tmp_path / "results" + (results / "x").mkdir(parents=True) + (results / "eval").symlink_to(snapshots, target_is_directory=True) + (results / "x" / "evaluations").symlink_to(snapshots, target_is_directory=True) + (results / "y").mkdir() + (results / "y" / "eval").symlink_to(tmp_path / "absent") # a dangling link has no files and is no error + expected = [*results.rglob("eval/*.json"), *results.rglob("evaluations/*.json")] + assert len(expected) == 2 + assert sorted(_result_files(results)) == sorted(expected) + + +class _WindowsEntry: + """A directory entry whose relative path is a Windows path, which matches names without regard to case.""" + + def __init__(self, rel, children=(), link=False): + self.name, self._rel, self._children, self._link = rel.rpartition("\\")[2], rel, children, link + + def relative_to(self, root): + return PureWindowsPath(self._rel) + + def is_symlink(self): + return self._link + + def is_dir(self): + return self._link + + def iterdir(self): + return iter(self._children) + + +def test_an_eval_symlink_is_read_through_whatever_its_case_where_names_match_without_case(tmp_path, monkeypatch): + snapshot = _WindowsEntry("a.json") + links = [_WindowsEntry("EVAL", [snapshot], link=True), _WindowsEntry("x\\Evaluations", [snapshot], link=True)] + monkeypatch.setattr("dokimi.digest_entries.listed_entries", lambda root: links) + assert _result_files(tmp_path) == [snapshot, snapshot] + + +@pytest.mark.skipif(not hasattr(os, "geteuid") or os.geteuid() == 0, reason="root lists a mode 111 directory") +def test_a_symlink_not_named_eval_is_not_listed(tmp_path): + closed = tmp_path / "closed" + closed.mkdir() + (tmp_path / "results").mkdir() + (tmp_path / "results" / "other").symlink_to(closed, target_is_directory=True) + closed.chmod(0o111) + try: + assert _result_files(tmp_path / "results") == [] + finally: + closed.chmod(0o755) + + # Two pairs, a question scored in the context arm only, one in the baseline arm only. _ONE_ARM_EVALS = [ _ev("q1", "Q1?", 80, 60), _ev("q2", "Q2?", 40, 40), diff --git a/dokimi/tests/test_dashboard_cli.py b/dokimi/tests/test_dashboard_cli.py index 0b6f4b7dc1..d0b104172e 100644 --- a/dokimi/tests/test_dashboard_cli.py +++ b/dokimi/tests/test_dashboard_cli.py @@ -6,6 +6,9 @@ from __future__ import annotations import json +import os + +import pytest from tests.cli_refusal import refusal @@ -47,6 +50,27 @@ def test_generate_exits_2_with_a_message_when_the_output_dir_is_a_file(tmp_path, assert "Traceback" not in err +@pytest.mark.skipif(not hasattr(os, "geteuid") or os.geteuid() == 0, reason="root lists a mode 111 directory") +def test_generate_exits_2_naming_a_results_directory_it_cannot_list(tmp_path, capsys): + results = _results(tmp_path) + (results / "sub").mkdir() + (results / "sub" / "eval_y.json").write_text((results / "oneTBB" / "eval_results.json").read_text(encoding="utf-8"), + encoding="utf-8") + (results / "sub").chmod(0o111) + args = build_parser().parse_args( + ["dashboard", "generate", "--results-dir", str(results), "--out-dir", str(tmp_path / "out")]) + try: + with refusal() as out: + args.func(args) + finally: + (results / "sub").chmod(0o755) + + assert out.code == 2, out.err + err = capsys.readouterr().err + assert err.startswith(f"Error: cannot list the results in {results}: ") and str(results / "sub") in err + assert not (tmp_path / "out").exists() + + def test_generate_writes_a_lone_surrogate_in_a_product_name_as_a_question_mark(tmp_path): results = _results(tmp_path) eval_file = results / "oneTBB" / "eval_results.json" diff --git a/dokimi/tests/test_repo_hits_judge_unlistable.py b/dokimi/tests/test_repo_hits_judge_unlistable.py new file mode 100644 index 0000000000..c08a1fb982 --- /dev/null +++ b/dokimi/tests/test_repo_hits_judge_unlistable.py @@ -0,0 +1,45 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +"""`repo hits judge` and `repo hits sheet` refuse a batch whose exported eval content has a directory they cannot list. + +The task directory is found by walking ``/_eval/content``: a task under a directory that cannot be listed is +not a missing task (#1364). +""" + +from __future__ import annotations + +import errno +import os +import shutil + +import pytest + +from dokimi import llm +from dokimi.repos.hits_judge import read_pairs +from tests.test_repo_hits_judge import JUDGE, _batch, _run + + +@pytest.mark.skipif(not hasattr(os, "geteuid") or os.geteuid() == 0, reason="root lists a mode 111 directory") +@pytest.mark.parametrize("argv", [["judge", "--judge", JUDGE], ["sheet", "--out", "sheet.json"]]) +def test_a_task_under_a_directory_that_cannot_be_listed_is_refused_not_reported_missing(tmp_path, capsys, argv): + batch = _batch(tmp_path) + tasks = batch / "_eval" / "content" / "tasks" + tasks.chmod(0o111) + argv = [a if a != "sheet.json" else str(tmp_path / "sheet.json") for a in argv] + try: + with llm.use_adapter(llm.FakeAdapter()) as fake: # an unscripted call fails the test + code, out, err = _run(capsys, argv[0], str(batch), *argv[1:]) + finally: + tasks.chmod(0o755) + assert (code, out, fake.requests) == (2, "", []) + assert err.startswith(f"Error: cannot list {tasks}: {os.strerror(errno.EACCES)}"), err + assert "no directory of task" not in err + assert not (tmp_path / "sheet.json").exists() + + +def test_a_batch_with_no_exported_eval_content_reports_each_task_as_missing(tmp_path): + batch = _batch(tmp_path) + shutil.rmtree(batch / "_eval") + _, pairs = read_pairs(batch) + assert pairs and all(p.problem and "no directory of task" in p.problem for p in pairs) diff --git a/dokimi/tests/test_task_format_detect.py b/dokimi/tests/test_task_format_detect.py index bcbd3da317..86ba25d251 100644 --- a/dokimi/tests/test_task_format_detect.py +++ b/dokimi/tests/test_task_format_detect.py @@ -711,3 +711,21 @@ def test_a_task_md_a_scan_cannot_read_is_reported_and_the_scan_goes_on(tmp_path) task_md.chmod(0o644) assert (found["hb"].format, found["t"].format) == ("harbor", "unknown") assert found["t"].problems == [f"cannot read: [Errno 13] Permission denied: '{task_md}'"] + + +@pytest.mark.skipif(os.name == "nt" or (hasattr(os, "geteuid") and os.geteuid() == 0), + reason="needs POSIX permissions that bind the user (root lists a mode-111 directory)") +def test_a_directory_a_scan_cannot_list_is_reported_and_the_scan_goes_on(tmp_path, capsys): + _write(tmp_path / "ok" / "task.md", "---\nname: ok\n---\nhi\n") + _write(tmp_path / "sub" / "mytask" / "task.md", "---\nname: mytask\n---\nhi\n") + (tmp_path / "sub").chmod(0o111) + try: + found = {r.path.name: r for r in inspect_path(tmp_path)} + _run(["eval", "inspect", str(tmp_path)]) + finally: + (tmp_path / "sub").chmod(0o755) + assert (found["ok"].format, found["sub"].format, found["sub"].kind) == ("task-md", "unknown", "unknown") + assert found["sub"].problems[0].startswith("cannot read: ") and str(tmp_path / "sub") in found["sub"].problems[0] + out = capsys.readouterr().out.splitlines() + assert any(line.startswith(f"{tmp_path / 'sub'}\tunknown\tunknown") for line in out) + assert any(line.startswith(" problem: cannot read: ") for line in out)