From 92f82047025982243bb900ccd534ceca9df0328c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 21 Oct 2026 17:56:38 +0200 Subject: [PATCH] Leave chunks that were never replayed out of score-outcomes' medians and rank correlations --- CHANGELOG.md | 2 +- bin/score_outcomes/main.py | 10 ++++---- bin/score_outcomes/outcomes.py | 6 ++--- bin/score_outcomes/test_score_outcomes.py | 31 ++++++++++++++++++++--- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8106963a..487cdd03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `score-outcomes` measures each chunk on the default branch's first-parent line: 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. +- `score-outcomes` measures each chunk on the default branch's first-parent line: 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 commits were pushed or fast-forwarded as committed may hold only part of its pull request, so the medians and rank correlations leave it out. - Every project now shares one achieve goal, code health: the code is easy to understand and change safely. `CLAUDE.md` → "Shared goal" states it, with its signal and counter-signal. `rank_todo.py` ranks it first among a project's achieve goals. A project's overall is the overall mean of the newest scoring run in `docs/comprehension-history.md`, averaged with every other run on its commit. While that overall is under 7.0, or no run has measured the project, code health weighs four times as much as it does at 7.0 or above. An item's Moves cell names it as in `code health by 6`. A README voids it with `**Void:** code health, since .` under `## Goals`, and `rank_todo.py` then refuses an item that names it. `larv-review record-scoring` re-ranks `todo.md` after it appends a run, and exits 1 where `rank_todo.py` would, keeping the run. Expect items that make code easier to read to rank higher in every project. On upgrade: 1. Move every machine to this release before any of them ranks a plan another machine shares: an older `rank_todo.py` scores it without code health and rejects a `code health` cell. 2. Void code health in each project that opts out of the comprehension check, or `rank_todo.py` refuses its plan. diff --git a/bin/score_outcomes/main.py b/bin/score_outcomes/main.py index e583e821..ccb4bffd 100644 --- a/bin/score_outcomes/main.py +++ b/bin/score_outcomes/main.py @@ -43,9 +43,9 @@ level named twice leaves the anchors out, saying why. Then the median of the outcome R and S each predict at each value they were guessed at: R against 🔴 findings, S against lines changed. And how well L, E and I each order chunks by review rounds past each pass's first and by 🔴 findings: Spearman's rank correlation, from -1 to +1, where +1 -orders them exactly; none where every chunk held the same level, or the same outcome. It counts only chunks that shipped one -item, since a chunk measures all its items at once, and reports a score only once 10 such chunks -hold it and its outcomes. +orders them exactly; none where every chunk held the same level, or the same outcome. It counts only chunks that +shipped one item, since a chunk measures all its items at once. It leaves out the chunks never replayed, which may +hold only part of a pull request. It reports a score only once 10 such chunks hold it and its outcomes. 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 @@ -71,7 +71,7 @@ UNMERGED = [ "", "- Each is the run of commits on the default branch that share one commit time, since a rebase merge replays a pull request's commits at once. Its guesses come from the todo.md before its first commit.", "- Two pull requests merged in the same second read as one chunk, so a pull request that shipped nothing adds its lines, files and rounds to the chunk it shares a time with.", - "- A run whose commits all kept their author time was never replayed: pushed or fast-forwarded as committed, it may hold only part of its pull request.", + "- A run whose commits all kept their author time was never replayed: pushed or fast-forwarded as committed. It may hold only part of its pull request, so the medians and the rank correlations leave it out.", "- Rebase drops a round's commit that changed no file, so their rounds and findings are at least what history shows, and the medians count them as shown.", ] @@ -106,7 +106,7 @@ def report_text(outcomes: list[Outcome], anchored: Anchors | Failure, given: dic near = [render(outcome) for outcome in nearest(outcomes, given | {"R": r})] or ["- None: no chunk on the default branch shipped an item from todo.md."] sections.append([f"Finished items nearest L {given['L']}, E {given['E']}, I {given['I']}, so R {r}, and S {given['S']}, closest first:", "", *near]) sections.append([f"Anchors in {ANCHORS_PATH}, each level's shipped items:", "", *anchor_lines(anchored, outcomes)]) - sections.append(["Median outcome at each guessed score, among chunks that shipped one item:", "", *report(outcomes)]) + sections.append(["Median outcome at each guessed score, among chunks that shipped one item, never-replayed ones left out:", "", *report(outcomes)]) if any(outcome.landed != "merge" for outcome in outcomes): sections.append(UNMERGED) return "\n\n".join("\n".join(section) for section in sections) diff --git a/bin/score_outcomes/outcomes.py b/bin/score_outcomes/outcomes.py index 93bb5ecf..42443fec 100644 --- a/bin/score_outcomes/outcomes.py +++ b/bin/score_outcomes/outcomes.py @@ -75,8 +75,8 @@ def nearest(outcomes: list[Outcome], given: dict[str, int], count: int = 5) -> l def report(outcomes: list[Outcome]) -> list[str]: - """Among chunks that shipped one item, since a chunk measures all its items at once: for each score in MEDIANS, the median outcome at each value it was guessed at; for each level in ORDERED, how well it orders chunks by review rounds and by 🔴 findings.""" - single = [outcome for outcome in outcomes if not outcome.shipped_with] + """Among chunks that shipped one item, since a chunk measures all its items at once, and that were merged or replayed, since a never-replayed one may hold only part of a pull request: for each score in MEDIANS, the median outcome at each value it was guessed at; for each level in ORDERED, how well it orders chunks by review rounds and by 🔴 findings.""" + single = [outcome for outcome in outcomes if not outcome.shipped_with and outcome.landed != "push"] lines = [] for name, (what, measure) in MEDIANS.items(): held = [(outcome.item.scores[name], value) for outcome in single if name in outcome.item.scores and (value := measure(outcome)) is not None] @@ -100,7 +100,7 @@ def report(outcomes: list[Outcome]) -> list[str]: def too_few(held: int, name: str, what: str) -> str: - chunks = "chunk that shipped one item records" if held == 1 else "chunks that shipped one item record" + chunks = "such chunk records" if held == 1 else "such chunks record" return f"{held} {chunks} {name} and {what}; the report needs {ENOUGH}." diff --git a/bin/score_outcomes/test_score_outcomes.py b/bin/score_outcomes/test_score_outcomes.py index 0a95840a..40b37d1f 100644 --- a/bin/score_outcomes/test_score_outcomes.py +++ b/bin/score_outcomes/test_score_outcomes.py @@ -111,11 +111,11 @@ class Report(unittest.TestCase): self.assertFalse([line for line in lines if line.startswith("- C")]) def test_says_how_many_chunks_it_has_under_ten(self): - self.assertIn("- S, lines changed: 1 chunk that shipped one item records S and its outcome; the report needs 10.", report([outcome(1, 2, 2, 4), outcome(2, 2, 2, None, shipped_with=(1,))])) + self.assertIn("- S, lines changed: 1 such chunk records S and its outcome; the report needs 10.", report([outcome(1, 2, 2, 4), outcome(2, 2, 2, None, shipped_with=(1,))])) too_few = report([outcome(1, 2, 2, None, levels={"L": 2, "E": 1, "I": 1}), outcome(2, 2, 2, None, levels={"L": 2}, findings=None)]) for name in "LEI": with self.subTest(name=name): - self.assertIn(f"- {name}, by review rounds past each pass's first and 🔴 findings: 1 chunk that shipped one item records {name} and both outcomes; the report needs 10.", too_few) + self.assertIn(f"- {name}, by review rounds past each pass's first and 🔴 findings: 1 such chunk records {name} and both outcomes; the report needs 10.", too_few) def test_ranks_ties_by_their_mean_rank(self): self.assertAlmostEqual(rank_correlation([1, 1, 2, 2, 2], [1, 2, 3, 4, 5]), 0.866, places=3) @@ -187,7 +187,7 @@ class Anchors(unittest.TestCase): class ReportText(unittest.TestCase): def test_lists_the_nearest_by_r_then_the_anchors_then_the_medians(self): found = [outcome(1, 5, 3, None, merged="2026-10-13T10:00:00Z"), outcome(2, 1, 3, None, merged="2026-10-12T10:00:00Z")] - too_few = "chunks that shipped one item record" + 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.** @@ -198,7 +198,7 @@ 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.** -Median outcome at each guessed score, among chunks that shipped one item: +Median outcome at each guessed score, among chunks that shipped one item, never-replayed ones left out: - R, 🔴 findings: 2 {too_few} R and its outcome; the report needs 10. - S, lines changed: 2 {too_few} S and its outcome; the report needs 10. @@ -214,6 +214,29 @@ Median outcome at each guessed score, among chunks that shipped one item: self.assertIn("Chunks that left no merge commit", report_text([outcome(1, 5, 3, None, landed="push")], [], None)) self.assertNotIn("Chunks that left no merge commit", report_text([outcome(1, 5, 3, None)], [], None)) + def test_leaves_a_never_replayed_chunk_out_of_the_s_medians_and_keeps_a_rebased_one(self): + found = [outcome(id_, 2, 2, None, lines=10 * id_, landed="rebase" if id_ == 1 else "merge") for id_ in range(1, 11)] + self.assertIn("- S, lines changed: 2 → 55 (10 chunks)", report_text(found + [outcome(11, 2, 2, None, lines=100000, landed="push")], [], None)) + + def test_leaves_a_never_replayed_chunk_out_of_the_r_medians_and_the_rank_correlations(self): + levels = [1, 1, 2, 2, 2, 3, 3, 3, 4, 4] + found = [outcome(id_, 2, 2, None, rounds=level, findings=(5 - level, 0), levels={"L": level, "E": 2, "I": level}) for id_, level in enumerate(levels, 1)] + pushed = outcome(11, 2, 2, None, rounds=9, findings=(9, 0), levels={"L": 1, "E": 2, "I": 1}, landed="push") + text = report_text(found + [pushed], [], None) + self.assertIn("- R, 🔴 findings: 2 → 2.5 (10 chunks)", text) + self.assertIn("- L, by review rounds past each pass's first and 🔴 findings: rank correlation +1.00 and -1.00 (10 chunks)", text) + self.assertIn("- I, by review rounds past each pass's first and 🔴 findings: rank correlation +1.00 and -1.00 (10 chunks)", text) + self.assertIn("- E, by review rounds past each pass's first and 🔴 findings: rank correlation none and none, since every chunk held one value (10 chunks)", text) + + def test_keeps_a_never_replayed_chunk_in_the_nearest_and_anchors_lists(self): + pushed = outcome(9, 2, 3, None, landed="push") + text = report_text([pushed], [("L 1", (9,))], {"L": 1, "E": 1, "I": 1, "S": 3}) + nearest_section, anchors_section = text.split("Anchors in ") + self.assertIn("- Item 9, R 2, S 3:", nearest_section) + self.assertIn("never replayed", nearest_section) + self.assertIn("- Item 9, R 2, S 3:", anchors_section) + self.assertIn("never replayed", anchors_section.split("Median outcome")[0]) + def test_lists_no_nearest_items_where_no_scores_are_given(self): self.assertTrue(report_text([], [], None).startswith("Anchors in docs/score-anchors.md"))