Answer stability round 1: 0 🔴, 2 🟡 (0 misread); read non-ASCII paths with numstat -z, and say on stderr when a chunk's details cannot be read

This commit is contained in:
2026-11-08 23:16:15 +01:00
parent 8a62df6bf5
commit b18e63653c
5 changed files with 31 additions and 17 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ def named_paths(text: str, tracked: list[str]) -> list[tuple[str, int]]:
def named_files(text: str, tracked: list[str]) -> list[str]:
"""Each tracked file that a backticked span in text names, itself or by a folder holding it, once, in tracked's order."""
"""Each tracked file that a backticked span in text names, either the file itself or a folder holding it, once, in tracked's order."""
named = spans(text)
return [path for path in tracked if any(holds(span, path) for span in named)]
+10 -5
View File
@@ -46,9 +46,12 @@ L, E and I, as rank_todo.py does, and lists the 5 finished items whose guesses s
first: the least mean squared difference over the scores both hold, so R and S alone for an item
scored before L, E and I, the newest first among equals. Each line gives what the item's chunk
measured, which items shipped with it, and its tagline. Where the item's tagline or detail names
tracked files or folders, each in backticks such as `bin/rank_todo.py`, the line gives their size
before the chunk beside the item's S: how many files and their lines, which bound what the change
could touch.
tracked files or folders in backticks, each by its path from the repository root such as
`bin/rank_todo.py`, the line also gives their size after the item's scores: how many files they
held before the chunk, and how many lines. A named folder counts the files it holds. This is the
size of the code the item said it would change; the chunk's change may reach beyond it. Where the
todo.md a chunk started from holds a ## Details section that cannot be read, it says so on stderr
and sizes that chunk's items by their taglines alone.
Then the project's anchors, the shipped items its docs/score-anchors.md names for each level of L,
E and I, read from the checkout's working tree, each line as above, or that no chunk shipped it. A
@@ -184,13 +187,15 @@ def read_results(default: str) -> list[Result] | Failure:
if isinstance(plan, Failure):
return plan
found = item_details(plan)
if isinstance(found, Failure):
print(f"score-outcomes: the todo.md before {chunk.label} cannot be read for its details, so its items are sized by their taglines alone: {found.reason}", file=sys.stderr)
details = {} if isinstance(found, Failure) else found
tracked = run("ls-tree", "-r", "-z", "--name-only", chunk.before)
if isinstance(tracked, Failure):
return tracked
# Only the files the items name, since counting every file's lines for every chunk doubles the run.
# Count only the files the items name, since counting every file's lines for every chunk doubles the run.
named = list(dict.fromkeys(path for item in chunk.shipped for path in named_files(item_text(item, details), tracked.split("\0")[:-1])))
tree = run("--literal-pathspecs", "diff", "--numstat", empty_tree.strip(), chunk.before, "--", *named) if named else ""
tree = run("--literal-pathspecs", "diff", "--numstat", "-z", empty_tree.strip(), chunk.before, "--", *named) if named else ""
if isinstance(tree, Failure):
return tree
results += results_of(chunk, numstat, details, file_lines(tree))
+5 -7
View File
@@ -12,10 +12,10 @@ from release_plan.named_code import named_files
ENOUGH = 10
# An item's size in lines, not an S: no published scale maps lines to S, and the report's S medians already set the S guessed beside the lines changed.
# A size in files and lines, not an S, since no published scale maps lines to S. The report's S medians show which S was guessed for how many lines changed.
@dataclasses.dataclass(frozen=True)
class NamedCode:
"""The tracked files an item's tagline and detail name, folders by the files they hold, as the chunk that shipped it found them: how many, and their lines, a binary file holding none. They bound what the chunk's change could touch."""
"""How many tracked files an item's tagline and detail name, and their lines, as they stood before the chunk that shipped it. A named folder counts the files it holds. A binary file counts no lines."""
files: int
lines: int
@@ -37,8 +37,6 @@ class Result:
named: NamedCode | None
# A measure's name and how to read it from a Result, None where the chunk did not record it.
Measure = tuple[str, typing.Callable[[Result], int | None]]
# The scores whose median result the report gives at each guessed value.
@@ -63,13 +61,13 @@ def results_of(chunk: BranchChunk, numstat: str, details: dict[int, str], tree:
def item_text(item: Item, details: dict[int, str]) -> str:
"""The tagline and detail, where the item names the files it changes."""
"""The text that may name files: the item's tagline and its detail."""
return f"{item.tagline}\n{details.get(item.id, '')}"
def file_lines(numstat: str) -> dict[str, int]:
"""Each file's lines from `git diff --numstat` against the empty tree, which counts every line as added; git counts a binary file's lines as "-", so it holds none."""
rows = [row.split("\t", 2) for row in numstat.splitlines()]
"""Each file's lines from `git diff --numstat -z` against the empty tree, which counts every line as added. Git prints "-" for a binary file's lines, so that file counts 0 lines."""
rows = [row.split("\t", 2) for row in numstat.split("\0")]
return {row[2]: int(row[0]) if row[0].isdigit() else 0 for row in rows if len(row) == 3}
+14 -3
View File
@@ -54,7 +54,7 @@ class ResultsOf(unittest.TestCase):
self.assertEqual([result.named for result in found], [NamedCode(3, 9), None, NamedCode(1, 9)])
def test_reads_each_files_lines_from_a_numstat_against_the_empty_tree_a_binary_file_holding_none(self):
self.assertEqual(file_lines("3\t0\ta.py\n-\t-\tlogo.png\n0\t0\tempty.txt\n"), {"a.py": 3, "logo.png": 0, "empty.txt": 0})
self.assertEqual(file_lines("3\t0\ta.py\0-\t-\tlogo.png\x000\t0\tempty.txt\x002\t0\tsrc/åäö.py\0"), {"a.py": 3, "logo.png": 0, "empty.txt": 0, "src/åäö.py": 2})
class Nearest(unittest.TestCase):
@@ -326,14 +326,25 @@ class ScoreOutcomesTool(unittest.TestCase):
return ran.stdout, item_4[0], first, last, pushed
def test_gives_the_lines_of_the_files_an_items_detail_names_as_its_chunk_found_them(self):
self.commit("Detail it", {"a.py": "1\n2\n", "todo.md": todo(FIRST, SECOND) + "\n## Details\n\n### 4. Do it.\n\nChange `a.py`.\n"})
self.commit("Detail it", {"a.py": "1\n2\n", "src/åäö.py": "1\n2\n3\n", "todo.md": todo(FIRST, SECOND) + "\n## Details\n\n### 4. Do it.\n\nChange `a.py` and `src`.\n"})
self.git("switch", "-q", "-c", "chunk")
self.commit("Do it", {"a.py": "1\n2\n3\n", "todo.md": todo(SECOND)})
self.git("switch", "-q", "main")
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.assertIn("- Item 4, R 2, S 3, C 10, naming code of 2 lines in 1 file: 1 line in 1 file, ", ran.stdout)
self.assertIn("- Item 4, R 2, S 3, C 10, naming code of 5 lines in 2 files: 1 line in 1 file, ", ran.stdout)
def test_says_on_stderr_when_a_chunks_details_cannot_be_read_and_sizes_its_items_by_their_taglines(self):
self.commit("Break the details", {"todo.md": todo(FIRST, SECOND) + "\n## Details\n\nloose text\n\n### 4. Do it.\n\nChange `a.py`.\n", "a.py": "1\n"})
self.git("switch", "-q", "-c", "chunk")
self.commit("Do it", {"a.py": "1\n2\n", "todo.md": todo(SECOND)})
self.git("switch", "-q", "main")
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.assertIn("cannot be read for its details, so its items are sized by their taglines alone: ## Details holds text before its first ### <ID>. heading", ran.stderr)
self.assertIn("- Item 4, R 2, S 3, C 10: 1 line in 1 file, ", ran.stdout)
def test_guesses_a_rebase_chunk_from_the_todo_md_before_its_first_commit(self):
_, item_4, _, _, _ = self.run_on_rebased_history()