okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
cd9745050
main
1"""Lane NET item 5: --model-path and the data folder Strata guesses from it (the folder above a `models` folder). Strata keeps its own files (the 2prepared data, the picture reader) there only when it can write there and it is not a Hugging Face cache; otherwise in the data folder every 3command agrees on, with one line saying so, instead of stopping with "Strata cannot write to ...". The finish marks of the person's own files go 4to Strata's own marks/ folder, never beside the files.""" 5 6from __future__import annotations 7 8import os 9import tempfile 10import unittest 11from pathlib import Path 12from unittest import mock 13 14import setup 15from strata_cli .launch import settings as S 16from strata_cli .launch .catalog import Catalog 17from strata_cli .launch .runner import Runner 18from strata_control import discovery 19from tests .terminal .launch_support import HW_12 ,Home ,catalog 20from tests .terminal .test_own_files import IQ3XXS ,gguf_bytes 21 22 23class Base (unittest .TestCase ): 24def setUp (self ): 25self .home = Home ().__enter__ () 26self .addCleanup (self .home .__exit__ ,None ,None ,None ) 27p = mock .patch .object (Catalog ,"hardware" ,lambda self ,fresh = False :dict (HW_12 ,disk_free_gb = 500.0 )) 28p .start () 29self .addCleanup (p .stop ) 30t = tempfile .TemporaryDirectory (prefix = "strata-netown-" ) 31self .addCleanup (t .cleanup ) 32self .base = Path (t .name ) 33 34def own (self ,folder :Path )-> Path : 35folder .mkdir (parents = True ,exist_ok = True ) 36for n in IQ3XXS : 37 (folder / n ).write_bytes (gguf_bytes (["IQ3_XXS" ])) 38return folder 39 40 41class HuggingFaceCache (Base ): 42def test_cache_layouts (self ): 43snap = self .base / "hub" / "models--unsloth--Qwen3.8-Flash-Next-GGUF" / "snapshots" / "38bb39ee" / "UD-Q4_K_XL" 44snap .mkdir (parents = True ) 45env = {"HOME" :str (self .base / "h" )} 46self .assertTrue (discovery .in_hf_cache (snap ,env )) 47self .assertTrue (discovery .in_hf_cache (self .base / "hub" ,env ),"a folder that holds models--* folders is a cache" ) 48self .assertTrue (discovery .in_hf_cache (self .base / "elsewhere" / "x" , {"HF_HOME" :str (self .base / "elsewhere" )})) 49self .assertFalse (discovery .in_hf_cache (self .base / "data" ,env )) 50 51def test_a_guessed_folder_inside_a_cache_is_not_used (self ): 52own = self .own (self .base / "hfhome" / "models" / "IQ3_XXS" ) 53first = own / IQ3XXS [0 ] 54self .assertEqual (discovery .prepared_beside (first )["data_dir" ],self .base / "hfhome" ) 55with mock .patch .dict (os .environ , {"HF_HOME" :str (self .base / "hfhome" )}): 56self .assertIsNone (discovery .writable_beside (first )) 57self .assertEqual (discovery .writable_beside (first ),self .base / "hfhome" ) 58 59 60@ unittest . skipIf ( os . name == "nt" or (hasattr( os , "geteuid" ) and os . geteuid () == 0 ), "a read-only folder needs POSIX permissions and no root" ) 61class ReadOnlyFolder (Base ): 62def test_launch_uses_the_data_folder_and_says_so (self ): 63top = self .base / "lender" 64own = self .own (top / "models" / "IQ3_XXS" ) 65os .chmod (top ,0o555 ) 66self .addCleanup (os .chmod ,top ,0o755 ) 67r = Runner (S .LaunchSettings (family = "qwen" ,model = "IQ3_XXS" ,vision = "off" ,mtp = "off" ,drafting = "off" ,context = 32768 ,model_path = str (own )), 68catalog = catalog (HW_12 )) 69self .assertIsNone (r .existing_data_dir (),"not the folder Strata cannot write to: setup's own data folder" ) 70self .assertEqual (r .beside_refused (),top ) 71self .assertNotIn ("--data-dir" ,r .setup_args ()) 72self .assertIn ("--gguf-dir" ,r .setup_args ()) 73 74def test_a_writable_folder_is_still_used (self ): 75top = self .base / "mine" 76own = self .own (top / "models" / "IQ3_XXS" ) 77r = Runner (S .LaunchSettings (family = "qwen" ,model = "IQ3_XXS" ,vision = "off" ,mtp = "off" ,drafting = "off" ,context = 32768 ,model_path = str (own )), 78catalog = catalog (HW_12 )) 79self .assertEqual (r .existing_data_dir (),top ) 80self .assertIsNone (r .beside_refused ()) 81 82 83class FinishMarks (Base ): 84def test_own_files_are_marked_in_stratas_folder (self ): 85own = self .own (self .base / "mine" / "IQ3_XXS" ) 86root = self .base / "strata" 87root .mkdir () 88shard = own / IQ3XXS [0 ] 89with mock .patch .object (setup ,"ROOT" ,root ),mock .patch .object (setup ,"_OWN_DIRS" , []): 90setup .own_files_in (own ) 91setup .mark (shard ,"whole" ) 92self .assertFalse (shard .with_name (shard .name + ".done" ).exists (),"nothing is written beside the person's files" ) 93self .assertTrue (setup .done (shard )) 94self .assertEqual (len (list ((root / "marks" ).glob ("*.done" ))),1 ) 95other = self .base / "data" / "x.gguf" 96other .parent .mkdir () 97other .write_bytes (b"x" ) 98setup .mark (other )# a download of Strata's own: beside it, as before 99self .assertTrue (other .with_name ("x.gguf.done" ).exists ()) 100 101 102if __name__ == "__main__" : 103unittest .main ()