|
22 | 22 | resolve_compose_flags = _mod.resolve_compose_flags |
23 | 23 | validate_core_recreate_ids = _mod.validate_core_recreate_ids |
24 | 24 | invalidate_compose_cache = _mod.invalidate_compose_cache |
| 25 | +_post_install_core_recreate = _mod._post_install_core_recreate |
25 | 26 |
|
26 | 27 |
|
27 | 28 | # --- _parse_mem_value --- |
@@ -321,6 +322,83 @@ def test_docker_compose_recreate_still_uses_no_deps(self): |
321 | 322 | ) |
322 | 323 |
|
323 | 324 |
|
| 325 | +# --- _post_install_core_recreate --- |
| 326 | +# |
| 327 | +# openclaw's compose.yaml adds OPENAI_API_BASE_URLS to open-webui as an overlay; |
| 328 | +# `docker compose up -d --no-deps openclaw` (used by _handle_install) won't |
| 329 | +# pick up overlay changes targeting already-running core services. Hence the |
| 330 | +# post-install recreate of open-webui whenever openclaw is installed. |
| 331 | + |
| 332 | + |
| 333 | +class TestPostInstallCoreRecreate: |
| 334 | + |
| 335 | + def test_openclaw_triggers_open_webui_recreate(self, monkeypatch): |
| 336 | + calls = [] |
| 337 | + |
| 338 | + def _fake_recreate(ids): |
| 339 | + calls.append(list(ids)) |
| 340 | + return True, "" |
| 341 | + |
| 342 | + monkeypatch.setattr(_mod, "docker_compose_recreate", _fake_recreate) |
| 343 | + _post_install_core_recreate("openclaw") |
| 344 | + assert calls == [["open-webui"]] |
| 345 | + |
| 346 | + def test_non_openclaw_service_is_noop(self, monkeypatch): |
| 347 | + calls = [] |
| 348 | + |
| 349 | + def _fake_recreate(ids): |
| 350 | + calls.append(list(ids)) |
| 351 | + return True, "" |
| 352 | + |
| 353 | + monkeypatch.setattr(_mod, "docker_compose_recreate", _fake_recreate) |
| 354 | + for svc in ("litellm", "n8n", "perplexica", "whisper", "comfyui"): |
| 355 | + _post_install_core_recreate(svc) |
| 356 | + assert calls == [] |
| 357 | + |
| 358 | + def test_recreate_failure_is_swallowed(self, monkeypatch): |
| 359 | + """Install must not fail if the post-install recreate errors — openclaw |
| 360 | + is already running; the overlay just won't take effect until a manual |
| 361 | + core restart.""" |
| 362 | + |
| 363 | + def _fake_recreate(_ids): |
| 364 | + return False, "docker compose exploded" |
| 365 | + |
| 366 | + monkeypatch.setattr(_mod, "docker_compose_recreate", _fake_recreate) |
| 367 | + # Must not raise |
| 368 | + _post_install_core_recreate("openclaw") |
| 369 | + |
| 370 | + |
| 371 | +class TestRunInstallCallsPostInstallRecreate: |
| 372 | + """Source-level check that the install closure calls |
| 373 | + _post_install_core_recreate after the "started" progress write. |
| 374 | +
|
| 375 | + The dynamic flow runs in a daemon thread + nested closure, which makes |
| 376 | + runtime mocking fragile (see TestInstallHookEnvAllowlist for the same |
| 377 | + reasoning). Source-level assertion is sufficient to lock the wiring.""" |
| 378 | + |
| 379 | + def _install_source(self): |
| 380 | + import inspect |
| 381 | + return inspect.getsource(_mod.AgentHandler._handle_install) |
| 382 | + |
| 383 | + def test_install_calls_post_install_core_recreate(self): |
| 384 | + src = self._install_source() |
| 385 | + assert "_post_install_core_recreate(service_id)" in src, ( |
| 386 | + "_run_install must invoke _post_install_core_recreate(service_id) " |
| 387 | + "after emitting the 'started' progress record" |
| 388 | + ) |
| 389 | + |
| 390 | + def test_recreate_is_after_started_progress_write(self): |
| 391 | + src = self._install_source() |
| 392 | + started_idx = src.find('"started"') |
| 393 | + recreate_idx = src.find("_post_install_core_recreate(") |
| 394 | + assert started_idx != -1, "expected 'started' progress write in _handle_install" |
| 395 | + assert recreate_idx != -1, "expected _post_install_core_recreate call in _handle_install" |
| 396 | + assert started_idx < recreate_idx, ( |
| 397 | + "_post_install_core_recreate must run AFTER the 'started' progress " |
| 398 | + "write so the client sees success even if the recreate fails" |
| 399 | + ) |
| 400 | + |
| 401 | + |
324 | 402 | # --- _handle_env_update --- |
325 | 403 |
|
326 | 404 |
|
|
0 commit comments