Test the environment git runs in, an unreadable digest and the history write of task-bench record-figures
CI / tests (pull_request) Successful in 5m28s

This commit is contained in:
2026-11-23 14:51:11 +01:00
parent 65398d5e96
commit 9207a6cf80
2 changed files with 36 additions and 10 deletions
+26 -2
View File
@@ -9,11 +9,13 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from task_bench.record_figures import appended_to, record_figures
from review_rules.comprehension_history import entries
from failure import Failure
from task_bench import main
from record_store.held import Held
from test_env import isolated_env
from task_bench.record_figures import record_figures
from task_bench import main
from record_store.fakes import MemoryStore
SCORING = "## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\n| Seat | Overall |\n|---|---|\n| Mean | 7.00 |\n"
TABLE = "| Bug | Side | Passed | Output |\n|---|---|---|---|\n"
@@ -90,6 +92,28 @@ class RecordFiguresTest(unittest.TestCase):
self.assertEqual(self.recorded(), f"{self.bench / 'digest.md'} is no task-bench digest: it lacks the line that names its base and head, or the table's three All rows")
self.assertFalse(self.history.exists())
def test_refuses_a_digest_it_cannot_read(self):
(self.bench / "digest.md").mkdir()
self.assertTrue(self.recorded().startswith(f"could not read {self.bench / 'digest.md'}: [Errno "), self.recorded())
def test_git_runs_in_the_environment_given(self):
(self.bench / "digest.md").write_text(DIGEST)
other = self.home / "code/other"
other.mkdir()
subprocess.run(["git", "init", "--quiet", "--initial-branch", "elsewhere"], cwd=other, env=self.env, check=True)
subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@localhost", "-c", "commit.gpgsign=false", "commit", "--quiet", "--allow-empty", "--message", "Base"], cwd=other, env=self.env, check=True)
self.env = {**self.env, "GIT_DIR": str(other / ".git"), "GIT_WORK_TREE": str(self.repo)}
with contextlib.redirect_stdout(io.StringIO()):
self.assertEqual(main.main(["record-figures"], self.env), 0)
self.assertIn(", task-bench of elsewhere: head ", self.history.read_text())
def test_writes_over_the_version_the_history_was_read_at_and_says_why_a_write_fails(self):
history = MemoryStore(label="history.md", version=5)
self.assertEqual(appended_to(history, Held("", "5"), "task-bench of item-7: head b against base a", "## an entry\n"), "Appended to history.md.")
self.assertEqual(history.overs, ["5"])
refused = appended_to(history, Held("", "5"), "task-bench of item-8: head b against base a", "## an entry\n")
self.assertEqual(refused.reason if isinstance(refused, Failure) else refused, "someone saved history.md since version 5")
def test_the_tool_prints_the_line_and_refuses_arguments(self):
(self.bench / "digest.md").write_text(DIGEST)
with contextlib.redirect_stdout(io.StringIO()) as out: