mirror of
https://github.com/dredx/prole.git
synced 2026-09-23 11:03:59 +00:00
54 lines
1.7 KiB
Python
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`/`$KNOE_HOME` must be expanded before mkdir/copy.
|
|
|
|
Without this, setting `KNOE_HOME=$HOME/knoe` 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 = {
|
|
"KNOE_HOME": "$HOME/knoe",
|
|
"KNOE_CONF": "$KNOE_HOME/conf",
|
|
"PROLE_DATA": "$KNOE_HOME/data",
|
|
"PROLE_LOGS": "$KNOE_HOME/logs",
|
|
"KNOE_SERVICE": "$KNOE_HOME/etc",
|
|
}
|
|
dummy._save_env_to_file(values)
|
|
|
|
expected_home = home_dir / "knoe"
|
|
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()
|