Count, per finished chunk, the findings that arose from misreading code that had already shipped

This commit is contained in:
2026-10-23 11:23:44 +02:00
parent e00eb558c2
commit 4d18b8e125
13 changed files with 113 additions and 33 deletions
+19 -4
View File
@@ -6,7 +6,7 @@ from comprehension_history import HISTORY
from todo_table import Item, items
from markdown_text import listed
from reading_cost.figures import RECORD
from round_titles import round_counts, round_findings
from round_titles import round_counts, round_findings, round_misreads
# Fewest single-item chunks a score needs before its medians print: the 10 figures the reading-cost trend waits for; no published standard sets either.
ENOUGH = 10
@@ -22,7 +22,7 @@ Chunk = tuple[str, str, int, Landing]
# The tool's name and report call a Result an outcome, a word the code keeps for an entry of a `.outcomes.md` file: docs/decisions.md → `bin/: an outcome is an entry`.
@dataclasses.dataclass(frozen=True)
class Result:
"""What the chunk that shipped an item measured. findings holds the 🔴 and 🟡 counts, None where a round title lacks them or the branch has no round. landed says how the chunk reached the default branch: by a merge commit, by a rebase that replayed its commits, or by commits never replayed."""
"""What the chunk that shipped an item measured. findings holds the 🔴 and 🟡 counts, None where a round title lacks them or the branch has no round. landed says how the chunk reached the default branch: by a merge commit, by a rebase that replayed its commits, or by commits never replayed. misread counts the 🔴 and 🟡 findings that arose from misreading code that had already shipped, None where a round title lacks the count or the branch has no round."""
item: Item
merge: str
merged: str
@@ -32,6 +32,7 @@ class Result:
rounds_past_first: int
findings: tuple[int, int] | None
landed: Landing
misread: int | None
# A measure's name and how to read it from a Result, None where the chunk did not record it.
@@ -63,7 +64,7 @@ def results_of(shipped: list[Item], merge: str, merged: str, numstat: str, title
lines = sum(int(count) for row in work for count in row[:2] if count.isdigit())
past_first = sum(max(0, count - 1) for count in round_counts(titles).values())
ids = [item.id for item in shipped]
return [Result(item, merge, merged, tuple(id_ for id_ in ids if id_ != item.id), lines, len(work), past_first, round_findings(titles), landed) for item in shipped]
return [Result(item, merge, merged, tuple(id_ for id_ in ids if id_ != item.id), lines, len(work), past_first, round_findings(titles), landed, round_misreads(titles)) for item in shipped]
def nearest(results: list[Result], given: dict[str, int], count: int = 5) -> list[Result]:
@@ -100,6 +101,19 @@ def report(results: list[Result]) -> list[str]:
return lines
def misreads(results: list[Result]) -> list[str]:
"""For each chunk whose round titles count them, newest first: its 🔴 and 🟡 findings from misread shipped code, among all its 🔴 and 🟡 findings."""
# A chunk that shipped several items gives each the same Result fields but item, so one line per chunk.
chunks = {result.merge: result for result in results}
lines = []
for result in sorted(chunks.values(), key=lambda result: result.merged, reverse=True):
if result.misread is None or result.findings is None:
continue
at_least = "" if result.landed == "merge" else "at least "
lines.append(f"- {result.merged} in {result.merge}: {at_least}{result.misread} of {result.findings[0]} 🔴, {result.findings[1]} 🟡")
return lines or ["- None: no chunk's round titles count them."]
def too_few(held: int, name: str, what: str) -> str:
chunks = "such chunk records" if held == 1 else "such chunks record"
return f"{held} {chunks} {name} and {what}; the report needs {ENOUGH}."
@@ -123,7 +137,8 @@ def render(result: Result) -> str:
# Rebase drops a round's commit that changed no file, so history shows such a chunk's rounds and findings short.
at_least = "" if result.landed == "merge" else "at least "
merged = {"merge": f"merged {result.merged} in {result.merge}", "rebase": f"merged {result.merged} by rebase in {result.merge}", "push": f"committed {result.merged} in {result.merge}, never replayed, so perhaps part of a pull request"}[result.landed]
findings = f"{at_least}{result.findings[0]} 🔴, {result.findings[1]} 🟡" if result.findings else "findings unknown"
misread = "" if result.misread is None else f" ({result.misread} misread)"
findings = f"{at_least}{result.findings[0]} 🔴, {result.findings[1]} 🟡{misread}" if result.findings else "findings unknown"
others = result.shipped_with
together = f", with item{'s' if len(others) > 1 else ''} {', '.join(map(str, others))}" if others else ""
return f"- Item {result.item.id}, {scores}: {plural(result.lines, 'line')} in {plural(result.files, 'file')}, {at_least}{plural(result.rounds_past_first, 'round')} past each pass's first, {findings}; {merged}{together}. {result.item.tagline}"