refactor: consolidate writable-dir probe into decnet/paths.py

bus.factory and vectorstore.factory carried byte-identical copies of the
'env override -> writable runtime dir -> ~/.decnet fallback' probe. Move
it to decnet.paths.resolve_runtime_path and call it from both.

The mkdir-create variants (deployer topologies dir, _pid_dir candidate
iteration, personas_pool existence-precedence) are deliberately left
inline: they're different policies, not the same probe.
This commit is contained in:
2026-06-18 21:27:36 -04:00
parent 2ca6533666
commit 3ed6d5dfc6
4 changed files with 87 additions and 15 deletions

View File

@@ -20,6 +20,7 @@ import os
from typing import Any, cast
from decnet.bus.base import BaseBus
from decnet.paths import resolve_runtime_path
def get_bus(**kwargs: Any) -> BaseBus:
@@ -58,14 +59,12 @@ def _default_socket_path() -> str:
``RuntimeDirectory=decnet`` sets it up with the right perms; the home
fallback keeps dev boxes usable without systemd.
"""
explicit = os.environ.get("DECNET_BUS_SOCKET")
if explicit:
return explicit
runtime_dir = "/run/decnet"
if os.path.isdir(runtime_dir) and os.access(runtime_dir, os.W_OK):
return f"{runtime_dir}/bus.sock"
return os.path.expanduser("~/.decnet/bus.sock")
return resolve_runtime_path(
"bus.sock",
env_var="DECNET_BUS_SOCKET",
runtime_dir="/run/decnet",
user_fallback="~/.decnet/bus.sock",
)
def _maybe_wrap_telemetry(bus: BaseBus) -> BaseBus: