fix: require executable tea fallback binary (#392)
All checks were successful
Gitea CI / test (push) Successful in 32s
Gitea CI / test (pull_request) Successful in 33s

This commit is contained in:
agentson
2026-03-02 18:32:07 +09:00
parent f4f8827353
commit bd9286a39f
2 changed files with 17 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ from __future__ import annotations
import argparse import argparse
import json import json
import os
import shutil import shutil
import re import re
import subprocess import subprocess
@@ -28,7 +29,7 @@ def resolve_tea_binary() -> str:
return tea_from_path return tea_from_path
tea_home = Path.home() / "bin" / "tea" tea_home = Path.home() / "bin" / "tea"
if tea_home.exists(): if tea_home.exists() and tea_home.is_file() and os.access(tea_home, os.X_OK):
return str(tea_home) return str(tea_home)
raise RuntimeError("tea binary not found (checked PATH and ~/bin/tea)") raise RuntimeError("tea binary not found (checked PATH and ~/bin/tea)")
@@ -63,7 +64,7 @@ def fetch_pr_body(pr_number: int) -> str:
capture_output=True, capture_output=True,
text=True, text=True,
) )
except (subprocess.CalledProcessError, FileNotFoundError) as exc: except (subprocess.CalledProcessError, FileNotFoundError, PermissionError) as exc:
raise RuntimeError(f"failed to fetch PR #{pr_number}: {exc}") from exc raise RuntimeError(f"failed to fetch PR #{pr_number}: {exc}") from exc
try: try:

View File

@@ -106,7 +106,21 @@ def test_resolve_tea_binary_falls_back_to_home_bin(monkeypatch, tmp_path) -> Non
tea_home = tmp_path / "bin" / "tea" tea_home = tmp_path / "bin" / "tea"
tea_home.parent.mkdir(parents=True) tea_home.parent.mkdir(parents=True)
tea_home.write_text("#!/usr/bin/env bash\n", encoding="utf-8") tea_home.write_text("#!/usr/bin/env bash\n", encoding="utf-8")
tea_home.chmod(0o755)
monkeypatch.setattr(module.shutil, "which", lambda _: None) monkeypatch.setattr(module.shutil, "which", lambda _: None)
monkeypatch.setattr(module.Path, "home", lambda: tmp_path) monkeypatch.setattr(module.Path, "home", lambda: tmp_path)
assert module.resolve_tea_binary() == str(tea_home) assert module.resolve_tea_binary() == str(tea_home)
def test_resolve_tea_binary_rejects_non_executable_home_bin(monkeypatch, tmp_path) -> None:
module = _load_module()
tea_home = tmp_path / "bin" / "tea"
tea_home.parent.mkdir(parents=True)
tea_home.write_text("not executable\n", encoding="utf-8")
tea_home.chmod(0o644)
monkeypatch.setattr(module.shutil, "which", lambda _: None)
monkeypatch.setattr(module.Path, "home", lambda: tmp_path)
with pytest.raises(RuntimeError):
module.resolve_tea_binary()