okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3b8dc8fa3
main
1"""The packaged Terminal (#4188 parts 2 and 3): setup.py without a CMakeLists.txt, and `strata install` handing setup its options. 2Nothing here starts an engine, downloads anything or reads the real profile.""" 3from __future__import annotations 4 5import os 6import subprocess 7import tempfile 8import unittest 9from pathlib import Path 10from unittest import mock 11 12import setup as S 13from strata_cli import cli 14 15 16class PackagedSetupWithoutCMake (unittest .TestCase ): 17"""#4188: the packaged Terminal ships VERSION and BUNDLE.json but no CMakeLists.txt.""" 18 19def test_source_version_is_zero_without_a_source_tree (self ): 20with tempfile .TemporaryDirectory ()as tmp ,mock .patch .object (S ,"ROOT" ,Path (tmp )): 21self .assertEqual (S .source_version (),"0" ) 22 (Path (tmp )/ "CMakeLists.txt" ).write_text ("project(strata VERSION 0.1.52 LANGUAGES C)\n" ,encoding = "utf-8" ) 23self .assertEqual (S .source_version (),"0.1.52" ) 24 (Path (tmp )/ "CMakeLists.txt" ).write_bytes (b"\xff\xfe\x00 not text" ) 25self .assertEqual (S .source_version (),"0" ) 26 27def test_prebuilt_bases_names_the_latest_release_when_there_is_no_source_tree (self ): 28with tempfile .TemporaryDirectory ()as tmp ,mock .patch .object (S ,"ROOT" ,Path (tmp )): 29self .assertEqual (S .prebuilt_bases (S .PREBUILT_URL ), [S .PREBUILT_URL ]) 30 (Path (tmp )/ "CMakeLists.txt" ).write_text ("project(strata VERSION 0.1.52)\n" ,encoding = "utf-8" ) 31bases = S .prebuilt_bases (S .PREBUILT_URL ) 32self .assertEqual (len (bases ),2 ) 33self .assertIn ("v0.1.52" ,bases [0 ]) 34self .assertEqual (S .prebuilt_bases ("https://example.org/engine" ), ["https://example.org/engine/" ]) 35 36def test_an_installed_engine_is_not_called_stale_just_because_there_is_no_source_to_compare (self ): 37with tempfile .TemporaryDirectory ()as tmp ,mock .patch .object (S ,"ROOT" ,Path (tmp )), \ 38mock .patch .object (S ,"binary_engine_version" ,return_value = "0.1.50" ): 39self .assertFalse (S .stale_binary ("x" )) 40 (Path (tmp )/ "CMakeLists.txt" ).write_text ("project(strata VERSION 0.1.52)\n" ,encoding = "utf-8" ) 41self .assertTrue (S .stale_binary ("x" )) 42 43 44class InstallForwardsSetupOptions (unittest .TestCase ): 45"""#4188: `strata install --source modelscope --family qwen ...` was refused by strata's own parser.""" 46 47def test_the_options_of_setup_go_behind_a_double_dash_and_update_stays_strata_s (self ): 48self .assertEqual (cli ._install_argv (["install" ,"--source" ,"modelscope" ,"--yes" ]), ["install" ,"--" ,"--source" ,"modelscope" ,"--yes" ]) 49self .assertEqual (cli ._install_argv (["install" ,"--family" ,"qwen" ,"--update" ]), ["install" ,"--update" ,"--" ,"--family" ,"qwen" ]) 50self .assertEqual (cli ._install_argv (["install" ]), ["install" ,"--" ]) 51self .assertEqual (cli ._install_argv (["install" ,"-h" ]), ["install" ,"-h" ]) 52self .assertEqual (cli ._install_argv (["status" ,"--source" ,"x" ]), ["status" ,"--source" ,"x" ]) 53self .assertEqual (cli ._install_argv ([]), []) 54 55def test_the_parser_hands_all_of_it_to_setup_in_order (self ): 56ap = cli .parser () 57for argv in (["install" ,"--source" ,"modelscope" ,"--family" ,"qwen" ,"--model" ,"IQ3_XXS" ,"--context" ,"32k" ,"--yes" ], 58 ["install" ,"--family" ,"qwen" ,"--yes" ], ["install" ,"--yes" ]): 59a ,extras = ap .parse_known_args (cli ._install_argv (argv )) 60self .assertEqual (extras , [],argv ) 61self .assertEqual ([x for x in a .setup_args if x != "--" ],argv [1 :],argv ) 62 63def test_main_runs_setup_with_every_option_and_in_order (self ): 64with tempfile .TemporaryDirectory ()as tmp : 65 (Path (tmp )/ "setup.py" ).write_text ("# stand-in\n" ,encoding = "utf-8" ) 66calls = [] 67with mock .patch .dict (os .environ , {"STRATA_INSTALL_DIR" :tmp }), \ 68mock .patch .object (subprocess ,"call" ,side_effect = lambda argv ,** kw :calls .append (argv )or 0 ): 69code = cli .main (["install" ,"--source" ,"modelscope" ,"--family" ,"qwen" ,"--model" ,"IQ3_XXS" ,"--context" ,"32k" ,"--yes" ]) 70self .assertEqual (code ,0 ) 71code = cli .main (["install" ,"--update" ,"--yes" ]) 72self .assertEqual (code ,0 ) 73self .assertEqual (calls [0 ][2 :], ["--setup" ,"--source" ,"modelscope" ,"--family" ,"qwen" ,"--model" ,"IQ3_XXS" ,"--context" ,"32k" ,"--yes" ]) 74self .assertEqual (calls [1 ][2 :], ["--update" ,"--yes" ]) 75 76 77if __name__ == "__main__" : 78unittest .main ()