4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
"""Tests for the /gateway slash command."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
from rich.console import Console
|
|
|
|
from surfaces.interactive_shell.command_registry.gateway_cmds import _cmd_gateway
|
|
|
|
_MODULE = "surfaces.interactive_shell.command_registry.gateway_cmds"
|
|
|
|
|
|
@pytest.fixture
|
|
def console() -> Console:
|
|
return Console(record=True, force_terminal=False, width=200)
|
|
|
|
|
|
def _output(console: Console) -> str:
|
|
return console.export_text()
|
|
|
|
|
|
def test_status_shows_running_daemon_and_components(
|
|
monkeypatch: pytest.MonkeyPatch, console: Console
|
|
) -> None:
|
|
monkeypatch.setattr(f"{_MODULE}.gateway_daemon_pid", lambda: 4242)
|
|
monkeypatch.setattr(
|
|
f"{_MODULE}.read_component_status",
|
|
lambda: {"web": "serving :8000", "telegram": "polling for messages"},
|
|
)
|
|
|
|
assert _cmd_gateway(MagicMock(), console, ["status"]) is True
|
|
|
|
out = _output(console)
|
|
assert "running (pid 4242)" in out
|
|
assert "web: serving :8000" in out
|
|
assert "telegram: polling for messages" in out
|
|
|
|
|
|
def test_bare_gateway_defaults_to_status(monkeypatch: pytest.MonkeyPatch, console: Console) -> None:
|
|
monkeypatch.setattr(f"{_MODULE}.gateway_daemon_pid", lambda: None)
|
|
monkeypatch.setattr(f"{_MODULE}.read_component_status", dict)
|
|
|
|
assert _cmd_gateway(MagicMock(), console, []) is True
|
|
assert "stopped" in _output(console)
|
|
|
|
|
|
def test_start_reports_outcome_and_log_path(
|
|
monkeypatch: pytest.MonkeyPatch, console: Console
|
|
) -> None:
|
|
monkeypatch.setattr(
|
|
f"{_MODULE}.start_gateway_daemon",
|
|
lambda: (True, "OpenSRE gateway started (pid 7)."),
|
|
)
|
|
|
|
assert _cmd_gateway(MagicMock(), console, ["start"]) is True
|
|
|
|
out = _output(console)
|
|
assert "started (pid 7)" in out
|
|
assert "gateway.log" in out
|
|
|
|
|
|
def test_logs_prints_tail(monkeypatch: pytest.MonkeyPatch, console: Console) -> None:
|
|
monkeypatch.setattr(f"{_MODULE}.read_gateway_log_tail", lambda lines: f"tail of {lines}")
|
|
|
|
assert _cmd_gateway(MagicMock(), console, ["logs", "7"]) is True
|
|
assert "tail of 7" in _output(console)
|
|
|
|
|
|
def test_unknown_subcommand_prints_usage(console: Console) -> None:
|
|
assert _cmd_gateway(MagicMock(), console, ["restart"]) is True
|
|
assert "usage:" in _output(console)
|