Files
hermes-agent/tests/test_deploy_synapse.py
Timmy 81fcd51d2f
Some checks failed
Forge CI / smoke-and-build (pull_request) Failing after 33s
feat: Matrix Phase 1 — Synapse deployment script for VPS (#272)
Part of Epic #269.

Add scripts/deploy_synapse.py — automated Synapse deployment:
- Checks prerequisites (Docker, docker-compose, curl)
- Auto-installs Docker if missing
- Deploys Synapse via Docker with generated homeserver.yaml
- Waits for health check
- Creates bot account (hermes-bot)
- Logs in and obtains access token
- Prints Hermes config (env vars) for easy copy-paste
- Supports --dry-run for safe testing
- 9 new tests
2026-04-13 20:32:54 -04:00

77 lines
2.9 KiB
Python

"""Tests for deploy_synapse.py helpers."""
import json
import pytest
from unittest.mock import MagicMock, patch, call
import subprocess
class TestSshCmd:
def test_basic(self):
from scripts.deploy_synapse import _ssh_cmd
cmd = _ssh_cmd("1.2.3.4", "root")
assert "root@1.2.3.4" in cmd
assert "ssh" in cmd[0]
def test_custom_port(self):
from scripts.deploy_synapse import _ssh_cmd
cmd = _ssh_cmd("1.2.3.4", "root", port=2222)
assert "-p" in cmd
assert "2222" in cmd
def test_key_path(self):
from scripts.deploy_synapse import _ssh_cmd
cmd = _ssh_cmd("1.2.3.4", "root", key_path="/root/.ssh/id_rsa")
assert "-i" in cmd
assert "/root/.ssh/id_rsa" in cmd
class TestRunRemote:
def test_dry_run(self):
from scripts.deploy_synapse import _run_remote
ok, stdout, stderr = _run_remote(["ssh", "root@host"], "echo hi", dry_run=True)
assert ok is True
assert stdout == ""
@patch("scripts.deploy_synapse.subprocess.run")
def test_success(self, mock_run):
from scripts.deploy_synapse import _run_remote
mock_run.return_value = MagicMock(returncode=0, stdout="hello\n", stderr="")
ok, stdout, stderr = _run_remote(["ssh", "root@host"], "echo hello")
assert ok is True
assert "hello" in stdout
@patch("scripts.deploy_synapse.subprocess.run")
def test_failure(self, mock_run):
from scripts.deploy_synapse import _run_remote
mock_run.return_value = MagicMock(returncode=1, stdout="", stderr="error")
ok, stdout, stderr = _run_remote(["ssh", "root@host"], "bad cmd")
assert ok is False
@patch("scripts.deploy_synapse.subprocess.run", side_effect=subprocess.TimeoutExpired("cmd", 10))
def test_timeout(self, mock_run):
from scripts.deploy_synapse import _run_remote
ok, stdout, stderr = _run_remote(["ssh", "root@host"], "slow cmd", timeout=10)
assert ok is False
assert "timed out" in stderr
class TestCreateBotAccount:
def test_returns_correct_structure(self):
from scripts.deploy_synapse import create_bot_account
with patch("scripts.deploy_synapse._run_remote") as mock:
mock.return_value = (True, "success", "")
result = create_bot_account(["ssh", "root@x"], "example.com", dry_run=True)
assert "user_id" in result
assert "password" in result
assert "homeserver_url" in result
assert result["user_id"] == "@hermes-bot:example.com"
class TestPrintConfig:
def test_runs_without_error(self, capsys):
from scripts.deploy_synapse import print_config
print_config("example.com", "hermes-bot", "tok_abc", "pass123")
captured = capsys.readouterr()
assert "MATRIX_HOMESERVER=https://example.com" in captured.out
assert "MATRIX_ACCESS_TOKEN=tok_abc" in captured.out