@@ -23,7 +23,9 @@ def test_setup_initializes_and_selects_english_model(monkeypatch, tmp_path: Path
2323 monkeypatch .setenv ("LANG" , "en_US.UTF-8" )
2424 monkeypatch .setattr (
2525 "hebb.cli.commands.setup.prefetch_model" ,
26- lambda model_id , workspace , hf_endpoint = None : workspace / "models" / model_id ,
26+ lambda model_id , workspace , hf_endpoint = None , progress_callback = None , suppress_native_progress = False : (
27+ workspace / "models" / model_id
28+ ),
2729 )
2830 monkeypatch .setattr ("hebb.cli.commands.setup._verify_model" , lambda model_id , hf_endpoint : 384 )
2931
@@ -46,7 +48,9 @@ def test_setup_initializes_and_selects_chinese_model(monkeypatch, tmp_path: Path
4648 monkeypatch .setenv ("LANG" , "zh_CN.UTF-8" )
4749 monkeypatch .setattr (
4850 "hebb.cli.commands.setup.prefetch_model" ,
49- lambda model_id , workspace , hf_endpoint = None : workspace / "models" / model_id ,
51+ lambda model_id , workspace , hf_endpoint = None , progress_callback = None , suppress_native_progress = False : (
52+ workspace / "models" / model_id
53+ ),
5054 )
5155 monkeypatch .setattr ("hebb.cli.commands.setup._verify_model" , lambda model_id , hf_endpoint : 384 )
5256
@@ -68,7 +72,9 @@ def test_setup_best_profile_selects_bge_english(monkeypatch, tmp_path: Path) ->
6872 monkeypatch .setenv ("LANG" , "en_US.UTF-8" )
6973 monkeypatch .setattr (
7074 "hebb.cli.commands.setup.prefetch_model" ,
71- lambda model_id , workspace , hf_endpoint = None : workspace / "models" / model_id ,
75+ lambda model_id , workspace , hf_endpoint = None , progress_callback = None , suppress_native_progress = False : (
76+ workspace / "models" / model_id
77+ ),
7278 )
7379 monkeypatch .setattr ("hebb.cli.commands.setup._verify_model" , lambda model_id , hf_endpoint : 1024 )
7480
@@ -88,7 +94,9 @@ def test_setup_explicit_language_and_region_are_independent(monkeypatch, tmp_pat
8894 monkeypatch .setenv ("HEBB_HOME" , str (home ))
8995 monkeypatch .setattr (
9096 "hebb.cli.commands.setup.prefetch_model" ,
91- lambda model_id , workspace , hf_endpoint = None : workspace / "models" / model_id ,
97+ lambda model_id , workspace , hf_endpoint = None , progress_callback = None , suppress_native_progress = False : (
98+ workspace / "models" / model_id
99+ ),
92100 )
93101 monkeypatch .setattr ("hebb.cli.commands.setup._verify_model" , lambda model_id , hf_endpoint : 384 )
94102
@@ -118,7 +126,9 @@ def test_setup_keeps_custom_model_without_explicit_language(monkeypatch, tmp_pat
118126
119127 monkeypatch .setattr (
120128 "hebb.cli.commands.setup.prefetch_model" ,
121- lambda model_id , workspace , hf_endpoint = None : workspace / "models" / model_id ,
129+ lambda model_id , workspace , hf_endpoint = None , progress_callback = None , suppress_native_progress = False : (
130+ workspace / "models" / model_id
131+ ),
122132 )
123133 monkeypatch .setattr ("hebb.cli.commands.setup._verify_model" , lambda model_id , hf_endpoint : 777 )
124134 result = runner .invoke (setup_cmd , ["--region" , "global" ])
@@ -155,11 +165,52 @@ def _fail_prefetch(*args: object, **kwargs: object) -> Path:
155165 assert result .exit_code == 0 , result .output
156166 assert called ["prefetch" ] is False
157167 assert "Model already present" in result .output
168+ assert "Downloading embedding model" not in result .output
158169 config = json .loads ((home / "hebb.json" ).read_text ())
159170 assert config ["embedding_model" ] == "sentence-transformers/all-MiniLM-L6-v2"
160171 assert config ["embedding_dim" ] == 384
161172
162173
174+ def test_setup_renders_live_download_progress (monkeypatch , tmp_path : Path ) -> None :
175+ home = tmp_path / "home"
176+ monkeypatch .setenv ("HEBB_HOME" , str (home ))
177+ _clear_locale_env (monkeypatch )
178+ monkeypatch .setenv ("LANG" , "en_US.UTF-8" )
179+ monkeypatch .setattr ("hebb.cli.commands.setup.workspace_model_available" , lambda workspace , model_id : False )
180+
181+ callback_received = False
182+
183+ def fake_prefetch (
184+ model_id : str ,
185+ workspace : Path ,
186+ hf_endpoint : str | None = None ,
187+ progress_callback = None ,
188+ suppress_native_progress : bool = False ,
189+ ) -> Path :
190+ nonlocal callback_received
191+ assert progress_callback is not None
192+ assert suppress_native_progress is True
193+ callback_received = True
194+ progress_callback (512 , 1024 , "model.safetensors" )
195+ progress_callback (1024 , 1024 , "model.safetensors" )
196+ progress_callback (12 , 12 , "Fetching 12 files" )
197+ return workspace / "models" / model_id
198+
199+ monkeypatch .setattr ("hebb.cli.commands.setup.prefetch_model" , fake_prefetch )
200+ monkeypatch .setattr ("hebb.cli.commands.setup._verify_model" , lambda model_id , hf_endpoint : 384 )
201+
202+ runner = CliRunner ()
203+ with runner .isolated_filesystem (temp_dir = tmp_path ):
204+ result = runner .invoke (setup_cmd , ["--region" , "global" ])
205+
206+ assert result .exit_code == 0 , result .output
207+ assert callback_received is True
208+ assert "model.safetensors" in result .output
209+ assert "small ~90MB" in result .output
210+ assert "100%" in result .output
211+ assert "Fetching 12 files" not in result .output
212+
213+
163214def test_initialize_workspace_uses_hebb_home (monkeypatch , tmp_path : Path ) -> None :
164215 home = tmp_path / "home"
165216 monkeypatch .setenv ("HEBB_HOME" , str (home ))
0 commit comments