okami.mom/strata

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

Niko1221Merge f-022-ownfiles: own GGUF files load again, plain download/prepare steps, chosen models folderc7938c2d3

main
2.5 KiB57 linesraw
1"""Terminal polish (0.2.1): "already downloaded" instead of a fake download, and `strata monitor` finding a running launch."""
2
3import io
4import json
5import os
6import unittest
7from contextlib import redirect_stdout
8from unittest import mock
9
10from strata_cli.cli import main
11from strata_cli.launch.runner import download_text
12
13
14class AlreadyDownloaded(unittest.TestCase):
15    def test_a_model_on_disk_is_not_called_a_download(self):
16        dl = {"done_gb": 58.5, "total_gb": 58.5, "percent": 100.0}
17        self.assertEqual(download_text(dl, True), "The model files are already on this computer (58.5 GB); checking them")
18
19    def test_a_real_download_keeps_its_numbers(self):
20        dl = {"done_gb": 12.0, "total_gb": 58.5, "percent": 20.5}
21        self.assertEqual(download_text(dl, False), "Downloading 12.0 of 58.5 GB")
22        self.assertEqual(download_text(dl, False, "Downloading the draft layer"), "Downloading the draft layer: 12.0 of 58.5 GB")
23
24
25class MonitorFindsLaunch(unittest.TestCase):
26    def _run(self, argv, info, env=None):
27        with mock.patch.dict(os.environ, env or {}, clear=False), \
28                mock.patch("strata_cli.launch.cmd.launch_info", return_value=info), \
29                mock.patch("strata_cli.monitor_commands.Endpoint") as endpoint:
30            os.environ.pop("STRATA_URL", None) if not env else None
31            endpoint.return_value.snapshot.return_value = {"schema_version": 1}
32            out = io.StringIO()
33            with redirect_stdout(out):
34                main(argv)
35        return endpoint
36
37    def test_no_url_uses_the_running_launch_and_its_key(self):
38        info = {"running": True, "url": "http://127.0.0.1:8080", "key": "launch-key"}
39        with mock.patch.dict(os.environ, {}, clear=False):
40            os.environ.pop("STRATA_API_KEY", None)
41            endpoint = self._run(["monitor", "--once", "--quiet"], info)
42        args = endpoint.call_args[0]
43        self.assertEqual(args[0], "http://127.0.0.1:8080")
44        self.assertEqual(args[1], "launch-key")
45
46    def test_an_explicit_url_wins(self):
47        info = {"running": True, "url": "http://127.0.0.1:8080", "key": "k"}
48        endpoint = self._run(["monitor", "--once", "--quiet", "--url", "http://127.0.0.1:9999"], info)
49        self.assertEqual(endpoint.call_args[0][0], "http://127.0.0.1:9999")
50
51    def test_nothing_running_keeps_the_default_address(self):
52        endpoint = self._run(["monitor", "--once", "--quiet"], None)
53        self.assertEqual(endpoint.call_args[0][0], "http://127.0.0.1:8095")
54
55
56if __name__ == "__main__":
57    unittest.main()