Files
hermes-agent/tests/gateway/test_matrix_plugin_setup.py
ethernet 3d12e86ef1 feat(pm): unified package manager — pm store foundation
Introduce the pm store: a unified, hash-verified package store that
replaces lazy_deps and the old installer's ad-hoc tool downloads.
Store tools are provisioned on PATH (ffmpeg, node/npm via pinned uv),
with a resumable 8-way downloader, verify() returning failure reasons,
and adopt() made EPERM-safe. chromium ships in the payload for every
target. The 3600-line install.sh is replaced by a staged bootstrapper
(heavy deps are pm's job after this); setup-hermes.sh, Dockerfile and
nix pin tables are rewired onto the store. Old install-script tests,
lazy_deps/managed_uv/build_info, and the ps1/bash installer test
batteries are removed with the machinery they tested.

Rebuilt from ethie/pm onto upstream/main (ac6c8028e0) after the
utf-8-sig sweep. 16 hot files (main also churned them) hand-merged:
platform adapters, main.py, electron/main.ts, tui_gateway/server.py,
cua_backend, installer-tests workflow, install.sh (full rewrite),
setup-hermes.sh, plugins doc.
2026-08-31 18:00:48 -04:00

86 lines
3.2 KiB
Python

"""Tests for the Matrix plugin's interactive_setup wizard home-channel flow.
The interactive_setup wizard lazy-imports its CLI helpers from
``hermes_cli.config`` (get_env_value / save_env_value / remove_env_value),
``hermes_cli.cli_output`` (prompt / prompt_yes_no / print_*), and
``pm`` (mautrix ensure_import). We patch each at its source module so
the wizard runs without touching pip or the network. Covers the home-channel
clear-on-blank behavior added in the follow-up to PR #58421.
"""
import hermes_cli.config as config_mod
import hermes_cli.cli_output as cli_output_mod
import pm as pm_mod
import pm.extras as pm_extras_mod
from plugins.platforms.matrix.adapter import interactive_setup
def _patch_setup_io(monkeypatch, prompts, yes_no_responses, saved, removed, existing):
prompt_iter = iter(prompts)
yes_no_iter = iter(yes_no_responses)
monkeypatch.setattr(config_mod, "get_env_value", lambda key: existing.get(key, ""))
monkeypatch.setattr(config_mod, "save_env_value", lambda k, v: saved.update({k: v}))
def _remove(key):
removed.append(key)
return existing.pop(key, None) is not None
monkeypatch.setattr(config_mod, "remove_env_value", _remove)
monkeypatch.setattr(cli_output_mod, "prompt", lambda *_a, **_kw: next(prompt_iter))
monkeypatch.setattr(
cli_output_mod, "prompt_yes_no", lambda *_a, **_kw: next(yes_no_iter)
)
for name in ("print_header", "print_info", "print_success", "print_warning"):
monkeypatch.setattr(cli_output_mod, name, lambda *_a, **_kw: None)
# Block the auto-install path so the test never invokes pip.
monkeypatch.setattr(pm_extras_mod, "missing", lambda extra: ())
monkeypatch.setattr(pm_mod, "ensure_import", lambda *a, **kw: None)
monkeypatch.setattr(pm_extras_mod, "ensure_import", lambda *a, **kw: None)
# Matrix prompts (after the E2EE yes_no): allowed_users, home_channel.
# Homeserver, token are still text prompts before E2EE.
_PROMPTS_NONEMPTY = [
"https://matrix.example.org", # homeserver
"syt_test_token_value", # access token (password)
"@bot:matrix.example.org", # user_id (optional)
"", # allowed_users
"!AbCdEfGhIjKlMn:matrix.example.org", # home room
]
_PROMPTS_BLANK = [
"https://matrix.example.org",
"syt_test_token_value",
"@bot:matrix.example.org",
"",
"",
]
_PROMPTS_WHITESPACE = [
"https://matrix.example.org",
"syt_test_token_value",
"@bot:matrix.example.org",
"",
" ",
]
# E2EE? = False so we don't pull the [encryption] extras.
_YES_NO = [False]
class TestMatrixHomeChannelClear:
"""Blank home-room answer must clear MATRIX_HOME_ROOM (#12423)."""
def test_blank_removes_existing_home_room(self, monkeypatch, tmp_path):
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
saved, removed = {}, []
_patch_setup_io(
monkeypatch,
_PROMPTS_BLANK,
_YES_NO,
saved,
removed,
existing={"MATRIX_HOME_ROOM": "!oldRoomId:matrix.example.org"},
)
interactive_setup()
assert "MATRIX_HOME_ROOM" in removed
assert "MATRIX_HOME_ROOM" not in saved