Skip to content
Merged
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 @@ -1827,18 +1827,18 @@ def _delete_tracking_ref(wt: Path, branch: str, expected_head: str) -> None:


def cmd_resolve(args: argparse.Namespace) -> int:

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: Merge resolution dropped the cmd_resolve docstring that main added

When the conflict was resolved, the branch's encoding = ... line replaced main's docstring """List open blocking findings, or reply to one with what changed and resolve its thread.""" instead of being added after it. Nothing else in the repo contains that docstring, and nothing reads cmd_resolve.__doc__, because argparse help only uses __doc__ in eligibility.py. So nothing breaks, but the merge quietly undoes documentation from #1863 that this task never meant to touch. Smallest fix: put the docstring back as the first statement of cmd_resolve and keep the encoding line below it.

"""List open blocking findings, or reply to one with what changed and resolve its thread."""
encoding = getattr(sys.stdout, "encoding", None) or "utf-8"

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: Unrelated removal of the cmd_resolve docstring

This diff replaces the docstring "List open blocking findings, or reply to one with what changed and resolve its thread." with the encoding = ... line. The docstring was the only summary of what the two modes of this command do, and removing it isn't needed for the encoding fix. Smallest fix: keep the docstring and put the encoding assignment on the line after it.

wt, config = _context(args, pin_checks=True) # publishers come from the base, not the PR
pr = _require_pr(config, worktree.branch(wt))
if pr.base_ref != config.base_branch: # trusted publishers belong to the configured base
raise CliError(f"PR #{pr.number} targets {pr.base_ref}, configured base is {config.base_branch}")
publishers = config.review_publishers or (github.login(),)
if not args.finding:
for marker_id, _thread, f in github.open_findings(config.repo, pr.number, publishers):
print(f"{marker_id} {f.severity} {f.path or '-'}:{f.line or '-'} {f.title}")
print(f"{marker_id} {f.severity} {f.path or '-'}:{f.line or '-'} {f.title}".encode(encoding, "backslashreplace").decode(encoding))

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 same encode/decode escaping is written out twice

Both resolve prints (lines 1675 and 1678) repeat .encode(encoding, "backslashreplace").decode(encoding) inline, which also makes line 1675 very long. If another resolve message later prints finding text, it would need to copy this again, and a missed copy would bring back the ASCII-stdout crash. The notes also describe a different approach: using the CLI's existing stdout configuration to pick the error handler, which is what the previous commit did. The per-print escaping in this commit is correct and more local, so this is non-blocking. Smallest fix: add a small _display(text) helper (or a local lambda) in cmd_resolve and call it from both prints.

return 0
finding = github.resolve_finding(config.repo, pr.number, args.finding, args.reply, publishers)
print(f"resolved {args.finding}: {finding.title}")
print(f"resolved {args.finding}: {finding.title}".encode(encoding, "backslashreplace").decode(encoding))
try:
with github.api_error_diagnostics():
remaining = github.open_blocking_findings(config.repo, pr.number, None, publishers)
Expand Down
18 changes: 9 additions & 9 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4056,25 +4056,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ź")
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")

expect_cli(capsys, 0, "resolve", stderr="", stdout="0b9b59e7 important src/a.py:3 Off by one\n")
title = r"\u0141\xf3d\u017a" if outcome == "refreshed" else "Łódź"
expect_cli(capsys, 0, "resolve", stderr="", stdout=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"] and "viewer {" not in c["argv"][3]][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