From 8529aefcad11a18d135bc89c5d210d7dfe449ee1 Mon Sep 17 00:00:00 2001 From: Nikolay Petrov Date: Fri, 4 Dec 2026 23:19:49 -0800 Subject: [PATCH] refactor(graders): read the command record with the shared run-record reader The commands grader had its own copy of the run-record checks (missing, not an object, the framework's problem key). It now calls run_record.read_run_record, as hidden_tests and mutation do, and keeps only its own check that the record has groups. Same messages, same order. Signed-off-by: Nikolay Petrov --- .../20261205_130000_napetrov_arch-r14-3a.md | 8 ++++++++ dokimi/dokimi/repos/graders/command.py | 17 +++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 dokimi/changelog.d/20261205_130000_napetrov_arch-r14-3a.md diff --git a/dokimi/changelog.d/20261205_130000_napetrov_arch-r14-3a.md b/dokimi/changelog.d/20261205_130000_napetrov_arch-r14-3a.md new file mode 100644 index 000000000..a920a8de1 --- /dev/null +++ b/dokimi/changelog.d/20261205_130000_napetrov_arch-r14-3a.md @@ -0,0 +1,8 @@ + + +### Changed + +- **No user-visible change.** The `commands` grader reads its run record with the shared run-record reader; the messages and their order are the same. diff --git a/dokimi/dokimi/repos/graders/command.py b/dokimi/dokimi/repos/graders/command.py index 7552001d7..e5b47cf04 100644 --- a/dokimi/dokimi/repos/graders/command.py +++ b/dokimi/dokimi/repos/graders/command.py @@ -25,16 +25,16 @@ from __future__ import annotations import importlib -import json import os import posixpath from pathlib import Path from typing import Any if __package__: - from . import hidden_tests + from . import hidden_tests, run_record else: # a script under -I, loaded by main.py, which put this directory on sys.path hidden_tests = importlib.import_module("hidden_tests") + run_record = importlib.import_module("run_record") # Bump when a result for the same inputs changes (a metric or ``pass``). VERSION = "1" @@ -122,16 +122,9 @@ def steps(raw: dict[str, Any]) -> list[tuple[str, int, str, list[str]]]: def _record(run_dir: Path) -> dict[str, Any]: - path = run_dir / RECORD - if not path.is_file(): - raise ValueError(f"no {RECORD}: the commands did not run") - doc = json.loads(path.read_text(encoding="utf-8")) - if not isinstance(doc, dict): - raise ValueError(f"{RECORD} is not an object") - if doc.get("problem"): # the framework could not stage the hidden files - raise ValueError(str(doc["problem"])) - groups = doc.get("groups") - if not isinstance(groups, dict): + # read_run_record raises the framework's problem, if the record holds one + doc = run_record.read_run_record(run_dir, RECORD, "the commands did not run") + if not isinstance(doc.get("groups"), dict): raise ValueError(f"{RECORD} has no groups") return doc