refactor: move bot_bottle_root/host_db_path to paths; kill the monkeypatch (#352)
Create bot_bottle/paths.py as the canonical home for the app-root path helpers (bot_bottle_root, host_db_path, HOST_DB_FILENAME) — foundational, not supervise- or db-specific. `bot_bottle_root()` now honours a BOT_BOTTLE_ROOT env override. Repoint every consumer (supervise, supervise_types, db_store, queue_store, audit_store, store_manager, bottle_state, cli/supervise, docker/cleanup, orchestrator/registry) at paths; remove the definitions (and supervise's duplicate host_db_path) and the now-dead `import sys`. Add paths.py to the sidecar bundle (Dockerfile.sidecars) for the flat-import copies. Tests: replace ~12 files' monkeypatching of supervise.bot_bottle_root (and the flat/pkg/supervise_types triple-patch dance) with a single `use_bottle_root()` helper that sets BOT_BOTTLE_ROOT — every module and flat/package copy reads the same env var, so one override covers them all. Net -97 lines. Behaviour-preserving: full unit suite unchanged (only the pre-existing /bin/sleep sidecar-init errors remain). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WBMWTEtQdJ4W5UrWuLHCck
This commit is contained in:
+21
-2
@@ -10,8 +10,12 @@ and unisolated tests otherwise pollute the developer's home dir.
|
||||
|
||||
Individual tests that need their own ``HOME`` still override
|
||||
``os.environ['HOME']`` and restore it; they now restore to this isolated
|
||||
dir rather than the real one, so isolation holds either way. Tests that
|
||||
patch ``supervise.bot_bottle_root`` directly are unaffected.
|
||||
dir rather than the real one, so isolation holds either way.
|
||||
|
||||
Tests that need their own app-data root call ``use_bottle_root`` (below),
|
||||
which sets ``BOT_BOTTLE_ROOT`` — the supported override read by
|
||||
``paths.bot_bottle_root`` — instead of monkey-patching. One env setting
|
||||
covers every module and every flat/package copy of the helper.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -20,6 +24,9 @@ import atexit
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
_real_home = os.environ.get("HOME")
|
||||
_tmp_home = tempfile.mkdtemp(prefix="bot-bottle-unit-home.")
|
||||
@@ -35,3 +42,15 @@ def _restore_home() -> None:
|
||||
|
||||
|
||||
atexit.register(_restore_home)
|
||||
|
||||
|
||||
def use_bottle_root(root: Path) -> Callable[[], None]:
|
||||
"""Redirect ``paths.bot_bottle_root()`` to ``root`` by setting
|
||||
``BOT_BOTTLE_ROOT`` — the supported override. Returns a callable that
|
||||
undoes it (store it as the test's restore hook, or pass to addCleanup).
|
||||
|
||||
Replaces monkey-patching ``supervise.bot_bottle_root``; one env var
|
||||
covers every module and the flat/package copies alike (they all read it)."""
|
||||
patcher = mock.patch.dict(os.environ, {"BOT_BOTTLE_ROOT": str(root)})
|
||||
patcher.start()
|
||||
return patcher.stop
|
||||
|
||||
Reference in New Issue
Block a user