c07ebca867
Delete the smolmachines backend (the whole bot_bottle/backend/smolmachines package and its tests). It had fatal Linux issues (TSI networking under sustained use, exec-channel contention, no SIGWINCH) and is superseded by the Firecracker backend (issue #342). Backend selection now: - default is macos-container on macOS, firecracker on KVM-capable Linux hosts, and docker as the last resort (was smolmachines). - firecracker is selected on a KVM host even when the `firecracker` binary isn't installed, so start routes through its preflight and prints an install pointer (same UX as require_container), instead of silently falling back. Split is_host_capable() (Linux + KVM) out of is_available() (adds the binary check) to drive this. Retarget the cross-backend tests (parity, print-parity, prepare, workspace, freezer, selection) from smolmachines to firecracker rather than dropping the coverage. Remove docker.util.image_id/save, which only smolmachines used. Update README/AGENTS/example bottles and stale comments; historical docs/prds are left as a point-in-time record. BREAKING: BOT_BOTTLE_BACKEND=smolmachines now errors as unknown. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WBMWTEtQdJ4W5UrWuLHCck
105 lines
3.6 KiB
Python
105 lines
3.6 KiB
Python
"""Unit: `cli.py cleanup` walks every backend (issue follow-up).
|
|
|
|
Asserts cmd_cleanup queries each backend's `prepare_cleanup`,
|
|
combines the y/N output, and runs each backend's `cleanup` when
|
|
the operator confirms. Mocks the backends and stdin."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
from bot_bottle.cli import cleanup as cmd
|
|
|
|
|
|
def _make_backend(empty: bool = True):
|
|
backend = MagicMock()
|
|
plan = MagicMock(empty=empty)
|
|
backend.prepare_cleanup.return_value = plan
|
|
backend.cleanup = MagicMock()
|
|
return backend, plan
|
|
|
|
|
|
class TestCmdCleanup(unittest.TestCase):
|
|
def test_iterates_every_backend(self):
|
|
docker, docker_plan = _make_backend(empty=False)
|
|
fc, fc_plan = _make_backend(empty=False)
|
|
backends_by_name = {"docker": docker, "firecracker": fc}
|
|
|
|
with patch.object(
|
|
cmd, "known_backend_names",
|
|
return_value=("docker", "firecracker"),
|
|
), patch.object(
|
|
cmd, "get_bottle_backend",
|
|
side_effect=lambda name: backends_by_name[name], # type: ignore
|
|
), patch.object(
|
|
cmd, "_prompt_yes", return_value=True,
|
|
):
|
|
self.assertEqual(0, cmd.cmd_cleanup([]))
|
|
|
|
docker.prepare_cleanup.assert_called_once()
|
|
fc.prepare_cleanup.assert_called_once()
|
|
docker.cleanup.assert_called_once_with(docker_plan)
|
|
fc.cleanup.assert_called_once_with(fc_plan)
|
|
|
|
def test_short_circuits_when_all_empty(self):
|
|
docker, _ = _make_backend(empty=True)
|
|
fc, _ = _make_backend(empty=True)
|
|
backends_by_name = {"docker": docker, "firecracker": fc}
|
|
|
|
with patch.object(
|
|
cmd, "known_backend_names",
|
|
return_value=("docker", "firecracker"),
|
|
), patch.object(
|
|
cmd, "get_bottle_backend",
|
|
side_effect=lambda name: backends_by_name[name], # type: ignore
|
|
), patch.object(
|
|
cmd, "_prompt_yes",
|
|
) as prompt:
|
|
self.assertEqual(0, cmd.cmd_cleanup([]))
|
|
prompt.assert_not_called()
|
|
docker.cleanup.assert_not_called()
|
|
fc.cleanup.assert_not_called()
|
|
|
|
def test_abort_at_prompt_runs_nothing(self):
|
|
docker, _ = _make_backend(empty=False)
|
|
fc, _ = _make_backend(empty=True)
|
|
backends_by_name = {"docker": docker, "firecracker": fc}
|
|
|
|
with patch.object(
|
|
cmd, "known_backend_names",
|
|
return_value=("docker", "firecracker"),
|
|
), patch.object(
|
|
cmd, "get_bottle_backend",
|
|
side_effect=lambda name: backends_by_name[name], # type: ignore
|
|
), patch.object(
|
|
cmd, "_prompt_yes", return_value=False,
|
|
):
|
|
self.assertEqual(0, cmd.cmd_cleanup([]))
|
|
docker.cleanup.assert_not_called()
|
|
fc.cleanup.assert_not_called()
|
|
|
|
def test_skips_empty_plans_when_others_have_work(self):
|
|
# docker has work, firecracker doesn't — only docker.cleanup
|
|
# is called.
|
|
docker, docker_plan = _make_backend(empty=False)
|
|
fc, _ = _make_backend(empty=True)
|
|
backends_by_name = {"docker": docker, "firecracker": fc}
|
|
|
|
with patch.object(
|
|
cmd, "known_backend_names",
|
|
return_value=("docker", "firecracker"),
|
|
), patch.object(
|
|
cmd, "get_bottle_backend",
|
|
side_effect=lambda name: backends_by_name[name], # type: ignore
|
|
), patch.object(
|
|
cmd, "_prompt_yes", return_value=True,
|
|
):
|
|
cmd.cmd_cleanup([])
|
|
docker.cleanup.assert_called_once_with(docker_plan)
|
|
fc.cleanup.assert_not_called()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|