hermes-agent/tests/hermes_cli/test_macos_fda_guidance.py
ethernet 16652eea18 Merge remote-tracking branch 'origin/main' into ethie/pm-clean
# Conflicts:
#	gateway/config.py
#	gateway/config_loader.py
#	gateway/readiness.py
#	hermes_cli/managed_scope.py
#	hermes_cli/plugin_python_deps.py
#	hermes_cli/plugins_cmd.py
#	hermes_cli/update_cmd_maint.py
#	plugin-catalog/hindsight.yaml
#	plugins/plugin_loader.py
#	providers/__init__.py
#	scripts/run_tests.sh
#	tests/gateway/test_control_socket_windows_live.py
#	tests/gateway/test_gateway_streaming_nested_config.py
#	tests/hermes_cli/test_doctor.py
#	tests/hermes_cli/test_plan_reconciliation_windows_live.py
#	tests/hermes_cli/test_update_apply_shallow_count.py
#	tests/hermes_cli/test_update_concurrent_quarantine.py
#	tests/hermes_cli/test_update_shim_self_lock.py
#	tests/hermes_cli/test_verify_console_scripts.py
#	tests/tools/test_lazy_deps.py
#	tests/tui_gateway/test_subprocess_encoding.py
#	tools/lazy_deps.py
2026-09-23 15:26:34 -04:00

90 lines
2.7 KiB
Python

"""macOS Full Disk Access onboarding guidance (issue #52010 follow-up).
One FDA grant silences every per-folder TCC prompt permanently. Doctor reports
the state and prints the one-switch setup; ``hermes setup`` surfaces the same
tip at onboarding. The probe reads the FDA-gated TCC db directory, which
returns EPERM (no dialog) without the grant; any other error is indeterminate
and must stay silent. The probe is gated on the real host, so the macOS
branches run on the macOS lane and the off-macOS silence runs on Linux.
"""
import contextlib
import io
import os
import pathlib
import pytest
from hermes_cli import doctor_platform
from hermes_cli.setup_quick import _print_macos_fda_tip
def _capture(fn):
buf = io.StringIO()
with contextlib.redirect_stdout(buf):
fn()
return buf.getvalue()
@pytest.fixture
def home(tmp_path, monkeypatch):
monkeypatch.setattr(pathlib.Path, "home", classmethod(lambda cls: tmp_path))
return tmp_path
@pytest.fixture
def tcc_dir(home):
tcc = home / "Library" / "Application Support" / "com.apple.TCC"
tcc.mkdir(parents=True)
return tcc
@pytest.fixture
def fda_denied(tcc_dir, monkeypatch):
"""The TCC dir exists but listing it fails with EPERM, exactly as without the grant."""
real_listdir = os.listdir
def _listdir(path="."):
if pathlib.Path(path) == tcc_dir:
raise PermissionError(13, "Operation not permitted", str(path))
return real_listdir(path)
monkeypatch.setattr(os, "listdir", _listdir)
return tcc_dir
@pytest.mark.platforms("linux")
def test_doctor_and_setup_are_silent_off_macos(tcc_dir):
assert _capture(doctor_platform.check_macos_full_disk_access) == ""
assert _capture(_print_macos_fda_tip) == ""
@pytest.mark.platforms("macos")
def test_doctor_reports_granted_without_guidance(tcc_dir):
out = _capture(doctor_platform.check_macos_full_disk_access)
assert "Full Disk Access granted" in out
assert "Privacy_AllFiles" not in out
@pytest.mark.platforms("macos")
def test_doctor_prints_one_switch_guidance_when_denied(fda_denied):
out = _capture(doctor_platform.check_macos_full_disk_access)
assert "Privacy_AllFiles" in out
assert "granted" not in out
@pytest.mark.platforms("macos")
def test_doctor_is_silent_when_probe_is_indeterminate(home):
"""Missing TCC dir (FileNotFoundError, not EPERM) must not nag."""
assert _capture(doctor_platform.check_macos_full_disk_access) == ""
@pytest.mark.platforms("macos")
def test_setup_tip_is_silent_when_already_granted(tcc_dir):
assert _capture(_print_macos_fda_tip) == ""
@pytest.mark.platforms("macos")
def test_setup_tip_printed_when_denied(fda_denied):
out = _capture(_print_macos_fda_tip)
assert "Privacy_AllFiles" in out