refactor(topology): introduce TopologyRepository protocol with DTO return types

Replace repo: BaseRepository with a structural TopologyRepository protocol
in persistence.py and allocator.py. All read methods now return typed DTOs
(TopologySummary, LANRow, DeckyRow, EdgeRow) instead of raw dicts, eliminating
silent field-shape regressions across the topology subsystem.

TopologySummary gains email_personas and language_default so api_personas.py
can continue reading those fields via attribute access. hydrate() converts
DTOs to dicts before passing to _backfill_decky_configs, keeping the mutable
working-state function dict-based at its boundary. All production callers
(router handlers, mutator, CLI, heartbeat) migrated from dict/get access to
attribute access. 134 tests pass.
This commit is contained in:
2026-04-30 23:51:41 -04:00
parent 3456d3ab45
commit fc1f0914b7
34 changed files with 231 additions and 175 deletions

View File

@@ -54,13 +54,13 @@ async def list_topology_personas(
topo = await repo.get_topology(topology_id)
if topo is None:
raise HTTPException(status_code=404, detail="Topology not found")
language_default = topo.get("language_default") or "en"
language_default = topo.language_default or "en"
personas = parse_personas(
topo.get("email_personas"), language_default=language_default,
topo.email_personas, language_default=language_default,
)
return {
"topology_id": topology_id,
"topology_name": topo.get("name", ""),
"topology_name": topo.name,
"language_default": language_default,
"personas": _serialize(personas),
}
@@ -100,7 +100,7 @@ async def replace_topology_personas(
topo = await repo.get_topology(topology_id)
if topo is None:
raise HTTPException(status_code=404, detail="Topology not found")
language_default = topo.get("language_default") or "en"
language_default = topo.language_default or "en"
parsed = parse_personas(raw, language_default=language_default)
if raw and not parsed:
@@ -125,7 +125,7 @@ async def replace_topology_personas(
)
return {
"topology_id": topology_id,
"topology_name": topo.get("name", ""),
"topology_name": topo.name,
"language_default": language_default,
"personas": serialized,
}