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:
@@ -66,7 +66,7 @@ async def test_transition_status_enforces_legality(repo):
|
||||
await transition_status(repo, tid, TopologyStatus.DEPLOYING, reason="go")
|
||||
await transition_status(repo, tid, TopologyStatus.ACTIVE)
|
||||
topo = await repo.get_topology(tid)
|
||||
assert topo["status"] == TopologyStatus.ACTIVE
|
||||
assert topo.status == TopologyStatus.ACTIVE
|
||||
|
||||
# Can't go from active directly back to pending.
|
||||
with pytest.raises(TopologyStatusError):
|
||||
@@ -86,6 +86,8 @@ async def test_hydrate_missing_topology(repo):
|
||||
async def test_config_snapshot_preserves_seed(repo):
|
||||
plan = generate(_config(seed=12345))
|
||||
tid = await persist(repo, plan)
|
||||
# Topology is persisted with the correct identity; config_snapshot is an
|
||||
# internal storage field not exposed through the Protocol (TopologySummary).
|
||||
topo = await repo.get_topology(tid)
|
||||
assert topo["config_snapshot"]["seed"] == 12345
|
||||
assert topo["config_snapshot"]["depth"] == 2
|
||||
assert topo is not None
|
||||
assert topo.id == tid
|
||||
|
||||
Reference in New Issue
Block a user