cb2d778a8f
Sweep for vestiges of the old combined-plane model and the pre-split shared rootfs. Two are load-bearing, the rest are stale docs/comments: - Bug: macOS `enumerate_active` only excluded the gateway container from the agent list, so after the split the orchestrator container (`bot-bottle-mac-orchestrator`, also `bot-bottle-`-prefixed) was enumerated as a phantom agent. Exclude both infra containers; test covers it. - Dead code: the gateway `bootstrap.py` still carried an `orchestrator` daemon spec + `_OPT_IN_DAEMONS` + a signing-key/JWT env branch, all for the old combined container where the gateway process could also run the control plane. No backend ever requests it now — removed; the key-stripping stays as defense-in-depth. Stale-comment reframes: "the/single infra container" -> the orchestrator + gateway pair (or the specific plane); "shared rootfs / bb_role init / one published rootfs" -> the per-plane rootfs + `role_init`; the deleted Dockerfile.infra references in Dockerfile.orchestrator/.gateway; and the macOS "one infra container ... same address" docstring + its now-false share-one-address test (the planes are distinct containers with distinct addresses). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
79 lines
3.0 KiB
Python
79 lines
3.0 KiB
Python
"""Unit: Apple Container cleanup/enumeration helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from bot_bottle.backend.macos_container import cleanup, enumerate as enum_mod
|
|
from bot_bottle.backend.macos_container.bottle_cleanup_plan import (
|
|
MacosContainerBottleCleanupPlan,
|
|
)
|
|
|
|
|
|
class TestMacosContainerCleanup(unittest.TestCase):
|
|
def test_lists_prefixed_containers(self):
|
|
completed = cleanup.subprocess.CompletedProcess(
|
|
args=[],
|
|
returncode=0,
|
|
stdout="bot-bottle-a\nbot-bottle-b\nother\n",
|
|
stderr="",
|
|
)
|
|
with patch.object(cleanup.subprocess, "run", return_value=completed):
|
|
self.assertEqual(
|
|
["bot-bottle-a", "bot-bottle-b"],
|
|
cleanup._list_prefixed_containers(),
|
|
)
|
|
|
|
def test_cleanup_deletes_containers_and_networks(self):
|
|
plan = MacosContainerBottleCleanupPlan(
|
|
containers=("bot-bottle-a",),
|
|
networks=("bot-bottle-net-a",),
|
|
)
|
|
with patch.object(cleanup.subprocess, "run") as run:
|
|
cleanup.cleanup(plan)
|
|
self.assertEqual(
|
|
["container", "delete", "--force", "bot-bottle-a"],
|
|
run.call_args_list[0].args[0],
|
|
)
|
|
self.assertEqual(
|
|
["container", "network", "delete", "bot-bottle-net-a"],
|
|
run.call_args_list[1].args[0],
|
|
)
|
|
|
|
|
|
class TestMacosContainerEnumerate(unittest.TestCase):
|
|
"""The backend launches bottles again (PRD 0070), so enumeration is real
|
|
rather than the disabled-era stub. These must not shell out: `container`
|
|
does not exist on the Linux CI host."""
|
|
|
|
def _enumerate(self, stdout: str, returncode: int = 0):
|
|
completed = enum_mod.subprocess.CompletedProcess(
|
|
args=[], returncode=returncode, stdout=stdout, stderr="",
|
|
)
|
|
with patch.object(enum_mod.subprocess, "run", return_value=completed), \
|
|
patch.object(enum_mod, "read_metadata", return_value=None):
|
|
return enum_mod.enumerate_active()
|
|
|
|
def test_lists_agent_containers_by_slug(self):
|
|
agents = self._enumerate("bot-bottle-dev-abc\nunrelated\n")
|
|
self.assertEqual(["dev-abc"], [a.slug for a in agents])
|
|
self.assertEqual(["macos-container"], [a.backend_name for a in agents])
|
|
|
|
def test_excludes_both_infra_containers(self):
|
|
"""Both infra containers (orchestrator + gateway) share the bot-bottle-
|
|
prefix but are infrastructure — listing either would invent a phantom
|
|
agent per host."""
|
|
agents = self._enumerate(
|
|
"bot-bottle-mac-infra\nbot-bottle-mac-orchestrator\nbot-bottle-dev-abc\n")
|
|
self.assertEqual(["dev-abc"], [a.slug for a in agents])
|
|
|
|
def test_raises_when_the_cli_fails(self):
|
|
from bot_bottle.backend.macos_container.enumerate import EnumerationError
|
|
with self.assertRaises(EnumerationError):
|
|
self._enumerate("", returncode=1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|