Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/loopzero/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1818,11 +1818,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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The error handler stays set on a shared stdout in later in-process main() calls

For non-resolve commands, errors=None keeps the stream's current handler. A real CLI process calls main() once, so this is harmless there. In tests (and any embedding that calls main() repeatedly on the same sys.stdout), a resolve call leaves backslashreplace in place for every later command. Encoding failures from other commands could then go unnoticed in the same test. This is not a shipped bug. If you want strict isolation, reset to the stream's original handler instead of passing None (for example, capture sys.stdout.errors once). The line is also 117 characters, over the configured 100-character line length; E501 isn't selected, so this is cosmetic.

if args.command == "resolve" and args.finding is not None and not args.reply.strip():
parser.error('expected resolve [<finding-id> "<reply>"] with a nonblank reply for a finding')
if args.command == "review" and args.repost:
Expand Down
18 changes: 9 additions & 9 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
listing = threads_json(finding_pr)
remaining = listing if outcome == "remaining" else threads_json()
gh.respond("api graphql", listing, listing, REPLY_ACCEPTED, THREAD_RESOLVED, remaining)
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ź")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The Unicode path case from the acceptance criteria has no test

The acceptance criteria cover findings with Unicode titles or paths. The test only changes the comment body ("Off by one" -> "Łódź"), so the listing line's f.path (cli.py:1668) never contains non-ASCII text. The fix works on the whole stream, so paths are handled too, but nothing would catch a future change that formats paths differently (for example .encode()/ascii()). Smallest fix with no net test lines: put the same substitution into the fixture's path (e.g. src/a.py -> src/ą.py) and fold it into the existing title expectation string.

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 == "0b9b59e7 important src/a.py:3 Off by one\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] == "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":
Expand Down
Loading