From 5c460a3704b6d2ad7a9431f267c054b9e2f074b9 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:32:14 +0100 Subject: [PATCH 1/2] Keep resolve output compatible with legacy encodings Architecture-Review: unchanged; stdout escaping preserves the existing resolution and eligibility sequence. Co-Authored-By: Codex --- src/loopzero/cli.py | 6 +++--- tests/test_cli.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 48a64159..2cbf297d 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -1811,11 +1811,11 @@ def _version() -> str: def main(argv: list[str] | None = None) -> int: - # Progress lines must precede the stderr verdict when both go to one file. - if isinstance(sys.stdout, io.TextIOWrapper): - sys.stdout.reconfigure(line_buffering=True) parser = build_parser() args = parser.parse_args(argv) + # Preserve output order and escape characters a legacy stream cannot write during resolve. + if isinstance(sys.stdout, io.TextIOWrapper): + sys.stdout.reconfigure(line_buffering=True, errors="backslashreplace" if args.command == "resolve" else None) if args.command == "resolve" and args.finding is not None and not args.reply.strip(): parser.error('expected resolve [ ""] with a nonblank reply for a finding') if args.command == "review" and args.repost: diff --git a/tests/test_cli.py b/tests/test_cli.py index b5536583..99d00861 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4016,25 +4016,25 @@ def finding_pr(wt, gh, head): @pytest.mark.parametrize("outcome", ["refreshed", "remaining", "dispatch failed"]) def test_resolve_lists_then_replies_and_resolves_one_finding(finding_pr, gh: FakeGh, capsys, outcome) -> None: + sys.stdout.reconfigure(encoding="ascii" if outcome == "refreshed" else "utf-8", errors="strict") + finding_pr["comments"]["nodes"][0]["body"] = finding_pr["comments"]["nodes"][0]["body"].replace("Off by one", "Łódź") listing = threads_json(finding_pr) - remaining = listing if outcome == "remaining" else threads_json() - gh.respond("api graphql", listing, listing, REPLY_ACCEPTED, THREAD_RESOLVED, remaining) + gh.respond("api graphql", listing, listing, REPLY_ACCEPTED, THREAD_RESOLVED, + listing if outcome == "remaining" else threads_json()) gh.respond("api -X", "", exit=int(outcome == "dispatch failed"), stderr="HTTP 403") - + title = r"\u0141\xf3d\u017a" if outcome == "refreshed" else "Łódź" code, out, err = run(capsys, "resolve") - assert (code, err) == (0, "") and out == "0b9b59e7 important src/a.py:3 Off by one\n" + assert (code, err) == (0, "") and out == f"0b9b59e7 important src/a.py:3 {title}\n" assert not any("eligibility.yml/dispatches" in " ".join(c["argv"]) for c in gh.calls) - code, out, err = run(capsys, "resolve", "0b9b59e7", "Fixed in abc1234: loop bound corrected.") - assert out.splitlines()[0] == "resolved 0b9b59e7: Off by one" + assert out.splitlines()[0] == f"resolved 0b9b59e7: {title}" calls = [c["argv"] for c in gh.calls if c["argv"][:2] == ["api", "graphql"]][2:] assert "addPullRequestReviewThreadReply" in calls[0][3] and "resolveReviewThread" in calls[1][3] assert "body=Fixed in abc1234: loop bound corrected." in calls[0] and "thread=THREAD_1" in calls[1] endpoint = f"repos/{REPO}/actions/workflows/eligibility.yml/dispatches" dispatches = [c["argv"] for c in gh.calls if endpoint in c["argv"]] if outcome == "remaining": - assert (code, err, dispatches) == (0, "", []) - assert len(out.splitlines()) == 1 + assert (code, err, dispatches, len(out.splitlines())) == (0, "", [], 1) else: assert dispatches == [["api", "-X", "POST", endpoint, "-f", "ref=main", "-f", "inputs[pr]=7", "--include"]] if outcome == "refreshed": From cd6e382d3c419530ed305c1ac5e445b7ad7d7105 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:45:59 +0100 Subject: [PATCH 2/2] Cover Unicode finding paths as well as titles --- tests/test_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 99d00861..9bf7c733 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4018,13 +4018,13 @@ def finding_pr(wt, gh, head): def test_resolve_lists_then_replies_and_resolves_one_finding(finding_pr, gh: FakeGh, capsys, outcome) -> None: sys.stdout.reconfigure(encoding="ascii" if outcome == "refreshed" else "utf-8", errors="strict") finding_pr["comments"]["nodes"][0]["body"] = finding_pr["comments"]["nodes"][0]["body"].replace("Off by one", "Łódź") - listing = threads_json(finding_pr) + listing = threads_json({**finding_pr, "path": "src/Łódź.py"}) gh.respond("api graphql", listing, listing, REPLY_ACCEPTED, THREAD_RESOLVED, listing if outcome == "remaining" else threads_json()) gh.respond("api -X", "", exit=int(outcome == "dispatch failed"), stderr="HTTP 403") title = r"\u0141\xf3d\u017a" if outcome == "refreshed" else "Łódź" code, out, err = run(capsys, "resolve") - assert (code, err) == (0, "") and out == f"0b9b59e7 important src/a.py:3 {title}\n" + assert (code, err) == (0, "") and out == f"0b9b59e7 important src/{title}.py:3 {title}\n" assert not any("eligibility.yml/dispatches" in " ".join(c["argv"]) for c in gh.calls) code, out, err = run(capsys, "resolve", "0b9b59e7", "Fixed in abc1234: loop bound corrected.") assert out.splitlines()[0] == f"resolved 0b9b59e7: {title}"