Have larv-review round-title print a round commit's counts from its report, and rule-hook refuse a title that differs
This commit is contained in:
@@ -3,6 +3,7 @@ import os
|
||||
import pathlib
|
||||
|
||||
from failure import Failure
|
||||
from review_rules.round_titles import Findings, reported
|
||||
|
||||
# Why here: docs/decisions.md → `review: each reviewer under agents/ writes its full report into the chunk's review folder`.
|
||||
REPORTS = ".local/state/larv-review"
|
||||
@@ -24,3 +25,29 @@ def made_review_folder(worktree: str, home: pathlib.Path) -> pathlib.Path | Fail
|
||||
except OSError as failure:
|
||||
return Failure(f"could not make the review folder {folder}: {failure}")
|
||||
return folder
|
||||
|
||||
|
||||
def round_report(folder: pathlib.Path, pass_: str, round_: int) -> pathlib.Path:
|
||||
"""The report of pass_'s round round_ in the review folder, which asks for the rerun one rung up where there is one."""
|
||||
return folder / f"{pass_}-round-{round_}.md"
|
||||
|
||||
|
||||
def rerun_report(asked: pathlib.Path) -> pathlib.Path:
|
||||
"""The report of the rerun one rung up that the report asked asks for, which stands in its place."""
|
||||
return asked.with_name(asked.stem + "-rerun.md")
|
||||
|
||||
|
||||
def standing_report(folder: pathlib.Path, pass_: str, round_: int) -> pathlib.Path:
|
||||
"""The report that stands for pass_'s round round_ in the review folder: the rerun's where there is one, else the round's."""
|
||||
asked = round_report(folder, pass_, round_)
|
||||
return rerun_report(asked) if rerun_report(asked).exists() else asked
|
||||
|
||||
|
||||
def findings_in(report: pathlib.Path) -> Findings | Failure:
|
||||
"""The findings a round's report gives, as round_titles.reported counts them."""
|
||||
try:
|
||||
return reported(report.read_text(encoding="utf-8"))
|
||||
except FileNotFoundError:
|
||||
return Failure(f"no report at {report}")
|
||||
except (OSError, UnicodeDecodeError) as failure:
|
||||
return Failure(f"could not read {report}: {failure}")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""The titles of larv-review's round commits, `Answer <pass> round <n>: <k> 🔴, <m> 🟡 (<j> misread); <summary>`: each pass's round count against its cap, and the findings the rounds reported. <j> counts the 🔴 and 🟡 findings a reviewer marked `[misread]`."""
|
||||
"""The titles of larv-review's round commits, `Answer <pass> round <n>: <k> 🔴, <m> 🟡 (<j> misread); <summary>`: each pass's round count against its cap, and the findings the rounds reported, as titled and as the round's report gives them. <j> counts the 🔴 and 🟡 findings a reviewer marked `[misread]`."""
|
||||
import dataclasses
|
||||
import re
|
||||
|
||||
@@ -16,6 +16,8 @@ EXAMPLE = "Answer stability round 1: 1 🔴, 2 🟡 (1 misread); flag a deleted
|
||||
ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):", re.IGNORECASE)
|
||||
# What follows a round title's colon: the round's 🔴 and 🟡 counts, then how many of them a reviewer marked `[misread]`, a count that titles from before it lack, then `;` and its summary, if any.
|
||||
FINDINGS = re.compile(r" ([0-9]+) 🔴, ([0-9]+) 🟡(?: \(([0-9]+) misread\))?(?:;|$)")
|
||||
# A 🔴 or 🟡 finding's heading in a round's report, as skills/larv-review/review-findings.md → "Report" pins it: `### `, the severity mark, then ` [misread]` where the reviewer marked it so.
|
||||
FINDING = re.compile(r"^### (🔴|🟡)( \[misread\])?", re.MULTILINE)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -93,3 +95,14 @@ def round_findings(titles: list[str]) -> Findings | None:
|
||||
return None
|
||||
misreads = [found.misread for found in counts if found.misread is not None]
|
||||
return Findings(sum(found.red for found in counts), sum(found.yellow for found in counts), sum(misreads) if len(misreads) == len(counts) else None)
|
||||
|
||||
|
||||
def reported(report: str) -> Findings:
|
||||
"""The 🔴 and 🟡 findings a round's report gives in FINDING headings, and how many of them the reviewer marked `[misread]`."""
|
||||
marks = FINDING.findall(report)
|
||||
return Findings(sum(mark == "🔴" for mark, _ in marks), sum(mark == "🟡" for mark, _ in marks), sum(bool(misread) for _, misread in marks))
|
||||
|
||||
|
||||
def round_prefix(pass_: str, round_: int, findings: Findings) -> str:
|
||||
"""The opening of the round's commit title, up to and including the `;` before its summary."""
|
||||
return f"Answer {pass_} round {round_}: {findings.red} 🔴, {findings.yellow} 🟡 ({findings.misread} misread);"
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import pathlib
|
||||
import tempfile
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from review_rules.review_folder import review_folder
|
||||
from failure import Failure
|
||||
from review_rules.review_folder import findings_in, review_folder, standing_report
|
||||
from review_rules.round_titles import Findings
|
||||
|
||||
|
||||
class ReviewFolder(unittest.TestCase):
|
||||
@@ -14,3 +17,19 @@ class ReviewFolder(unittest.TestCase):
|
||||
def test_keys_a_worktree_outside_home_by_its_path_relative_to_the_root(self):
|
||||
self.assertEqual(review_folder("/h", "/srv/proj-item-3"), "/h/.local/state/larv-review/srv/proj-item-3")
|
||||
self.assertEqual(review_folder("/h", "/hx/proj"), "/h/.local/state/larv-review/hx/proj", "a sibling of home that shares its prefix is outside it")
|
||||
|
||||
|
||||
class RoundReport(unittest.TestCase):
|
||||
def test_counts_the_rounds_report_or_its_rerun_one_rung_up_where_there_is_one(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
folder = pathlib.Path(temp)
|
||||
(folder / "prose-round-1.md").write_text("BLOCK\n\n### 🟡 a\n")
|
||||
self.assertEqual(findings_in(standing_report(folder, "prose", 1)), Findings(0, 1, 0))
|
||||
(folder / "prose-round-1-rerun.md").write_text("BLOCK\n\n### 🔴 [misread] a\n")
|
||||
self.assertEqual(findings_in(standing_report(folder, "prose", 1)), Findings(1, 0, 1))
|
||||
|
||||
def test_names_a_missing_report(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
missing = findings_in(standing_report(pathlib.Path(temp), "prose", 2))
|
||||
self.assertIsInstance(missing, Failure)
|
||||
self.assertEqual(missing.reason, f"no report at {temp}/prose-round-2.md")
|
||||
|
||||
@@ -4,7 +4,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from review_rules.round_titles import Findings, lacks_counts, past_cap, round_counts, round_findings, rounds_past_first
|
||||
from review_rules.round_titles import Findings, lacks_counts, past_cap, reported, round_counts, round_findings, round_prefix, rounds_past_first, title_counts
|
||||
|
||||
|
||||
class Rounds(unittest.TestCase):
|
||||
@@ -81,3 +81,17 @@ class RoundFindings(unittest.TestCase):
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
class Reported(unittest.TestCase):
|
||||
REPORT = "BLOCK\n\n### 🔴 [misread] `a.py:1` `f`: wrong\n\n### 🟡 `b.py:2`: worse\n\n### 🟡 [misread] `c.py:3`: worse\n\n### 🟢 `d.py:4`: nit\n\n### ❓ `e.py:5`: why\n\n- 🔴 `a.py:1` `f`: wrong, as the reply lists it\n#### 🟡 a sub-heading\nText naming 🔴 and [misread].\n"
|
||||
|
||||
def test_counts_the_findings_whose_heading_opens_with_their_mark(self):
|
||||
self.assertEqual(reported(self.REPORT), Findings(1, 2, 2))
|
||||
|
||||
def test_counts_none_in_a_report_without_findings(self):
|
||||
self.assertEqual(reported("APPROVE\n\nNothing found.\n"), Findings(0, 0, 0))
|
||||
|
||||
def test_spells_the_title_prefix_a_round_commit_opens_with(self):
|
||||
self.assertEqual(round_prefix("prose", 2, Findings(1, 2, 0)), "Answer prose round 2: 1 🔴, 2 🟡 (0 misread);")
|
||||
self.assertEqual(title_counts(round_prefix("prose", 2, Findings(1, 2, 1))), Findings(1, 2, 1), "the prefix parses as the counts it spells")
|
||||
|
||||
Reference in New Issue
Block a user