fix: label becomes the full slug; re-prompt on collision
When a label is given it is now used verbatim as the slug (no random suffix), so two launches with the same label collide by design. The CLI re-prompts via the TUI name modal with a disclaimer when the candidate slug is already in use among running bottles.
This commit is contained in:
@@ -14,6 +14,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import bot_bottle.cli.start as start_mod
|
||||
import bot_bottle.cli.tui as tui_mod
|
||||
from bot_bottle.backend import ActiveAgent
|
||||
|
||||
|
||||
def _make_manifest(agent_names: list[str]):
|
||||
@@ -133,5 +134,63 @@ class TestCmdStartSelector(unittest.TestCase):
|
||||
self._launch_mock.assert_not_called()
|
||||
|
||||
|
||||
def _active_agent(slug: str) -> ActiveAgent:
|
||||
return ActiveAgent(
|
||||
backend_name="docker",
|
||||
slug=slug,
|
||||
agent_name="demo",
|
||||
started_at="2026-01-01T00:00:00+00:00",
|
||||
services=(),
|
||||
)
|
||||
|
||||
|
||||
class TestCmdStartLabelCollision(unittest.TestCase):
|
||||
"""cmd_start re-prompts when the label's slug is already running."""
|
||||
|
||||
def setUp(self):
|
||||
self._manifest = _make_manifest(["researcher"])
|
||||
patch("bot_bottle.cli.start.Manifest.resolve", return_value=self._manifest).start()
|
||||
self._launch_mock = patch(
|
||||
"bot_bottle.cli.start._launch_bottle", return_value=0,
|
||||
).start()
|
||||
self.addCleanup(patch.stopall)
|
||||
|
||||
def test_no_collision_proceeds_without_reprompt(self):
|
||||
with (
|
||||
patch.object(tui_mod, "name_color_modal", return_value=("researcher", "")) as modal,
|
||||
patch("bot_bottle.cli.start.enumerate_active_agents", return_value=[]),
|
||||
):
|
||||
rc = start_mod.cmd_start(["researcher"])
|
||||
self.assertEqual(0, rc)
|
||||
modal.assert_called_once()
|
||||
self._launch_mock.assert_called_once()
|
||||
|
||||
def test_collision_reprompts_with_disclaimer(self):
|
||||
collision_agent = _active_agent("researcher")
|
||||
call_count = 0
|
||||
|
||||
def _modal(default_label, *, disclaimer="", **_kw):
|
||||
nonlocal call_count
|
||||
call_count += 1
|
||||
if call_count == 1:
|
||||
return "researcher", ""
|
||||
return "researcher-2", ""
|
||||
|
||||
with (
|
||||
patch.object(tui_mod, "name_color_modal", side_effect=_modal) as modal,
|
||||
patch(
|
||||
"bot_bottle.cli.start.enumerate_active_agents",
|
||||
side_effect=[[collision_agent], []],
|
||||
),
|
||||
):
|
||||
rc = start_mod.cmd_start(["researcher"])
|
||||
|
||||
self.assertEqual(0, rc)
|
||||
self.assertEqual(2, modal.call_count)
|
||||
second_call_kwargs = modal.call_args_list[1][1]
|
||||
self.assertIn("researcher", second_call_kwargs.get("disclaimer", ""))
|
||||
self.assertIn("already in use", second_call_kwargs.get("disclaimer", ""))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user