Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

fix(docs): stop a text annotation being read as a device's zone

Pouzor5b06a1b8c9fe
diff --git a/backend/app/api/routes/documents.py b/backend/app/api/routes/documents.py
index 6a37230..a91521a 100644
--- a/backend/app/api/routes/documents.py
+++ b/backend/app/api/routes/documents.py
@@ -60,9 +60,12 @@ from app.services.doc_tree import (
router = APIRouter()
-# Node.type values that are canvas furniture. A zone or a group is documented
-# through its node; everything else is documented through its device.
-_FURNITURE_TYPES = {"group", "groupRect", "text"}
+# The furniture a device can sit *in*, and so be located by. Deliberately not
+# `inventory_sync.FURNITURE_TYPES`, which answers a different question: a `text`
+# annotation is furniture — it draws no device — but it is a caption, not a
+# place, and its content is nobody's zone name (#446). A device parented in one
+# keeps walking up to the zone that really holds it, if there is one.
+_ZONE_TYPES = {"group", "groupRect"}
_INTERVAL = re.compile(r"^\s*(\d+)\s*([dwmy])\s*$", re.IGNORECASE)
_INTERVAL_DAYS = {"d": 1, "w": 7, "m": 30, "y": 365}
@@ -150,7 +153,7 @@ async def _device_context(db: AsyncSession, device_id: str) -> dict[str, Any]:
parent = await db.get(Node, parent_id)
if parent is None:
break
- if parent.type in _FURNITURE_TYPES:
+ if parent.type in _ZONE_TYPES:
context["zone_label"] = parent.label
break
parent_id = parent.parent_id
diff --git a/backend/app/api/routes/nodes.py b/backend/app/api/routes/nodes.py
index a383402..d25c736 100644
--- a/backend/app/api/routes/nodes.py
+++ b/backend/app/api/routes/nodes.py
@@ -204,6 +204,19 @@ async def update_node(
# Dropped rather than rejected so the rest of the edit still lands.
if sent.get("parent_id") == node_id:
sent.pop("parent_id")
+ # A `text` annotation is a caption, not a container. The canvas never nests
+ # anything under one, but the API is reachable without it (MCP write tools,
+ # scripts), and a device that lands there is read back as being *in* the
+ # annotation — its content is printed as the device's zone in the generated
+ # document (#446). Rejected rather than dropped: unlike a self-parent this is
+ # a wrong argument, not a slip, and the caller should hear about it.
+ if sent.get("parent_id"):
+ parent = await db.get(Node, sent["parent_id"])
+ if parent is not None and parent.type == "text":
+ raise HTTPException(
+ status_code=status.HTTP_400_BAD_REQUEST,
+ detail="A text annotation cannot be a parent node",
+ )
# Before the new counts land: the old ones are what says which handles go away.
await _remap_shrunk_handles(db, node, sent)
for field, value in node_columns(sent).items():
diff --git a/backend/tests/test_documents.py b/backend/tests/test_documents.py
index 29e3fa9..f0bbcf6 100644
--- a/backend/tests/test_documents.py
+++ b/backend/tests/test_documents.py
@@ -211,6 +211,83 @@ async def test_a_device_document_records_its_zone_and_neighbours(client: AsyncCl
assert "`switch-core`" in doc["body"]
+async def test_a_text_annotation_is_never_read_as_a_zone(client: AsyncClient, headers: dict):
+ """A device parented in a text annotation has no zone, not the caption (#446).
+
+ The annotation's content is arbitrary user text; printed as `zone_label` it
+ is indistinguishable from a real zone in the Physical Location section.
+ """
+ design_id = await _design(client, headers)
+ device = await _device(client, headers)
+ annotation = await client.post(
+ "/api/v1/nodes",
+ json={"type": "text", "label": "\u26a0 maintenance zone", "design_id": design_id, "pos_x": 0, "pos_y": 0},
+ headers=headers,
+ )
+ node = await client.post(
+ "/api/v1/nodes",
+ json={
+ "type": "nas",
+ "label": "nas-01",
+ "design_id": design_id,
+ "ip": "192.168.1.20",
+ "hostname": "nas-01.lan",
+ "parent_id": annotation.json()["id"],
+ "pos_x": 0,
+ "pos_y": 0,
+ },
+ headers=headers,
+ )
+ # Without the link there is no node to walk up from and the test would pass
+ # on nothing at all.
+ assert node.json()["device_id"] == device["id"], node.text
+
+ doc = await _create(client, headers, title="nas-01", kind="device", device_id=device["id"])
+ assert "maintenance zone" not in doc["body"]
+ assert "Zone **" not in doc["body"]
+
+
+async def test_a_zone_above_a_text_annotation_still_names_the_device(client: AsyncClient, headers: dict):
+ """Skipping the annotation means walking past it, not giving up (#446)."""
+ design_id = await _design(client, headers)
+ device = await _device(client, headers)
+ zone = await client.post(
+ "/api/v1/nodes",
+ json={"type": "groupRect", "label": "Garage", "design_id": design_id, "pos_x": 0, "pos_y": 0},
+ headers=headers,
+ )
+ annotation = await client.post(
+ "/api/v1/nodes",
+ json={
+ "type": "text",
+ "label": "\u26a0 maintenance",
+ "design_id": design_id,
+ "parent_id": zone.json()["id"],
+ "pos_x": 0,
+ "pos_y": 0,
+ },
+ headers=headers,
+ )
+ node = await client.post(
+ "/api/v1/nodes",
+ json={
+ "type": "nas",
+ "label": "nas-01",
+ "design_id": design_id,
+ "ip": "192.168.1.20",
+ "hostname": "nas-01.lan",
+ "parent_id": annotation.json()["id"],
+ "pos_x": 0,
+ "pos_y": 0,
+ },
+ headers=headers,
+ )
+ assert node.json()["device_id"] == device["id"], node.text
+
+ doc = await _create(client, headers, title="nas-01", kind="device", device_id=device["id"])
+ assert "Zone **Garage**." in doc["body"]
+
+
# ── blocks ──────────────────────────────────────────────────────────────────
diff --git a/backend/tests/test_nodes.py b/backend/tests/test_nodes.py
index d17e977..acdea17 100644
--- a/backend/tests/test_nodes.py
+++ b/backend/tests/test_nodes.py
@@ -443,6 +443,40 @@ async def test_update_node_self_parent_leaves_a_real_parent_alone(client: AsyncC
assert res.json()["parent_id"] == host_id
+# ── text-parent guard (#446) ─────────────────────────────────────────────────
+
+async def test_update_node_refuses_a_text_annotation_as_parent(client: AsyncClient, headers: dict):
+ annotation = await client.post(
+ "/api/v1/nodes", json={"type": "text", "label": "\u26a0 maintenance zone"}, headers=headers
+ )
+ node = await client.post("/api/v1/nodes", json={"type": "nas", "label": "nas1"}, headers=headers)
+
+ res = await client.patch(
+ f"/api/v1/nodes/{node.json()['id']}",
+ json={"parent_id": annotation.json()["id"], "label": "renamed"},
+ headers=headers,
+ )
+
+ assert res.status_code == 400
+ assert "text annotation" in res.json()["detail"]
+ # Rejected whole: unlike the self-parent slip, the rest of the edit does not land.
+ read = await client.get(f"/api/v1/nodes/{node.json()['id']}", headers=headers)
+ assert read.json()["parent_id"] is None
+ assert read.json()["label"] == "nas1"
+
+
+async def test_update_node_still_accepts_a_group_as_parent(client: AsyncClient, headers: dict):
+ group = await client.post("/api/v1/nodes", json={"type": "groupRect", "label": "Garage"}, headers=headers)
+ node = await client.post("/api/v1/nodes", json={"type": "nas", "label": "nas1"}, headers=headers)
+
+ res = await client.patch(
+ f"/api/v1/nodes/{node.json()['id']}", json={"parent_id": group.json()["id"]}, headers=headers
+ )
+
+ assert res.status_code == 200
+ assert res.json()["parent_id"] == group.json()["id"]
+
+
# ── furniture descriptions ───────────────────────────────────────────────────
async def test_create_and_update_a_group_description(client: AsyncClient, headers: dict):