Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(cli): return failures from channel commands

xkam7arb95c1c2a1a70
diff --git a/agent/cli/_legacy.py b/agent/cli/_legacy.py
index 7c5d1f792..1c745fbe4 100644
--- a/agent/cli/_legacy.py
+++ b/agent/cli/_legacy.py
@@ -2963,31 +2963,35 @@ def cmd_channels_status(*, json_mode: bool = False, local: bool = False) -> int:
def cmd_channels_start(*, json_mode: bool = False) -> int:
"""Start configured IM channels through the API runtime."""
payload = _channels_api_call("POST", "/channels/start")
+ failed = payload.get("status") == "error"
if json_mode:
print(json.dumps(payload, indent=2, ensure_ascii=False))
- elif payload.get("status") == "error":
+ elif failed:
console.print(f"[red]Failed to start IM channels:[/red] {payload.get('error')}")
- console.print("[dim]Run `vibe-trading serve --port 8000` first, or set VIBE_TRADING_API_URL.[/dim]")
- return EXIT_RUN_FAILED
+ console.print(
+ "[dim]Run `vibe-trading serve --port 8000` first, or set VIBE_TRADING_API_URL.[/dim]"
+ )
else:
console.print("[green]IM channels started.[/green]")
_print_channels_status(payload)
- return EXIT_SUCCESS
+ return EXIT_RUN_FAILED if failed else EXIT_SUCCESS
def cmd_channels_stop(*, json_mode: bool = False) -> int:
"""Stop configured IM channels through the API runtime."""
payload = _channels_api_call("POST", "/channels/stop")
+ failed = payload.get("status") == "error"
if json_mode:
print(json.dumps(payload, indent=2, ensure_ascii=False))
- elif payload.get("status") == "error":
+ elif failed:
console.print(f"[red]Failed to stop IM channels:[/red] {payload.get('error')}")
- console.print("[dim]Run `vibe-trading serve --port 8000` first, or set VIBE_TRADING_API_URL.[/dim]")
- return EXIT_RUN_FAILED
+ console.print(
+ "[dim]Run `vibe-trading serve --port 8000` first, or set VIBE_TRADING_API_URL.[/dim]"
+ )
else:
console.print("[green]IM channels stopped.[/green]")
_print_channels_status(payload)
- return EXIT_SUCCESS
+ return EXIT_RUN_FAILED if failed else EXIT_SUCCESS
def cmd_channels_pairing(channel: str, command: str) -> int:
diff --git a/agent/tests/test_cli_channels.py b/agent/tests/test_cli_channels.py
index 717d69e55..cd1c252ef 100644
--- a/agent/tests/test_cli_channels.py
+++ b/agent/tests/test_cli_channels.py
@@ -4,6 +4,8 @@ from __future__ import annotations
from pathlib import Path
+import pytest
+
from cli import _legacy
@@ -77,3 +79,36 @@ def test_channels_api_call_sends_configured_bearer_token(monkeypatch) -> None:
assert _legacy._channels_api_call("GET", "/channels/status") == {"status": "ok"}
assert captured["headers"] == {"Authorization": "Bearer secret-token"}
+
+
+ "command", [_legacy.cmd_channels_start, _legacy.cmd_channels_stop]
+)
[email protected]("json_mode", [False, True])
+def test_channels_start_stop_return_failure_in_every_output_mode(
+ command, json_mode, monkeypatch
+) -> None:
+ monkeypatch.setattr(
+ _legacy,
+ "_channels_api_call",
+ lambda *args, **kwargs: {"status": "error", "error": "offline"},
+ )
+
+ assert command(json_mode=json_mode) == _legacy.EXIT_RUN_FAILED
+
+
+ "command", [_legacy.cmd_channels_start, _legacy.cmd_channels_stop]
+)
[email protected]("json_mode", [False, True])
+def test_channels_start_stop_return_success_in_every_output_mode(
+ command, json_mode, monkeypatch
+) -> None:
+ monkeypatch.setattr(
+ _legacy,
+ "_channels_api_call",
+ lambda *args, **kwargs: {"status": "ok", "channels": {}},
+ )
+ monkeypatch.setattr(_legacy, "_print_channels_status", lambda payload: None)
+
+ assert command(json_mode=json_mode) == _legacy.EXIT_SUCCESS