mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
A compose deploy job labelled centos or arch built its stack image from pkgmgr-debian and ran it as infinito_nexus_debian (#794). distros.sh exports INFINITO_DISTRO per iteration and sources load.sh again, but the loader returned early because INFINITO_ENV_LOADED and the .env mtime were unchanged. A full reload would not have helped either: the debian values were already exported, so the restore step kept them as caller intent. load.sh now records the distro it loaded for. Another INFINITO_DISTRO defeats the early return and drops INFINITO_CONTAINER, INFINITO_PARENT_IMAGE and INFINITO_IMAGE, the three keys the env handlers derive from the distro. When the requested distro also differs from the one .env was generated for, the loader sources a set that `python -m cli.meta.env --output` generates for it in a private temp directory and leaves .env untouched, so a local multi-distro run does not switch the checkout's distro. A caller value set for the loaded distro still wins. Verified: tests/unit/python/scripts/meta/env/test_load.py and the new distros.sh case pass. Against main's loader both fail with the symptom of the issue: INFINITO_DISTRO=centos next to infinito_nexus_debian and pkgmgr-debian:stable, and distros.sh handing debian, arch and centos the same debian parent. shellcheck is clean. Consequence: CI jobs labelled arch, ubuntu, fedora or centos now build and deploy that distro, so a failure that shows up there was masked before. feature/store-i18n carries3f973eb137, which resolves the parent image for scripts/image/push.sh on its own, and05e4dbafcb, which inserts the INFINITO_INSTANCE slot check into the block this commit restructures. The merge keeps the slot check ahead of the distro check. Closes #794 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
import cli.meta.env.__main__ as env_main
|
|
|
|
|
|
class TestDotenvHostOwned(unittest.TestCase):
|
|
def _run(
|
|
self,
|
|
*,
|
|
dotenv_exists: bool,
|
|
host_owned: str | None,
|
|
argv: list[str] | None = None,
|
|
) -> tuple[int, bool]:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
(root / "default.env").write_text("INFINITO_DISTRO=debian\n")
|
|
if dotenv_exists:
|
|
(root / ".env").write_text("INFINITO_RUNNING_ON_GITHUB=true\n")
|
|
environ = (
|
|
{} if host_owned is None else {env_main.HOST_OWNED_KEY: host_owned}
|
|
)
|
|
with (
|
|
patch.object(env_main, "REPO_ROOT", root),
|
|
patch.dict("os.environ", environ, clear=True),
|
|
patch.object(
|
|
env_main, "parse_static_env_with_comments", return_value=({}, {})
|
|
),
|
|
patch.object(env_main, "build_env") as build_env,
|
|
patch.object(env_main, "write_dotenv") as write_dotenv,
|
|
):
|
|
build_env.return_value.values = {}
|
|
rc = env_main.main(argv)
|
|
return rc, write_dotenv.called
|
|
|
|
def test_a_host_owned_dotenv_is_kept(self) -> None:
|
|
self.assertEqual(self._run(dotenv_exists=True, host_owned="true"), (0, False))
|
|
|
|
def test_a_missing_dotenv_is_generated_even_when_host_owned(self) -> None:
|
|
self.assertEqual(self._run(dotenv_exists=False, host_owned="true"), (0, True))
|
|
|
|
def test_without_the_marker_the_dotenv_is_regenerated(self) -> None:
|
|
self.assertEqual(self._run(dotenv_exists=True, host_owned=None), (0, True))
|
|
|
|
def test_an_explicit_output_is_written_even_when_host_owned(self) -> None:
|
|
self.assertEqual(
|
|
self._run(
|
|
dotenv_exists=True,
|
|
host_owned="true",
|
|
argv=["--output", "/nonexistent/distro.env"],
|
|
),
|
|
(0, True),
|
|
)
|
|
|
|
|
|
if __name__ == "__main__": # pragma: no cover
|
|
unittest.main()
|