Activation reaches plugin discovery before the application dependencies exist. Give PM its own locked Python project and runtime so it can install or repair the application without importing that dependency tree. Keep PM outside the application workspace. A shared uv workspace resolves the application graph and cannot provide this isolation. Route mutations through an isolated worker and preserve transaction callbacks, cancellation, custom package registrations, and correlated receipts. Use the same runtime builder for source installs and packaged payloads. Keep offline wheelhouse support in that builder. Nix builds the independent PM lock as a separate derivation. Refuse lazy-disabled bootstrap before installing tools or dependencies. Move first-party YAML readers and writers to ruamel. Keep the application lock's transitive PyYAML requirements for third-party packages. Verification: - Focused canonical Python suite: 177 passed, 1 host-gated skip. - Electron backend probes: 12 passed. Electron typecheck passed. - Both uv locks, scoped lint, Bash syntax, and whitespace checks passed. - Cold activation, corrupt-app repair, offline staging, and relocation ran. - Built and exercised the Nix PM runtime and standalone YAML merge script. Six broader caller test files retain the same 24 failing test IDs as an archive of HEAD. The existing real-home guard blocks those tests before they can exercise the affected paths. No full-suite pass is claimed. Native Windows signing and full Bionic package execution remain unverified.
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
"""Gateway contract and live dispatch for /approvals."""
|
|
|
|
from types import SimpleNamespace
|
|
from unittest.mock import AsyncMock, MagicMock, patch
|
|
|
|
import pytest
|
|
import hermes_yaml as yaml
|
|
|
|
import gateway.run as gateway_run
|
|
from gateway.config import Platform
|
|
from gateway.platforms.event import MessageEvent
|
|
from gateway.session import SessionSource
|
|
|
|
|
|
def _event(text: str = "/approvals") -> MessageEvent:
|
|
return MessageEvent(
|
|
text=text,
|
|
source=SessionSource(
|
|
platform=Platform.TELEGRAM,
|
|
user_id="user-1",
|
|
chat_id="chat-1",
|
|
chat_type="dm",
|
|
),
|
|
)
|
|
|
|
|
|
def _runner():
|
|
runner = object.__new__(gateway_run.GatewayRunner)
|
|
runner.config = SimpleNamespace(platforms={})
|
|
runner.hooks = MagicMock(loaded_hooks=[])
|
|
runner.hooks.emit = AsyncMock(return_value=[])
|
|
runner._running_agents = {}
|
|
runner._get_or_create_gateway_honcho = lambda _key: (None, None)
|
|
runner._is_user_authorized = lambda _source: True
|
|
runner.session_store = SimpleNamespace(get_or_create_session=lambda _source: None)
|
|
return runner
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_gateway_rejects_non_admin_persistent_approval_change():
|
|
runner = _runner()
|
|
runner.config = SimpleNamespace(
|
|
platforms={
|
|
Platform.TELEGRAM: SimpleNamespace(
|
|
extra={
|
|
"allow_admin_from": ["admin-1"],
|
|
"user_allowed_commands": ["approvals"],
|
|
}
|
|
)
|
|
}
|
|
)
|
|
|
|
with patch("hermes_cli.approval_mode.run_approval_mode_command") as run:
|
|
output = await runner._handle_approvals_command(_event("/approvals off"))
|
|
|
|
assert "admin" in output.lower()
|
|
run.assert_not_called()
|
|
|
|
|