Keep beta profile isolated even when application bundle is renamed

This commit is contained in:
Vickenty Zherebov 2026-10-19 15:39:48 +03:00
parent 96c5e95683
commit c5bd2213c7
2 changed files with 17 additions and 2 deletions

View file

@ -3,10 +3,13 @@
from __future__ import annotations
import os
import re
import sys
from dataclasses import dataclass
from pathlib import Path
from voice_dictation import __version__
@dataclass(frozen=True, slots=True)
class AppPaths:
@ -40,8 +43,9 @@ class AppPaths:
AppPaths с путями в ~/.dictate/.
"""
override = os.environ.get("VOICE_DICTATION_HOME")
beta = bool(getattr(sys, "frozen", False)) and any(
parent.name == "Voice Dictation Beta.app" for parent in Path(sys.executable).parents
# Build identity must survive renaming or moving the .app bundle.
beta = bool(getattr(sys, "frozen", False)) and bool(
re.search(r"(?:a|b|rc|\.dev)\d", __version__)
)
root = (
Path(override).expanduser()

View file

@ -162,3 +162,14 @@ def test_checkpoint_model_change_is_rejected(tmp_paths):
recording, Config(transcription_backend="local", local_model="whisper-small")
)
orchestrator.shutdown()
def test_renamed_beta_bundle_still_cannot_use_production_profile(tmp_path, monkeypatch):
import sys
monkeypatch.delenv("VOICE_DICTATION_HOME", raising=False)
monkeypatch.setattr(Path, "home", lambda: tmp_path)
monkeypatch.setattr(sys, "frozen", True, raising=False)
monkeypatch.setattr(sys, "executable", "/tmp/Renamed.app/Contents/MacOS/VoiceDictation")
assert AppPaths.default().root == tmp_path / ".dictate-beta"
assert AppPaths.default().pid_file != tmp_path / ".dictate/dictate.pid"