Files
computer-playbook/tests/unit/cli/administration/deploy/development/test_profile.py
T
kevinveenbirkenbachandClaude Opus 4.7 9a578952c3 feat(env): SPOT env-pipeline + INFINITO_* namespace
Replace 8 bash env modules with a single Python generator
(cli.meta.env) that materialises env/static.env + runtime context
into a gitignored .env. Each variable lives in its own handler
under utils/env/handlers/; defaults carry inline one-line `# ...`
comments.

Rename to the INFINITO_* schema:
- workflow inputs: APPS, SERVICES_DISABLED, CMD, DEBUG, WHITELIST,
  BUNDLES, FULL_CYCLE, VARIANT, RUN_FLAGS, LIMIT_HOST, PARALLEL
- inventory: INVENTORY_DIR / INVENTORY_FILE / HOST_VARS_FILE,
  PW_FILE -> INVENTORY_PASSWORD_FILE
- venv: VENV_BASE / VENV_FALLBACK / VENV_NAME
- new SPOT defaults: COMPILE_SILENCE, CONTAINER_NO_CA,
  WAIT_HEALTH_TIMEOUT_S, PACKAGE_CACHE_FRONTEND_INIT_IMAGE,
  promoted IMAGE_TAG from GHA-only to general passthrough

compose.yml hardening:
- inline \${VAR:-default} removed; strict \${VAR:?...} everywhere
- new integration lint blocks regressions

Tooling:
- scripts/install/all.sh owns the stamp-file install logic
  (Makefile target delegates)
- scripts/meta/env/load.sh is the single shell entry point;
  8 bash modules deleted
- new shell lint: no INFINITO_* defaults outside env/static.env

Tests:
- 93 new unit tests for utils/env/{builder,parser,runtime,writer}
- restructure tests/lint into repository/ (file-content rules) vs
  filesystem/{shell,python,env}/ (filesystem-shape rules)
- drift + smoke integration tests against the generator

Docs:
- variables.md is now a pointer; per-variable docs live next to
  the key in env/static.env / env/ci.env
- compose.yml.md drops the Default column

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 20:40:34 +02:00

96 lines
3.4 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 explicit signals; clear=True would unset PATH.
_BLANK_CI_ENV = {
"GITHUB_ACTIONS": "",
"INFINITO_RUNNING_ON_GITHUB": "",
"CI": "",
}
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 TestProfileRegistryCacheActive(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().registry_cache_active())
@patch.dict(os.environ, {**_BLANK_CI_ENV, "GITHUB_ACTIONS": "true"}, clear=False)
def test_inactive_under_github_actions(self) -> None:
self.assertFalse(Profile().registry_cache_active())
@patch.dict(os.environ, {**_BLANK_CI_ENV, "CI": "true"}, clear=False)
def test_inactive_under_generic_ci_signal(self) -> None:
self.assertFalse(Profile().registry_cache_active())
@patch.dict(
os.environ, {**_BLANK_CI_ENV, "INFINITO_RUNNING_ON_GITHUB": "true"}, clear=False
)
def test_is_strict_inverse_of_is_ci(self) -> None:
p = Profile()
self.assertEqual(p.registry_cache_active(), not p.is_ci())
class TestProfileArgs(unittest.TestCase):
@patch.dict(os.environ, {**_BLANK_CI_ENV, "CI": "true"}, clear=False)
def test_args_ci_only_on_runner(self) -> None:
self.assertEqual(Profile().args(), ["--profile", "ci"])
@patch.dict(os.environ, _BLANK_CI_ENV, clear=False)
def test_args_returns_only_ci_profile_locally(self) -> None:
self.assertEqual(Profile().args(), ["--profile", "ci"])
@patch.dict(os.environ, _BLANK_CI_ENV, clear=False)
def test_args_returns_a_fresh_list_each_call(self) -> None:
# Callers may mutate the returned list.
p = Profile()
first = p.args()
first.append("--mutated")
self.assertNotIn("--mutated", p.args())
if __name__ == "__main__": # pragma: no cover
unittest.main()