Merge pull request #1969 from infinito-nexus/fix/deploy/cache-stack-infra-owner

fix(deploy): keep the legacy cache stack off while the infra runner owns the cache base
This commit is contained in:
kevinveenbirkenbach authored and GitHub committed 2026-11-14 19:56:24 +01:00
commit fbc392dc54
4 files changed
+106 -3

No files matched your search

@@ -15,6 +15,14 @@ from cli.administration.deploy.development.compose import (
class TestComposeUpRetries(unittest.TestCase):
def setUp(self) -> None:
patcher = patch(
"cli.administration.deploy.development.profile.infra_owns_cache",
return_value=False,
)
patcher.start()
self.addCleanup(patcher.stop)
def _compose(self) -> Compose:
return Compose(repo_root=Path("/tmp/infinito-nexus"), distro="arch")
@@ -54,6 +54,14 @@ _WORKTREE = {
class TestComposeFileArgs(unittest.TestCase):
def setUp(self) -> None:
patcher = patch(
"cli.administration.deploy.development.profile.infra_owns_cache",
return_value=False,
)
patcher.start()
self.addCleanup(patcher.stop)
@patch.dict(os.environ, _LOCAL_PRIMARY, clear=False)
def test_primary_instance_loads_the_cache_stack(self) -> None:
self.assertEqual(
@@ -2,10 +2,15 @@
from __future__ import annotations
import contextlib
import io
import os
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
from cli.administration.deploy.development import profile
from cli.administration.deploy.development.profile import Profile
_BLANK_CI_ENV = {
@@ -56,7 +61,17 @@ class TestProfileIsCI(unittest.TestCase):
self.assertFalse(Profile().is_ci())
class TestProfileCacheStackEnabled(unittest.TestCase):
class _WithoutInfraOwner(unittest.TestCase):
def setUp(self) -> None:
patcher = patch(
"cli.administration.deploy.development.profile.infra_owns_cache",
return_value=False,
)
patcher.start()
self.addCleanup(patcher.stop)
class TestProfileCacheStackEnabled(_WithoutInfraOwner):
@patch.dict(os.environ, _BLANK_CI_ENV, clear=False)
def test_active_locally_when_no_ci_signal_set(self) -> None:
self.assertTrue(Profile().cache_stack_enabled())
@@ -80,7 +95,7 @@ class TestProfileCacheStackEnabled(unittest.TestCase):
_ON_CI = {**_BLANK_CI_ENV, "GITHUB_ACTIONS": "true"}
class TestProfileDeclaredCapabilities(unittest.TestCase):
class TestProfileDeclaredCapabilities(_WithoutInfraOwner):
@patch.dict(os.environ, {**_ON_CI, "INFINITO_CACHE_STACK": "true"}, clear=False)
def test_declaration_wins_over_the_ci_default(self) -> None:
p = Profile()
@@ -156,7 +171,7 @@ class TestProfileInstance(unittest.TestCase):
self.assertEqual(Profile().instance(), 0)
class TestProfileOwnsCacheStack(unittest.TestCase):
class TestProfileOwnsCacheStack(_WithoutInfraOwner):
@patch.dict(os.environ, _BLANK_CI_ENV, clear=False)
def test_owns_the_stack_when_no_network_was_handed_over(self) -> None:
self.assertTrue(Profile().owns_cache_stack())
@@ -178,5 +193,58 @@ class TestProfileOwnsCacheStack(unittest.TestCase):
self.assertFalse(Profile().owns_cache_stack())
class TestProfileInfraOwner(unittest.TestCase):
def setUp(self) -> None:
tmp = tempfile.TemporaryDirectory()
self.addCleanup(tmp.cleanup)
self.base = Path(tmp.name)
patcher = patch.object(profile.paths, "base", return_value=self.base)
patcher.start()
self.addCleanup(patcher.stop)
profile._NOTICED.clear()
self.addCleanup(profile._NOTICED.clear)
def _mark_owner(self) -> None:
(self.base / "infra.owner").write_text("infinito-infra\n", encoding="utf-8")
def test_infra_owns_cache_follows_the_marker_file(self) -> None:
self.assertFalse(profile.infra_owns_cache())
self._mark_owner()
self.assertTrue(profile.infra_owns_cache())
def test_a_directory_named_like_the_marker_is_not_the_marker(self) -> None:
(self.base / "infra.owner").mkdir()
self.assertFalse(profile.infra_owns_cache())
@patch.dict(os.environ, {**_BLANK_CI_ENV, "INFINITO_CACHE_STACK": "true"})
def test_marker_switches_the_stack_off_despite_the_declaration(self) -> None:
self._mark_owner()
p = Profile()
with contextlib.redirect_stderr(io.StringIO()):
self.assertFalse(p.cache_stack_enabled())
self.assertFalse(p.owns_cache_stack())
@patch.dict(os.environ, _BLANK_CI_ENV)
def test_notice_is_printed_once_per_process(self) -> None:
self._mark_owner()
stderr = io.StringIO()
with contextlib.redirect_stderr(stderr):
Profile().cache_stack_enabled()
Profile().cache_stack_enabled()
self.assertEqual(stderr.getvalue().count("NOTICE"), 1)
self.assertIn("infra.owner", stderr.getvalue())
@patch.dict(os.environ, {**_BLANK_CI_ENV, "INFINITO_CACHE_STACK": "true"})
def test_without_the_marker_the_declaration_still_applies(self) -> None:
stderr = io.StringIO()
with contextlib.redirect_stderr(stderr):
self.assertTrue(Profile().cache_stack_enabled())
self.assertEqual(stderr.getvalue(), "")
@patch.dict(os.environ, _BLANK_CI_ENV)
def test_without_the_marker_local_default_is_unchanged(self) -> None:
self.assertTrue(Profile().cache_stack_enabled())
if __name__ == "__main__": # pragma: no cover
unittest.main()