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: 5 additions & 1 deletion src/github_agent_bridge/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ def __init__(self, gh_bin: str = "gh", mode: RunMode = RunMode.LIVE):
self.gh_bin = gh_bin

def _run(self, args: list[str]) -> subprocess.CompletedProcess[str]:
return subprocess.run([self.gh_bin, *args], check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
command = [self.gh_bin, *args]
try:
return subprocess.run(command, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
except FileNotFoundError as exc:
return subprocess.CompletedProcess(command, 127, "", str(exc))

def current_login(self) -> str | None:
result = self._run(["api", "user", "--jq", ".login"])
Expand Down
10 changes: 10 additions & 0 deletions tests/test_modes_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ def test_shadow_github_reaction_has_no_external_failure():
assert GitHubClient(gh_bin="definitely-not-present", mode=RunMode.SHADOW).react_eyes(make_job().context) is True


def test_live_github_command_handles_missing_gh_binary():
client = GitHubClient(gh_bin="definitely-not-present", mode=RunMode.LIVE)

result = client._run(["api", "user"])

assert result.returncode == 127
assert result.stdout == ""
assert "definitely-not-present" in result.stderr


class RecordingGitHubClient(GitHubClient):
def __init__(self):
super().__init__(mode=RunMode.LIVE)
Expand Down