- add static 'role' (authority|follower) to NodeConfig/CastleConfig, wired from castle.yaml through the registry to the mesh wire; civil pinned authority - castle-presence: TTL KV bucket each node renews (churn signal); delete-on-stop - castle-config: authority-gated get/put + change-watch SSE (follower reconcile hook hangs off it) - bound the NATS drain on stop() so shutdown can't hang - tests: role config/registry round-trip, wire round-trip, role write-gating Single-node verified; follower reconcile pending the second node.
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
"""Fleet role (authority/follower) — config loading + registry round-trip."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
from castle_core.config import load_config
|
|
from castle_core.registry import (
|
|
NodeConfig,
|
|
NodeRegistry,
|
|
load_registry,
|
|
save_registry,
|
|
)
|
|
|
|
|
|
def _write_min_config(root: Path, role: str | None) -> None:
|
|
data: dict = {"gateway": {"port": 18000}}
|
|
if role is not None:
|
|
data["role"] = role
|
|
(root / "castle.yaml").write_text(yaml.safe_dump(data))
|
|
|
|
|
|
def test_role_defaults_to_follower(tmp_path: Path) -> None:
|
|
_write_min_config(tmp_path, None)
|
|
assert load_config(tmp_path).role == "follower"
|
|
|
|
|
|
def test_role_loaded_from_yaml(tmp_path: Path) -> None:
|
|
_write_min_config(tmp_path, "authority")
|
|
assert load_config(tmp_path).role == "authority"
|
|
|
|
|
|
def test_registry_role_round_trip(tmp_path: Path) -> None:
|
|
reg = NodeRegistry(
|
|
node=NodeConfig(hostname="civil", role="authority"), deployed={}
|
|
)
|
|
path = tmp_path / "registry.yaml"
|
|
save_registry(reg, path)
|
|
assert load_registry(path).node.role == "authority"
|
|
|
|
|
|
def test_registry_role_defaults_follower(tmp_path: Path) -> None:
|
|
"""A node with no explicit role round-trips as follower."""
|
|
reg = NodeRegistry(node=NodeConfig(hostname="n"), deployed={})
|
|
path = tmp_path / "registry.yaml"
|
|
save_registry(reg, path)
|
|
assert load_registry(path).node.role == "follower"
|