Answer principles round 1: 0 🔴, 3 🟡 (0 misread); hand the home folder, the clock and the output to larv-review's commands from their wiring

This commit is contained in:
2026-11-13 03:04:44 +01:00
parent 87d5023773
commit e6da7b0b9c
22 changed files with 155 additions and 131 deletions
+2 -1
View File
@@ -35,6 +35,7 @@ cannot read.
"""
import json
import os
import pathlib
import sys
import time
import typing
@@ -118,5 +119,5 @@ def bash_breaches(command: str, cwd: str, home: str) -> list[Breach]:
found = commits(simples, home)
in_files = [breach for directory in dict.fromkeys(commit.directory for commit in found) for breach in committed_file_breaches(directory)]
round_cap = [breach for commit in found for breach in round_cap_breaches(commit)]
todo = [breach for commit in found for breach in todo_breaches(commit.directory)]
todo = [breach for commit in found for breach in todo_breaches(commit.directory, pathlib.Path(home))]
return command_breaches(command, simples, home) + round_cap + todo + in_files
+15 -8
View File
@@ -75,14 +75,14 @@ class Commits(unittest.TestCase):
self.assertEqual(committed("cd a # go there\nGIT_EDITOR=true git commit -m x"), [CommitCall("/r/a", ["x"], False, False)])
def test_a_commit_after_a_heredoc_or_a_blank_line_is_seen(self):
self.assertEqual(len(committed("cat <<EOF > notes\nhello\nEOF\ngit commit -m a")), 1)
self.assertEqual(len(committed("git status &&\n\ngit commit -m a")), 1)
self.assertEqual(committed("cat <<EOF > notes\nhello\nEOF\ngit commit -m a"), [CommitCall("/r", ["a"], False, False)])
self.assertEqual(committed("git status &&\n\ngit commit -m a"), [CommitCall("/r", ["a"], False, False)])
def test_an_arithmetic_shift_is_no_heredoc(self):
self.assertEqual(len(committed("echo $((1<<2))\ngit commit -m a\n2")), 1)
self.assertEqual(committed("echo $((1<<2))\ngit commit -m a\n2"), [CommitCall("/r", ["a"], False, False)])
def test_a_line_that_does_not_parse_hides_only_itself(self):
self.assertEqual(len(committed("echo 'open\ngit commit -m a")), 1)
self.assertEqual(committed("echo 'open\ngit commit -m a"), [CommitCall("/r", ["a"], False, False)])
def test_a_redirect_keeps_its_command_s_words_together(self):
self.assertEqual(segments("echo hi > f arg"), [["echo", "hi", "arg"]])
@@ -892,16 +892,23 @@ class TodoRankCheck(unittest.TestCase):
self.config = configured(self, pathlib.Path(checkout)) / "config.toml"
return checkout
def test_a_changed_plan_that_cannot_be_read_is_a_breach(self):
checkout = self.changed_plan(self.other, "")
pathlib.Path(checkout, "todo.md").chmod(0)
self.addCleanup(pathlib.Path(checkout, "todo.md").chmod, 0o600)
self.assertEqual(len(self.details(checkout)), 1)
self.assertIn("Permission denied", self.details(checkout)[0])
def details(self, checkout: str) -> list[str]:
return [breach.detail for breach in todo_breaches(checkout, pathlib.Path(self.own))]
return [breach.detail for breach in todo_breaches(checkout, pathlib.Path.home(), pathlib.Path(self.own))]
def test_a_checkout_of_the_hooks_repo_runs_its_own_rank_todo(self):
checkout = self.changed_plan(f"{self.folder}/clone", self.STUB)
self.assertEqual(self.details(checkout), [f"own script checked {checkout}/todo.md"])
top = str(pathlib.Path(checkout).resolve())
self.assertEqual([(breach.rule, breach.directory) for breach in todo_breaches(checkout, pathlib.Path(self.own))], [("todo-rank-check", top)])
self.assertEqual([(breach.rule, breach.directory) for breach in todo_breaches(checkout, pathlib.Path.home(), pathlib.Path(self.own))], [("todo-rank-check", top)])
self.config.unlink()
self.assertEqual([(breach.rule, breach.directory) for breach in todo_breaches(checkout, pathlib.Path(self.own))], [("todo-rank-check", top)], "a todo.md with no config")
self.assertEqual([(breach.rule, breach.directory) for breach in todo_breaches(checkout, pathlib.Path.home(), pathlib.Path(self.own))], [("todo-rank-check", top)], "a todo.md with no config")
def test_its_own_rank_todo_passing_passes(self):
self.assertEqual(self.details(self.changed_plan(f"{self.folder}/clone", "")), [])
@@ -935,7 +942,7 @@ class TodoRankCheck(unittest.TestCase):
self.config.write_text(self.config.read_text().replace('"checkout:todo.md"', '"folder:todo.md"'))
(self.config.parent / "todo.md").write_text("# todo\n")
self.assertEqual(self.details(folder), [f"own script checked {folder}/todo.md"], "checked with the checkout's own rank_todo.py, as a commit there would be")
self.assertEqual([(breach.rule, breach.directory) for breach in todo_breaches(folder, pathlib.Path(self.own))], [("todo-rank-check", str(pathlib.Path(folder).resolve()))])
self.assertEqual([(breach.rule, breach.directory) for breach in todo_breaches(folder, pathlib.Path.home(), pathlib.Path(self.own))], [("todo-rank-check", str(pathlib.Path(folder).resolve()))])
git(folder, "add", "-A")
git(folder, "commit", "-q", "-m", "plan")
self.assertEqual(self.details(folder), [], "committed, so unchanged")
+8 -4
View File
@@ -19,15 +19,15 @@ OWN = pathlib.Path(__file__).resolve().parents[2]
OWN_CHECK_SECONDS = 20
def todo_breaches(directory: str, own: pathlib.Path = OWN) -> list[Breach]:
def todo_breaches(directory: str, home: pathlib.Path, own: pathlib.Path = OWN) -> list[Breach]:
"""Why the plan of directory's project is not ranked, where the plan has changed; the plan is the todo.md its config names. directory may also be in a config's folder, a git repo of its own."""
top = guarded_git(directory, "rev-parse", "--show-toplevel")
if isinstance(top, Failure):
return []
held_here = held(pathlib.Path(top), pathlib.Path.home())
held_here = held(pathlib.Path(top), home)
if held_here is not None:
return folder_breaches(top, held_here, own)
config = located(top, pathlib.Path.home(), functools.partial(git, guarded=True))
config = located(top, home, functools.partial(git, guarded=True))
if isinstance(config, Failure):
# A checkout whose todo.md changes with no config is one whose config is still to write. An unchanged todo.md may be a third party's, whose clone needs no config.
unconfigured = pathlib.Path(top) / "todo.md"
@@ -78,6 +78,10 @@ def changed(top: str, todo: pathlib.Path, tracked: str) -> bool:
# Hashed here, never by `git status`, which would run a clean filter the checkout's own config names before the call is allowed.
staged, committed = guarded_git(top, "rev-parse", f":{tracked}"), guarded_git(top, "rev-parse", f"HEAD:{tracked}")
algorithm = guarded_git(top, "rev-parse", "--show-object-format")
content = todo.read_bytes()
try:
content = todo.read_bytes()
except OSError:
# An unreadable plan counts as changed, so the check runs and its breach says why the plan cannot be read. Raising here would end the hook with an exit that lets the commit through unchecked.
return True
worktree = hashlib.new("sha1" if isinstance(algorithm, Failure) else algorithm, b"blob %d\0" % len(content) + content).hexdigest()
return isinstance(staged, Failure) or staged != worktree or staged != committed