@@ -185,3 +185,126 @@ def test_select_hardware_profile_skips_when_not_needed(monkeypatch):
185185 )
186186
187187 assert result is None
188+
189+
190+ def test_run_service_setup_openmemory_prefills_local_embeddings_from_backend (
191+ monkeypatch ,
192+ ):
193+ captured = {}
194+
195+ def fake_run (cmd , cwd , check , timeout ):
196+ captured ["cmd" ] = cmd
197+ return argparse .Namespace (returncode = 0 )
198+
199+ def mock_read_env_value (path , key ):
200+ if path == "backends/advanced/.env" :
201+ values = {
202+ "OPENAI_API_KEY" : "local-embeddings-key" ,
203+ "OPENAI_BASE_URL" : "http://host.docker.internal:11434/v1" ,
204+ "OPENAI_EMBEDDING_MODEL" : "nomic-embed-text" ,
205+ "OPENAI_EMBEDDING_DIMENSIONS" : "768" ,
206+ }
207+ return values .get (key )
208+ return None
209+
210+ monkeypatch .setattr (wizard , "check_service_exists" , lambda * _ : (True , "OK" ))
211+ monkeypatch .setattr (wizard , "read_env_value" , mock_read_env_value )
212+ monkeypatch .setattr (wizard .subprocess , "run" , fake_run )
213+
214+ ok = wizard .run_service_setup (
215+ service_name = "openmemory-mcp" ,
216+ selected_services = ["advanced" , "openmemory-mcp" ],
217+ )
218+
219+ assert ok is True
220+ cmd = captured ["cmd" ]
221+ assert "--embeddings-provider" in cmd
222+ provider_idx = cmd .index ("--embeddings-provider" ) + 1
223+ assert cmd [provider_idx ] == "local"
224+ assert "--embeddings-base-url" in cmd
225+ assert (
226+ cmd [cmd .index ("--embeddings-base-url" ) + 1 ]
227+ == "http://host.docker.internal:11434/v1"
228+ )
229+ assert "--embeddings-model" in cmd
230+ assert cmd [cmd .index ("--embeddings-model" ) + 1 ] == "nomic-embed-text"
231+ assert "--embeddings-api-key" in cmd
232+ assert cmd [cmd .index ("--embeddings-api-key" ) + 1 ] == "local-embeddings-key"
233+ assert "--embeddings-dimensions" in cmd
234+ assert cmd [cmd .index ("--embeddings-dimensions" ) + 1 ] == "768"
235+ assert "--openai-api-key" not in cmd
236+
237+
238+ def test_run_service_setup_openmemory_reuses_existing_local_config (monkeypatch ):
239+ captured = {}
240+
241+ def fake_run (cmd , cwd , check , timeout ):
242+ captured ["cmd" ] = cmd
243+ return argparse .Namespace (returncode = 0 )
244+
245+ def mock_read_env_value (path , key ):
246+ if path == "extras/openmemory-mcp/.env" :
247+ values = {
248+ "OPENMEMORY_EMBEDDINGS_PROVIDER" : "local" ,
249+ "OPENMEMORY_EMBEDDINGS_BASE_URL" : "http://local-embeddings:11434/v1" ,
250+ "OPENMEMORY_EMBEDDINGS_MODEL" : "mxbai-embed-large" ,
251+ "OPENMEMORY_EMBEDDINGS_API_KEY" : "existing-local-key" ,
252+ "OPENMEMORY_EMBEDDINGS_DIMENSIONS" : "1024" ,
253+ }
254+ return values .get (key )
255+ if path == "backends/advanced/.env" and key == "OPENAI_API_KEY" :
256+ return "unused-openai-key"
257+ return None
258+
259+ monkeypatch .setattr (wizard , "check_service_exists" , lambda * _ : (True , "OK" ))
260+ monkeypatch .setattr (wizard , "read_env_value" , mock_read_env_value )
261+ monkeypatch .setattr (wizard .subprocess , "run" , fake_run )
262+
263+ ok = wizard .run_service_setup (
264+ service_name = "openmemory-mcp" ,
265+ selected_services = ["advanced" , "openmemory-mcp" ],
266+ )
267+
268+ assert ok is True
269+ cmd = captured ["cmd" ]
270+ assert "--embeddings-provider" in cmd
271+ assert cmd [cmd .index ("--embeddings-provider" ) + 1 ] == "local"
272+ assert (
273+ cmd [cmd .index ("--embeddings-base-url" ) + 1 ]
274+ == "http://local-embeddings:11434/v1"
275+ )
276+ assert cmd [cmd .index ("--embeddings-model" ) + 1 ] == "mxbai-embed-large"
277+ assert cmd [cmd .index ("--embeddings-api-key" ) + 1 ] == "existing-local-key"
278+ assert cmd [cmd .index ("--embeddings-dimensions" ) + 1 ] == "1024"
279+
280+
281+ def test_run_service_setup_openmemory_falls_back_to_openai_key (monkeypatch ):
282+ captured = {}
283+
284+ def fake_run (cmd , cwd , check , timeout ):
285+ captured ["cmd" ] = cmd
286+ return argparse .Namespace (returncode = 0 )
287+
288+ def mock_read_env_value (path , key ):
289+ if path == "backends/advanced/.env" :
290+ values = {
291+ "OPENAI_API_KEY" : "sk-openai" ,
292+ "OPENAI_BASE_URL" : "https://api.openai.com/v1" ,
293+ }
294+ return values .get (key )
295+ return None
296+
297+ monkeypatch .setattr (wizard , "check_service_exists" , lambda * _ : (True , "OK" ))
298+ monkeypatch .setattr (wizard , "read_env_value" , mock_read_env_value )
299+ monkeypatch .setattr (wizard .subprocess , "run" , fake_run )
300+
301+ ok = wizard .run_service_setup (
302+ service_name = "openmemory-mcp" ,
303+ selected_services = ["advanced" , "openmemory-mcp" ],
304+ )
305+
306+ assert ok is True
307+ cmd = captured ["cmd" ]
308+ assert "--openai-api-key" in cmd
309+ assert cmd [cmd .index ("--openai-api-key" ) + 1 ] == "sk-openai"
310+ assert "--embeddings-provider" not in cmd
0 commit comments