prole/tests/installer/test_environment_screen_expands_shell_vars.py
chrisfu a445c77233 checkpoint: installer env var expansion + k3s registry + CNPG backups
- Expand nested $VAR/${VAR} (and ~) when resolving PROLE_* paths in installer core/UI to avoid literal $HOME dirs\n- Improve k3s registry host:port derivation (explicit cfg/env, server URL, kubeconfig fallback) and registry status UX\n- Update CNPG backup/init scripts for plugin-based backups + ScheduledBackup; improve plugin socket readiness and status output\n- Add/extend tests covering env var expansion, registry hostport resolution, and CNPG backup behavior
2026-03-14 22:55:32 -07:00

56 lines
1.7 KiB
Python

from __future__ import annotations
import os
from pathlib import Path
import pytest
def test_environment_screen_expands_shell_vars_for_filesystem(monkeypatch, tmp_path: Path):
"""Regression: `$HOME`/`$PROLE_HOME` must be expanded before mkdir/copy.
Without this, setting `PROLE_HOME=$HOME/prole` can create a literal `$HOME`
directory in the current working directory.
"""
# Isolate CWD so a regression can't pollute the repo checkout.
monkeypatch.chdir(tmp_path)
home_dir = tmp_path / "home"
home_dir.mkdir(parents=True, exist_ok=True)
monkeypatch.setenv("HOME", str(home_dir))
# Provide a minimal PROJECT_ROOT so `_save_env_to_file` has tiny copy sources.
proj = tmp_path / "project_root"
(proj / "etc").mkdir(parents=True, exist_ok=True)
(proj / "etc" / "init-port-forward.sh").write_text("#!/usr/bin/env bash\necho ok\n")
import installer.ui.screens.environment as env_screen
monkeypatch.setattr(env_screen, "PROJECT_ROOT", proj)
class Dummy(env_screen.EnvironmentScreenMixin):
pass
dummy = Dummy()
values = {
"PROLE_HOME": "$HOME/prole",
"PROLE_CONF": "$PROLE_HOME/conf",
"PROLE_DATA": "$PROLE_HOME/data",
"PROLE_LOGS": "$PROLE_HOME/logs",
"PROLE_SERVICE": "$PROLE_HOME/etc",
}
dummy._save_env_to_file(values)
expected_home = home_dir / "prole"
assert expected_home.is_dir()
assert (expected_home / "conf").is_dir()
assert (expected_home / "data").is_dir()
assert (expected_home / "logs").is_dir()
assert (expected_home / "etc").is_dir()
assert (expected_home / "env.sh").is_file()
# Critical assertion: we must NOT create a literal `$HOME` directory in CWD.
assert not (tmp_path / "$HOME").exists()