prole/tests/installer/test_environment_screen_expands_shell_vars.py
chrisfu c0a7d0c5dc Refine installer orchestration and Supabase rendering paths
- improve installer/action/controller flow and shell-variable expansion handling across screens\n- adjust Supabase Helm rendering and storage deployment templates\n- align monitoring, cloudnative-pg and repair pipeline behavior with updated config paths\n- refresh and expand installer/core regression tests around milestones, navigation and repair logic

Co-authored-by: Junie <junie@jetbrains.com>
2026-03-31 23:15:54 -07:00

54 lines
1.7 KiB
Python

from __future__ import annotations
import os
from pathlib import Path
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 knoe.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()