Skip to content

The agent that grows with you

fix: use event.get_command_args() and add persistence tests

Abdias Joel5b8074dad487
diff --git a/gateway/slash_commands.py b/gateway/slash_commands.py
index 2cd55f21ea1..71d42e9c131 100644
--- a/gateway/slash_commands.py
+++ b/gateway/slash_commands.py
@@ -4254,9 +4254,8 @@ class GatewaySlashCommandsMixin:
/busy steer Inject messages mid-run without interrupting
/busy interrupt Interrupt the current run (default)
"""
- text = (event.text or "").strip()
- parts = text.split(maxsplit=1)
- if len(parts) < 2 or parts[1].strip().lower() == "status":
+ arg = event.get_command_args().strip().lower()
+ if not arg or arg == "status":
mode = self._busy_input_mode
if mode == "queue":
behavior = "queues for next turn"
@@ -4265,18 +4264,17 @@ class GatewaySlashCommandsMixin:
else:
behavior = "interrupts current run"
return EphemeralReply(
- f"**Busy input mode: `{mode}`**\n"
- f"Messages while busy: _{behavior}_\n"
+ f"**Busy input mode: `{mode}`" + "\n"
+ f"Messages while busy: _{behavior}_" + "\n"
f"Change with `/busy queue`, `/busy steer`, or `/busy interrupt`."
)
- arg = parts[1].strip().lower()
if arg not in {"queue", "interrupt", "steer"}:
return EphemeralReply(
f"Unknown mode `{arg}`. Use `/busy queue`, `/busy steer`, or `/busy interrupt`."
)
- # Persist before mutate — prevents divergent state when save fails
+ # Persist before mutate
try:
from cli import save_config_value
if save_config_value("display.busy_input_mode", arg):
@@ -4288,7 +4286,7 @@ class GatewaySlashCommandsMixin:
else:
behavior = "Messages will interrupt the current run while Hermes is busy."
return EphemeralReply(
- f"Busy input mode set to **`{arg}`** (saved).\n"
+ f"Busy input mode set to **`{arg}`** (saved)." + "\n"
f"_{behavior}_"
)
else:
diff --git a/tests/gateway/test_busy_command.py b/tests/gateway/test_busy_command.py
index d08ad55923f..42c03b93e4a 100644
--- a/tests/gateway/test_busy_command.py
+++ b/tests/gateway/test_busy_command.py
@@ -64,3 +64,71 @@ class TestBusyCommand:
reply_text = str(result)
assert "queue" in reply_text.lower()
assert "busy" in reply_text.lower()
+
+
+class TestBusyCommandPersistence:
+ """Test /busy persistence with mocked save_config_value."""
+
+ @pytest.mark.asyncio
+ async def test_set_queue_persists(self, monkeypatch):
+ """/busy queue saves config and updates mode."""
+ runner = _make_runner(busy_mode="interrupt")
+ monkeypatch.setattr(
+ "cli.save_config_value", lambda k, v: True
+ )
+ event = _make_event("/busy queue")
+ result = await runner._handle_busy_command(event)
+ assert "queue" in str(result).lower()
+ assert runner._busy_input_mode == "queue"
+
+ @pytest.mark.asyncio
+ async def test_set_steer_persists(self, monkeypatch):
+ """/busy steer saves config and updates mode."""
+ runner = _make_runner(busy_mode="queue")
+ monkeypatch.setattr(
+ "cli.save_config_value", lambda k, v: True
+ )
+ event = _make_event("/busy steer")
+ result = await runner._handle_busy_command(event)
+ assert "steer" in str(result).lower()
+ assert runner._busy_input_mode == "steer"
+
+ @pytest.mark.asyncio
+ async def test_set_interrupt_persists(self, monkeypatch):
+ """/busy interrupt saves config and updates mode."""
+ runner = _make_runner(busy_mode="queue")
+ monkeypatch.setattr(
+ "cli.save_config_value", lambda k, v: True
+ )
+ event = _make_event("/busy interrupt")
+ result = await runner._handle_busy_command(event)
+ assert "interrupt" in str(result).lower()
+ assert runner._busy_input_mode == "interrupt"
+
+ @pytest.mark.asyncio
+ async def test_save_failure_preserves_mode(self, monkeypatch):
+ """When save_config_value returns False, mode is unchanged."""
+ runner = _make_runner(busy_mode="steer")
+ monkeypatch.setattr(
+ "cli.save_config_value", lambda k, v: False
+ )
+ event = _make_event("/busy queue")
+ result = await runner._handle_busy_command(event)
+ assert "unchanged" in str(result).lower()
+ assert runner._busy_input_mode == "steer"
+
+ @pytest.mark.asyncio
+ async def test_save_exception_preserves_mode(self, monkeypatch):
+ """When save_config_value raises, mode is unchanged."""
+ runner = _make_runner(busy_mode="interrupt")
+
+ def _raise(*args, **kwargs):
+ raise RuntimeError("disk full")
+
+ monkeypatch.setattr(
+ "cli.save_config_value", _raise
+ )
+ event = _make_event("/busy steer")
+ result = await runner._handle_busy_command(event)
+ assert "Could not save" in str(result)
+ assert runner._busy_input_mode == "interrupt"