okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fd0e3766a
main
1"""The desktop app never adopts an older command-line Strata install (tester report 2026-10-17: the app wrote 2strata-gyro-gyro-s.log/.json into the tester's old T:\\Strata). The app points Control and the installer at a settings file of its 3own (STRATA_SETTINGS_FILE); the shared %APPDATA% / ~/.config file with the old install's folders is not read.""" 4 5import json 6import os 7import sys 8import tempfile 9import unittest 10from pathlib import Path 11from unittest import mock 12 13ROOT = Path (__file__ ).resolve ().parents [2 ] 14sys .path .insert (0 ,str (ROOT )) 15from strata_control import models # noqa: E402 16import setup as strata_setup # noqa: E402 17 18 19class AppIsolation (unittest .TestCase ): 20def setUp (self ): 21self .dir = tempfile .TemporaryDirectory () 22self .addCleanup (self .dir .cleanup ) 23base = Path (self .dir .name ) 24self .old = base / "T-Strata" 25self .old .mkdir () 26 (self .old / "strata-gyro-gyro-s.json" ).write_text (json .dumps ({"exe" :"strata.exe" ,"tokenizer" :"t" ,"args" : []})) 27shared = base / "appdata" / "Strata" 28shared .mkdir (parents = True ) 29 (shared / "settings.json" ).write_text (json .dumps ({"installs" : [str (self .old )],"data_dir" :str (base / "T-data" )})) 30 (base / "xdg" / "strata" ).mkdir (parents = True ) 31 (base / "xdg" / "strata" / "settings.json" ).write_text (json .dumps ({"installs" : [str (self .old )],"data_dir" :str (base / "T-data" )})) 32self .app_data = base / "app" / "Strata" 33self .app_data .mkdir (parents = True ) 34self .env = {"APPDATA" :str (base / "appdata" ),"XDG_CONFIG_HOME" :str (base / "xdg" ), 35"LOCALAPPDATA" :str (base / "local" ),"XDG_DATA_HOME" :str (base / "xdg-data" ),"STRATA_COMPONENTS_DIR" :"" } 36self .base = base 37self .terminal = base / "terminal" 38self .terminal .mkdir () 39 40def test_the_terminal_still_remembers_the_old_install (self ): 41with mock .patch .dict (os .environ ,self .env ),mock .patch .dict (os .environ , {},clear = False ),mock .patch .object (models ,"ROOT" ,self .terminal ): 42os .environ .pop ("STRATA_SETTINGS_FILE" ,None ) 43os .environ .pop ("STRATA_INSTALL_DIR" ,None ) 44self .assertEqual (models .resolve_install (), (self .old .resolve (),"remembered" )) 45 46def test_the_app_does_not (self ): 47env = {** self .env ,"STRATA_SETTINGS_FILE" :str (self .app_data / "app-settings.json" )} 48with mock .patch .dict (os .environ ,env ),mock .patch .object (models ,"ROOT" ,self .terminal ): 49os .environ .pop ("STRATA_INSTALL_DIR" ,None ) 50self .assertEqual (models .settings_path (),self .app_data / "app-settings.json" ) 51self .assertEqual (models .remembered_installs (), []) 52# no older install is adopted: with nothing of its own yet the app gets its own install folder (beside its components folder) 53found ,how = models .resolve_install () 54self .assertEqual (how ,"default" ) 55self .assertNotEqual (found ,self .old .resolve ()) 56self .assertEqual (strata_setup .settings_path (),self .app_data / "app-settings.json" ) 57self .assertEqual (strata_setup .load_settings (), {}) 58# the installer's own list of "other installs" has no sibling scan and no shared settings 59self .assertEqual (strata_setup .other_installs (strata_setup .load_settings ()), []) 60 61def test_saving_settings_goes_to_the_app_file_only (self ): 62env = {** self .env ,"STRATA_SETTINGS_FILE" :str (self .app_data / "app-settings.json" )} 63shared = self .base / "appdata" / "Strata" / "settings.json" 64before = shared .read_bytes () 65with mock .patch .dict (os .environ ,env ): 66strata_setup .save_settings ({"data_dir" :str (self .app_data / "data" )}) 67self .assertEqual (shared .read_bytes (),before ) 68self .assertIn ("data_dir" ,json .loads ((self .app_data / "app-settings.json" ).read_text ())) 69 70 71if __name__ == "__main__" : 72unittest .main ()