okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2e0f28e7d
main
1"""Tests for the model configs setup.py lists: the server keeps a config's Chat settings next to it as 2`strata-<model>.shared-settings.json`, which matches the configs' own `strata-*.json` but is not one (no exe, no 3args), so the start menu and the "set up like the last one" lookup must leave it out. 4 5python -m unittest tools.test_setup_configs 6""" 7from __future__import annotations 8 9import json 10import os 11import sys 12import tempfile 13import unittest 14from pathlib import Path 15from unittest import mock 16 17ROOT = Path (__file__ ).resolve ().parents [1 ] 18sys .path .insert (0 ,str (ROOT )) 19sys .path .insert (0 ,str (ROOT / "tools" )) 20import setup # noqa: E402 21 22CONFIG = {"exe" :"engine/strata.exe" ,"args" : ["--max-context" ,"131072" ]} 23SHARED = {"reasoning_effort" :"high" ,"temperature" :0.6 } 24 25 26def write (folder :Path ,name :str ,data :dict )-> Path : 27path = folder / name 28path .write_text (json .dumps (data ),encoding = "utf-8" ) 29return path 30 31 32class ModelConfigs (unittest .TestCase ): 33def setUp (self ): 34tmp = tempfile .TemporaryDirectory () 35self .addCleanup (tmp .cleanup ) 36self .dir = Path (tmp .name ) 37self .config = write (self .dir ,"strata-iq3_s.json" ,CONFIG ) 38self .shared = write (self .dir ,"strata-iq3_s.shared-settings.json" ,SHARED ) 39# previous_config also looks into the Strata folders next to this checkout: keep the real ones out 40patch = mock .patch .object (setup ,"other_installs" ,return_value = []) 41patch .start () 42self .addCleanup (patch .stop ) 43 44def test_the_start_menu_lists_the_config_but_not_its_shared_settings (self ): 45with mock .patch .object (setup ,"ROOT" ,self .dir ): 46self .assertEqual (setup .installed_configs (), [self .config ]) 47 48def test_the_last_config_of_another_install_is_never_its_shared_settings (self ): 49# the shared settings are written after the config (the first time Chat settings are saved), so they are 50# the newest strata-*.json there 51later = self .config .stat ().st_mtime + 60 52os .utime (self .shared , (later ,later )) 53self .assertEqual (setup .previous_config ([self .dir ], {}),self .config ) 54 55def test_a_folder_with_only_shared_settings_has_no_config (self ): 56self .config .unlink () 57with mock .patch .object (setup ,"ROOT" ,self .dir ): 58self .assertEqual (setup .installed_configs (), []) 59self .assertIsNone (setup .previous_config ([self .dir ], {})) 60 61 62if __name__ == "__main__" : 63unittest .main ()