Answer stability round 1: refuse two more seats once the first two agree, compare scores as decimals, read only ASCII digits as item IDs, refuse a shallow clone's base search, and sort release candidates below their release; also holds product-owner round 1's fixes
This commit is contained in:
@@ -65,6 +65,11 @@ def file_at(revision: str, path: str) -> str | Failure:
|
||||
|
||||
def history_changes(default: str) -> list[HistoryChange] | Failure:
|
||||
"""Each merged change on the default branch that touched the history, newest first; a merge commit counts as one change against its first parent."""
|
||||
shallow = git("rev-parse", "--is-shallow-repository")
|
||||
if isinstance(shallow, Failure):
|
||||
return shallow
|
||||
if shallow.strip() == "true":
|
||||
return Failure("a shallow clone lacks the commits the base search reads; run `git fetch --unshallow origin`")
|
||||
commits = git("log", "--first-parent", "--format=%H", default, "--", HISTORY)
|
||||
if isinstance(commits, Failure):
|
||||
return commits
|
||||
@@ -82,7 +87,8 @@ def history_changes(default: str) -> list[HistoryChange] | Failure:
|
||||
|
||||
def landed_since_release(default: str) -> bool | Failure:
|
||||
"""Whether the default branch holds a commit after its newest `v*` tag, or any commit when it has none."""
|
||||
tags = git("tag", "--list", "v*", "--merged", default, "--sort=-v:refname")
|
||||
# Sorts v1.0.0-rc.1 below v1.0.0.
|
||||
tags = git("-c", "versionsort.suffix=-", "tag", "--list", "v*", "--merged", default, "--sort=-v:refname")
|
||||
if isinstance(tags, Failure):
|
||||
return tags
|
||||
newest = tags.split()[:1]
|
||||
|
||||
@@ -110,8 +110,10 @@ def resolved(places: list[Place], tracked: list[str]) -> tuple[list[Place], list
|
||||
|
||||
def heading(at: float, read: str, paired: bool, moved: bool) -> re.Match[str] | Failure:
|
||||
"""An entry's heading, matched by HEADING: when the seats finished, in UTC, and what they read. A run moved from a decision entry opens instead with the date or time that entry gives."""
|
||||
if moved != bool(DATED.match(read)):
|
||||
return Failure(f"only a seats file holding a {MEAN} line alone opens with a date or UTC time, then `, `: {read}")
|
||||
if moved and not DATED.match(read):
|
||||
return Failure(f"a seats file holding a {MEAN} line alone opens with YYYY-MM-DD or YYYY-MM-DDTHH:MM:SSZ, then `, `: {read}")
|
||||
if DATED.match(read) and not moved:
|
||||
return Failure(f"only a seats file holding a {MEAN} line alone opens with a date: {read}")
|
||||
title = read if moved else f"{time.strftime(STAMP, time.gmtime(at))}, {read}"
|
||||
if (named := HEADING.match(title)) and bool(named.group(4)) == paired:
|
||||
return named
|
||||
@@ -126,10 +128,14 @@ def appended(history: str, entry: str) -> str:
|
||||
|
||||
def ruling_entry(title: str, seats: list[Seat], counted: dict[str, str], ruled: str) -> str:
|
||||
"""A paired ruling's entry; a seat's vote that counted as same for naming no place says so."""
|
||||
votes = [[seat.name, counted[seat.name] if counted[seat.name] == seat.said else f"same (voted {seat.said}, naming no place)"] for seat in seats]
|
||||
votes = [[seat.name, vote_text(seat, counted[seat.name])] for seat in seats]
|
||||
return entry_text(title, [f"Ruling: {ruled}"], [["Seat", "Vote"], *votes], [(f"{seat.name}, {DECIDED_BY}:", seat.places) for seat in seats])
|
||||
|
||||
|
||||
def vote_text(seat: Seat, counted: str) -> str:
|
||||
return counted if counted == seat.said else f"same (voted {seat.said}, naming no place)"
|
||||
|
||||
|
||||
def scoring_entry(title: str, seats: list[Seat], scores: dict[str, list[str]], means: list[str]) -> str:
|
||||
rows = [[seat, *values] for seat, values in scores.items() if seat != MEAN] + [[MEAN, *means]]
|
||||
labels = [(f"{seat.name}, {RESTRUCTURE_FIRST if seat.name == ARCHITECT else HARDEST_FIRST}:", seat.places) for seat in seats if seat.name != MEAN]
|
||||
|
||||
+25
-14
@@ -1,6 +1,6 @@
|
||||
"""Hold larv-review's mechanical rules: the paired ruling's base and vote count, each pass's rounds, the scoring run's trigger, and the comprehension history's format.
|
||||
|
||||
usage: larv-review ruling-base | round-count | needs-scoring-run <item ID>... | record-ruling <seats file> | record-scoring <seats file>
|
||||
usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <seats file> | record-scoring <seats file>
|
||||
|
||||
Run it inside a project checkout or one of its worktrees. ruling-base, round-count and
|
||||
needs-scoring-run first fetch origin, when the checkout has that remote, and take origin's default
|
||||
@@ -18,15 +18,17 @@ round-count prints, for each pass, the highest <n> among this branch's commit ti
|
||||
`Answer <pass> round <n>:`, counting commits the default branch does not hold, and marks a pass at
|
||||
the cap of {cap} rounds, and a name in such a title that is no pass.
|
||||
|
||||
needs-scoring-run prints why the chunk shipping the given todo.md item IDs takes a scoring run, or
|
||||
`No scoring run due.` It is due when the chunk ships an item whose tagline names the comprehension
|
||||
needs-scoring-run prints why the chunk shipping the given todo.md item IDs, none for a chunk that
|
||||
ships no item, takes a scoring run, or `No scoring run due.` It is due when the chunk ships an item whose tagline names the comprehension
|
||||
floor, or when a release the default branch's todo.md names has no item left in the checkout's
|
||||
todo.md, less the items shipped, and work has landed towards it: the chunk ships one of its items,
|
||||
or it is the earliest release the default branch's todo.md names and the default branch has a
|
||||
commit after its newest v* tag, or has no such tag.
|
||||
|
||||
record-ruling and record-scoring read a seats file: a first line naming what the seats read, then
|
||||
each seat's line, each followed by its places, one `- ` bullet each, as the history writes them:
|
||||
each seat's line, each followed by its places, one `- ` bullet each, as the history writes them. A
|
||||
seat's line opens with its label, written exactly: `Junior A:`, `Mid A:`, `Maintainability
|
||||
senior:` or `Inherited architect:`.
|
||||
|
||||
PR #231 at abc1234, against def5678
|
||||
|
||||
@@ -39,30 +41,33 @@ each seat's line, each followed by its places, one `- ` bullet each, as the hist
|
||||
- `bin/x.py:12` `run`: ...
|
||||
|
||||
record-ruling takes Mid A's and the inherited architect's votes, better, same or worse; a better or
|
||||
worse vote naming no `path:line` place counts as same. When the two counted votes differ, it
|
||||
appends nothing and says to add the maintainability senior's and Junior A's lines. Otherwise the
|
||||
ruling is the vote that leads each other vote by two or more, else same, and it appends the ruling.
|
||||
worse vote naming no place in backticks, `path:line`, counts as same, and the printed votes say so.
|
||||
When the two counted votes differ, it appends nothing and prints `Split:`, saying to add the
|
||||
maintainability senior's and Junior A's lines. Otherwise the ruling is the vote that leads each
|
||||
other vote by two or more, else same; it prints `Ruling:` and appends the ruling.
|
||||
|
||||
record-scoring takes Junior A's, Mid A's, the maintainability senior's and the inherited
|
||||
architect's lines in that order, or a `Mean:` line alone for a run moved from a decision entry.
|
||||
Each line is `Navigation <n>, Locality <n>, Shape <n>, Self-sufficiency <n>, Overall <n>`, each
|
||||
score from 1 to 10 and the overall at most 1 above the line's lowest dimension. A first line names no `, against`. It appends the seats' scores and their means, rounded
|
||||
half up to two decimals, and prints the means and each one under the floor of {floor}.
|
||||
score from 1 to 10 and the overall at most 1 above the line's lowest dimension. Its first line
|
||||
names no `, against`. It appends the seats' scores and their means, rounded half up to two
|
||||
decimals, and prints the means and each one under the floor of {floor}.
|
||||
|
||||
Each record is appended to the history, created when missing, under a heading of the current UTC
|
||||
time and the seats file's first line, or of that line alone when it opens with a date. Each commit
|
||||
the line names must be in the checkout.
|
||||
the line names must be in the checkout. Each run appends, so record a ruling or a run once.
|
||||
|
||||
Exit 1, saying why, on unknown arguments, an unknown item ID, a seats file it cannot read or that
|
||||
breaks the shape above, or when git cannot start, finds no checkout or no default branch, cannot
|
||||
fetch origin for ruling-base or needs-scoring-run, or cannot read or write the history or todo.md.
|
||||
"""
|
||||
import pathlib
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import typing
|
||||
|
||||
from larv_review.history import appended, heading, ruling_entry, scoring_entry
|
||||
from larv_review.history import appended, heading, ruling_entry, scoring_entry, vote_text
|
||||
from larv_review.rules import base, CAP, FLOOR, means, PASSES, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes
|
||||
from larv_review.git import commit_exists, default_branch, file_at, git, HISTORY, history_changes, landed_since_release, top
|
||||
from larv_review.seats import DIMENSIONS, MEAN, Report, report, scores
|
||||
@@ -70,7 +75,7 @@ from failure import Failure
|
||||
from rank_todo import ITEMS_HEADER
|
||||
from file_writes import replace_file
|
||||
|
||||
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run <item ID>... | record-ruling <seats file> | record-scoring <seats file>"
|
||||
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <seats file> | record-scoring <seats file>"
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
@@ -82,12 +87,18 @@ def main(argv: list[str]) -> int:
|
||||
done = with_default_branch(ruling_base, stale_ok=False)
|
||||
elif command == "round-count" and not given:
|
||||
done = with_default_branch(round_count, stale_ok=True)
|
||||
elif command == "needs-scoring-run" and given and all(id_.isdigit() for id_ in given):
|
||||
elif command == "needs-scoring-run" and all(re.fullmatch(r"[0-9]+", id_) for id_ in given):
|
||||
done = with_default_branch(lambda default: needs_scoring_run(default, [int(id_) for id_ in given]), stale_ok=False)
|
||||
elif command == "record-ruling" and len(given) == 1:
|
||||
done = record_ruling(pathlib.Path(given[0]))
|
||||
elif command == "record-scoring" and len(given) == 1:
|
||||
done = record_scoring(pathlib.Path(given[0]))
|
||||
elif command == "needs-scoring-run":
|
||||
print(f"needs-scoring-run takes item IDs, the numbers in todo.md's ID column: {' '.join(given)}", file=sys.stderr)
|
||||
return 1
|
||||
elif not argv:
|
||||
print(USAGE, file=sys.stderr)
|
||||
return 1
|
||||
else:
|
||||
print(f"unknown arguments {' '.join(argv)}; {USAGE}", file=sys.stderr)
|
||||
return 1
|
||||
@@ -169,7 +180,7 @@ def record_ruling(seats_file: pathlib.Path) -> Failure | None:
|
||||
counted = votes(given.seats)
|
||||
if isinstance(counted, Failure):
|
||||
return counted
|
||||
tally = ", ".join(f"{seat} {vote}" for seat, vote in counted.items())
|
||||
tally = ", ".join(f"{seat.name} {vote_text(seat, counted[seat.name])}" for seat in given.seats)
|
||||
ruled = ruling(list(counted.values()))
|
||||
if ruled is None:
|
||||
print(f"Split: {tally}. Launch the maintainability senior and Junior A together, add their lines to the seats file, and run this again.")
|
||||
|
||||
@@ -20,7 +20,11 @@ def votes(seats: list[Seat]) -> dict[str, str] | Failure:
|
||||
return Failure(f"a paired ruling's seats are {' and '.join(FIRST_SEATS)}, then, when their votes differ, {' and '.join(SPLIT_SEATS)}, in that order; the file has {', '.join(names) or 'none'}")
|
||||
if unknown := [seat for seat in seats if seat.said not in VOTES]:
|
||||
return Failure(f"{unknown[0].name}'s vote {unknown[0].said!r} is not better, same or worse")
|
||||
return {seat.name: seat.said if names_a_place(seat) else "same" for seat in seats}
|
||||
counted = {seat.name: seat.said if names_a_place(seat) else "same" for seat in seats}
|
||||
first, second, *more = counted.values()
|
||||
if more and first == second:
|
||||
return Failure(f"{' and '.join(FIRST_SEATS)} both count as {first}, which settles the ruling; drop the other seats' lines")
|
||||
return counted
|
||||
|
||||
|
||||
def names_a_place(seat: Seat) -> bool:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import dataclasses
|
||||
import decimal
|
||||
import re
|
||||
|
||||
from failure import Failure
|
||||
@@ -47,7 +48,7 @@ def report(text: str) -> Report | Failure:
|
||||
elif seats and seats[-1].places and line.startswith(" "):
|
||||
seats[-1].places[-1] += " " + line.strip()
|
||||
else:
|
||||
return Failure(f"the seats file has a line that is neither a seat's line nor one of its places: {line}")
|
||||
return Failure(f"the seats file has a line that is neither a seat's line, opening with one of {', '.join((*SCORING_SEATS, MEAN))} and a colon, nor one of its places: {line}")
|
||||
return Report(lines[0].strip(), seats)
|
||||
|
||||
|
||||
@@ -59,7 +60,7 @@ def scores(seats: list[Seat]) -> dict[str, list[str]] | Failure:
|
||||
for seat in seats:
|
||||
if not (written := SCORES.fullmatch(seat.said)):
|
||||
return Failure(f"{seat.name}'s line is not {', '.join(name + ' <score>' for name in DIMENSIONS)}: {seat.said}")
|
||||
values = [float(value) for value in written.groups()]
|
||||
values = [decimal.Decimal(value) for value in written.groups()]
|
||||
if not all(1 <= value <= 10 for value in values):
|
||||
return Failure(f"{seat.name}'s scores are not each from 1 to 10: {seat.said}")
|
||||
if values[-1] > min(values[:-1]) + 1:
|
||||
|
||||
@@ -47,6 +47,10 @@ class Seats(unittest.TestCase):
|
||||
seats = [Seat("Mid A", "worse", ["the whole skill"]), Seat("Inherited architect", "better", ["`a.py:3` `f`: shorter"])]
|
||||
self.assertEqual(votes(seats), {"Mid A": "same", "Inherited architect": "better"})
|
||||
|
||||
def test_refuses_two_more_seats_once_the_first_two_agree(self):
|
||||
seats = [Seat(name, vote, ["`f.py:1` `f`: x"]) for name, vote in (("Mid A", "worse"), ("Inherited architect", "worse"), ("Maintainability senior", "better"), ("Junior A", "better"))]
|
||||
self.assertIsInstance(votes(seats), Failure)
|
||||
|
||||
def test_takes_the_first_two_seats_then_the_other_two_in_order(self):
|
||||
first = [Seat("Mid A", "same", []), Seat("Inherited architect", "same", [])]
|
||||
self.assertIsInstance(votes(first[::-1]), Failure)
|
||||
@@ -74,6 +78,7 @@ class Seats(unittest.TestCase):
|
||||
self.assertIsInstance(scores(seats[:3]), Failure)
|
||||
self.assertIsInstance(scores([*seats[:3], Seat("Inherited architect", line.replace("Overall 7", "Overall 8"), [])]), Failure)
|
||||
self.assertIsInstance(scores([*seats[:3], Seat("Inherited architect", line.replace("Shape 7", "Shape 11"), [])]), Failure)
|
||||
self.assertEqual(scores([Seat("Mean", "Navigation 7.38, Locality 7.38, Shape 8, Self-sufficiency 8, Overall 8.38", [])])["Mean"][-1], "8.38")
|
||||
|
||||
def test_rounds_each_mean_half_up_and_names_each_under_the_floor(self):
|
||||
found = means({"a": ["7.5", "6.5", "7", "7", "7"], "b": ["7.5", "7", "7", "6.5", "7"], "c": ["7", "6.5", "7", "6.5", "6.5"], "d": ["7.5", "6.5", "7", "6.5", "7"]})
|
||||
@@ -218,6 +223,8 @@ class LarvReviewTool(unittest.TestCase):
|
||||
unknown = self.run_tool("needs-scoring-run", "9")
|
||||
self.assertEqual(unknown.returncode, 1)
|
||||
self.assertIn("item 9", unknown.stderr)
|
||||
self.assertEqual(self.run_tool("needs-scoring-run").stdout, "No scoring run due.\n")
|
||||
self.assertIn("todo.md's ID column", self.run_tool("needs-scoring-run", "item-85").stderr)
|
||||
|
||||
def test_records_a_ruling_once_four_seats_settle_a_split(self):
|
||||
lines = """\
|
||||
@@ -237,7 +244,7 @@ class LarvReviewTool(unittest.TestCase):
|
||||
self.assertFalse(history.exists())
|
||||
lines += "\n\t\t\tMaintainability senior: worse\n\n\t\t\t- `bin/a.py:3` `f`: hard\n\n\t\t\tJunior A: worse\n"
|
||||
ran = self.run_tool("record-ruling", self.seats_file(lines))
|
||||
self.assertEqual(ran.stdout.splitlines()[0], "Ruling: same. Votes as counted: Mid A worse, Inherited architect same, Maintainability senior worse, Junior A same.")
|
||||
self.assertEqual(ran.stdout.splitlines()[0], "Ruling: same. Votes as counted: Mid A worse, Inherited architect same, Maintainability senior worse, Junior A same (voted worse, naming no place).")
|
||||
recorded = entries(history.read_text())
|
||||
self.assertEqual([(entry.commit, entry.against, entry.ruling) for entry in recorded], [(self.start, self.start, "same")])
|
||||
self.assertEqual(recorded[0].places, [Place("bin/a.py", "f")] * 2)
|
||||
|
||||
@@ -39,7 +39,7 @@ A pass is one kind of review, a row of the table, named by its first column. Its
|
||||
| Product-owner | product-owner-reviewer | changes an external surface: API, CLI, UI, error or deprecation text a consumer reads, README and docs an outside reader lands on |
|
||||
| Prose | prose-reviewer | every chunk, one round |
|
||||
|
||||
`~/.claude/bin/larv-review` holds this section's mechanical rules: the round count, the paired ruling's base and vote count, the scoring run's trigger and the history's format. Run it in the chunk's worktree; `~/.claude/bin/larv-review --help` states each rule. On exit 1, repair what its message names and run it again.
|
||||
`~/.claude/bin/larv-review` holds this section's mechanical rules: the round count, the paired ruling's base and vote count, the scoring run's trigger and the history's format. Run it in the chunk's worktree; `~/.claude/bin/larv-review --help` states each rule. On exit 1, repair what its message names and run it again; when you cannot, ask the user.
|
||||
|
||||
A comment is prose, not code. Passes run in this order: line-level polish on code the architect wants restructured, or on a call the security pass will rewrite, is wasted work.
|
||||
|
||||
@@ -97,7 +97,7 @@ Then the comprehension check: simulated readers, launched per `~/.claude/skills/
|
||||
- **Seats.** Mid A and the inherited architect. Write what they read and their replies into a seats file in your scratchpad, in the shape `~/.claude/bin/larv-review --help` shows, and run `~/.claude/bin/larv-review record-ruling <file>`. On `Split:`, launch the maintainability senior and Junior A together, add their lines, and run it again.
|
||||
- **Ruling.** The `Ruling:` line it prints, which it appends to the history.
|
||||
|
||||
**Scoring run**, when `~/.claude/bin/larv-review needs-scoring-run <the IDs of the items the chunk ships>` prints `Scoring run due:`. Run it before removing the chunk's items from `todo.md`. Junior A, Mid A, the maintainability senior and the inherited architect each score the project at the head from 1 to 10 overall and on four dimensions: Navigation, Locality, Shape and Self-sufficiency. Write their lines into a seats file and run `~/.claude/bin/larv-review record-scoring <file>`, which appends the run to the history and prints the four seats' means.
|
||||
**Scoring run**, when `~/.claude/bin/larv-review needs-scoring-run <the IDs of the items the chunk ships, if any>` prints `Scoring run due:`. Run it before removing the chunk's items from `todo.md`. Junior A, Mid A, the maintainability senior and the inherited architect each score the project at the head from 1 to 10 overall and on four dimensions: Navigation, Locality, Shape and Self-sufficiency. Write their lines into a seats file and run `~/.claude/bin/larv-review record-scoring <file>`, which appends the run to the history and prints the four seats' means.
|
||||
|
||||
The chunk does not merge while either holds:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user