Add cached image quickstart
This commit is contained in:
@@ -187,6 +187,56 @@ class TestAgentFromPath(unittest.TestCase):
|
||||
dockerfile="/repo/Dockerfile",
|
||||
)
|
||||
|
||||
def test_cached_policy_uses_existing_artifact_without_build(self):
|
||||
with tempfile.TemporaryDirectory(prefix="cached-smolmachine.") as tmp:
|
||||
digest = "abcdef0123456789"
|
||||
artifact = Path(tmp) / f"{digest}.smolmachine.smolmachine"
|
||||
artifact.write_text("")
|
||||
plan = SimpleNamespace(
|
||||
slug="dev-abc12",
|
||||
agent_image="bot-bottle-claude:latest",
|
||||
spec=SimpleNamespace(image_policy="cached"),
|
||||
)
|
||||
with patch.object(
|
||||
_launch_mod, "_SMOLMACHINE_CACHE_DIR", Path(tmp),
|
||||
), patch.object(
|
||||
_launch_mod, "read_committed_image", return_value="",
|
||||
), patch.object(
|
||||
_launch_mod.docker_mod, "image_exists", return_value=True,
|
||||
), patch.object(
|
||||
_launch_mod.docker_mod, "image_id",
|
||||
return_value=f"sha256:{digest}fffffffffffffffff",
|
||||
), patch.object(
|
||||
_launch_mod, "warn_if_stale_path",
|
||||
), patch.object(
|
||||
_launch_mod, "_ensure_smolmachine",
|
||||
) as ensure:
|
||||
result = _launch_mod._agent_from_path(cast(Any, plan))
|
||||
|
||||
self.assertEqual(artifact, result)
|
||||
ensure.assert_not_called()
|
||||
|
||||
def test_cached_policy_dies_when_artifact_missing(self):
|
||||
with tempfile.TemporaryDirectory(prefix="cached-smolmachine.") as tmp:
|
||||
plan = SimpleNamespace(
|
||||
slug="dev-abc12",
|
||||
agent_image="bot-bottle-claude:latest",
|
||||
spec=SimpleNamespace(image_policy="cached"),
|
||||
)
|
||||
with patch.object(
|
||||
_launch_mod, "_SMOLMACHINE_CACHE_DIR", Path(tmp),
|
||||
), patch.object(
|
||||
_launch_mod, "read_committed_image", return_value="",
|
||||
), patch.object(
|
||||
_launch_mod.docker_mod, "image_exists", return_value=True,
|
||||
), patch.object(
|
||||
_launch_mod.docker_mod, "image_id",
|
||||
return_value="sha256:abcdef0123456789fffffffffffffffff",
|
||||
):
|
||||
from bot_bottle.log import Die
|
||||
with self.assertRaises(Die):
|
||||
_launch_mod._agent_from_path(cast(Any, plan))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user