feat(mesh): fleet role + shared config/presence KV (Phase 2)
- 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.
This commit is contained in:
@@ -95,6 +95,18 @@ class TestRegistrySerialization:
|
||||
assert bare.schedule is None
|
||||
assert bare.managed is False
|
||||
|
||||
def test_node_role_preserved(self) -> None:
|
||||
reg = NodeRegistry(
|
||||
node=NodeConfig(hostname="civil", role="authority"), deployed={}
|
||||
)
|
||||
restored = json_to_registry(registry_to_json(reg))
|
||||
assert restored.node.role == "authority"
|
||||
|
||||
def test_node_role_defaults_follower(self) -> None:
|
||||
reg = NodeRegistry(node=NodeConfig(hostname="n"), deployed={})
|
||||
restored = json_to_registry(registry_to_json(reg))
|
||||
assert restored.node.role == "follower"
|
||||
|
||||
def test_no_secrets_in_payload(self) -> None:
|
||||
"""env vars, run_cmd, and castle_root must never appear on the wire."""
|
||||
original = _make_registry()
|
||||
|
||||
30
castle-api/tests/test_nats_client.py
Normal file
30
castle-api/tests/test_nats_client.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""CastleNATSClient role gating — hermetic (no live NATS server needed).
|
||||
|
||||
The write-gate is checked before touching the KV bucket, so a follower is denied
|
||||
without any connection.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
from castle_core.registry import NodeConfig, NodeRegistry
|
||||
|
||||
from castle_api.nats_client import CastleNATSClient
|
||||
|
||||
|
||||
def _client(role: str) -> CastleNATSClient:
|
||||
reg = NodeRegistry(node=NodeConfig(hostname="n", role=role), deployed={})
|
||||
return CastleNATSClient("n", reg, servers="nats://localhost:4222")
|
||||
|
||||
|
||||
def test_role_property() -> None:
|
||||
assert _client("authority").role == "authority"
|
||||
assert _client("follower").role == "follower"
|
||||
|
||||
|
||||
def test_follower_cannot_write_shared_config() -> None:
|
||||
client = _client("follower")
|
||||
with pytest.raises(PermissionError):
|
||||
asyncio.run(client.put_shared_config("fleet/key", "value"))
|
||||
Reference in New Issue
Block a user