from __future__ import annotations from pathlib import Path import pytest from installer.ui.screens.docker import DockerScreenMixin import installer.ui.screens.docker as docker_mod class _DummyDockerScreen(DockerScreenMixin): def __init__(self, tmp_path: Path): self._tmp_path = tmp_path self.prole_cfg_data = { # Global deployment mode may remain k3d, while the UI selection is Service. "Global": {"DEPLOYMENT_MODE": "k3d"}, "Docker Build": {}, } self.local_registry_url = None self.local_registry_internal = None def _cluster_env_key(self, env_label=None) -> str: return "service" def _deployment_mode(self) -> str: return "k3d" def _k3s_registry_hostport(self) -> str: return "myrddin.prole.org:5000" def _registry_namespace(self) -> str: return "knoe-system" def check_docker_running(self) -> bool: return True def safe_after(self, fn): # Execute inline for tests try: fn() except Exception: pass def _save_prole_cfg(self): return None def _registry_log_path(self) -> Path: return self._tmp_path / "local_registry.log" def test_ensure_local_registry_available_prefers_selected_env_over_global_mode(monkeypatch, tmp_path): """Regression: Service (k3s) selection must not trigger localhost/k3d registry checks.""" def _unexpected_ping(*_args, **_kwargs): raise AssertionError("_http_ping_registry should not be called for k3s branch") def _unexpected_run(*args, **kwargs): raise AssertionError(f"subprocess.run should not be used for k3s branch: {args}") monkeypatch.setattr(docker_mod, "_http_ping_registry", _unexpected_ping) monkeypatch.setattr(docker_mod.subprocess, "run", _unexpected_run) screen = _DummyDockerScreen(tmp_path) info = screen.ensure_local_registry_available() assert info == ( "myrddin.prole.org:5000", "registry.knoe-system.svc.cluster.local:5000", )