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

@@ -110,7 +110,7 @@ async def test_resync_agent_topology_pushes_current_hash(repo, fake_agent) -> No
assert hydrated["topology"]["id"] == tid
row = await repo.get_topology(tid)
assert row["status"] == TopologyStatus.ACTIVE # unchanged
assert row.status == TopologyStatus.ACTIVE # unchanged
@pytest.mark.anyio
@@ -133,7 +133,7 @@ async def test_reconcile_agent_resyncs_drains_flag(repo, fake_agent) -> None:
drained = await _mut_engine.reconcile_agent_resyncs(repo)
assert drained == 1
row = await repo.get_topology(tid)
assert row["needs_resync"] is False
assert row.needs_resync is False
assert len(fake_agent.instances) == 1
@@ -156,7 +156,7 @@ async def test_reconcile_retains_flag_on_push_failure(repo, monkeypatch) -> None
drained = await _mut_engine.reconcile_agent_resyncs(repo)
assert drained == 0
row = await repo.get_topology(tid)
assert row["needs_resync"] is True # still flagged — next tick retries
assert row.needs_resync is True # still flagged — next tick retries
@pytest.mark.anyio