8000 refactor(pr_review): run subprocesses through tool_utils.run_command by VLukiantsev · Pull Request #1559 · google/xmc · GitHub
[go: up one dir, main page]

Skip to content

refactor(pr_review): run subprocesses through tool_utils.run_command - #1559

Merged
VLukiantsev merged 2 commits into
refactor/shared-positive-int-parserfrom
refactor/pr-review-run-command
Nov 3, 2026
Merged

VLukiantsev merged 2 commits into
refactor/shared-positive-int-parserfrom
refactor/pr-review-run-command

Conversation

@VLukiantsev
@VLukiantsev VLukiantsev commented Nov 3, 2026 •
Copy link
Copy Markdown
Collaborator

Summary

Moves the remaining direct subprocess calls in tools/pr_review (github_utils.py, reply_pr_comment.py, wait_for_ci.py) onto tool_utils.run_command, which #1532 hardened with input_text, timeout and errors.

Motivation & Context

Each of these tools set its own capture, timeout and decoding options on subprocess.run or check_output. Sending them through the shared wrapper gives one place to harden process handling. CLI behavior and exit codes stay the same.

Key Changes

  • github_utils._call_api_with_gh: run_command(..., input_text=payload_json). A CalledProcessError still falls through to the GITHUB_TOKEN and unauthenticated fallbacks.
  • reply_pr_comment: the SKILL.md commit lookup uses run_command(capture_output=True). stderr is captured instead of sent to DEVNULL, and any failure still falls back to "unknown".
  • wait_for_ci: both gh calls go through a small _run_gh(cmd, *, check) helper. It keeps the 60s per-call timeout and errors="replace", and raw CalledProcessError, TimeoutExpired and OSError still reach the existing transient-retry loop and the log-tail placeholders.
  • Every call passes log_cmd=False and log_on_error=False, so stdout stays JSON-only and stderr is unchanged. No handled_instruction is set, so callers see the same exceptions as before.
  • github_utils now depends on //tools/common:tool_utils in BUILD.bazel.
  • Tests patch <module>.run_command instead of subprocess.*, and assert the exact kwargs.

Reused: tool_utils.run_command (keyword-only input_text, timeout, errors from #1532).

Assumptions

  • run_command passes a copy of os.environ as env=. This matches inheriting the environment, so it has no effect.
  • Deferred follow-up (predates this PR, left unchanged to keep the refactor behavior-preserving): github_utils._call_api_with_gh sets no timeout on the gh call, and an OSError (gh on PATH but not executable) is not caught by its CalledProcessError/JSONDecodeError fallback.

Verification & Testing

  • Commands Executed: bazel test //tools/pr_review/... (11/11 pass), ./.githooks/pre-commit. Live run: wait_for_ci.py 1535 --repo google/xmc printed only JSON on stdout and exited 0.
  • Coverage & Test Status: Existing retry, timeout, fallback and placeholder tests still pass against the new patch target. New tests cover the gh stdin payload (--input - with input_text) and the quiet kwargs of the git lookup.

Related Issues / Bugs

N/A

TAG=agy
CONV=2937a1a9-78d5-4d4f-806c-262c963bb857

@VLukiantsev
VLukiantsev added this pull request to stack #1561 November 3, 2026 11:27
@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors several PR review tools, including github_utils, reply_pr_comment, and wait_for_ci, to replace raw subprocess calls with the shared run_command utility from tools.common.tool_utils. The corresponding unit tests have been updated to mock and assert on run_command instead of subprocess. No review comments were provided, and the changes appear correct and consistent.

@VLukiantsev
VLukiantsev force-pushed the refactor/pr-review-run-command branch from b6467d0 to edacaef Compare November 3, 2026 11:40
github_utils, reply_pr_comment and wait_for_ci called subprocess directly
with hand-rolled capture, timeout and decoding options. Route them through
tool_utils.run_command, which now supports input_text, timeout and errors.

All calls pass log_cmd=False and log_on_error=False so stdout stays
JSON-only and stderr is unchanged. No handled_instruction is set, so the
raw CalledProcessError/TimeoutExpired/OSError still reach the existing
handlers: github_utils' credential fallback, reply_pr_comment's "unknown"
commit fallback, and wait_for_ci's transient-retry loop with its 60s
per-call timeout. wait_for_ci's two gh calls share a small _run_gh helper.

TAG=agy
CONV=2937a1a9-78d5-4d4f-806c-262c963bb857
@VLukiantsev
VLukiantsev force-pushed the refactor/pr-review-run-command branch from edacaef to 0cc403a Compare November 3, 2026 12:09
@VLukiantsev
VLukiantsev marked this pull request as ready for review November 3, 2026 14:40
@github-actions
github-actions Bot requested a review from janzak-dev November 3, 2026 14:41
janzak-dev
janzak-dev previously approved these changes Nov 3, 2026
Comment thread tools/pr_review/github_utils_test.py Resolved
test_call_github_api_gh_cli_sends_payload_on_stdin only checked the argv
tail and input_text, so a changed method or endpoint, or dropped
log_cmd/log_on_error flags (which keep tool stdout JSON-only), would
still pass. Assert the complete run_command call and the return value,
matching the GET test.

TAG=agy
CONV=2937a1a9-78d5-4d4f-806c-262c963bb857
@github-actions github-actions Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Incremental PR Approval

PR author is a code owner and changes since last approval (0 lines, excluding 12 test file lines) are within the 50-line grace delta.

Preserving prior approval by @janzak-dev on commit 0cc403a.

@VLukiantsev
VLukiantsev added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit ee0ca4a Nov 3, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0