okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-140' into f-140-j2e0f28e7d

main
2.4 KiB63 linesraw
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
5    python -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:
27    path = folder / name
28    path.write_text(json.dumps(data), encoding="utf-8")
29    return path
30
31
32class ModelConfigs(unittest.TestCase):
33    def setUp(self):
34        tmp = tempfile.TemporaryDirectory()
35        self.addCleanup(tmp.cleanup)
36        self.dir = Path(tmp.name)
37        self.config = write(self.dir, "strata-iq3_s.json", CONFIG)
38        self.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
40        patch = mock.patch.object(setup, "other_installs", return_value=[])
41        patch.start()
42        self.addCleanup(patch.stop)
43
44    def test_the_start_menu_lists_the_config_but_not_its_shared_settings(self):
45        with mock.patch.object(setup, "ROOT", self.dir):
46            self.assertEqual(setup.installed_configs(), [self.config])
47
48    def 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
51        later = self.config.stat().st_mtime + 60
52        os.utime(self.shared, (later, later))
53        self.assertEqual(setup.previous_config([self.dir], {}), self.config)
54
55    def test_a_folder_with_only_shared_settings_has_no_config(self):
56        self.config.unlink()
57        with mock.patch.object(setup, "ROOT", self.dir):
58            self.assertEqual(setup.installed_configs(), [])
59        self.assertIsNone(setup.previous_config([self.dir], {}))
60
61
62if __name__ == "__main__":
63    unittest.main()