fix(gateway): inject PATH + VIRTUAL_ENV into launchd plist for macOS service (#3585)

Salvage of PR #2173 (hanai) and PR #3432 (timknip).

Injects PATH, VIRTUAL_ENV, and HERMES_HOME into the macOS launchd plist so gateway subprocesses find user-installed tools (node, ffmpeg, etc.). Matches systemd unit parity with venv/bin, node_modules/.bin, and resolved node dir in PATH. Includes 7 new tests and docs updates across 4 pages.

Co-Authored-By: Han <ihanai1991@gmail.com>
Co-Authored-By: timknip <timknip@users.noreply.github.com>
This commit is contained in:
Teknium 2026-03-28 14:23:26 -07:00 committed by GitHub
parent 5cdc24c2e2
commit 6893c3befc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 131 additions and 7 deletions

View file

@ -101,6 +101,69 @@ class TestLaunchdPlistReplace:
assert replace_idx == run_idx + 1
class TestLaunchdPlistPath:
def test_plist_contains_environment_variables(self):
plist = gateway_cli.generate_launchd_plist()
assert "<key>EnvironmentVariables</key>" in plist
assert "<key>PATH</key>" in plist
assert "<key>VIRTUAL_ENV</key>" in plist
assert "<key>HERMES_HOME</key>" in plist
def test_plist_path_includes_venv_bin(self):
plist = gateway_cli.generate_launchd_plist()
detected = gateway_cli._detect_venv_dir()
venv_bin = str(detected / "bin") if detected else str(gateway_cli.PROJECT_ROOT / "venv" / "bin")
assert venv_bin in plist
def test_plist_path_starts_with_venv_bin(self):
plist = gateway_cli.generate_launchd_plist()
lines = plist.splitlines()
for i, line in enumerate(lines):
if "<key>PATH</key>" in line.strip():
path_value = lines[i + 1].strip()
path_value = path_value.replace("<string>", "").replace("</string>", "")
detected = gateway_cli._detect_venv_dir()
venv_bin = str(detected / "bin") if detected else str(gateway_cli.PROJECT_ROOT / "venv" / "bin")
assert path_value.startswith(venv_bin + ":")
break
else:
raise AssertionError("PATH key not found in plist")
def test_plist_path_includes_node_modules_bin(self):
plist = gateway_cli.generate_launchd_plist()
node_bin = str(gateway_cli.PROJECT_ROOT / "node_modules" / ".bin")
lines = plist.splitlines()
for i, line in enumerate(lines):
if "<key>PATH</key>" in line.strip():
path_value = lines[i + 1].strip()
path_value = path_value.replace("<string>", "").replace("</string>", "")
assert node_bin in path_value.split(":")
break
else:
raise AssertionError("PATH key not found in plist")
def test_plist_path_includes_current_env_path(self, monkeypatch):
monkeypatch.setenv("PATH", "/custom/bin:/usr/bin:/bin")
plist = gateway_cli.generate_launchd_plist()
assert "/custom/bin" in plist
def test_plist_path_deduplicates_venv_bin_when_already_in_path(self, monkeypatch):
detected = gateway_cli._detect_venv_dir()
venv_bin = str(detected / "bin") if detected else str(gateway_cli.PROJECT_ROOT / "venv" / "bin")
monkeypatch.setenv("PATH", f"{venv_bin}:/usr/bin:/bin")
plist = gateway_cli.generate_launchd_plist()
lines = plist.splitlines()
for i, line in enumerate(lines):
if "<key>PATH</key>" in line.strip():
path_value = lines[i + 1].strip()
path_value = path_value.replace("<string>", "").replace("</string>", "")
parts = path_value.split(":")
assert parts.count(venv_bin) == 1
break
else:
raise AssertionError("PATH key not found in plist")
# ---------------------------------------------------------------------------
# cmd_update — macOS launchd detection
# ---------------------------------------------------------------------------