test: cover explicit git -C terminal probe

This commit is contained in:
2026-07-09 10:43:42 -04:00
parent 223cde1b94
commit f558b80cc8
3 changed files with 44 additions and 6 deletions
+10 -2
View File
@@ -7928,8 +7928,16 @@ def gitea_diagnose_terminal(
return {
"healthy": probe_res["healthy"],
"error_type": None if probe_res["healthy"] else probe_res["error_type"] or diag["error_type"],
"error_msg": "" if probe_res["healthy"] else probe_res["error_msg"] or diag["error_msg"],
"error_type": (
None
if probe_res["healthy"]
else probe_res["error_type"] or diag["error_type"]
),
"error_msg": (
""
if probe_res["healthy"]
else probe_res["error_msg"] or diag["error_msg"]
),
"cwd": resolved_cwd,
"command": probe_cmd,
"diagnostics": diag,
+10 -3
View File
@@ -380,11 +380,15 @@ def _resolve_executable(cwd: str | None, executable: str | None) -> str | None:
if not executable:
return None
if os.path.isabs(executable):
return executable if os.path.exists(executable) and os.access(executable, os.X_OK) else None
if os.path.exists(executable) and os.access(executable, os.X_OK):
return executable
return None
if "/" in executable or "\\" in executable:
target_cwd = cwd or os.getcwd()
full_path = os.path.abspath(os.path.join(target_cwd, executable))
return full_path if os.path.exists(full_path) and os.access(full_path, os.X_OK) else None
if os.path.exists(full_path) and os.access(full_path, os.X_OK):
return full_path
return None
return shutil.which(executable)
@@ -443,7 +447,10 @@ def diagnose_terminal_failure(cwd: str | None, command: list[str]) -> dict[str,
if not has_any_shell:
diagnostics["shell_exists"] = False
diagnostics["error_type"] = "missing shell"
diagnostics["error_msg"] = "No standard system shell (/bin/sh, /bin/zsh, /bin/bash) is available or executable."
diagnostics["error_msg"] = (
"No standard system shell (/bin/sh, /bin/zsh, /bin/bash) is "
"available or executable."
)
return diagnostics
return diagnostics
+24 -1
View File
@@ -1,6 +1,7 @@
"""Tests for native MCP preference gate and shell circuit breaker (#270)."""
import sys
import unittest
import shutil
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
@@ -76,11 +77,33 @@ class TestTerminalDiagnostics(unittest.TestCase):
self.assertEqual(res["error_type"], "missing cwd")
def test_probe_terminal_spawn_honors_custom_command(self):
res = nmp.probe_terminal_spawn(command=[sys.executable, "-c", "raise SystemExit(3)"])
res = nmp.probe_terminal_spawn(
command=[sys.executable, "-c", "raise SystemExit(3)"]
)
self.assertTrue(res["healthy"])
self.assertEqual(res["command"][0], sys.executable)
self.assertEqual(res["exit_code"], 3)
@unittest.skipUnless(shutil.which("git"), "git is required for git -C probe")
def test_probe_terminal_spawn_supports_explicit_git_c_worktree(self):
import subprocess
import tempfile
with tempfile.TemporaryDirectory() as tmp:
subprocess.run(
["git", "init", tmp],
check=True,
capture_output=True,
text=True,
)
res = nmp.probe_terminal_spawn(
cwd="/",
command=["git", "-C", tmp, "status", "--short"],
)
self.assertTrue(res["healthy"])
self.assertEqual(res["command"][1], "-C")
def test_probe_terminal_spawn_blocks_missing_custom_command(self):
res = nmp.probe_terminal_spawn(command=["nonexistent_exec_for_test"])
self.assertFalse(res["healthy"])