Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--
Copyright (C) 2026 Intel Corporation
SPDX-License-Identifier: Apache-2.0
-->

### 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.
4 changes: 3 additions & 1 deletion dokimi/docs/benchmarking-and-comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion dokimi/docs/coding-harnesses.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion dokimi/dokimi/commands/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
21 changes: 18 additions & 3 deletions dokimi/dokimi/dashboard/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Comment thread
antonwolfy marked this conversation as resolved.
Resolved
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."""

Expand All @@ -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()
Expand Down
12 changes: 9 additions & 3 deletions dokimi/dokimi/repos/hits_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)}"
Expand Down
3 changes: 2 additions & 1 deletion dokimi/dokimi/task_formats/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
70 changes: 69 additions & 1 deletion dokimi/tests/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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),
Expand Down
24 changes: 24 additions & 0 deletions dokimi/tests/test_dashboard_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from __future__ import annotations

import json
import os

import pytest

from tests.cli_refusal import refusal

Expand Down Expand Up @@ -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"
Expand Down
45 changes: 45 additions & 0 deletions dokimi/tests/test_repo_hits_judge_unlistable.py
Original file line number Diff line number Diff line change
@@ -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 ``<batch>/_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)
18 changes: 18 additions & 0 deletions dokimi/tests/test_task_format_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading