Files
strata/tests/terminal/test_state_paths.py
T
Niko1221 236cca71bb host: no /usr/bin/tar, /usr/bin/env or HOME/.local/state on Windows
- engine-install.mjs extracts with tarBinary(): System32\tar.exe on Windows (bsdtar reads .zip and .tar.*), /usr/bin/tar
  elsewhere.
- util.mjs which() asks System32\where.exe on Windows (first match), /usr/bin/env which elsewhere.
- the tuning and Time-skip state default to %LOCALAPPDATA%\Strata\tuning and \time-skip on Windows
  (apps/host/server/platform-paths.mjs; POSIX keeps $XDG_STATE_HOME/strata). The Python side resolves the same folders
  (strata_control/paths.py, used by the runtime directory and the tune and timeskip commands), so the host and the
  terminal agree.
- tests: apps/host/tests/platform-paths.test.mjs (both platforms from either host) and tests/terminal/test_state_paths.py.
2026-10-15 12:31:49 +02:00

48 lines
2.1 KiB
Python

"""Per-user state locations: %LOCALAPPDATA%\\Strata on Windows, $XDG_STATE_HOME/strata elsewhere."""
import os
import tempfile
import unittest
from pathlib import Path
from unittest import mock
from strata_cli.cli import main
from strata_control import paths, runtime
class StatePaths(unittest.TestCase):
def test_windows_uses_localappdata(self):
env = {"LOCALAPPDATA": "C:\\Users\\me\\AppData\\Local", "XDG_STATE_HOME": "/ignored"}
self.assertEqual(paths.state_base(env, windows=True, home=Path("C:\\Users\\other")),
Path("C:\\Users\\me\\AppData\\Local") / "Strata")
def test_windows_without_localappdata_falls_back_to_the_profile(self):
self.assertEqual(paths.state_base({}, windows=True, home=Path("C:\\Users\\me")),
Path("C:\\Users\\me") / "AppData" / "Local" / "Strata")
def test_posix_is_unchanged(self):
self.assertEqual(paths.state_base({"XDG_STATE_HOME": "/x"}, windows=False), Path("/x") / "strata")
self.assertEqual(paths.state_base({}, windows=False, home=Path("/home/me")),
Path("/home/me") / ".local" / "state" / "strata")
def test_runtime_dir_default_lives_under_the_state_base(self):
with tempfile.TemporaryDirectory() as d:
env = {"LOCALAPPDATA": d, "XDG_STATE_HOME": d}
with mock.patch.dict(os.environ, env):
os.environ.pop("STRATA_RUNTIME_DIR", None)
self.assertEqual(runtime.runtime_dir(), paths.state_base() / "runtime")
self.assertEqual(runtime.runtime_dir().parent.parent, Path(d))
def test_cli_defaults_for_tuning_and_timeskip_follow_the_same_base(self):
with tempfile.TemporaryDirectory() as d:
env = {"LOCALAPPDATA": d, "XDG_STATE_HOME": d}
with mock.patch.dict(os.environ, env):
for var in ("STRATA_TUNE_DIR", "STRATA_TIMESKIP_DIR"):
os.environ.pop(var, None)
self.assertEqual(main(["tune", "list", "--output", "json"]), 0)
self.assertEqual(main(["timeskip", "list", "--output", "json"]), 0)
if __name__ == "__main__":
unittest.main()