Count each finished chunk's later fixes in score-outcomes and the routing figures

This commit is contained in:
2026-10-28 19:27:09 +01:00
parent f2149adc46
commit 1a81b55925
15 changed files with 630 additions and 101 deletions
+30 -26
View File
@@ -23,7 +23,15 @@ holds R and S, and C too where its table also had A, G and Goals. The chunk meas
round title lacks the counts, or the branch has no round;
- misread findings: how many of those 🔴 and 🟡 findings a reviewer marked `[misread]`, the
`(<j> misread)` after the 🟡 count, summed over the titles. Unknown where a round title lacks
that count, as every title written before the count does, or the branch has no round.
that count, as every title written before the count does, or the branch has no round;
- later fixes: the later chunks that fixed code it shipped, each counted once. A later chunk fixed
it where a change of the later chunk removes or rewrites lines, outside todo.md and the records,
that `git blame` traces to a commit this chunk brought to the default branch. The change is the
later chunk's whole change where it ships a todo.md item whose Exempt cell is `defect` or
`security`, or one of its round commits whose title counts a 🔴 and a misread finding, since a
title counts misread 🔴 and 🟡 findings together. A fixing chunk that also ships other items
counts all of its change, so the count can run high; a fix that ships no such item, and answers
no such round, goes uncounted.
A chunk is marked `by rebase` where a commit in it has a committer time apart from its author time,
since a rebase replays a pull request's commits at once, and `never replayed` where none does, since
@@ -55,6 +63,10 @@ Then, newest first, each finished chunk's 🔴 and 🟡 findings with its misrea
chunk whose round titles count them: code health's counter-signal in
~/.claude/CLAUDE.md → "Shared goal".
Then, newest first, each finished chunk's later fixes, naming the fixing chunks, for every chunk
that has any, then how many have none: the defects that reappear in what already shipped, the
other half of that counter-signal.
Exit 1, saying why, on bad arguments, when git cannot start, finds no checkout or reads a shallow
clone, or the default branch cannot be read; or, after the rest of the report, when the anchors are
left out.
@@ -64,9 +76,10 @@ import re
import sys
from score_outcomes.anchors import anchor_lines, Anchors, ANCHORS_PATH, parse_anchors
from score_outcomes.results import Chunk, Landing, misreads, nearest, render, report, Result, results_of, shipped
from score_outcomes.results import chunk_log, fixed_later, label, Landing, misreads, nearest, render, report, Result, results_of, shipped
from git_repo import default_branch, file_at, full_history, git, top
from failure import Failure
from score_outcomes.later_fixes import later_fixes
from todo_table import LEVELS, risk, TOP_SCORE
from markdown_text import listed
from utc_stamp import utc
@@ -107,7 +120,7 @@ def main(argv: list[str]) -> int:
def report_text(results: list[Result], anchored: Anchors | Failure, given: dict[str, int] | None) -> str:
"""The report: the finished items nearest the given scores, where any are given, then the anchors, then the medians, then each chunk's misread findings."""
"""The report: the finished items nearest the given scores, where any are given, then the anchors, then the medians, then each chunk's misread findings, then its later fixes."""
sections = []
if given is not None:
r = risk(given["L"], given["E"], given["I"])
@@ -116,6 +129,7 @@ def report_text(results: list[Result], anchored: Anchors | Failure, given: dict[
sections.append([f"Anchors in {ANCHORS_PATH}, each level's shipped items:", "", *anchor_lines(anchored, results)])
sections.append(["Median outcome at each guessed score, among chunks that shipped one item, never-replayed ones left out:", "", *report(results)])
sections.append(["🔴 and 🟡 findings, with how many a reviewer marked `[misread]`, per finished chunk whose round titles count them, newest first:", "", *misreads(results)])
sections.append(["Later fixes, the later chunks that fixed code each finished chunk shipped, newest first:", "", *fixed_later(results)])
if any(result.landed != "merge" for result in results):
sections.append(UNMERGED)
return "\n\n".join("\n".join(section) for section in sections)
@@ -143,9 +157,17 @@ def read_results(default: str) -> list[Result] | Failure:
"""What each chunk on the default branch's first-parent line measured."""
if partial := full_history():
return partial
log = git("log", "--first-parent", "--format=%x1e%h %ct %at %p", "--name-only", default)
# Both logs read one commit, so a fetch that moves the branch between them cannot cut chunks two ways.
tip = git("rev-parse", "--verify", f"{default}^{{commit}}")
if isinstance(tip, Failure):
return tip
log = git("log", "--first-parent", "--format=%x1e%h %ct %at %p", "--name-only", tip.strip())
if isinstance(log, Failure):
return log
fixes = later_fixes(tip.strip())
if isinstance(fixes, Failure):
return fixes
fixed_by = {landed.label: landed.fixed_by for landed in fixes}
# Each commit's part of the log is its line, then the files it changed against its first parent.
commits = [part.splitlines() for part in log.split("\x1e")[1:]]
headers = [commit[0] for commit in commits]
@@ -156,34 +178,16 @@ def read_results(default: str) -> list[Result] | Failure:
# Only a chunk that changed todo.md can ship an item, so the others skip measure's git calls.
if not any(short in plan for short in hashes[hashes.index(last):hashes.index(first) + 1]):
continue
label = first if first == last else f"{first}^..{last}"
titled = f"{first}^1..{first}^2" if landed == "merge" else f"{first}^1..{last}"
measured = measure(f"{first}^1", last, label, utc(committed), titled, landed)
named = label(first, last)
measured = measure(f"{first}^1", last, named, utc(committed), titled, landed, fixed_by[named])
if isinstance(measured, Failure):
return measured
results += measured
return results
def chunk_log(lines: list[str]) -> list[Chunk]:
"""The chunks `git log --first-parent --format=%h %ct %at %p` lines cut, newest first: each chunk's first and last commit as short hashes, its commit time, and how it reached the branch. A merge commit is a chunk of its own; any other commit joins the run of the newer commit above it when both share a commit time."""
chunks: list[Chunk] = []
joinable = False
for line in lines:
short, committed, authored, *parents = line.split()
if len(parents) > 1:
chunks.append((short, short, int(committed), "merge"))
joinable = False
elif joinable and chunks[-1][2] == int(committed):
_, newest, time, landed = chunks[-1]
chunks[-1] = (short, newest, time, "rebase" if landed == "rebase" or committed != authored else "push")
else:
chunks.append((short, short, int(committed), "rebase" if committed != authored else "push"))
joinable = True
return chunks
def measure(before: str, tip: str, label: str, merged: str, titled: str, landed: Landing) -> list[Result] | Failure:
def measure(before: str, tip: str, named: str, merged: str, titled: str, landed: Landing, fixed_by: tuple[str, ...]) -> list[Result] | Failure:
"""What one chunk measured for each item it shipped: its change from the commit before it to its tip, and the titles of the commits in the range titled."""
planned = file_at(before, "todo.md")
if isinstance(planned, Failure):
@@ -200,4 +204,4 @@ def measure(before: str, tip: str, label: str, merged: str, titled: str, landed:
titles = git("log", "--format=%s", titled)
if isinstance(titles, Failure):
return titles
return results_of(items, label, merged, numstat, titles.splitlines(), landed)
return results_of(items, named, merged, numstat, titles.splitlines(), landed, fixed_by)