From f558b80cc8641fd60c8cb1f4ea9f9beee5f32f72 Mon Sep 17 00:00:00 2001 From: Jason Walker <913443@dadeschools.net> Date: Thu, 9 Jul 2026 10:43:42 -0400 Subject: [PATCH] test: cover explicit git -C terminal probe --- gitea_mcp_server.py | 12 ++++++++++-- native_mcp_preference.py | 13 ++++++++++--- tests/test_native_mcp_preference.py | 25 ++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/gitea_mcp_server.py b/gitea_mcp_server.py index 0c05920..c960185 100644 --- a/gitea_mcp_server.py +++ b/gitea_mcp_server.py @@ -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, diff --git a/native_mcp_preference.py b/native_mcp_preference.py index 2e3d1ee..60cb420 100644 --- a/native_mcp_preference.py +++ b/native_mcp_preference.py @@ -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 diff --git a/tests/test_native_mcp_preference.py b/tests/test_native_mcp_preference.py index 82ec6f0..9566759 100644 --- a/tests/test_native_mcp_preference.py +++ b/tests/test_native_mcp_preference.py @@ -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"])