Answer stability round 1: 1 🔴, 3 🟡; read chunks by one pure function, and skip chunks that never changed todo.md
This commit is contained in:
+20
-15
@@ -7,8 +7,8 @@ that remote, and reads origin's default branch, or else the local main or master
|
||||
reads origin as last fetched and says so on stderr.
|
||||
|
||||
Git history is the record. The default branch's first-parent line is cut into chunks by one rule: a
|
||||
merge commit is a chunk of its own, and any other commit joins the commit above it when both share a
|
||||
commit time, else starts a chunk. A chunk whose change removed items from todo.md, and changed more
|
||||
merge commit is a chunk of its own, and any other commit joins the run of the newer commit above it when
|
||||
both share a commit time, else starts a chunk. A chunk whose change removed items from todo.md, and changed more
|
||||
than todo.md and the records below, shipped those items. Each item's guess is the scores it held in
|
||||
the todo.md the chunk started from: L, E, I, R and S. An item scored before L, E and I replaced C
|
||||
holds R and S, and C too where its table also had A, G and Goals. The chunk measures:
|
||||
@@ -26,7 +26,7 @@ A chunk is marked `by rebase` where a commit in it has a committer time apart fr
|
||||
since a rebase replays a pull request's commits at once, and `never replayed` where none does, since
|
||||
a pushed or fast-forwarded commit may be part of a pull request. A merge's titles are its branch's
|
||||
commits'; any other chunk's are its own. Two pull requests merged in the same second read as one
|
||||
chunk. Rebase drops a round's commit that changed no file, so such a chunk gives its rounds and
|
||||
chunk. Rebase drops a round's commit that changed no file, so a rebase or push chunk gives its rounds and
|
||||
findings as lower bounds, `at least`, and the report ends saying all this.
|
||||
|
||||
Given L, E and I, on the levels ~/.claude/rules/todo-items.md defines, and S, it works out R from
|
||||
@@ -58,7 +58,7 @@ import sys
|
||||
from score_outcomes.anchors import anchor_lines, Anchors, ANCHORS_PATH, parse_anchors
|
||||
from git_repo import default_branch, file_at, full_history, git, top
|
||||
from failure import Failure
|
||||
from score_outcomes.outcomes import Landing, nearest, Outcome, outcomes_of, render, report, shipped
|
||||
from score_outcomes.outcomes import Chunk, Landing, nearest, Outcome, outcomes_of, render, report, shipped
|
||||
from todo_table import LEVELS, risk, TOP_SCORE
|
||||
from markdown_text import listed
|
||||
from utc_stamp import utc
|
||||
@@ -134,11 +134,19 @@ def read_outcomes(default: str) -> list[Outcome] | Failure:
|
||||
"""What each chunk on the default branch's first-parent line measured."""
|
||||
if partial := full_history():
|
||||
return partial
|
||||
chunks = read_chunks(default)
|
||||
if isinstance(chunks, Failure):
|
||||
return chunks
|
||||
log = git("log", "--first-parent", "--format=%x1e%h %ct %at %p", "--name-only", default)
|
||||
if isinstance(log, Failure):
|
||||
return log
|
||||
# Each record is a commit's line, then the files it changed against its first parent.
|
||||
records = [record.splitlines() for record in log.split("\x1e")[1:]]
|
||||
headers = [record[0] for record in records]
|
||||
hashes = [header.split()[0] for header in headers]
|
||||
plan = {short for short, record in zip(hashes, records) if "todo.md" in record}
|
||||
outcomes: list[Outcome] = []
|
||||
for first, last, committed, landed in chunks:
|
||||
for first, last, committed, landed in chunk_log(headers):
|
||||
# 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)
|
||||
@@ -148,14 +156,11 @@ def read_outcomes(default: str) -> list[Outcome] | Failure:
|
||||
return outcomes
|
||||
|
||||
|
||||
def read_chunks(default: str) -> list[tuple[str, str, int, Landing]] | Failure:
|
||||
"""Each chunk on the default branch's first-parent line, newest first: its 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 commit above it when both share a commit time."""
|
||||
log = git("log", "--first-parent", "--format=%h %ct %at %p", default)
|
||||
if isinstance(log, Failure):
|
||||
return log
|
||||
chunks: list[tuple[str, str, int, Landing]] = []
|
||||
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 log.splitlines():
|
||||
for line in lines:
|
||||
short, committed, authored, *parents = line.split()
|
||||
if len(parents) > 1:
|
||||
chunks.append((short, short, int(committed), "merge"))
|
||||
|
||||
@@ -15,6 +15,8 @@ NOT_WORK = ("todo.md", HISTORY, RECORD)
|
||||
|
||||
# How a chunk reached the default branch; rebase and push leave no merge commit to bound it.
|
||||
Landing = typing.Literal["merge", "rebase", "push"]
|
||||
# A chunk's first and last commit as short hashes, its commit time, and how it reached the default branch.
|
||||
Chunk = tuple[str, str, int, Landing]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -28,7 +30,7 @@ class Outcome:
|
||||
files: int
|
||||
rounds_past_first: int
|
||||
findings: tuple[int, int] | None
|
||||
landed: Landing = "merge"
|
||||
landed: Landing
|
||||
|
||||
|
||||
# An outcome's name and how to read it from an Outcome, None where the chunk did not record it.
|
||||
@@ -50,7 +52,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 outcomes_of(shipped: list[Item], merge: str, merged: str, numstat: str, titles: list[str], landed: Landing = "merge") -> list[Outcome]:
|
||||
def outcomes_of(shipped: list[Item], merge: str, merged: str, numstat: str, titles: list[str], landed: Landing) -> list[Outcome]:
|
||||
"""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]
|
||||
|
||||
@@ -12,7 +12,7 @@ from failure import Failure
|
||||
from test_env import isolated_env
|
||||
from todo_table import Item
|
||||
from score_outcomes.outcomes import Landing, nearest, Outcome, outcomes_of, rank_correlation, render, report, shipped
|
||||
from score_outcomes.main import report_text
|
||||
from score_outcomes.main import chunk_log, 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"
|
||||
@@ -50,16 +50,38 @@ class Shipped(unittest.TestCase):
|
||||
self.assertEqual(shipped(todo(FIRST, "| x | 0.1.0 | | **Bad.** | 2 | 3 | 5 | 6 | 7 | 1 | 9.0 |"), todo()), [])
|
||||
|
||||
|
||||
class ChunkLog(unittest.TestCase):
|
||||
# Lines are `%h %ct %at %p`, newest first: short hash, commit time, author time, parents.
|
||||
|
||||
def test_a_merge_is_a_chunk_of_its_own_and_joins_no_run_below_it(self):
|
||||
self.assertEqual(chunk_log(["m 100 100 a b", "c 100 100 a"]), [("m", "m", 100, "merge"), ("c", "c", 100, "push")])
|
||||
|
||||
def test_commits_sharing_a_commit_time_form_one_run_labelled_rebase_when_any_differs(self):
|
||||
self.assertEqual(chunk_log(["c2 200 150 c1", "c1 200 100 r"]), [("c1", "c2", 200, "rebase")])
|
||||
|
||||
def test_a_run_of_commits_that_all_kept_their_author_time_is_labelled_push(self):
|
||||
self.assertEqual(chunk_log(["c2 200 200 c1", "c1 200 200 r"]), [("c1", "c2", 200, "push")])
|
||||
|
||||
def test_a_run_is_rebase_when_only_its_older_commit_was_replayed(self):
|
||||
self.assertEqual(chunk_log(["c2 200 200 c1", "c1 200 100 r"]), [("c1", "c2", 200, "rebase")])
|
||||
|
||||
def test_a_run_is_rebase_when_only_its_newer_commit_was_replayed(self):
|
||||
self.assertEqual(chunk_log(["c2 200 100 c1", "c1 200 200 r"]), [("c1", "c2", 200, "rebase")])
|
||||
|
||||
def test_a_commit_at_another_time_starts_a_new_chunk(self):
|
||||
self.assertEqual(chunk_log(["c2 300 300 c1", "c1 200 200 r"]), [("c2", "c2", 300, "push"), ("c1", "c1", 200, "push")])
|
||||
|
||||
|
||||
class OutcomesOf(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 = outcomes_of([item(4, {"R": 2}), item(5, {"R": 3})], "abc1234", "2026-10-13T10:00:00Z", numstat, titles)
|
||||
self.assertEqual(found[0], Outcome(item(4, {"R": 2}), "abc1234", "2026-10-13T10:00:00Z", (5,), 5, 3, 1, (1, 6)))
|
||||
found = outcomes_of([item(4, {"R": 2}), item(5, {"R": 3})], "abc1234", "2026-10-13T10:00:00Z", numstat, titles, "merge")
|
||||
self.assertEqual(found[0], Outcome(item(4, {"R": 2}), "abc1234", "2026-10-13T10:00:00Z", (5,), 5, 3, 1, (1, 6), "merge"))
|
||||
self.assertEqual(found[1].shipped_with, (4,))
|
||||
|
||||
def test_measures_no_chunk_that_changed_only_the_plan(self):
|
||||
self.assertEqual(outcomes_of([item(4, {"R": 2})], "abc1234", "2026-10-13T10:00:00Z", "0\t5\ttodo.md\n", []), [])
|
||||
self.assertEqual(outcomes_of([item(4, {"R": 2})], "abc1234", "2026-10-13T10:00:00Z", "0\t5\ttodo.md\n", [], "merge"), [])
|
||||
|
||||
|
||||
class Nearest(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user