The fork takes its own name everywhere a user can see it: binaries (voculinux, voculinux-gui), desktop entry, autostart, tray, D-Bus namespace (com.voculinux.Voculinux, no alias for the old name), config/data/cache dirs, single-instance lock, IBus engine identity, tray icons, resource prefixes, VOCULINUX_* environment names, and the update-checker user agent. The internal Python module stays vocalinux and the distribution metadata keeps the upstream URLs as provenance. On first run a previous Vocalinux install's config.json, custom dictionary, and portal restore token are copied once into the new locations (new config always wins, no merge, no write-back); models re-resolve through the pinned-checksum download path. An offline naming-sweep test proves no old-name strings remain on user-visible surfaces outside the allowlist. Refs #18
72 lines
3.2 KiB
Python
72 lines
3.2 KiB
Python
"""Tests for the XDG base-directory helpers in vocalinux.utils.paths."""
|
|
|
|
import os
|
|
from unittest.mock import patch
|
|
|
|
from vocalinux.utils import paths
|
|
|
|
|
|
class TestXdgHelpers:
|
|
def test_defaults_when_env_unset(self):
|
|
with patch.dict(os.environ, {}, clear=True):
|
|
assert paths.xdg_config_home() == os.path.expanduser("~/.config")
|
|
assert paths.xdg_data_home() == os.path.expanduser("~/.local/share")
|
|
assert paths.config_dir() == os.path.expanduser("~/.config/voculinux")
|
|
assert paths.data_dir() == os.path.expanduser("~/.local/share/voculinux")
|
|
assert paths.models_dir() == os.path.expanduser("~/.local/share/voculinux/models")
|
|
|
|
def test_honours_xdg_environment(self):
|
|
env = {
|
|
"XDG_CONFIG_HOME": "/run/user/1000/cfg",
|
|
"XDG_DATA_HOME": "/run/user/1000/data",
|
|
}
|
|
with patch.dict(os.environ, env, clear=True):
|
|
assert paths.config_dir() == "/run/user/1000/cfg/voculinux"
|
|
assert paths.data_dir() == "/run/user/1000/data/voculinux"
|
|
assert paths.models_dir() == "/run/user/1000/data/voculinux/models"
|
|
|
|
def test_empty_env_falls_back_to_default(self):
|
|
# The XDG spec says empty values must be treated as unset.
|
|
with patch.dict(os.environ, {"XDG_CONFIG_HOME": "", "XDG_DATA_HOME": ""}, clear=True):
|
|
assert paths.xdg_config_home() == os.path.expanduser("~/.config")
|
|
assert paths.xdg_data_home() == os.path.expanduser("~/.local/share")
|
|
|
|
def test_flatpak_style_data_home(self):
|
|
# Flatpak points XDG_DATA_HOME at ~/.var/app/<app-id>/data.
|
|
flatpak_data = "/home/user/.var/app/com.voculinux.Voculinux/data"
|
|
with patch.dict(os.environ, {"XDG_DATA_HOME": flatpak_data}, clear=True):
|
|
assert paths.models_dir() == os.path.join(flatpak_data, "voculinux", "models")
|
|
|
|
def test_is_within_directory(self, tmp_path):
|
|
nested = tmp_path / "models" / "ggml-tiny.bin"
|
|
nested.parent.mkdir()
|
|
nested.write_bytes(b"x")
|
|
|
|
assert paths.is_within_directory(str(nested), str(tmp_path / "models"))
|
|
assert not paths.is_within_directory(str(tmp_path / "models"), str(tmp_path / "models"))
|
|
assert paths.is_within_directory(
|
|
str(tmp_path / "models"), str(tmp_path / "models"), allow_root=True
|
|
)
|
|
assert not paths.is_within_directory(str(tmp_path / "other"), str(tmp_path / "models"))
|
|
assert not paths.is_within_directory("/etc/passwd", str(tmp_path / "models"))
|
|
|
|
|
|
class TestCollapseRepeatedExtension:
|
|
def test_collapses_doubled_suffix(self) -> None:
|
|
assert paths.collapse_repeated_extension("a.txt.txt", ".txt") == "a.txt"
|
|
|
|
def test_keeps_single_suffix(self) -> None:
|
|
assert paths.collapse_repeated_extension("a.txt", ".txt") == "a.txt"
|
|
|
|
def test_keeps_no_suffix(self) -> None:
|
|
assert paths.collapse_repeated_extension("a", ".txt") == "a"
|
|
|
|
def test_case_insensitive_match(self) -> None:
|
|
assert paths.collapse_repeated_extension("a.TXT.txt", ".txt") == "a.TXT"
|
|
|
|
def test_full_path(self) -> None:
|
|
assert (
|
|
paths.collapse_repeated_extension("/home/u/dir/log.txt.txt", ".txt")
|
|
== "/home/u/dir/log.txt"
|
|
)
|