cd9f023f3d
prd-number-check / require-numbered-prds (pull_request) Successful in 11s
tracker-policy-pr / check-pr (pull_request) Successful in 14s
test / unit (pull_request) Successful in 59s
test / integration-docker (pull_request) Successful in 1m6s
test / coverage (push) Successful in 21s
test / image-input-builds (push) Successful in 44s
test / image-input-builds (pull_request) Successful in 1m15s
test / unit (push) Successful in 57s
test / coverage (pull_request) Successful in 20s
lint / lint (push) Successful in 1m3s
Update Quality Badges / update-badges (push) Successful in 1m12s
test / integration-docker (push) Successful in 1m0s
`doctor` told users to run `./cli.py backend setup`. cli.py is a four-line wrapper at the repo root that calls bot_bottle.cli:main, and it does not ship — [tool.setuptools.packages.find] includes only bot_bottle*, so anyone who installed rather than cloned has no such file. Confirmed against a real install: the user's tree contains exactly one executable, `bot-bottle`, and no cli.py anywhere, while doctor recommended `./cli.py` three times. Invisible in development, where ./cli.py works fine from a checkout, which is why only a clean-install test surfaced it. The two entry points are the same code, so the fix is to name the one that always exists. 141 replacements across 45 files: the runtime messages that caused this, plus README, docs, PRDs, research notes and test prose, so nothing teaches the invocation a user cannot run. scripts/demo.sh is deliberately untouched — it *executes* ./cli.py from a checkout, where that is the correct and available path. Verified end to end: a sandbox install now reports "Run: bot-bottle backend setup --backend=firecracker", and bot-bottle is on that user's PATH. Unit suite unchanged against the pre-existing baseline. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WEfZZhakx13bxTfXcZCoS5
92 lines
3.5 KiB
Python
92 lines
3.5 KiB
Python
"""Unit: the generic `backend` CLI command.
|
|
|
|
`bot-bottle backend {setup,status} [--backend=NAME]` resolves a backend
|
|
and dispatches to its `setup()` / `status()` classmethods — no
|
|
backend-specific commands. Also covers the docker backend's own
|
|
setup/status logic (the firecracker path is exercised by
|
|
test_firecracker_backend via netpool)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import unittest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from bot_bottle.cli.commands import backend as cmd
|
|
from bot_bottle.backend.docker import setup as docker_setup
|
|
|
|
|
|
class TestCmdBackendDispatch(unittest.TestCase):
|
|
def _fake_backend(self):
|
|
b = MagicMock()
|
|
b.setup.return_value = 0
|
|
b.status.return_value = 3
|
|
b.teardown.return_value = 0
|
|
return b
|
|
|
|
def test_setup_dispatches_to_backend(self):
|
|
b = self._fake_backend()
|
|
with patch.object(cmd, "get_bottle_backend", return_value=b) as gbb:
|
|
rc = cmd.cmd_backend(["setup", "--backend", "firecracker"])
|
|
gbb.assert_called_once_with("firecracker")
|
|
b.setup.assert_called_once_with()
|
|
b.status.assert_not_called()
|
|
self.assertEqual(0, rc)
|
|
|
|
def test_status_dispatches_and_returns_backend_code(self):
|
|
b = self._fake_backend()
|
|
with patch.object(cmd, "get_bottle_backend", return_value=b):
|
|
rc = cmd.cmd_backend(["status", "--backend", "docker"])
|
|
b.status.assert_called_once_with()
|
|
self.assertEqual(3, rc)
|
|
|
|
def test_teardown_dispatches_to_backend(self):
|
|
b = self._fake_backend()
|
|
with patch.object(cmd, "get_bottle_backend", return_value=b):
|
|
rc = cmd.cmd_backend(["teardown", "--backend", "firecracker"])
|
|
b.teardown.assert_called_once_with()
|
|
b.setup.assert_not_called()
|
|
self.assertEqual(0, rc)
|
|
|
|
def test_no_backend_flag_uses_host_default(self):
|
|
b = self._fake_backend()
|
|
with patch.object(cmd, "get_bottle_backend", return_value=b) as gbb:
|
|
cmd.cmd_backend(["status"])
|
|
gbb.assert_called_once_with(None)
|
|
|
|
def test_unknown_action_exits(self):
|
|
with self.assertRaises(SystemExit):
|
|
cmd.cmd_backend(["bogus"])
|
|
|
|
def test_unknown_backend_rejected_by_argparse(self):
|
|
with self.assertRaises(SystemExit):
|
|
cmd.cmd_backend(["status", "--backend", "nope"])
|
|
|
|
|
|
class TestDockerSetupStatus(unittest.TestCase):
|
|
def _ok(self):
|
|
return subprocess.CompletedProcess([], 0, stdout="", stderr="")
|
|
|
|
def test_setup_ok_when_docker_and_daemon_present(self):
|
|
with patch.object(docker_setup.shutil, "which", return_value="/usr/bin/docker"), \
|
|
patch.object(docker_setup, "_daemon_reachable", return_value=True), \
|
|
patch.object(docker_setup._util, "runsc_available", return_value=True):
|
|
self.assertEqual(0, docker_setup.setup())
|
|
|
|
def test_setup_fails_when_docker_missing(self):
|
|
with patch.object(docker_setup.shutil, "which", return_value=None):
|
|
self.assertEqual(1, docker_setup.setup())
|
|
|
|
def test_status_fails_when_daemon_unreachable(self):
|
|
with patch.object(docker_setup.shutil, "which", return_value="/usr/bin/docker"), \
|
|
patch.object(docker_setup, "_daemon_reachable", return_value=False), \
|
|
patch.object(docker_setup._util, "runsc_available", return_value=False):
|
|
self.assertEqual(1, docker_setup.status())
|
|
|
|
def test_teardown_is_noop_success(self):
|
|
self.assertEqual(0, docker_setup.teardown())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|