Expose Python facade document sync

This commit is contained in:
Meta Vens 2026-06-27 22:58:50 +01:00
commit 1885e2244a
3 changed files with 43 additions and 7 deletions

View file

@ -383,7 +383,13 @@ client.sync_peer_catalog(peers, verse_id="python-interop", roles=["read-replica"
client.fanout_peer_catalog(peers, verse_id="python-interop", roles=["read-replica"])
raw_client = CultNetRawClient("127.0.0.1", 3075)
node.database.sync_snapshot(raw_client, schema_ids=[note_doc.catalog_entry().schema_id])
synced_note = node.database.sync_document(raw_client, note_doc, "note:remote")
synced_stock = CultMesh.sync_document(
node,
raw_client,
station_stock_ui_doc,
"station:starbridge:stock",
)
node.database.sync_shard_log(raw_client, shard_id="interop", shard_epoch=1)
replicator = CultNetShardReplicator(
node.database,

View file

@ -7,6 +7,7 @@ from pathlib import Path
from typing import Any
from urllib.parse import urlparse
from cultcache_py.documents import DocumentDefinition
from cultnet_py import (
CultNetRawClient,
CultNetReconnectPolicy,
@ -273,6 +274,24 @@ class CultMesh:
def create_simulation_fact_committer(node: CultMeshNode) -> CultMeshSimulationFactCommitter:
return CultMeshSimulationFactCommitter(node)
@staticmethod
def sync_document(
node: CultMeshNode,
client: CultNetRawClient,
document: DocumentDefinition[Any],
key: str,
*,
shard_id: str | None = None,
shard_epoch: int | None = None,
) -> Any:
return node.sync_document(
client,
document,
key,
shard_id=shard_id,
shard_epoch=shard_epoch,
)
@staticmethod
def create_game_session(
node: CultMeshNode,

View file

@ -2113,17 +2113,28 @@ class CultCacheTests(unittest.TestCase):
}
synced = node.sync_document(SnapshotClient(), alias, "note:remote")
facade_synced = CultMesh.sync_document(node, SnapshotClient(), alias, "note:remote")
self.assertIsInstance(synced, UiNote)
self.assertEqual(synced.body, "synced-alias")
self.assertIsInstance(facade_synced, UiNote)
self.assertEqual(facade_synced.body, "synced-alias")
self.assertEqual(node.get_required(document, "note:remote").body, "synced-alias")
self.assertIsInstance(node.get_required(alias, "note:remote"), UiNote)
self.assertEqual(requests, [{
"schema_ids": ["mesh.sync_alias_note.v1"],
"record_keys": ["note:remote"],
"shard_id": None,
"shard_epoch": None,
}])
self.assertEqual(requests, [
{
"schema_ids": ["mesh.sync_alias_note.v1"],
"record_keys": ["note:remote"],
"shard_id": None,
"shard_epoch": None,
},
{
"schema_ids": ["mesh.sync_alias_note.v1"],
"record_keys": ["note:remote"],
"shard_id": None,
"shard_epoch": None,
},
])
def test_cultmesh_node_emits_raw_put_and_delete_messages_for_local_writes(self) -> None:
document = define_database_entry_type(