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

@@ -60,7 +60,7 @@ async def test_dry_run_writes_compose_and_preserves_pending(repo, tmp_path, monk
assert compose_path.exists(), "dry run must emit a compose file"
topo = await repo.get_topology(tid)
assert topo["status"] == TopologyStatus.PENDING, (
assert topo.status == TopologyStatus.PENDING, (
"dry run must not transition status"
)
@@ -85,7 +85,7 @@ async def test_deploy_failure_transitions_to_failed(repo, tmp_path, monkeypatch)
await deploy_topology(repo, tid)
topo = await repo.get_topology(tid)
assert topo["status"] == TopologyStatus.FAILED
assert topo.status == TopologyStatus.FAILED
events = await repo.list_topology_status_events(tid)
# Events are returned newest-first.
@@ -149,7 +149,7 @@ async def test_deploy_failure_rolls_back_created_networks(repo, tmp_path, monkey
assert set(fake.removed) == set(fake.created)
topo = await repo.get_topology(tid)
assert topo["status"] == TopologyStatus.FAILED
assert topo.status == TopologyStatus.FAILED
@pytest.mark.anyio
@@ -172,7 +172,7 @@ async def test_teardown_from_failed_marks_torn_down(repo, tmp_path, monkeypatch)
await teardown_topology(repo, tid)
topo = await repo.get_topology(tid)
assert topo["status"] == TopologyStatus.TORN_DOWN
assert topo.status == TopologyStatus.TORN_DOWN
def test_teardown_order_is_stable():