"""The command line, and the one ordering it depends on.""" import subprocess import sys from pathlib import Path from fluksio.cli import load_or_create_secret_key def test_importing_the_cli_does_not_build_the_settings() -> None: """`_configure_environment` has to run before anything reads a setting. The settings are built on the first import of `fluksio.core.config`, and every engine module reaches it within an import or two. If importing the CLI pulled it in, `DATA_DIR` would be fixed at whatever directory the command was run from — which is how the database ends up in the cwd. """ leaked = subprocess.run( [ sys.executable, "-c", "import fluksio.cli, sys; print('fluksio.core.config' in sys.modules)", ], capture_output=True, text=True, check=True, ) assert leaked.stdout.strip() == "False", leaked.stdout def test_the_secret_key_is_kept_rather_than_regenerated(tmp_path: Path) -> None: """A new key each start would sign out every session and orphan secrets.enc.""" path = tmp_path / "secret_key" first = load_or_create_secret_key(path) assert load_or_create_secret_key(path) == first assert path.stat().st_mode & 0o777 == 0o600