diff --git a/packages/cultcache-py/PARITY.md b/packages/cultcache-py/PARITY.md index 723a2682..291ff0ec 100644 --- a/packages/cultcache-py/PARITY.md +++ b/packages/cultcache-py/PARITY.md @@ -89,9 +89,10 @@ CultCache, CultNet, and CultMesh. It is evidence, not confetti. endpoints, apply peer snapshots through a caller-owned database, run lightweight scheduled snapshot and simulation-observation fanout loops, probe peer-card endpoints for hello-level reachability, preserve hello capability - metadata on health results, run immediate scheduled health probes on start, - and upsert results into local catalogs with the same count-returning - ergonomics as the C# discovery clients. + metadata on health results including document types, message versions, and + mutation contracts, run immediate scheduled health probes on start, and + upsert results into local catalogs with the same count-returning ergonomics + as the C# discovery clients. - Python CultMesh facade: Exposes C#-matching client entrypoints for Verse discovery, peer exchange, raw CultNet client construction, local nodes, catalogs, sessions, streams, diff --git a/packages/cultcache-py/README.md b/packages/cultcache-py/README.md index 0043dc98..4656a0a6 100644 --- a/packages/cultcache-py/README.md +++ b/packages/cultcache-py/README.md @@ -327,6 +327,10 @@ path, so peers can read them through both snapshot and shard-log catch-up. Add `--verse-id` and one or more `--role` values to publish the launched endpoint in its own Verse and peer catalogs for discovery clients. +`CultMeshPeerHealthMonitor` probes peer-card endpoints with `cultnet.hello.v0` +and preserves the runtime id, display name, document types, message versions, +and mutation contracts reported by the peer. + ```python client = CultMesh.create_verse_discovery_client("127.0.0.1", 3075) diff --git a/packages/cultcache-py/src/cultmesh_py/client.py b/packages/cultcache-py/src/cultmesh_py/client.py index b2ae0baf..89a9b442 100644 --- a/packages/cultcache-py/src/cultmesh_py/client.py +++ b/packages/cultcache-py/src/cultmesh_py/client.py @@ -498,7 +498,9 @@ class CultMeshPeerHealth: runtime_id: str | None = None runtime_kind: str | None = None display_name: str | None = None + supported_document_types: tuple[str, ...] = () supported_message_versions: tuple[str, ...] = () + supported_mutation_contracts: tuple[dict[str, Any], ...] = () error: str | None = None @@ -599,11 +601,21 @@ class CultMeshPeerHealthMonitor: runtime_id=str(response.get("runtimeId") or ""), runtime_kind=_optional_string(response.get("runtimeKind")), display_name=_optional_string(response.get("displayName")), + supported_document_types=tuple( + str(value) + for value in response.get("supportedDocumentTypes") or () + if value is not None + ), supported_message_versions=tuple( str(value) for value in response.get("supportedMessageVersions") or () if value is not None ), + supported_mutation_contracts=tuple( + dict(value) + for value in response.get("supportedMutationContracts") or () + if isinstance(value, dict) + ), ) except Exception as error: return CultMeshPeerHealth( diff --git a/packages/cultcache-py/tests/test_cultcache.py b/packages/cultcache-py/tests/test_cultcache.py index d15a0595..6c06432d 100644 --- a/packages/cultcache-py/tests/test_cultcache.py +++ b/packages/cultcache-py/tests/test_cultcache.py @@ -2942,7 +2942,14 @@ class CultCacheTests(unittest.TestCase): self.assertEqual(target.database.get_required(document, "note:background")["body"], "from-background") def test_cultmesh_peer_health_monitor_probes_reachable_and_failed_endpoints(self) -> None: - server = CultMesh.serve_node(CultMesh.create_node(runtime_id="health-peer")) + document = define_database_entry_type( + "mesh.health_note", + [("body", 0)], + schema_id="mesh.health_note.v1", + ) + node = CultMesh.create_node(runtime_id="health-peer") + node.database.register_document(document) + server = CultMesh.serve_node(node) closed_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) closed_socket.bind(("127.0.0.1", 0)) closed_port = closed_socket.getsockname()[1] @@ -2977,11 +2984,16 @@ class CultCacheTests(unittest.TestCase): self.assertEqual(by_peer["health-peer"].runtime_id, "health-peer") self.assertEqual(by_peer["health-peer"].runtime_kind, "python") self.assertEqual(by_peer["health-peer"].display_name, "health-peer") + self.assertEqual(by_peer["health-peer"].supported_document_types, ("mesh.health_note",)) self.assertIn("cultnet.hello.v0", by_peer["health-peer"].supported_message_versions) self.assertIn("cultnet.error.v0", by_peer["health-peer"].supported_message_versions) + self.assertEqual(by_peer["health-peer"].supported_mutation_contracts[0]["documentType"], "mesh.health_note") + self.assertIn("shardLog", by_peer["health-peer"].supported_mutation_contracts[0]["operations"]) self.assertFalse(by_peer["closed-peer"].is_reachable) self.assertIsNone(by_peer["closed-peer"].runtime_kind) + self.assertEqual(by_peer["closed-peer"].supported_document_types, ()) self.assertEqual(by_peer["closed-peer"].supported_message_versions, ()) + self.assertEqual(by_peer["closed-peer"].supported_mutation_contracts, ()) self.assertTrue(by_peer["closed-peer"].error) self.assertEqual({peer_id for peer_id, _ in seen}, {"health-peer", "closed-peer"}) self.assertEqual(len(monitor.latest()), 2) @@ -3119,6 +3131,13 @@ class CultCacheTests(unittest.TestCase): self.assertEqual(peers[0].endpoints, (ready["endpoint"],)) self.assertEqual(peers[0].roles, ("shard-primary",)) self.assertEqual(peers[0].shard_ids, ("daemon-interop",)) + + monitor = CultMeshPeerHealthMonitor(runtime_id="daemon-health-prober", timeout_seconds=2.0) + health = monitor.probe_peer(peers[0])[0] + self.assertTrue(health.is_reachable) + self.assertEqual(health.runtime_id, "daemon-test-peer") + self.assertEqual(health.supported_document_types, ("cultcache.interop-note",)) + self.assertEqual(health.supported_mutation_contracts[0]["documentType"], "cultcache.interop-note") finally: process.terminate() try: