feat: support macos-container bottle commits

This commit is contained in:
2026-06-23 00:36:35 -04:00
parent 6e73cc4d86
commit cb3bb209d6
6 changed files with 224 additions and 31 deletions
+24 -20
View File
@@ -76,7 +76,7 @@ class TestCmdCommitSlugArg(_FakeHomeMixin, unittest.TestCase):
))
with patch(
"bot_bottle.cli.commit.commit_container",
"bot_bottle.cli.commit.docker_commit_container",
) as mock_commit, patch(
"bot_bottle.cli.commit.info",
):
@@ -95,7 +95,7 @@ class TestCmdCommitSlugArg(_FakeHomeMixin, unittest.TestCase):
started_at="t", backend="docker",
))
with patch("bot_bottle.cli.commit.commit_container"), \
with patch("bot_bottle.cli.commit.docker_commit_container"), \
patch("bot_bottle.cli.commit.info"):
cmd_commit([slug])
@@ -111,7 +111,7 @@ class TestCmdCommitSlugArg(_FakeHomeMixin, unittest.TestCase):
started_at="t", backend="docker",
))
with patch("bot_bottle.cli.commit.commit_container"), \
with patch("bot_bottle.cli.commit.docker_commit_container"), \
patch("bot_bottle.cli.commit.info"):
cmd_commit([slug])
@@ -125,13 +125,33 @@ class TestCmdCommitSlugArg(_FakeHomeMixin, unittest.TestCase):
started_at="t", backend="",
))
with patch("bot_bottle.cli.commit.commit_container") as mock_commit, \
with patch("bot_bottle.cli.commit.docker_commit_container") as mock_commit, \
patch("bot_bottle.cli.commit.info"):
rc = cmd_commit([slug])
self.assertEqual(0, rc)
mock_commit.assert_called_once()
def test_commits_macos_container_bottle(self):
slug = "dev-abc12"
bottle_state.write_metadata(bottle_state.BottleMetadata(
identity=slug, agent_name="dev", cwd="", copy_cwd=False,
started_at="t", backend="macos-container",
))
with patch(
"bot_bottle.cli.commit.macos_commit_container",
) as mock_commit, patch(
"bot_bottle.cli.commit.info",
):
rc = cmd_commit([slug])
self.assertEqual(0, rc)
mock_commit.assert_called_once_with(
f"bot-bottle-{slug}",
f"bot-bottle-committed-{slug}:latest",
)
class TestCmdCommitSmolmachinesBackend(_FakeHomeMixin, unittest.TestCase):
def setUp(self):
@@ -173,22 +193,6 @@ class TestCmdCommitUnsupportedBackend(_FakeHomeMixin, unittest.TestCase):
def tearDown(self):
self._teardown_fake_home()
def test_dies_for_macos_container_backend(self):
slug = "dev-abc12"
bottle_state.write_metadata(bottle_state.BottleMetadata(
identity=slug, agent_name="dev", cwd="", copy_cwd=False,
started_at="t", backend="macos-container",
))
with patch(
"bot_bottle.cli.commit.die", side_effect=SystemExit("die"),
) as mock_die:
with self.assertRaises(SystemExit):
cmd_commit([slug])
mock_die.assert_called_once()
self.assertIn("macos-container", mock_die.call_args.args[0])
class TestCmdCommitNoActiveBottles(_FakeHomeMixin, unittest.TestCase):
def setUp(self):
+76
View File
@@ -9,6 +9,7 @@ from types import SimpleNamespace
from typing import cast
from unittest.mock import patch
from bot_bottle.agent_provider import AgentProvisionPlan
from bot_bottle.backend.macos_container import launch
from bot_bottle.backend.macos_container.bottle_plan import MacosContainerBottlePlan
from bot_bottle.manifest import ManifestIndex
@@ -261,5 +262,80 @@ class TestMacosContainerLaunchArgv(unittest.TestCase):
)
def _build_plan(stage_dir: Path) -> MacosContainerBottlePlan:
return MacosContainerBottlePlan(
spec=SimpleNamespace(),
manifest=_MANIFEST,
stage_dir=stage_dir,
git_gate_plan=SimpleNamespace(upstreams=()),
egress_plan=SimpleNamespace(),
supervise_plan=None,
agent_provision=AgentProvisionPlan(
template="claude",
command="claude",
prompt_mode="append_file",
image="bot-bottle-agent:latest",
dockerfile="/repo/Dockerfile",
guest_home="/home/node",
instance_name="bot-bottle-dev-abc",
prompt_file=stage_dir / "prompt.txt",
guest_env={},
),
slug="dev-abc",
forwarded_env={},
)
class TestMacosContainerLaunchCommittedImage(unittest.TestCase):
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.stage_dir = Path(self._tmp.name)
def tearDown(self):
self._tmp.cleanup()
def test_build_images_uses_committed_image_when_present(self):
plan = _build_plan(self.stage_dir)
calls = []
def fake_build(image, context, *, dockerfile=""):
calls.append((image, context, dockerfile))
with patch.object(
launch, "read_committed_image",
return_value="bot-bottle-committed-dev-abc:latest",
), patch.object(
launch.container_mod, "image_exists", return_value=True,
), patch.object(
launch.container_mod, "build_image", side_effect=fake_build,
), patch.object(launch, "info"):
updated = launch._build_images(plan)
self.assertEqual("bot-bottle-committed-dev-abc:latest", updated.image)
self.assertEqual(1, len(calls))
self.assertEqual(launch.SIDECAR_BUNDLE_IMAGE, calls[0][0])
def test_build_images_builds_agent_when_committed_image_missing(self):
plan = _build_plan(self.stage_dir)
calls = []
def fake_build(image, context, *, dockerfile=""):
calls.append((image, context, dockerfile))
with patch.object(
launch, "read_committed_image",
return_value="bot-bottle-committed-dev-abc:latest",
), patch.object(
launch.container_mod, "image_exists", return_value=False,
), patch.object(
launch.container_mod, "build_image", side_effect=fake_build,
):
updated = launch._build_images(plan)
self.assertEqual("bot-bottle-agent:latest", updated.image)
self.assertEqual(2, len(calls))
self.assertEqual("bot-bottle-agent:latest", calls[1][0])
if __name__ == "__main__":
unittest.main()
+46
View File
@@ -73,6 +73,52 @@ resolver #2
)
self.assertTrue(run.call_args_list[-1].kwargs["check"])
def test_commit_container_exports_rootfs_and_builds_image(self):
completed = util.subprocess.CompletedProcess(
args=[], returncode=0, stdout="", stderr="",
)
dockerfile_text = ""
def fake_build_image(image_tag, context, *, dockerfile=""):
nonlocal dockerfile_text
with open(dockerfile, encoding="utf-8") as f:
dockerfile_text = f.read()
with patch.object(util.subprocess, "run", return_value=completed) as run, \
patch.object(util, "build_image", side_effect=fake_build_image) as build_image, \
patch.object(util, "info"):
util.commit_container(
"bot-bottle-dev-abc12",
"bot-bottle-committed-dev-abc12:latest",
)
argv = run.call_args.args[0]
self.assertEqual("container", argv[0])
self.assertEqual("export", argv[1])
self.assertEqual("-o", argv[2])
self.assertTrue(argv[3].endswith("/rootfs.tar"))
self.assertEqual("bot-bottle-dev-abc12", argv[4])
build_image.assert_called_once()
self.assertEqual(
"bot-bottle-committed-dev-abc12:latest",
build_image.call_args.args[0],
)
self.assertIn("ADD rootfs.tar /\n", dockerfile_text)
self.assertIn("USER node\n", dockerfile_text)
self.assertIn("WORKDIR /home/node\n", dockerfile_text)
def test_commit_container_dies_on_export_failure(self):
failed = util.subprocess.CompletedProcess(
args=[], returncode=1, stdout="", stderr="No such container",
)
with patch.object(util.subprocess, "run", return_value=failed), \
patch.object(util, "die", side_effect=SystemExit("die")) as die:
with self.assertRaises(SystemExit):
util.commit_container("missing-container", "some:tag")
die.assert_called_once()
self.assertIn("missing-container", die.call_args.args[0])
def test_build_image_restarts_builder_when_dns_mismatches(self):
status = util.subprocess.CompletedProcess(
args=[],