Count each finished chunk's later fixes in score-outcomes and the routing figures
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
"""Each chunk on a default branch, with the later chunks that fixed code it shipped: its escaped defects.
|
||||
|
||||
A later chunk fixed code an earlier chunk shipped where one of its changes removes or rewrites lines that `git blame` traces to a commit the earlier chunk brought. Two kinds of change count: the chunk's whole change, where it ships a todo.md item marked `defect` or `security`; and a round commit of the chunk answering a 🔴 that a reviewer marked `[misread]`. Chunks are cut as score-outcomes cuts them, and each counts at most once against each earlier chunk."""
|
||||
import dataclasses
|
||||
import re
|
||||
import typing
|
||||
|
||||
from failure import Failure
|
||||
from git_repo import file_at, git
|
||||
from round_titles import title_counts
|
||||
from score_outcomes.results import chunk_log, label, NOT_WORK, shipped
|
||||
from utc_stamp import utc
|
||||
|
||||
# The Exempt cells, per ~/.claude/rules/todo-items.md, that mark an item fixing a defect.
|
||||
FIXES = ("defect", "security")
|
||||
# A todo.md row that may hold one of FIXES, as the extended regex `git log -G` takes; shipped confirms it.
|
||||
FIX_ROW = r"[|] *(defect|security) *[|]"
|
||||
HUNK = re.compile(r"@@ -([0-9]+)(?:,([0-9]+))? \+[0-9]+(?:,([0-9]+))? @@")
|
||||
BLAME_HEADER = re.compile(r"([0-9a-f]{40}|[0-9a-f]{64}) [0-9]+ [0-9]+")
|
||||
# Runs git with the given arguments, in the checkout's top.
|
||||
Run = typing.Callable[..., str | Failure]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Landed:
|
||||
"""A chunk: its label as score-outcomes names it, its commit time, the titles of every commit it brought to the default branch, and the labels of the later chunks that fixed code it shipped, newest first."""
|
||||
label: str
|
||||
landed: str
|
||||
titles: frozenset[str]
|
||||
fixed_by: tuple[str, ...]
|
||||
|
||||
|
||||
def later_fixes(default: str, cwd: str | None = None, guarded: bool = False, timeout: float | None = None) -> list[Landed] | Failure:
|
||||
"""Each chunk on default's first-parent line, newest first, read in the checkout holding cwd, else the current directory, each git call run as `git` runs it with timeout and guarded."""
|
||||
top = git("rev-parse", "--show-toplevel", cwd=cwd, timeout=timeout, guarded=guarded)
|
||||
if isinstance(top, Failure):
|
||||
return top
|
||||
# Blame and a pathspec read a path from the current directory, and the diff names each from the top.
|
||||
root = top.strip()
|
||||
|
||||
def run(*args: str) -> str | Failure:
|
||||
return git(*args, cwd=root, timeout=timeout, guarded=guarded)
|
||||
log = run("log", "--format=%x1e%H %h %ct %at %P%x1f%s", default)
|
||||
if isinstance(log, Failure):
|
||||
return log
|
||||
shorts: dict[str, str] = {}
|
||||
parents: dict[str, list[str]] = {}
|
||||
titles: dict[str, str] = {}
|
||||
headers: dict[str, str] = {}
|
||||
for record in log.split("\x1e")[1:]:
|
||||
header, _, title = record.rstrip("\n").partition("\x1f")
|
||||
full, short, committed, authored, *above = header.split()
|
||||
shorts[full], parents[full], titles[full] = short, above, title
|
||||
headers[full] = " ".join([full, committed, authored, *above])
|
||||
# git log prints the commit it starts from first.
|
||||
line = [next(iter(parents))]
|
||||
while parents[line[-1]]:
|
||||
line.append(parents[line[-1]][0])
|
||||
chunks = chunk_log([headers[commit] for commit in line])
|
||||
owner = owners(chunks, line, parents)
|
||||
changes = fixing_changes(chunks, owner, parents, titles, run, lambda revision: file_at(revision, "todo.md", root, timeout, guarded), default)
|
||||
if isinstance(changes, Failure):
|
||||
return changes
|
||||
fixed: dict[int, set[int]] = {}
|
||||
for index, before, tip in changes:
|
||||
traced = traced_to(before, tip, run)
|
||||
if isinstance(traced, Failure):
|
||||
return traced
|
||||
for commit in traced:
|
||||
# A commit no chunk owns cannot be one before can reach; take it as the fixing chunk's own.
|
||||
if owner.get(commit, index) > index:
|
||||
fixed.setdefault(owner[commit], set()).add(index)
|
||||
owned: dict[int, set[str]] = {}
|
||||
for commit, index in owner.items():
|
||||
owned.setdefault(index, set()).add(titles[commit])
|
||||
names = [label(shorts[first], shorts[last]) for first, last, _, _ in chunks]
|
||||
return [Landed(names[index], utc(time), frozenset(owned[index]), tuple(names[later] for later in sorted(fixed.get(index, ())))) for index, (_, _, time, _) in enumerate(chunks)]
|
||||
|
||||
|
||||
def owners(chunks: list, line: list[str], parents: dict[str, list[str]]) -> dict[str, int]:
|
||||
"""Each commit's chunk, as its index in chunks, newest first: the oldest chunk on the first-parent line whose commits reach it."""
|
||||
at = {commit: place for place, commit in enumerate(line)}
|
||||
owner: dict[str, int] = {}
|
||||
for index in reversed(range(len(chunks))):
|
||||
first, last, _, _ = chunks[index]
|
||||
for commit in reversed(line[at[last]:at[first] + 1]):
|
||||
unowned = [commit]
|
||||
while unowned:
|
||||
found = unowned.pop()
|
||||
if found not in owner:
|
||||
owner[found] = index
|
||||
unowned += parents[found]
|
||||
return owner
|
||||
|
||||
|
||||
def fixing_changes(chunks: list, owner: dict[str, int], parents: dict[str, list[str]], titles: dict[str, str], run: Run, plan_at: typing.Callable[[str], str | Failure], default: str) -> list[tuple[int, str, str]] | Failure:
|
||||
"""Each change that fixes a defect, as its chunk's index, the commit before it and its tip: the whole change of each chunk that ships a FIXES item, and each round commit answering a 🔴 a reviewer marked `[misread]`."""
|
||||
touched = run("log", "--first-parent", f"-G{FIX_ROW}", "--format=%H", default, "--", "todo.md")
|
||||
if isinstance(touched, Failure):
|
||||
return touched
|
||||
changes = []
|
||||
for index in sorted({owner[commit] for commit in touched.split()}):
|
||||
first, last, _, _ = chunks[index]
|
||||
if not parents[first]:
|
||||
continue
|
||||
before = parents[first][0]
|
||||
planned, after = plan_at(before), plan_at(last)
|
||||
if isinstance(planned, Failure):
|
||||
return planned
|
||||
if isinstance(after, Failure):
|
||||
return after
|
||||
if any(item.exempt in FIXES for item in shipped(planned, after)):
|
||||
changes.append((index, before, last))
|
||||
for commit, title in titles.items():
|
||||
counts = title_counts(title)
|
||||
# A title counts misread 🔴 and 🟡 findings together, so it takes one with both a 🔴 and a misread finding to answer a misread 🔴.
|
||||
if counts and counts.red and counts.misread and parents[commit]:
|
||||
changes.append((owner[commit], parents[commit][0], commit))
|
||||
return changes
|
||||
|
||||
|
||||
def traced_to(before: str, tip: str, run: Run) -> set[str] | Failure:
|
||||
"""The commits that last changed each line the change from before to tip removes or rewrites, outside the plan and the records."""
|
||||
# The prefixes and options keep the checkout's diff config out of the output.
|
||||
diff = run("diff", "-U0", "-M", "--no-color", "--no-ext-diff", "--no-textconv", "--ignore-submodules", "--src-prefix=a/", "--dst-prefix=b/", before, tip)
|
||||
if isinstance(diff, Failure):
|
||||
return diff
|
||||
traced: set[str] = set()
|
||||
for path, spans in removed(diff).items():
|
||||
if path in NOT_WORK:
|
||||
continue
|
||||
# An empty --ignore-revs-file drops a configured one, which blame fails on where the file is missing.
|
||||
blame = run("blame", "--porcelain", "--no-textconv", "--ignore-revs-file=", *(f"-L{start},+{count}" for start, count in spans), before, "--", path)
|
||||
if isinstance(blame, Failure):
|
||||
return blame
|
||||
traced |= blamed(blame)
|
||||
return traced
|
||||
|
||||
|
||||
def removed(diff: str) -> dict[str, list[tuple[int, int]]]:
|
||||
"""The old lines each hunk of a `git diff -U0` removes or rewrites, as its first line and count, by the path the file had before; none for a path git quotes, as it does one holding a byte it cannot print."""
|
||||
spans: dict[str, list[tuple[int, int]]] = {}
|
||||
path, left = None, 0
|
||||
for row in diff.splitlines():
|
||||
if left and row[:1] in ("-", "+", " "):
|
||||
left -= 1
|
||||
elif row.startswith("diff --git "):
|
||||
path, left = None, 0
|
||||
elif row.startswith("--- "):
|
||||
# Git ends a path holding a space with a tab.
|
||||
path = row[len("--- a/"):].removesuffix("\t") if row.startswith("--- a/") else None
|
||||
elif hunk := HUNK.match(row):
|
||||
start, count = int(hunk.group(1)), int(hunk.group(2) or 1)
|
||||
left = count + int(hunk.group(3) or 1)
|
||||
if path and count:
|
||||
spans.setdefault(path, []).append((start, count))
|
||||
return spans
|
||||
|
||||
|
||||
def blamed(porcelain: str) -> set[str]:
|
||||
"""The commit each line of `git blame --porcelain` output comes from."""
|
||||
return {header.group(1) for row in porcelain.splitlines() if (header := BLAME_HEADER.match(row))}
|
||||
+30
-26
@@ -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)
|
||||
|
||||
@@ -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, and how many of them a reviewer marked `[misread]`, None where a round title lacks the 🔴 and 🟡 counts or the branch has no round; its misread is None where a round title lacks that count. 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, and how many of them a reviewer marked `[misread]`, None where a round title lacks the 🔴 and 🟡 counts or the branch has no round; its misread is None where a round title lacks that count. 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. fixed_by names the later chunks that fixed code it shipped, newest first, as later_fixes counts them."""
|
||||
item: Item
|
||||
merge: str
|
||||
merged: str
|
||||
@@ -32,6 +32,7 @@ class Result:
|
||||
rounds_past_first: int
|
||||
findings: Findings | None
|
||||
landed: Landing
|
||||
fixed_by: tuple[str, ...]
|
||||
|
||||
|
||||
# A measure's name and how to read it from a Result, None where the chunk did not record it.
|
||||
@@ -53,7 +54,7 @@ def shipped(before: str, after: str) -> list[Item]:
|
||||
return sorted((item for item in planned if item.id not in kept), key=lambda item: item.id)
|
||||
|
||||
|
||||
def results_of(shipped: list[Item], merge: str, merged: str, numstat: str, titles: list[str], landed: Landing) -> list[Result]:
|
||||
def results_of(shipped: list[Item], merge: str, merged: str, numstat: str, titles: list[str], landed: Landing, fixed_by: tuple[str, ...]) -> list[Result]:
|
||||
"""What one chunk measured for each item it shipped, from `git diff --numstat` against the commit before it and its commit titles; none where it changed nothing but the plan and the records."""
|
||||
changed = [row.split("\t", 2) for row in numstat.splitlines()]
|
||||
work = [row for row in changed if len(row) == 3 and row[2] not in NOT_WORK]
|
||||
@@ -63,7 +64,30 @@ 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, fixed_by) for item in shipped]
|
||||
|
||||
|
||||
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 label(first: str, last: str) -> str:
|
||||
"""How the report names a chunk: its one commit's short hash, or its first and last commits' as a range."""
|
||||
return first if first == last else f"{first}^..{last}"
|
||||
|
||||
|
||||
def nearest(results: list[Result], given: dict[str, int], count: int = 5) -> list[Result]:
|
||||
@@ -109,6 +133,17 @@ def misreads(results: list[Result]) -> list[str]:
|
||||
return lines or ["- None: no chunk's round titles count them."]
|
||||
|
||||
|
||||
def fixed_later(results: list[Result]) -> list[str]:
|
||||
"""Newest first, each finished chunk that later chunks fixed code of, naming them, then how many finished chunks none fixed."""
|
||||
chunks = {result.merge: result for result in results}
|
||||
newest_first = sorted(chunks.values(), key=lambda result: result.merged, reverse=True)
|
||||
lines = [f"- {result.merged} in {result.merge}: {later(result)}, by {listed(result.fixed_by, 'and')}" for result in newest_first if result.fixed_by]
|
||||
if not lines:
|
||||
return ["- None: no later chunk fixed code a finished chunk shipped."]
|
||||
others = len(chunks) - len(lines)
|
||||
return lines + ([f"- The other {plural(others, 'finished chunk')}: none."] if others else [])
|
||||
|
||||
|
||||
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}."
|
||||
@@ -132,7 +167,7 @@ def render(result: Result) -> str:
|
||||
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]
|
||||
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(result)}{plural(result.rounds_past_first, 'round')} past each pass's first, {counted(result)}; {merged}{together}. {result.item.tagline}"
|
||||
return f"- Item {result.item.id}, {scores}: {plural(result.lines, 'line')} in {plural(result.files, 'file')}, {at_least(result)}{plural(result.rounds_past_first, 'round')} past each pass's first, {counted(result)}, {later(result)}; {merged}{together}. {result.item.tagline}"
|
||||
|
||||
|
||||
def at_least(result: Result) -> str:
|
||||
@@ -148,5 +183,10 @@ def counted(result: Result) -> str:
|
||||
return f"{at_least(result)}{result.findings.red} 🔴, {result.findings.yellow} 🟡{misread}"
|
||||
|
||||
|
||||
def later(result: Result) -> str:
|
||||
count = len(result.fixed_by)
|
||||
return f"{count} later fix{'' if count == 1 else 'es'}"
|
||||
|
||||
|
||||
def plural(count: int, noun: str) -> str:
|
||||
return f"{count} {noun}{'' if count == 1 else 's'}"
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from score_outcomes.later_fixes import blamed, Landed, later_fixes, removed
|
||||
from failure import Failure
|
||||
from test_env import isolated_env
|
||||
|
||||
HEADER = "| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |\n|---|---|---|---|---|---|---|---|---|---|---|---|\n"
|
||||
ROWS = {
|
||||
4: "| 4 | 0.1.0 | | | **Do four.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 3 | 1.0 |",
|
||||
5: "| 5 | 0.1.0 | | | **Do five.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 3 | 1.0 |",
|
||||
6: "| 6 | 0.1.0 | | defect | **Fix six.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 3 | 1.0 |",
|
||||
7: "| 7 | 0.1.0 | | security | **Close seven.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 3 | 1.0 |",
|
||||
8: "| 8 | 0.1.0 | | defect | **Fix eight.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 3 | 1.0 |",
|
||||
9: "| 9 | 0.1.0 | | defect | **Fix nine.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 3 | 1.0 |",
|
||||
}
|
||||
|
||||
|
||||
def todo(*ids: int) -> str:
|
||||
return "# todo\n\n## Items\n\n" + HEADER + "".join(f"{ROWS[id_]}\n" for id_ in ids)
|
||||
|
||||
|
||||
class Removed(unittest.TestCase):
|
||||
def test_reads_the_old_lines_each_hunk_removes_or_rewrites_by_the_path_they_had(self):
|
||||
diff = "\n".join([
|
||||
"diff --git a/a.py b/a.py",
|
||||
"--- a/a.py",
|
||||
"+++ b/a.py",
|
||||
"@@ -2 +2 @@ def f():",
|
||||
"-x",
|
||||
"+y",
|
||||
"@@ -5,3 +4,0 @@",
|
||||
"@@ -9,0 +8,2 @@",
|
||||
"diff --git a/old.py b/new.py",
|
||||
"--- a/old.py",
|
||||
"+++ b/new.py",
|
||||
"@@ -1,2 +1,2 @@",
|
||||
"diff --git a/gone.py b/gone.py",
|
||||
"--- a/gone.py",
|
||||
"+++ /dev/null",
|
||||
"@@ -1,4 +0,0 @@",
|
||||
"diff --git a/born.py b/born.py",
|
||||
"--- /dev/null",
|
||||
"+++ b/born.py",
|
||||
"@@ -0,0 +1,3 @@",
|
||||
"diff --git \"a/tab\\there.py\" \"b/tab\\there.py\"",
|
||||
"--- \"a/tab\\there.py\"",
|
||||
"+++ \"b/tab\\there.py\"",
|
||||
"@@ -1 +1 @@",
|
||||
"diff --git a/my file.py b/my file.py",
|
||||
"--- a/my file.py\t",
|
||||
"+++ b/my file.py\t",
|
||||
"@@ -7,2 +7 @@",
|
||||
])
|
||||
self.assertEqual(removed(diff), {"a.py": [(2, 1), (5, 3)], "old.py": [(1, 2)], "gone.py": [(1, 4)], "my file.py": [(7, 2)]})
|
||||
|
||||
def test_reads_a_hunk_line_inside_the_changed_text_as_text(self):
|
||||
diff = "--- a/a.md\n+++ b/a.md\n@@ -3 +3 @@\n---- a/quoted\n+text\n"
|
||||
self.assertEqual(removed(diff), {"a.md": [(3, 1)]})
|
||||
|
||||
|
||||
class Blamed(unittest.TestCase):
|
||||
def test_reads_the_commit_of_each_line_from_porcelain_output(self):
|
||||
first, second = "a" * 40, "b" * 40
|
||||
porcelain = f"{first} 2 2 1\nauthor t\nfilename a.py\n\tx\n{second} 5 5 2\nauthor t\n\ty\n{second} 6 6\n\t{first} 1 1 1\n"
|
||||
self.assertEqual(blamed(porcelain), {first, second})
|
||||
|
||||
|
||||
class LaterFixes(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(temp.cleanup)
|
||||
self.checkout = pathlib.Path(os.path.realpath(temp.name))
|
||||
self.env = {**isolated_env(), "GIT_CONFIG_GLOBAL": os.devnull, "HOME": str(self.checkout)}
|
||||
self.git("init", "-q", "-b", "main")
|
||||
self.commit("Start", {"todo.md": todo(4, 5, 6, 7, 8), "a.py": "1\n2\n3\n"})
|
||||
|
||||
def git(self, *args):
|
||||
return subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", *args], cwd=self.checkout, check=True, env=self.env, capture_output=True, text=True).stdout
|
||||
|
||||
def commit(self, title, files, at=None):
|
||||
for name, text in files.items():
|
||||
(self.checkout / name).write_text(text)
|
||||
self.git("add", name)
|
||||
dates = {"GIT_COMMITTER_DATE": at, "GIT_AUTHOR_DATE": at} if at else {}
|
||||
self.env.update(dates)
|
||||
self.git("commit", "-q", "-m", title)
|
||||
for name in dates:
|
||||
self.env.pop(name)
|
||||
return self.git("rev-parse", "--short", "HEAD").strip()
|
||||
|
||||
def chunk(self, branch, *commits):
|
||||
"""Merges a branch holding each (title, files) commit, and returns the merge commit's short hash."""
|
||||
self.git("switch", "-q", "-c", branch)
|
||||
for title, files in commits:
|
||||
self.commit(title, files)
|
||||
self.git("switch", "-q", "main")
|
||||
self.git("merge", "-q", "--no-ff", "-m", f"Merge {branch}", branch)
|
||||
return self.git("rev-parse", "--short", "HEAD").strip()
|
||||
|
||||
def fixes(self):
|
||||
found = later_fixes("main", cwd=str(self.checkout))
|
||||
self.assertNotIsInstance(found, Failure)
|
||||
return {landed.label: landed.fixed_by for landed in found}
|
||||
|
||||
def test_counts_a_later_chunk_that_ships_a_defect_item_and_rewrites_a_line_an_earlier_chunk_added(self):
|
||||
shipped = self.chunk("four", ("Do four", {"b.py": "x\ny\n", "todo.md": todo(5, 6, 7, 8)}))
|
||||
fixed = self.chunk("six", ("Fix six", {"b.py": "x\nY\n", "todo.md": todo(5, 7, 8)}))
|
||||
found = self.fixes()
|
||||
self.assertEqual(found[shipped], (fixed,))
|
||||
self.assertEqual(found[fixed], ())
|
||||
|
||||
def test_counts_a_chunk_that_ships_a_security_item_as_a_fix(self):
|
||||
shipped = self.chunk("four", ("Do four", {"b.py": "x\ny\n", "todo.md": todo(5, 6, 7, 8)}))
|
||||
fixed = self.chunk("seven", ("Close seven", {"b.py": "x\n", "todo.md": todo(5, 6, 8)}))
|
||||
self.assertEqual(self.fixes()[shipped], (fixed,))
|
||||
|
||||
def test_counts_no_chunk_whose_shipped_items_are_neither_defect_nor_security(self):
|
||||
shipped = self.chunk("four", ("Do four", {"b.py": "x\ny\n", "todo.md": todo(5, 6, 7, 8)}))
|
||||
self.chunk("five", ("Do five", {"b.py": "x\nY\n", "todo.md": todo(6, 7, 8)}))
|
||||
self.assertEqual(self.fixes()[shipped], ())
|
||||
|
||||
def test_counts_no_chunk_that_only_edits_a_defect_items_row(self):
|
||||
shipped = self.chunk("four", ("Do four", {"b.py": "x\ny\n", "todo.md": todo(5, 6, 7, 8)}))
|
||||
self.chunk("edit", ("Re-score six", {"b.py": "x\nY\n", "todo.md": todo(5, 6, 7, 8).replace("**Fix six.**", "**Fix six now.**")}))
|
||||
self.assertEqual(self.fixes()[shipped], ())
|
||||
|
||||
def test_leaves_the_plans_row_out_so_a_fix_does_not_trace_to_the_chunk_that_filed_it(self):
|
||||
filed = self.chunk("file", ("File item 9", {"c.py": "c\n", "todo.md": todo(4, 5, 6, 7, 8, 9)}))
|
||||
self.chunk("nine", ("Fix nine", {"d.py": "d\n", "todo.md": todo(4, 5, 6, 7, 8)}))
|
||||
self.assertEqual(self.fixes()[filed], ())
|
||||
|
||||
def test_counts_a_round_commit_that_answers_a_misread_red_finding_and_rewrites_an_earlier_chunks_line(self):
|
||||
shipped = self.chunk("four", ("Do four", {"b.py": "x\ny\n", "todo.md": todo(5, 6, 7, 8)}))
|
||||
fixed = self.chunk("five", ("Do five", {"c.py": "c\n", "todo.md": todo(6, 7, 8)}), ("Answer stability round 1: 1 🔴, 0 🟡 (1 misread); keep y's caller", {"b.py": "x\nY\n"}))
|
||||
self.assertEqual(self.fixes()[shipped], (fixed,))
|
||||
|
||||
def test_counts_no_round_commit_without_both_a_red_and_a_misread_finding(self):
|
||||
shipped = self.chunk("four", ("Do four", {"b.py": "w\nx\ny\n", "todo.md": todo(5, 6, 7, 8)}))
|
||||
self.chunk("five", ("Do five", {"c.py": "c\n", "todo.md": todo(6, 7, 8)}), ("Answer stability round 1: 1 🔴, 0 🟡 (0 misread); fix", {"b.py": "W\nx\ny\n"}), ("Answer prose round 1: 0 🔴, 1 🟡 (1 misread); fix", {"b.py": "W\nX\ny\n"}), ("Answer principles round 1: 1 🔴, 0 🟡; fix", {"b.py": "W\nX\nY\n"}))
|
||||
self.assertEqual(self.fixes()[shipped], ())
|
||||
|
||||
def test_counts_no_fix_of_lines_its_own_chunk_wrote(self):
|
||||
self.chunk("six", ("Fix six", {"b.py": "x\ny\n", "todo.md": todo(4, 5, 7, 8)}), ("Answer stability round 1: 1 🔴, 0 🟡 (1 misread); fix", {"b.py": "x\nY\n"}))
|
||||
self.assertEqual(set(self.fixes().values()), {()})
|
||||
|
||||
def test_counts_a_fixing_chunk_once_against_each_chunk_it_fixes_newest_first(self):
|
||||
first = self.chunk("four", ("Do four", {"b.py": "x\ny\n", "d.py": "d\n", "todo.md": todo(5, 6, 7, 8)}))
|
||||
second = self.chunk("five", ("Do five", {"c.py": "z\n", "todo.md": todo(6, 7, 8)}))
|
||||
fixed = self.chunk("six", ("Fix six", {"b.py": "X\ny\n", "todo.md": todo(7, 8)}), ("Answer stability round 1: 1 🔴, 0 🟡 (1 misread); fix", {"b.py": "X\nY\n", "c.py": "Z\n"}))
|
||||
again = self.chunk("eight", ("Fix eight", {"b.py": "XX\nY\n", "d.py": "D\n", "todo.md": todo(7)}))
|
||||
found = self.fixes()
|
||||
self.assertEqual(found[first], (again, fixed))
|
||||
self.assertEqual(found[second], (fixed,))
|
||||
self.assertEqual(found[fixed], (again,))
|
||||
|
||||
def test_traces_a_line_to_the_rebased_run_that_added_it_and_labels_runs_as_score_outcomes_does(self):
|
||||
first = self.commit("Do four", {"b.py": "x\ny\n", "todo.md": todo(5, 6, 7, 8)}, at="2026-10-13T09:00:00Z")
|
||||
last = self.commit("Answer stability round 1: 0 🔴, 0 🟡 (0 misread)", {"c.py": "c\n"}, at="2026-10-13T09:00:00Z")
|
||||
fixed = self.commit("Fix six", {"b.py": "x\nY\n", "todo.md": todo(5, 7, 8)}, at="2026-10-13T10:00:00Z")
|
||||
self.assertEqual(self.fixes()[f"{first}^..{last}"], (fixed,))
|
||||
|
||||
def test_holds_each_chunks_commit_titles_and_landing_time(self):
|
||||
self.git("switch", "-q", "-c", "four")
|
||||
self.commit("Do four", {"b.py": "x\n", "todo.md": todo(5, 6, 7, 8)})
|
||||
self.git("switch", "-q", "main")
|
||||
self.env.update({"GIT_COMMITTER_DATE": "2026-10-14T10:00:00Z", "GIT_AUTHOR_DATE": "2026-10-14T10:00:00Z"})
|
||||
self.git("merge", "-q", "--no-ff", "-m", "Merge four", "four")
|
||||
merged = self.git("rev-parse", "--short", "HEAD").strip()
|
||||
newest = later_fixes("main", cwd=str(self.checkout))[0]
|
||||
self.assertEqual(newest, Landed(merged, "2026-10-14T10:00:00Z", frozenset({"Do four", "Merge four"}), ()))
|
||||
|
||||
def test_reads_paths_from_the_checkouts_top_when_run_in_a_folder_of_it(self):
|
||||
(self.checkout / "sub").mkdir()
|
||||
shipped = self.chunk("four", ("Do four", {"sub/b.py": "x\ny\n", "todo.md": todo(5, 6, 7, 8)}))
|
||||
fixed = self.chunk("six", ("Fix six", {"sub/b.py": "x\nY\n", "todo.md": todo(5, 7, 8)}))
|
||||
found = later_fixes("main", cwd=str(self.checkout / "sub"))
|
||||
self.assertNotIsInstance(found, Failure)
|
||||
self.assertEqual({landed.label: landed.fixed_by for landed in found}[shipped], (fixed,))
|
||||
|
||||
def test_fails_where_git_cannot_read_the_branch(self):
|
||||
self.assertIsInstance(later_fixes("missing", cwd=str(self.checkout)), Failure)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -8,18 +8,19 @@ import unittest
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from score_outcomes.anchors import anchor_lines, parse_anchors
|
||||
from score_outcomes.main import chunk_log, report_text
|
||||
from score_outcomes.results import chunk_log, Landing, nearest, rank_correlation, render, report, Result, results_of, shipped
|
||||
from failure import Failure
|
||||
from round_titles import Findings
|
||||
from test_env import isolated_env
|
||||
from todo_table import Item
|
||||
from score_outcomes.results import Landing, nearest, rank_correlation, render, report, Result, results_of, shipped
|
||||
from score_outcomes.main import report_text
|
||||
|
||||
TOOL = pathlib.Path(__file__).resolve().parents[1] / "score-outcomes"
|
||||
HEADER = "| ID | Release | Exempt | Item | R | S | C | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|---|\n"
|
||||
WITHOUT_C = "| ID | Release | Exempt | Item | R | S | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|\n"
|
||||
FIRST = "| 4 | 0.1.0 | | **Do it.** | 2 | 3 | 10 | 6 | 7 | 1 | 9.0 |"
|
||||
SECOND = "| 5 | 0.1.0 | | **Then this.** | 4 | 6 | 8 | 6 | 7 | 1 | 9.0 |"
|
||||
FIX = "| 6 | 0.1.0 | defect | **Fix it.** | 1 | 1 | 1 | 6 | 7 | 1 | 9.0 |"
|
||||
|
||||
|
||||
def todo(*rows: str, header: str = HEADER) -> str:
|
||||
@@ -30,8 +31,8 @@ def item(id_: int, scores: dict[str, int]) -> Item:
|
||||
return Item(id_, (0, 1, 0), "", f"**Item {id_}.**", scores, (("1", None),), ())
|
||||
|
||||
|
||||
def result(id_: int, r: int, s: int, c: int | None, lines: int = 10, rounds: int = 1, findings: tuple[int, int] | None = (0, 0), merged: str = "2026-10-13T10:00:00Z", shipped_with: tuple[int, ...] = (), levels: dict[str, int] | None = None, landed: Landing = "merge", misread: int | None = None, merge: str = "aaaaaaa") -> Result:
|
||||
return Result(item(id_, {"R": r, "S": s} | ({"C": c} if c else {}) | (levels or {})), merge, merged, shipped_with, lines, 1, rounds, None if findings is None else Findings(*findings, misread), landed)
|
||||
def result(id_: int, r: int, s: int, c: int | None, lines: int = 10, rounds: int = 1, findings: tuple[int, int] | None = (0, 0), merged: str = "2026-10-13T10:00:00Z", shipped_with: tuple[int, ...] = (), levels: dict[str, int] | None = None, landed: Landing = "merge", misread: int | None = None, merge: str = "aaaaaaa", fixed_by: tuple[str, ...] = ()) -> Result:
|
||||
return Result(item(id_, {"R": r, "S": s} | ({"C": c} if c else {}) | (levels or {})), merge, merged, shipped_with, lines, 1, rounds, None if findings is None else Findings(*findings, misread), landed, fixed_by)
|
||||
|
||||
|
||||
class Shipped(unittest.TestCase):
|
||||
@@ -77,12 +78,12 @@ class ResultsOf(unittest.TestCase):
|
||||
def test_measures_the_change_less_the_plan_and_the_tool_records_and_counts_binary_files(self):
|
||||
numstat = "3\t1\ta.py\n-\t-\tlogo.png\n0\t1\t2026\n5\t0\ttodo.md\n9\t0\tdocs/reading-cost.md\n4\t0\tdocs/comprehension-history.md\n"
|
||||
titles = ["Answer stability round 1: 1 🔴, 2 🟡; fix", "Answer stability round 2: 0 🔴, 1 🟡; fix", "Answer prose round 1: 0 🔴, 3 🟡", "Do it"]
|
||||
found = results_of([item(4, {"R": 2}), item(5, {"R": 3})], "abc1234", "2026-10-13T10:00:00Z", numstat, titles, "merge")
|
||||
self.assertEqual(found[0], Result(item(4, {"R": 2}), "abc1234", "2026-10-13T10:00:00Z", (5,), 5, 3, 1, Findings(1, 6, None), "merge"))
|
||||
found = results_of([item(4, {"R": 2}), item(5, {"R": 3})], "abc1234", "2026-10-13T10:00:00Z", numstat, titles, "merge", ("def5678",))
|
||||
self.assertEqual(found[0], Result(item(4, {"R": 2}), "abc1234", "2026-10-13T10:00:00Z", (5,), 5, 3, 1, Findings(1, 6, None), "merge", ("def5678",)))
|
||||
self.assertEqual(found[1].shipped_with, (4,))
|
||||
|
||||
def test_measures_no_chunk_that_changed_only_the_plan(self):
|
||||
self.assertEqual(results_of([item(4, {"R": 2})], "abc1234", "2026-10-13T10:00:00Z", "0\t5\ttodo.md\n", [], "merge"), [])
|
||||
self.assertEqual(results_of([item(4, {"R": 2})], "abc1234", "2026-10-13T10:00:00Z", "0\t5\ttodo.md\n", [], "merge", ()), [])
|
||||
|
||||
|
||||
class Nearest(unittest.TestCase):
|
||||
@@ -140,20 +141,24 @@ class Render(unittest.TestCase):
|
||||
self.assertTrue(render(result(4, 3, 3, None, levels={"L": 2, "E": 2, "I": 1})).startswith("- Item 4, L 2, E 2, I 1, R 3, S 3:"))
|
||||
|
||||
def test_names_the_items_shipped_together_and_unknown_findings(self):
|
||||
self.assertEqual(render(result(4, 2, 3, None, lines=1, rounds=2, findings=None, shipped_with=(5, 6))), "- Item 4, R 2, S 3: 1 line in 1 file, 2 rounds past each pass's first, findings unknown; merged 2026-10-13T10:00:00Z in aaaaaaa, with items 5, 6. **Item 4.**")
|
||||
self.assertEqual(render(result(4, 2, 3, 4, findings=(1, 2))), "- Item 4, R 2, S 3, C 4: 10 lines in 1 file, 1 round past each pass's first, 1 🔴, 2 🟡; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 4.**")
|
||||
self.assertIn("1 round past each pass's first, 0 🔴, 0 🟡; merged 2026-10-13T10:00:00Z in aaaaaaa, with item 5. ", render(result(4, 2, 3, 4, rounds=1, shipped_with=(5,))))
|
||||
self.assertEqual(render(result(4, 2, 3, None, lines=1, rounds=2, findings=None, shipped_with=(5, 6))), "- Item 4, R 2, S 3: 1 line in 1 file, 2 rounds past each pass's first, findings unknown, 0 later fixes; merged 2026-10-13T10:00:00Z in aaaaaaa, with items 5, 6. **Item 4.**")
|
||||
self.assertEqual(render(result(4, 2, 3, 4, findings=(1, 2))), "- Item 4, R 2, S 3, C 4: 10 lines in 1 file, 1 round past each pass's first, 1 🔴, 2 🟡, 0 later fixes; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 4.**")
|
||||
self.assertIn("1 round past each pass's first, 0 🔴, 0 🟡, 0 later fixes; merged 2026-10-13T10:00:00Z in aaaaaaa, with item 5. ", render(result(4, 2, 3, 4, rounds=1, shipped_with=(5,))))
|
||||
|
||||
def test_counts_the_later_fixes_of_the_chunk_that_shipped_it(self):
|
||||
self.assertIn("0 🔴, 0 🟡, 1 later fix; merged", render(result(4, 2, 3, None, fixed_by=("bbbbbbb",))))
|
||||
self.assertIn("0 🔴, 0 🟡, 2 later fixes; merged", render(result(4, 2, 3, None, fixed_by=("bbbbbbb", "ccccccc"))))
|
||||
|
||||
def test_gives_the_misread_count_where_the_round_titles_do(self):
|
||||
self.assertIn("1 round past each pass's first, 1 🔴, 2 🟡 (1 misread); merged", render(result(4, 2, 3, None, findings=(1, 2), misread=1)))
|
||||
self.assertIn("1 round past each pass's first, 0 🔴, 0 🟡 (0 misread); merged", render(result(4, 2, 3, None, misread=0)))
|
||||
self.assertIn("1 round past each pass's first, 1 🔴, 2 🟡 (1 misread), 0 later fixes; merged", render(result(4, 2, 3, None, findings=(1, 2), misread=1)))
|
||||
self.assertIn("1 round past each pass's first, 0 🔴, 0 🟡 (0 misread), 0 later fixes; merged", render(result(4, 2, 3, None, misread=0)))
|
||||
|
||||
def test_gives_a_rebase_merged_chunks_rounds_and_findings_as_lower_bounds(self):
|
||||
self.assertEqual(render(result(4, 2, 3, None, findings=(1, 2), landed="rebase")), "- Item 4, R 2, S 3: 10 lines in 1 file, at least 1 round past each pass's first, at least 1 🔴, 2 🟡; merged 2026-10-13T10:00:00Z by rebase in aaaaaaa. **Item 4.**")
|
||||
self.assertIn("at least 1 round past each pass's first, findings unknown; merged 2026-10-13T10:00:00Z by rebase in aaaaaaa", render(result(4, 2, 3, None, findings=None, landed="rebase")))
|
||||
self.assertEqual(render(result(4, 2, 3, None, findings=(1, 2), landed="rebase")), "- Item 4, R 2, S 3: 10 lines in 1 file, at least 1 round past each pass's first, at least 1 🔴, 2 🟡, 0 later fixes; merged 2026-10-13T10:00:00Z by rebase in aaaaaaa. **Item 4.**")
|
||||
self.assertIn("at least 1 round past each pass's first, findings unknown, 0 later fixes; merged 2026-10-13T10:00:00Z by rebase in aaaaaaa", render(result(4, 2, 3, None, findings=None, landed="rebase")))
|
||||
|
||||
def test_says_a_chunk_never_replayed_may_be_part_of_a_pull_request(self):
|
||||
self.assertEqual(render(result(4, 2, 3, None, findings=(1, 2), landed="push")), "- Item 4, R 2, S 3: 10 lines in 1 file, at least 1 round past each pass's first, at least 1 🔴, 2 🟡; committed 2026-10-13T10:00:00Z in aaaaaaa, never replayed, so perhaps part of a pull request. **Item 4.**")
|
||||
self.assertEqual(render(result(4, 2, 3, None, findings=(1, 2), landed="push")), "- Item 4, R 2, S 3: 10 lines in 1 file, at least 1 round past each pass's first, at least 1 🔴, 2 🟡, 0 later fixes; committed 2026-10-13T10:00:00Z in aaaaaaa, never replayed, so perhaps part of a pull request. **Item 4.**")
|
||||
|
||||
|
||||
ANCHORS_TEXT = "# Score anchors\n\nWhy these.\n\n| Level | Items |\n|---|---|\n| L 1 | 4, 9 |\n| I 3 | 5 |\n"
|
||||
@@ -179,7 +184,7 @@ class Anchors(unittest.TestCase):
|
||||
|
||||
def test_lists_each_anchor_with_what_its_chunk_measured_and_says_which_it_cannot_find(self):
|
||||
lines = anchor_lines([("L 1", (4, 9))], [result(4, 2, 3, None, findings=(1, 2))])
|
||||
self.assertEqual(lines, ["L 1:", "- Item 4, R 2, S 3: 10 lines in 1 file, 1 round past each pass's first, 1 🔴, 2 🟡; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 4.**", "- Item 9: no chunk shipped it."])
|
||||
self.assertEqual(lines, ["L 1:", "- Item 4, R 2, S 3: 10 lines in 1 file, 1 round past each pass's first, 1 🔴, 2 🟡, 0 later fixes; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 4.**", "- Item 9: no chunk shipped it."])
|
||||
|
||||
def test_points_to_the_rules_where_the_project_names_no_anchors(self):
|
||||
self.assertIn("docs/score-anchors.md", anchor_lines([], [])[0])
|
||||
@@ -195,13 +200,13 @@ class ReportText(unittest.TestCase):
|
||||
too_few = "such chunks record"
|
||||
self.assertEqual(report_text(found, [("L 1", (2,))], {"L": 1, "E": 1, "I": 1, "S": 3}), f"""Finished items nearest L 1, E 1, I 1, so R 1, and S 3, closest first:
|
||||
|
||||
- Item 2, R 1, S 3: 10 lines in 1 file, 1 round past each pass's first, 0 🔴, 0 🟡; merged 2026-10-12T10:00:00Z in aaaaaaa. **Item 2.**
|
||||
- Item 1, R 5, S 3: 10 lines in 1 file, 1 round past each pass's first, 0 🔴, 0 🟡; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 1.**
|
||||
- Item 2, R 1, S 3: 10 lines in 1 file, 1 round past each pass's first, 0 🔴, 0 🟡, 0 later fixes; merged 2026-10-12T10:00:00Z in aaaaaaa. **Item 2.**
|
||||
- Item 1, R 5, S 3: 10 lines in 1 file, 1 round past each pass's first, 0 🔴, 0 🟡, 0 later fixes; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 1.**
|
||||
|
||||
Anchors in docs/score-anchors.md, each level's shipped items:
|
||||
|
||||
L 1:
|
||||
- Item 2, R 1, S 3: 10 lines in 1 file, 1 round past each pass's first, 0 🔴, 0 🟡; merged 2026-10-12T10:00:00Z in aaaaaaa. **Item 2.**
|
||||
- Item 2, R 1, S 3: 10 lines in 1 file, 1 round past each pass's first, 0 🔴, 0 🟡, 0 later fixes; merged 2026-10-12T10:00:00Z in aaaaaaa. **Item 2.**
|
||||
|
||||
Median outcome at each guessed score, among chunks that shipped one item, never-replayed ones left out:
|
||||
|
||||
@@ -213,7 +218,11 @@ Median outcome at each guessed score, among chunks that shipped one item, never-
|
||||
|
||||
🔴 and 🟡 findings, with how many a reviewer marked `[misread]`, per finished chunk whose round titles count them, newest first:
|
||||
|
||||
- None: no chunk's round titles count them.""")
|
||||
- None: no chunk's round titles count them.
|
||||
|
||||
Later fixes, the later chunks that fixed code each finished chunk shipped, newest first:
|
||||
|
||||
- None: no later chunk fixed code a finished chunk shipped.""")
|
||||
|
||||
def test_lists_each_chunks_findings_with_their_misread_count_newest_first_once_per_chunk(self):
|
||||
found = [result(1, 5, 3, None, findings=(1, 2), misread=1, merge="bbbbbbb", merged="2026-10-12T10:00:00Z", shipped_with=(2,)), result(2, 5, 3, None, findings=(1, 2), misread=1, merge="bbbbbbb", merged="2026-10-12T10:00:00Z", shipped_with=(1,)), result(3, 5, 3, None, findings=(0, 4), misread=0, merge="ccccccc", merged="2026-10-14T10:00:00Z", landed="rebase"), result(4, 5, 3, None)]
|
||||
@@ -222,6 +231,14 @@ Median outcome at each guessed score, among chunks that shipped one item, never-
|
||||
- 2026-10-14T10:00:00Z in ccccccc: at least 0 🔴, 4 🟡 (0 misread)
|
||||
- 2026-10-12T10:00:00Z in bbbbbbb: 1 🔴, 2 🟡 (1 misread)""", report_text(found, [], None))
|
||||
|
||||
def test_lists_each_chunks_later_fixes_newest_first_once_per_chunk_then_counts_the_others(self):
|
||||
found = [result(1, 5, 3, None, merge="bbbbbbb", merged="2026-10-12T10:00:00Z", shipped_with=(2,), fixed_by=("ddddddd",)), result(2, 5, 3, None, merge="bbbbbbb", merged="2026-10-12T10:00:00Z", shipped_with=(1,), fixed_by=("ddddddd",)), result(3, 5, 3, None, merge="ccccccc", merged="2026-10-14T10:00:00Z", fixed_by=("eeeeeee", "ddddddd")), result(4, 5, 3, None), result(5, 5, 3, None, merge="fffffff")]
|
||||
self.assertTrue(report_text(found, [], None).endswith("""Later fixes, the later chunks that fixed code each finished chunk shipped, newest first:
|
||||
|
||||
- 2026-10-14T10:00:00Z in ccccccc: 2 later fixes, by eeeeeee and ddddddd
|
||||
- 2026-10-12T10:00:00Z in bbbbbbb: 1 later fix, by ddddddd
|
||||
- The other 2 finished chunks: none."""))
|
||||
|
||||
def test_ends_with_how_it_reads_chunks_merged_by_rebase_only_where_it_measured_one(self):
|
||||
text = report_text([result(1, 5, 3, None, landed="rebase")], [], None)
|
||||
self.assertIn("\n\nChunks that left no merge commit:\n\n- Each is the run of commits", text.split("Median outcome")[1])
|
||||
@@ -302,9 +319,24 @@ class ScoreOutcomesTool(unittest.TestCase):
|
||||
ran = self.run_tool("1", "2", "1", "3")
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
self.assertIn("Finished items nearest L 1, E 2, I 1, so R 2, and S 3, closest first:", ran.stdout)
|
||||
self.assertIn("- Item 4, R 2, S 3, C 10: 3 lines in 1 file, 0 rounds past each pass's first, 1 🔴, 2 🟡; merged ", ran.stdout)
|
||||
self.assertIn("- Item 4, R 2, S 3, C 10: 3 lines in 1 file, 0 rounds past each pass's first, 1 🔴, 2 🟡, 0 later fixes; merged ", ran.stdout)
|
||||
self.assertNotIn("Item 5", ran.stdout)
|
||||
|
||||
def test_counts_a_later_chunk_that_ships_a_defect_item_and_rewrites_a_line_a_chunk_shipped(self):
|
||||
self.commit("File a fix", {"todo.md": todo(FIRST, SECOND, FIX)})
|
||||
self.git("switch", "-q", "-c", "chunk")
|
||||
self.commit("Do it", {"a.py": "1\n2\n3\n", "todo.md": todo(SECOND, FIX)})
|
||||
self.git("switch", "-q", "main")
|
||||
shipped = self.merge_branch("chunk", "2026-10-13T10:00:00Z")
|
||||
self.git("switch", "-q", "-c", "fix")
|
||||
self.commit("Fix it", {"a.py": "1\n2\n4\n", "todo.md": todo(SECOND)})
|
||||
self.git("switch", "-q", "main")
|
||||
fixed = self.merge_branch("fix", "2026-10-14T10:00:00Z")
|
||||
ran = self.run_tool("1", "2", "1", "3")
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
self.assertIn(f"findings unknown, 1 later fix; merged 2026-10-13T10:00:00Z in {shipped}. **Do it.**", ran.stdout)
|
||||
self.assertIn(f"- 2026-10-13T10:00:00Z in {shipped}: 1 later fix, by {fixed}\n- The other 1 finished chunk: none.", ran.stdout)
|
||||
|
||||
def run_on_rebased_history(self):
|
||||
self.commit("Re-score item 4", {"todo.md": todo(FIRST.replace("| 2 | 3 |", "| 1 | 3 |"), SECOND)}, at="2026-10-13T08:00:00Z")
|
||||
first = self.commit("Score item 4 higher", {"todo.md": todo(FIRST, SECOND)}, at="2026-10-13T09:00:00Z")
|
||||
@@ -328,11 +360,11 @@ class ScoreOutcomesTool(unittest.TestCase):
|
||||
|
||||
def test_labels_a_run_of_commits_that_kept_their_author_time_never_replayed(self):
|
||||
stdout, _, _, _, pushed = self.run_on_rebased_history()
|
||||
self.assertIn(f"- Item 5, R 4, S 6, C 8: 1 line in 1 file, at least 0 rounds past each pass's first, findings unknown; committed 2026-10-13T11:00:00Z in {pushed}, never replayed, so perhaps part of a pull request. **Then this.**", stdout)
|
||||
self.assertIn(f"- Item 5, R 4, S 6, C 8: 1 line in 1 file, at least 0 rounds past each pass's first, findings unknown, 0 later fixes; committed 2026-10-13T11:00:00Z in {pushed}, never replayed, so perhaps part of a pull request. **Then this.**", stdout)
|
||||
|
||||
def test_measures_a_rebase_run_at_one_commit_time_as_one_chunk_whose_rounds_read_at_least(self):
|
||||
_, item_4, first, last, _ = self.run_on_rebased_history()
|
||||
self.assertIn(f"at least 0 rounds past each pass's first, at least 1 🔴, 2 🟡; merged 2026-10-13T09:00:00Z by rebase in {first}^..{last}. **Do it.**", item_4)
|
||||
self.assertIn(f"at least 0 rounds past each pass's first, at least 1 🔴, 2 🟡, 0 later fixes; merged 2026-10-13T09:00:00Z by rebase in {first}^..{last}. **Do it.**", item_4)
|
||||
|
||||
def test_explains_the_chunks_that_left_no_merge_commit_after_a_rebase(self):
|
||||
stdout, _, _, _, _ = self.run_on_rebased_history()
|
||||
@@ -346,8 +378,8 @@ class ScoreOutcomesTool(unittest.TestCase):
|
||||
self.git("merge", "-q", "--no-ff", "-m", "Merge chunk", "chunk")
|
||||
ran = self.run_tool("1", "2", "1", "3")
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
self.assertRegex(ran.stdout, r"- Item 4, R 2, S 3, C 10: 1 line in 1 file, 0 rounds past each pass's first, findings unknown; merged \S+ in [0-9a-f]{7,}\. ")
|
||||
self.assertIn(f"- Item 5, R 4, S 6, C 8: 1 line in 1 file, at least 0 rounds past each pass's first, findings unknown; committed 2026-10-12T09:00:00Z in {drop}, never replayed, so perhaps part of a pull request. **Then this.**", ran.stdout)
|
||||
self.assertRegex(ran.stdout, r"- Item 4, R 2, S 3, C 10: 1 line in 1 file, 0 rounds past each pass's first, findings unknown, 0 later fixes; merged \S+ in [0-9a-f]{7,}\. ")
|
||||
self.assertIn(f"- Item 5, R 4, S 6, C 8: 1 line in 1 file, at least 0 rounds past each pass's first, findings unknown, 0 later fixes; committed 2026-10-12T09:00:00Z in {drop}, never replayed, so perhaps part of a pull request. **Then this.**", ran.stdout)
|
||||
self.assertNotIn("by rebase", ran.stdout)
|
||||
|
||||
def test_labels_a_merge_merge_even_when_its_author_and_commit_times_are_equal(self):
|
||||
@@ -384,7 +416,7 @@ class ScoreOutcomesTool(unittest.TestCase):
|
||||
self.merge_branch("other", "2026-10-13T10:00:00Z")
|
||||
ran = self.run_tool("1", "2", "1", "3")
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
self.assertIn(f"- Item 4, R 2, S 3, C 10: 3 lines in 1 file, at least 0 rounds past each pass's first, at least 1 🔴, 2 🟡; merged 2026-10-13T09:00:00Z by rebase in {first}^..{last}. **Do it.**", ran.stdout)
|
||||
self.assertIn(f"- Item 4, R 2, S 3, C 10: 3 lines in 1 file, at least 0 rounds past each pass's first, at least 1 🔴, 2 🟡, 0 later fixes; merged 2026-10-13T09:00:00Z by rebase in {first}^..{last}. **Do it.**", ran.stdout)
|
||||
|
||||
def test_lists_the_projects_anchors_with_what_their_chunks_measured(self):
|
||||
self.git("switch", "-q", "-c", "chunk")
|
||||
|
||||
Reference in New Issue
Block a user