From 9ad62d8177052bcdd35306774e627b5692939441 Mon Sep 17 00:00:00 2001 From: anti Date: Thu, 30 Apr 2026 22:09:26 -0400 Subject: [PATCH] fix(compose): name the topology_id prefix length constant topology_id[:8] appeared twice with no explanation. 8 chars is the git short-SHA convention; collision-safe within a single deployment's network namespace. --- decnet/topology/compose.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/decnet/topology/compose.py b/decnet/topology/compose.py index 0cb41357..7de8a86a 100644 --- a/decnet/topology/compose.py +++ b/decnet/topology/compose.py @@ -26,6 +26,10 @@ from decnet.services.registry import get_service _DEFAULT_BASE_IMAGE = "debian:bookworm-slim" +# 8 chars matches the git short-SHA convention; collision-safe within +# a single deployment's network namespace. +_TOPOLOGY_ID_PREFIX_LEN = 8 + _DOCKER_LOGGING = { "driver": "json-file", "options": {"max-size": "10m", "max-file": "5"}, @@ -34,12 +38,12 @@ _DOCKER_LOGGING = { def _network_name(topology_id: str, lan_name: str) -> str: """Docker network name for a given (topology, LAN) pair.""" - return f"decnet_t_{topology_id[:8]}_{lan_name.lower()}" + return f"decnet_t_{topology_id[:_TOPOLOGY_ID_PREFIX_LEN]}_{lan_name.lower()}" def _container_name(topology_id: str, decky_name: str) -> str: """Container name for a decky base in a topology.""" - return f"decnet_t_{topology_id[:8]}_{decky_name}" + return f"decnet_t_{topology_id[:_TOPOLOGY_ID_PREFIX_LEN]}_{decky_name}" def generate_topology_compose(hydrated: dict[str, Any]) -> dict: