test: keep tirith checks hermetic
This commit is contained in:
@@ -65,11 +65,11 @@ class TestCompress:
|
|||||||
assert result == msgs
|
assert result == msgs
|
||||||
|
|
||||||
def test_truncation_fallback_no_client(self, compressor):
|
def test_truncation_fallback_no_client(self, compressor):
|
||||||
# compressor has client=None and abort_on_summary_failure=False (default),
|
# Simulate "no summarizer available" explicitly. call_llm can otherwise
|
||||||
# so the LEGACY fallback path inserts a static "summary unavailable"
|
# discover the developer's real auxiliary credentials from auth state.
|
||||||
# placeholder and the middle window is dropped.
|
|
||||||
msgs = [{"role": "system", "content": "System prompt"}] + self._make_messages(10)
|
msgs = [{"role": "system", "content": "System prompt"}] + self._make_messages(10)
|
||||||
result = compressor.compress(msgs)
|
with patch("agent.context_compressor.call_llm", side_effect=RuntimeError("no provider")):
|
||||||
|
result = compressor.compress(msgs)
|
||||||
assert len(result) < len(msgs)
|
assert len(result) < len(msgs)
|
||||||
# Should keep system message and last N
|
# Should keep system message and last N
|
||||||
assert result[0]["role"] == "system"
|
assert result[0]["role"] == "system"
|
||||||
|
|||||||
@@ -358,6 +358,10 @@ def _hermetic_environment(tmp_path, monkeypatch):
|
|||||||
monkeypatch.setenv("AWS_EC2_METADATA_DISABLED", "true")
|
monkeypatch.setenv("AWS_EC2_METADATA_DISABLED", "true")
|
||||||
monkeypatch.setenv("AWS_METADATA_SERVICE_TIMEOUT", "1")
|
monkeypatch.setenv("AWS_METADATA_SERVICE_TIMEOUT", "1")
|
||||||
monkeypatch.setenv("AWS_METADATA_SERVICE_NUM_ATTEMPTS", "1")
|
monkeypatch.setenv("AWS_METADATA_SERVICE_NUM_ATTEMPTS", "1")
|
||||||
|
# Tirith auto-installs from GitHub when enabled and missing. Unit tests
|
||||||
|
# should never perform that implicit network/bootstrap path; Tirith-specific
|
||||||
|
# tests opt back in by patching the security config directly.
|
||||||
|
monkeypatch.setenv("TIRITH_ENABLED", "false")
|
||||||
|
|
||||||
# 5. Reset plugin singleton so tests don't leak plugins from
|
# 5. Reset plugin singleton so tests don't leak plugins from
|
||||||
# ~/.hermes/plugins/ (which, per step 3, is now empty — but the
|
# ~/.hermes/plugins/ (which, per step 3, is now empty — but the
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ async def test_start_gateway_replace_force_uses_terminate_pid(monkeypatch, tmp_p
|
|||||||
lambda **kwargs: 0,
|
lambda **kwargs: 0,
|
||||||
)
|
)
|
||||||
monkeypatch.setattr("gateway.status.terminate_pid", lambda pid, force=False: calls.append((pid, force)))
|
monkeypatch.setattr("gateway.status.terminate_pid", lambda pid, force=False: calls.append((pid, force)))
|
||||||
|
monkeypatch.setattr("gateway.status._pid_exists", lambda pid: True)
|
||||||
monkeypatch.setattr("gateway.run.os.getpid", lambda: 100)
|
monkeypatch.setattr("gateway.run.os.getpid", lambda: 100)
|
||||||
monkeypatch.setattr("gateway.run.os.kill", lambda pid, sig: None)
|
monkeypatch.setattr("gateway.run.os.kill", lambda pid, sig: None)
|
||||||
monkeypatch.setattr("time.sleep", lambda _: None)
|
monkeypatch.setattr("time.sleep", lambda _: None)
|
||||||
|
|||||||
@@ -831,7 +831,8 @@ class TestDiskFailureMarker:
|
|||||||
with patch("tools.tirith_security._failure_marker_path", return_value=marker):
|
with patch("tools.tirith_security._failure_marker_path", return_value=marker):
|
||||||
from tools.tirith_security import _mark_install_failed, _is_install_failed_on_disk
|
from tools.tirith_security import _mark_install_failed, _is_install_failed_on_disk
|
||||||
_mark_install_failed("cosign_missing")
|
_mark_install_failed("cosign_missing")
|
||||||
assert _is_install_failed_on_disk() # cosign still absent
|
with patch("tools.tirith_security.shutil.which", return_value=None):
|
||||||
|
assert _is_install_failed_on_disk() # cosign still absent
|
||||||
|
|
||||||
# Now cosign appears on PATH
|
# Now cosign appears on PATH
|
||||||
with patch("tools.tirith_security.shutil.which", return_value="/usr/local/bin/cosign"):
|
with patch("tools.tirith_security.shutil.which", return_value="/usr/local/bin/cosign"):
|
||||||
|
|||||||
@@ -10,6 +10,18 @@ from unittest.mock import MagicMock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def _non_wsl_proc_version(real_open):
|
||||||
|
"""Return an open() shim that makes host WSL detection deterministic."""
|
||||||
|
def _fake_open(file, *args, **kwargs):
|
||||||
|
if file == "/proc/version":
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
return StringIO("Linux test-kernel")
|
||||||
|
return real_open(file, *args, **kwargs)
|
||||||
|
|
||||||
|
return _fake_open
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Fixtures
|
# Fixtures
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
@@ -68,6 +80,7 @@ class TestDetectAudioEnvironment:
|
|||||||
monkeypatch.delenv("SSH_CONNECTION", raising=False)
|
monkeypatch.delenv("SSH_CONNECTION", raising=False)
|
||||||
monkeypatch.setattr("tools.voice_mode._import_audio",
|
monkeypatch.setattr("tools.voice_mode._import_audio",
|
||||||
lambda: (MagicMock(), MagicMock()))
|
lambda: (MagicMock(), MagicMock()))
|
||||||
|
monkeypatch.setattr("builtins.open", _non_wsl_proc_version(open))
|
||||||
|
|
||||||
from tools.voice_mode import detect_audio_environment
|
from tools.voice_mode import detect_audio_environment
|
||||||
result = detect_audio_environment()
|
result = detect_audio_environment()
|
||||||
@@ -225,6 +238,7 @@ class TestDetectAudioEnvironment:
|
|||||||
monkeypatch.setattr("tools.voice_mode.shutil.which", lambda cmd: "/data/data/com.termux/files/usr/bin/termux-microphone-record" if cmd == "termux-microphone-record" else None)
|
monkeypatch.setattr("tools.voice_mode.shutil.which", lambda cmd: "/data/data/com.termux/files/usr/bin/termux-microphone-record" if cmd == "termux-microphone-record" else None)
|
||||||
monkeypatch.setattr("tools.voice_mode._termux_api_app_installed", lambda: True)
|
monkeypatch.setattr("tools.voice_mode._termux_api_app_installed", lambda: True)
|
||||||
monkeypatch.setattr("tools.voice_mode._import_audio", lambda: (_ for _ in ()).throw(ImportError("no audio libs")))
|
monkeypatch.setattr("tools.voice_mode._import_audio", lambda: (_ for _ in ()).throw(ImportError("no audio libs")))
|
||||||
|
monkeypatch.setattr("builtins.open", _non_wsl_proc_version(open))
|
||||||
|
|
||||||
from tools.voice_mode import detect_audio_environment
|
from tools.voice_mode import detect_audio_environment
|
||||||
result = detect_audio_environment()
|
result = detect_audio_environment()
|
||||||
|
|||||||
Reference in New Issue
Block a user