diff --git a/.workflow/tasks/WB-59.json b/.workflow/tasks/WB-59.json new file mode 100644 index 0000000..d1d81f0 --- /dev/null +++ b/.workflow/tasks/WB-59.json @@ -0,0 +1,16 @@ +{ + "key": "WB-59", + "title": "wb finish counts every line of a file rewritten with CRLF as changed", + "type": "bug", + "status": "done", + "desc": "gitctx.lines_changed runs git diff --numstat without --ignore-cr-at-eol. In a repo without core.autocrlf, a session on Windows that rewrites a file with CRLF endings changes one line and is measured as changing all of them, so wb finish sends small work to the standard route as outgrown, and impl check reports a light plan as oversize. Seen recording the demo: a 2-line fix measured 66 lines.\n\nACCEPTANCE:\n- a CRLF rewrite of an LF file with one changed line measures as that line\n- regression test in tests/test_gitctx.py that fails without the fix", + "created": "2026-09-27T03:22:28Z", + "updated": "2026-09-27T03:31:03Z", + "comments": [], + "linked": [ + { + "key": "WB-53", + "type": "relates" + } + ] +} diff --git a/lib/workbench/gitctx.py b/lib/workbench/gitctx.py index d5e07c5..56c92be 100644 --- a/lib/workbench/gitctx.py +++ b/lib/workbench/gitctx.py @@ -290,7 +290,9 @@ def lines_changed(cwd: Path, base: str, paths: list[str], *, staged: bool = Fals """ if not paths: return 0 - args = ["diff", "--numstat", "--no-renames", "--no-color"] + # --ignore-cr-at-eol: a file rewritten with CRLF on Windows, in a repo that + # does not convert endings, is one changed line, not all of them (WB-59). + args = ["diff", "--numstat", "--no-renames", "--no-color", "--ignore-cr-at-eol"] if staged: args.append("--cached") output = _git_raw([*args, base or "HEAD", "--", *paths], cwd) diff --git a/lib/workbench/light.py b/lib/workbench/light.py index af9f492..ad950b8 100644 --- a/lib/workbench/light.py +++ b/lib/workbench/light.py @@ -206,7 +206,19 @@ def check(key: str, root: Path, message: str, base: str, kind: str) -> Finish: pairs.append((target, command_for)) else: result.regression = verify.run_regression(pairs, root, base, tests) - weak = [outcome.target for outcome in result.regression if not outcome.ok] + # Two different failures, told apart: a test that cannot run on its + # own (an import path the suite supplies and one file does not) was + # reported as a test that does not catch the bug (WB-59). + broken = [outcome for outcome in result.regression if not outcome.with_fix.ok] + weak = [outcome.target for outcome in result.regression if outcome.with_fix.ok and not outcome.ok] + for outcome in broken: + last = (outcome.with_fix.output.strip().splitlines() or [""])[-1] + result.blocked.append(f"{outcome.command} fails with the fix in place: {last}") + if broken: + result.fix.append( + "run that test file on its own until it passes; an import path the suite supplies " + "can go in the environment wb finish runs in (PYTHONPATH=...)" + ) if weak: result.blocked.append( f"{', '.join(weak)} passes without the fix too, so it does not prove the bug is fixed" diff --git a/tests/test_gitctx.py b/tests/test_gitctx.py index 1b5ac59..241ae68 100644 --- a/tests/test_gitctx.py +++ b/tests/test_gitctx.py @@ -193,6 +193,22 @@ def test_branch_is_reported(self) -> None: self.assertIsNotNone(gitctx.branch(self.root)) +class LinesChangedLineEndings(unittest.TestCase): + def test_a_crlf_rewrite_counts_only_the_lines_that_changed(self) -> None: + """WB-59: a 2-line fix rewritten with CRLF measured 66 lines, and wb finish + sent the ticket to the standard route as outgrown.""" + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + _git(["init", "-q", "."], root) + _git(["config", "core.autocrlf", "false"], root) + (root / "f.py").write_bytes(b"a = 1" + bytes([10]) + b"b = 2" + bytes([10]) + b"c = 3" + bytes([10])) + _git(["add", "-A"], root) + _git(["-c", "user.email=t@example.com", "-c", "user.name=T", "commit", "-qm", "init"], root) + crlf = bytes([13, 10]) + (root / "f.py").write_bytes(b"a = 1" + crlf + b"b = 20" + crlf + b"c = 3" + crlf) + self.assertEqual(2, gitctx.lines_changed(root, "HEAD", ["f.py"])) + + class DefaultBranchUnborn(unittest.TestCase): def test_a_repo_with_no_commits_names_the_branch_head_is_on(self) -> None: """The bench found it: `wb init` before the first commit recorded "main" diff --git a/tests/test_light.py b/tests/test_light.py index e49d7ed..f68dfb1 100644 --- a/tests/test_light.py +++ b/tests/test_light.py @@ -213,6 +213,22 @@ def test_a_bug_s_test_must_fail_without_the_fix(self) -> None: self.assertEqual(EXIT_AUDIT, code) self.assertIn("passes without the fix", err) + def test_a_test_that_cannot_run_alone_is_not_called_weak(self) -> None: + """WB-59: the file failed to import on its own, and finish said it passed without the fix.""" + from workbench import verify + + run("start", "ABC-1") + self.write("shop/money.py", MONEY_FIXED) + self.write("tests/test_money.py", TEST_REFUND) + broken = verify.Result(command="python -m unittest tests/test_money.py", exit_code=1, duration_ms=1, + output="ModuleNotFoundError: No module named 'shop'", truncated=False) + outcome = verify.Regression("tests/test_money.py", broken.command, broken, broken) + with mock.patch("workbench.verify.run_regression", return_value=[outcome]): + code, _, err = self.finish() + self.assertEqual(EXIT_AUDIT, code) + self.assertIn("fails with the fix in place: ModuleNotFoundError", err) + self.assertNotIn("passes without the fix", err) + def test_a_bug_s_regression_test_is_proven(self) -> None: run("start", "ABC-1") self.write("shop/money.py", MONEY_FIXED)