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
CI / tests (pull_request) Successful in 5m28s
This commit is contained in:
@@ -9,8 +9,10 @@ from task_bench.gather import DIGEST
|
||||
from failure import Failure
|
||||
from git_cli import git_repo
|
||||
from task_bench.bench_folder import held
|
||||
from record_store.held import Held
|
||||
from larv_review.history_commands import held_history
|
||||
from review_rules.review_folder import made_review_folder
|
||||
from record_store.stores import RecordStore
|
||||
from git_cli.git_repo import top
|
||||
from text_files.utc_stamp import utc
|
||||
|
||||
@@ -46,17 +48,17 @@ def record_figures(env: typing.Mapping[str, str], home: pathlib.Path, now: float
|
||||
entry = bench_entry(digest, branch.strip(), now)
|
||||
if entry is None:
|
||||
return Failure(f"{folder / DIGEST} is no task-bench digest: it lacks the line that names its base and head, or the table's three All rows")
|
||||
name, text = entry
|
||||
read = held_history(home)
|
||||
if isinstance(read, Failure):
|
||||
return read
|
||||
history, found = read
|
||||
if f", {name}\n" in found.text:
|
||||
return Failure(f"{history.label} already holds {name}; record each bench once")
|
||||
written = history.write(appended(found.text, text), found.version)
|
||||
return written if isinstance(written, Failure) else f"Appended to {history.label}."
|
||||
return read if isinstance(read, Failure) else appended_to(*read, *entry)
|
||||
|
||||
|
||||
def appended_to(history: RecordStore, held: Held, name: str, entry: str) -> str | Failure:
|
||||
"""Writes entry, of the bench the history calls name, onto held, the history as history's store read it, over held's version; the line the tool prints, or why the entry isn't written."""
|
||||
if f", {name}\n" in held.text:
|
||||
return Failure(f"{history.label} already holds {name}; record each bench once")
|
||||
written = history.write(appended(held.text, entry), held.version)
|
||||
return written if isinstance(written, Failure) else f"Appended to {history.label}."
|
||||
|
||||
def bench_entry(digest: str, branch: str, now: float) -> tuple[str, str] | None:
|
||||
"""What the history calls the bench of branch that digest tells of, and its entry, stamped with now: the table's header and its rows over every bug. None where digest is no task-bench digest."""
|
||||
sides = SIDES.search(digest)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user