Leave items a chunk drops by a 'Drop item' title out of score-outcomes, check this repo's branches with their own rank_todo.py, and test the replays' model, floor and checkout
This commit is contained in:
@@ -80,7 +80,7 @@ RULES: dict[RuleName, Rule] = {
|
||||
"a docker build, docker buildx build or docker compose build, and a run of cargo mutants, Infection, mutmut or Stryker, the mutation tools stability-reviewer names, whether direct, through a launcher such as uvx, or inside docker run, docker exec or docker compose run or exec. A gate script is not checked, since no program can tell it from a light one",
|
||||
),
|
||||
"todo-rank-check": Rule(
|
||||
"while todo.md has changes, staged or not, a git commit waits until ~/.claude/bin/rank_todo.py --check passes on it",
|
||||
"while todo.md has changes, staged or not, a git commit waits until rank_todo.py --check passes on it: the checkout's own bin/rank_todo.py where the checkout is of this setup's repo, else ~/.claude/bin/rank_todo.py",
|
||||
"a git commit in a checkout whose todo.md has changes",
|
||||
),
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ from rule_hook.call import Call, parsed_call
|
||||
from git_cli.git_command import commit_message, CommitCall, commits
|
||||
from release_plan.test_ranking import DECISIONS, README, TODO
|
||||
from rule_hook.git import guarded_git
|
||||
from rule_hook.todo_check import todo_breaches
|
||||
from test_env import isolated_env
|
||||
from rule_hook.override_log import LogLine, parsed_entry, this_chunks
|
||||
from rule_hook.reviewer_rung import reviewer_breaches, skill_breaches
|
||||
@@ -850,3 +851,46 @@ class Hook(unittest.TestCase):
|
||||
self.assertIn("reviewer-report\n The rule: a reviewer writes nothing but its report", helped)
|
||||
self.assertRegex(helped, r" reviewer-report\n( .*\n){2} Takes no override\.\n")
|
||||
self.assertRegex(helped, r" image-pin\n( .*\n){2} \S", "a rule a marker waives says nothing of overrides")
|
||||
|
||||
|
||||
class TodoRankCheck(unittest.TestCase):
|
||||
"""A checkout of the repo the hook runs from checks todo.md with its own bin/rank_todo.py; any other checkout with the hook's."""
|
||||
STUB = "import sys\nprint('own script checked ' + sys.argv[-1], file=sys.stderr)\nsys.exit(int(sys.argv[1] == '--check'))\n"
|
||||
|
||||
def setUp(self):
|
||||
self.folder = tempfile.mkdtemp()
|
||||
self.addCleanup(subprocess.run, ["rm", "-rf", self.folder])
|
||||
self.own = f"{self.folder}/own"
|
||||
pathlib.Path(self.own).mkdir()
|
||||
git(self.own, "init", "-q", "-b", "main")
|
||||
git(self.own, "commit", "-q", "--allow-empty", "-m", "root")
|
||||
git(self.folder, "clone", "-q", self.own, "clone")
|
||||
self.other = f"{self.folder}/other"
|
||||
pathlib.Path(self.other).mkdir()
|
||||
git(self.other, "init", "-q", "-b", "main")
|
||||
git(self.other, "commit", "-q", "--allow-empty", "-m", "another root")
|
||||
|
||||
def changed_plan(self, checkout: str, stub: str) -> str:
|
||||
pathlib.Path(checkout, "bin").mkdir()
|
||||
pathlib.Path(checkout, "bin", "rank_todo.py").write_text(stub)
|
||||
pathlib.Path(checkout, "todo.md").write_text("# todo\n")
|
||||
return checkout
|
||||
|
||||
def details(self, checkout: str) -> list[str]:
|
||||
return [breach.detail for breach in todo_breaches(checkout, 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"])
|
||||
|
||||
def test_its_own_rank_todo_passing_passes(self):
|
||||
self.assertEqual(self.details(self.changed_plan(f"{self.folder}/clone", "")), [])
|
||||
|
||||
def test_its_own_rank_todo_failing_silently_is_named(self):
|
||||
checkout = self.changed_plan(f"{self.folder}/clone", "import sys\nsys.exit(3)\n")
|
||||
self.assertEqual(self.details(checkout), [f"{checkout}/bin/rank_todo.py --check failed with exit 3 and printed nothing"])
|
||||
|
||||
def test_another_repos_rank_todo_never_runs(self):
|
||||
reasons = self.details(self.changed_plan(self.other, self.STUB))
|
||||
self.assertTrue(reasons)
|
||||
self.assertNotIn("own script", " ".join(reasons))
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import hashlib
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from rule_hook.rules import Breach
|
||||
from failure import Failure
|
||||
@@ -7,12 +9,40 @@ from rule_hook.git import guarded_git
|
||||
from release_plan import ranking
|
||||
|
||||
|
||||
def todo_breaches(directory: str) -> list[Breach]:
|
||||
# The checkout this hook runs from: bin/rule_hook/ sits two folders below it.
|
||||
OWN = pathlib.Path(__file__).resolve().parents[2]
|
||||
# rank_todo.py --check takes about a tenth of a second; the hook must answer well within Claude Code's minute.
|
||||
OWN_CHECK_SECONDS = 20
|
||||
|
||||
|
||||
def todo_breaches(directory: str, own: pathlib.Path = OWN) -> list[Breach]:
|
||||
top = guarded_git(directory, "rev-parse", "--show-toplevel")
|
||||
if isinstance(top, Failure) or not (pathlib.Path(top) / "todo.md").is_file():
|
||||
return []
|
||||
todo = pathlib.Path(top) / "todo.md"
|
||||
return [Breach("todo-rank-check", line, top) for line in ranking.check_failures(todo)] if changed(top, todo) else []
|
||||
return [Breach("todo-rank-check", line, top) for line in check_failures(top, todo, own)] if changed(top, todo) else []
|
||||
|
||||
|
||||
def check_failures(top: str, todo: pathlib.Path, own: pathlib.Path) -> list[str]:
|
||||
"""Why rank_todo.py --check fails on todo. A checkout of the repo the hook runs from checks with its own bin/rank_todo.py, so a branch that changes the table's shape is held to its own rules. Any other checkout checks with the hook's ranking: running its script would run its code before every commit."""
|
||||
script = pathlib.Path(top) / "bin" / "rank_todo.py"
|
||||
if not script.is_file() or not same_repo(top, own):
|
||||
return ranking.check_failures(todo)
|
||||
try:
|
||||
ran = subprocess.run([sys.executable, str(script), "--check", str(todo)], capture_output=True, cwd=top, text=True, timeout=OWN_CHECK_SECONDS)
|
||||
except subprocess.TimeoutExpired:
|
||||
return [f"{script} --check did not finish in {OWN_CHECK_SECONDS} seconds"]
|
||||
except OSError as failure:
|
||||
return [f"{script} --check could not run: {failure}"]
|
||||
if ran.returncode == 0:
|
||||
return []
|
||||
return ran.stderr.splitlines() or [f"{script} --check failed with exit {ran.returncode} and printed nothing"]
|
||||
|
||||
|
||||
def same_repo(top: str, own: pathlib.Path) -> bool:
|
||||
"""Whether the checkout's history and the hook's share a root commit."""
|
||||
theirs, mine = guarded_git(top, "rev-list", "--max-parents=0", "HEAD"), guarded_git(str(own), "rev-list", "--max-parents=0", "HEAD")
|
||||
return not isinstance(theirs, Failure) and not isinstance(mine, Failure) and bool(set(theirs.split()) & set(mine.split()))
|
||||
|
||||
|
||||
def changed(top: str, todo: pathlib.Path) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user