Answer architecture round 1: move the base fallback, heading check and seat names into the pure modules, move legacy scores through record-scoring, and read origin as last fetched when a fetch fails
This commit is contained in:
+17
-20
@@ -1,29 +1,18 @@
|
||||
import dataclasses
|
||||
import decimal
|
||||
import re
|
||||
|
||||
from larv_review.seats import DIMENSIONS, Seat
|
||||
from larv_review.history import entries, Entry, PLACE
|
||||
from larv_review.seats import DIMENSIONS, FIRST_SEATS, Seat, SPLIT_SEATS
|
||||
from larv_review.history import entries, Entry, HistoryChange, PLACE
|
||||
from failure import Failure
|
||||
from rank_todo import Item, ITEMS_HEADER, parse_row, table_rows
|
||||
|
||||
CAP = 3
|
||||
FIRST_SEATS = ("Mid A", "Inherited architect")
|
||||
FLOOR = decimal.Decimal("7.0")
|
||||
PASSES = ("architecture", "full scan", "security", "stability", "product-owner", "prose")
|
||||
ROUND = re.compile(r"^Answer (.+) round ([0-9]+):")
|
||||
SPLIT_SEATS = ("Maintainability senior", "Junior A")
|
||||
ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):")
|
||||
VOTES = ("better", "same", "worse")
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class HistoryChange:
|
||||
"""A merged change on the default branch that touched the history, and the history before and after it."""
|
||||
commit: str
|
||||
before: str
|
||||
after: str
|
||||
|
||||
|
||||
def votes(seats: list[Seat]) -> dict[str, str] | Failure:
|
||||
"""Each seat's vote as it counts: a better or worse vote naming no `path:line` place counts as same."""
|
||||
names = [seat.name for seat in seats]
|
||||
@@ -86,12 +75,18 @@ def first_ruling(history: str) -> Entry | None:
|
||||
return rulings[0] if rulings else None
|
||||
|
||||
|
||||
def base(changes: list[HistoryChange], history: str, merge_base: str, default: str) -> tuple[str, str]:
|
||||
"""The commit a paired ruling reads against, and how it was found: the last measured commit, else the base the history's first paired ruling names, else the merge base of HEAD and the default branch. history is the default branch's."""
|
||||
if found := measured_commit(changes):
|
||||
return found, f"The newest merged change on {default} that adds a scoring run to the history, or whose last added paired ruling is better."
|
||||
if (first := first_ruling(history)) and first.against:
|
||||
return first.against, f"No merged change on {default} adds a scoring run or a better ruling; the base its first paired ruling names."
|
||||
return merge_base, f"No merged change on {default} adds a scoring run or a paired ruling; the merge base of HEAD and {default}."
|
||||
|
||||
|
||||
def plan_items(todo: str) -> list[Item] | Failure:
|
||||
"""Each row of a todo.md's items table, read as `rank_todo.py` reads it; a plan with no table has no items."""
|
||||
lines = todo.splitlines()
|
||||
if ITEMS_HEADER not in lines:
|
||||
return []
|
||||
table = table_rows(lines, ITEMS_HEADER)
|
||||
"""Each row of a todo.md's items table, read as `rank_todo.py` reads it."""
|
||||
table = table_rows(todo.splitlines(), ITEMS_HEADER)
|
||||
if isinstance(table, Failure):
|
||||
return table
|
||||
items = []
|
||||
@@ -103,9 +98,11 @@ def plan_items(todo: str) -> list[Item] | Failure:
|
||||
return items
|
||||
|
||||
|
||||
def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool) -> list[str]:
|
||||
def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool) -> list[str] | Failure:
|
||||
"""Why the chunk takes a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs it ships, and landed whether the default branch holds a commit after the newest release tag. A release has work landed towards it when the chunk ships one of its items, or when it is the earliest release before names and landed holds."""
|
||||
plan = {item.id: item for item in before + after}
|
||||
if unknown := sorted(set(ships) - set(plan)):
|
||||
return Failure(f"neither plan holds item {', '.join(map(str, unknown))}")
|
||||
shipped = [plan[id_] for id_ in ships]
|
||||
reasons = [f"ships item {item.id}, which names the comprehension floor" for item in shipped if "comprehension floor" in item.tagline.lower()]
|
||||
left = {item.release for item in after if item.id not in ships}
|
||||
|
||||
Reference in New Issue
Block a user