mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
The workspace jobs pulled every image anonymously from Docker Hub and two of them failed on its rate limit in run 39059128678 (#990): the fedora swarm drill on busybox:1.38 on all three nodes, the centos compose drill while building tor-smtp_custom. The regular deploy jobs pull through the GHCR mirror, but the mirror was tied to being a real GitHub runner: Profile.image_mirror_enabled() returned runs_on_github(), and the swarm routine generated mirrors.yml only when cli.meta.runtime reported github, which is act inside make swarm-zombie. The mirror is now its own capability, INFINITO_GHCR_MIRROR (next to INFINITO_GHCR_MIRROR_PREFIX), written as a run fact like INFINITO_CACHE_STACK: true on a real GitHub runner, false everywhere else, and a non-empty exported value wins for the run. Profile.image_mirror_enabled() reads the declaration and keeps runs_on_github() as the fallback, and 02_provision_inventory.sh gates on the same value instead of the runtime name. make swarm-zombie forwards it into act through ACT_ENV, since act ignores the host env. call-test-workspace.yml declares INFINITO_GHCR_MIRROR=true and passes INFINITO_GHCR_MIRROR_PREFIX into the workspace container. Nothing else of the workspace changes: is_ci, runs_on_github, the cache stack and the docker root stay local-like. The step that loads the rescue paths now removes the .env it generated on the runner, because on debian rows load.sh sourced it inside the container and the run inherited INFINITO_RUNNING_ON_GITHUB=true. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
183 lines
6.7 KiB
Python
183 lines
6.7 KiB
Python
"""Unit tests for Profile."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from cli.administration.deploy.development.profile import Profile
|
|
|
|
_BLANK_CI_ENV = {
|
|
"GITHUB_ACTIONS": "",
|
|
"INFINITO_RUNNING_ON_GITHUB": "",
|
|
"CI": "",
|
|
"INFINITO_INSTANCE": "0",
|
|
"INFINITO_GIT_COMMON_DIR": "",
|
|
"INFINITO_CACHE_NETWORK": "",
|
|
"INFINITO_CACHE_STACK": "",
|
|
"INFINITO_GHCR_MIRROR": "",
|
|
}
|
|
|
|
|
|
class TestProfileIsCI(unittest.TestCase):
|
|
@patch.dict(os.environ, _BLANK_CI_ENV, clear=False)
|
|
def test_is_ci_false_when_no_signals_set(self) -> None:
|
|
self.assertFalse(Profile().is_ci())
|
|
|
|
@patch.dict(os.environ, {**_BLANK_CI_ENV, "GITHUB_ACTIONS": "true"}, clear=False)
|
|
def test_is_ci_true_when_github_actions_signal_set(self) -> None:
|
|
self.assertTrue(Profile().is_ci())
|
|
|
|
@patch.dict(
|
|
os.environ, {**_BLANK_CI_ENV, "INFINITO_RUNNING_ON_GITHUB": "true"}, clear=False
|
|
)
|
|
def test_is_ci_true_when_running_on_github_signal_set(self) -> None:
|
|
self.assertTrue(Profile().is_ci())
|
|
|
|
@patch.dict(os.environ, {**_BLANK_CI_ENV, "CI": "true"}, clear=False)
|
|
def test_is_ci_true_when_generic_ci_signal_set(self) -> None:
|
|
self.assertTrue(Profile().is_ci())
|
|
|
|
@patch.dict(
|
|
os.environ,
|
|
{**_BLANK_CI_ENV, "GITHUB_ACTIONS": "1"},
|
|
clear=False,
|
|
)
|
|
def test_is_ci_false_when_signal_value_is_one(self) -> None:
|
|
self.assertFalse(Profile().is_ci())
|
|
|
|
@patch.dict(os.environ, {**_BLANK_CI_ENV, "GITHUB_ACTIONS": "false"}, clear=False)
|
|
def test_is_ci_false_when_signal_value_is_explicit_false(self) -> None:
|
|
self.assertFalse(Profile().is_ci())
|
|
|
|
@patch.dict(os.environ, {**_BLANK_CI_ENV, "GITHUB_ACTIONS": "yes"}, clear=False)
|
|
def test_is_ci_false_when_signal_value_is_yes(self) -> None:
|
|
self.assertFalse(Profile().is_ci())
|
|
|
|
|
|
class TestProfileCacheStackEnabled(unittest.TestCase):
|
|
@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())
|
|
|
|
@patch.dict(os.environ, {**_BLANK_CI_ENV, "GITHUB_ACTIONS": "true"}, clear=False)
|
|
def test_inactive_under_github_actions(self) -> None:
|
|
self.assertFalse(Profile().cache_stack_enabled())
|
|
|
|
@patch.dict(os.environ, {**_BLANK_CI_ENV, "CI": "true"}, clear=False)
|
|
def test_inactive_under_generic_ci_signal(self) -> None:
|
|
self.assertFalse(Profile().cache_stack_enabled())
|
|
|
|
@patch.dict(
|
|
os.environ, {**_BLANK_CI_ENV, "INFINITO_RUNNING_ON_GITHUB": "true"}, clear=False
|
|
)
|
|
def test_defaults_to_the_inverse_of_is_ci(self) -> None:
|
|
p = Profile()
|
|
self.assertEqual(p.cache_stack_enabled(), not p.is_ci())
|
|
|
|
|
|
_ON_CI = {**_BLANK_CI_ENV, "GITHUB_ACTIONS": "true"}
|
|
|
|
|
|
class TestProfileDeclaredCapabilities(unittest.TestCase):
|
|
@patch.dict(os.environ, {**_ON_CI, "INFINITO_CACHE_STACK": "true"}, clear=False)
|
|
def test_declaration_wins_over_the_ci_default(self) -> None:
|
|
p = Profile()
|
|
self.assertTrue(p.is_ci())
|
|
self.assertTrue(p.cache_stack_enabled())
|
|
|
|
@patch.dict(os.environ, {**_ON_CI, "INFINITO_CACHE_STACK": "yes"}, clear=False)
|
|
def test_a_non_boolean_declaration_falls_back_to_the_default(self) -> None:
|
|
self.assertFalse(Profile().cache_stack_enabled())
|
|
|
|
@patch.dict(os.environ, _ON_CI, clear=False)
|
|
def test_act_gets_no_mirrors_and_keeps_its_docker_root(self) -> None:
|
|
p = Profile()
|
|
self.assertTrue(p.is_ci())
|
|
self.assertFalse(p.runs_on_github())
|
|
self.assertFalse(p.cache_stack_enabled())
|
|
self.assertFalse(p.image_mirror_enabled())
|
|
self.assertFalse(p.docker_root_ephemeral())
|
|
|
|
@patch.dict(
|
|
os.environ,
|
|
{**_BLANK_CI_ENV, "INFINITO_RUNNING_ON_GITHUB": "true"},
|
|
clear=False,
|
|
)
|
|
def test_a_real_github_runner_mirrors_and_wipes(self) -> None:
|
|
p = Profile()
|
|
self.assertTrue(p.runs_on_github())
|
|
self.assertFalse(p.cache_stack_enabled())
|
|
self.assertTrue(p.image_mirror_enabled())
|
|
self.assertTrue(p.docker_root_ephemeral())
|
|
|
|
@patch.dict(
|
|
os.environ,
|
|
{**_BLANK_CI_ENV, "INFINITO_GHCR_MIRROR": "true"},
|
|
clear=False,
|
|
)
|
|
def test_a_mirror_declaration_changes_nothing_but_the_mirror(self) -> None:
|
|
p = Profile()
|
|
self.assertTrue(p.image_mirror_enabled())
|
|
self.assertFalse(p.runs_on_github())
|
|
self.assertFalse(p.is_ci())
|
|
self.assertTrue(p.cache_stack_enabled())
|
|
self.assertFalse(p.docker_root_ephemeral())
|
|
|
|
@patch.dict(
|
|
os.environ,
|
|
{
|
|
**_BLANK_CI_ENV,
|
|
"INFINITO_RUNNING_ON_GITHUB": "true",
|
|
"INFINITO_GHCR_MIRROR": "false",
|
|
},
|
|
clear=False,
|
|
)
|
|
def test_a_declared_false_turns_the_mirror_off_on_github(self) -> None:
|
|
self.assertFalse(Profile().image_mirror_enabled())
|
|
|
|
|
|
class TestProfileInstance(unittest.TestCase):
|
|
@patch.dict(os.environ, {**_BLANK_CI_ENV, "INFINITO_INSTANCE": ""}, clear=False)
|
|
def test_unset_instance_is_primary(self) -> None:
|
|
self.assertEqual(Profile().instance(), 0)
|
|
|
|
@patch.dict(os.environ, {**_BLANK_CI_ENV, "INFINITO_INSTANCE": "7"}, clear=False)
|
|
def test_numeric_instance_is_parsed(self) -> None:
|
|
self.assertEqual(Profile().instance(), 7)
|
|
|
|
@patch.dict(os.environ, {**_BLANK_CI_ENV, "INFINITO_INSTANCE": " 3 "}, clear=False)
|
|
def test_surrounding_whitespace_is_tolerated(self) -> None:
|
|
self.assertEqual(Profile().instance(), 3)
|
|
|
|
@patch.dict(os.environ, {**_BLANK_CI_ENV, "INFINITO_INSTANCE": "abc"}, clear=False)
|
|
def test_garbage_falls_back_to_primary(self) -> None:
|
|
self.assertEqual(Profile().instance(), 0)
|
|
|
|
|
|
class TestProfileOwnsCacheStack(unittest.TestCase):
|
|
@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())
|
|
|
|
@patch.dict(
|
|
os.environ, {**_BLANK_CI_ENV, "INFINITO_CACHE_NETWORK": "primary_default"}
|
|
)
|
|
def test_shares_instead_of_owning_when_a_network_is_named(self) -> None:
|
|
p = Profile()
|
|
self.assertFalse(p.owns_cache_stack())
|
|
self.assertTrue(p.cache_stack_enabled())
|
|
|
|
@patch.dict(os.environ, {**_BLANK_CI_ENV, "INFINITO_INSTANCE": "7"}, clear=False)
|
|
def test_a_stray_slot_alone_does_not_give_the_stack_away(self) -> None:
|
|
self.assertTrue(Profile().owns_cache_stack())
|
|
|
|
@patch.dict(os.environ, {**_BLANK_CI_ENV, "CI": "true"}, clear=False)
|
|
def test_ci_never_owns_the_stack(self) -> None:
|
|
self.assertFalse(Profile().owns_cache_stack())
|
|
|
|
|
|
if __name__ == "__main__": # pragma: no cover
|
|
unittest.main()
|