Add Rust shard catalog helpers
This commit is contained in:
parent
9c21270f40
commit
3a8844be11
10 changed files with 434 additions and 1 deletions
|
|
@ -346,6 +346,13 @@ Current progress:
|
|||
contact hints. The facade delegates to the existing Rust RUDP socket
|
||||
transport; discovery contact remains separate from trust, which is still
|
||||
gated by the authority lease catalog.
|
||||
- Rust now also has substrate-shaped shard catalog helpers:
|
||||
`CultNetShardDescriptor`, `CultNetShardCatalog`, request filtering by schema
|
||||
id and record key, response creation, response application, and built-in
|
||||
schema registry entries for `cultnet.shard_catalog_request.v0` /
|
||||
`cultnet.shard_catalog_response.v0`. This gives Rust the same topology
|
||||
vocabulary without claiming stream catalog or production game-session server
|
||||
ownership.
|
||||
- The remaining parity work is to finish production service-body adoption
|
||||
behind the shared transport ports, then wire any remaining daemon/socket
|
||||
reconnect loops through the shared controller. C# built-in LiteNetLib service
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ CultMesh.
|
|||
| C# | Reference implementation and production game/server substrate | CultCache typed documents and SoA, CultNet schema-v0, LiteNetLib production path with adapter profile, shared transport profiles, shared RUDP socket transport, RUDP reconnect policy/controller and reconnect-loop helper, LiteNetLib client reconnect-controller adoption, schema-client transport port for service request/response clients, CultMesh node/session/catalog/stream/simulation surfaces | No need to abandon LiteNetLib before the CultNet adapter fully owns production service adoption |
|
||||
| Python | Package runtime, local daemon endpoint, raw interop peer, typed state participant | CultCache/CultNet/CultMesh package surface, schema catalogs, shard catalogs/logs, local TCP CultMesh server, session/prediction/simulation fact helpers, authority leases, streams, RUDP codec/session/socket transport, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence, benchmark evidence against C# cache paths | Universal C# throughput, full C# daemon/server stack, and RUDP as the only public service pipe |
|
||||
| TypeScript | Node/browser-adjacent projection and interop runtime | CultCache parity tests, CultNet schema-v0 peer, schema/shard catalog request/sync helpers, transport profiles, TCP-framed transport port and peer helper, shared RUDP socket transport, RUDP reconnect policy/controller, RUDP reconnect-loop helper, local CultMesh node/catalog/authority/stream ergonomics | Full C# game session/server stack |
|
||||
| Rust | Low-level cache/transport/runtime substrate | CultCache/CultNet interop lane, transport profiles, TCP-framed port, shared RUDP codec/session/socket transport, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence, small CultMesh facade for peer cards, authority leases, RUDP endpoint parsing, and peer-card RUDP client construction | Full CultMesh game-session/server facade, stream catalog, or production game-session server |
|
||||
| Rust | Low-level cache/transport/runtime substrate | CultCache/CultNet interop lane, schema and shard catalog helpers, transport profiles, TCP-framed port, shared RUDP codec/session/socket transport, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence, small CultMesh facade for peer cards, authority leases, RUDP endpoint parsing, and peer-card RUDP client construction | Full CultMesh game-session/server facade, stream catalog, or production game-session server |
|
||||
| Kotlin | JVM/Android client substrate | Typed MessagePack cache, schema/shard catalogs with shared schema-message transport fetch/sync helpers, authority leases, stream catalog, branded `CultMesh` facade, WebSocket transport profile/connection helper, RUDP client/server sugar, RUDP reconnect policy/controller and reconnect-loop helper, schema-v0 MessagePack over RUDP evidence | C# SoA store, full C# server daemon, or Unity hot-loop memory layout |
|
||||
|
||||
## Evidence Gates
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ The initial tests prove:
|
|||
- schema-versioned message round trips
|
||||
- legacy `gamecult.networking.v0` login mapping
|
||||
- schema discovery catalog responses with canonical JSON schema hashes
|
||||
- shard catalog request/response filtering and response application
|
||||
- CultCache snapshot replication through registered typed documents
|
||||
- raw snapshot replication that preserves the original payload bytes
|
||||
- document mutation contract advertisement through hello frames and registries
|
||||
|
|
@ -52,6 +53,7 @@ surface:
|
|||
- core wire messages
|
||||
- legacy `gamecult.networking.v0` auth/sample payloads
|
||||
- schema catalog request/response messages
|
||||
- shard catalog request/response messages
|
||||
- the canonical `ghostlight.agent-state` document payload schema
|
||||
|
||||
Use `builtin_schema_registry()` when you want the standard catalog, or register
|
||||
|
|
@ -60,6 +62,41 @@ explicit on purpose: peers advertise only the contracts they were compiled to
|
|||
understand, the same way CultCache only consumes the document types you
|
||||
registered instead of pretending polymorphism is a public park.
|
||||
|
||||
## Shard Catalogs
|
||||
|
||||
Rust now exposes the same shard topology vocabulary as the other runtimes
|
||||
without claiming to be the full C# service body:
|
||||
|
||||
```rust
|
||||
use cultnet_rs::{CultNetMessage, CultNetShardCatalog, CultNetShardDescriptor};
|
||||
|
||||
let mut catalog = CultNetShardCatalog::new();
|
||||
catalog.upsert(CultNetShardDescriptor {
|
||||
shard_id: "notes-a".to_string(),
|
||||
owner_runtime_id: "rust-primary".to_string(),
|
||||
epoch: 3,
|
||||
is_primary: Some(true),
|
||||
schema_ids: vec!["note.v0".to_string()],
|
||||
key_prefix: Some("note:".to_string()),
|
||||
primary_endpoints: vec!["rudp://127.0.0.1:4100".to_string()],
|
||||
replica_endpoints: vec![],
|
||||
read_replica_endpoints: vec![],
|
||||
region: None,
|
||||
authority_lease_id: None,
|
||||
})?;
|
||||
|
||||
let response = catalog.create_catalog_response(&CultNetMessage::ShardCatalogRequest {
|
||||
message_id: "discover-shards".to_string(),
|
||||
schema_ids: Some(vec!["note.v0".to_string()]),
|
||||
record_keys: Some(vec!["note:1".to_string()]),
|
||||
})?;
|
||||
```
|
||||
|
||||
`CultNetShardCatalog::apply_response(...)` imports remote
|
||||
`cultnet.shard_catalog_response.v0` descriptors into the local catalog. The
|
||||
catalog owns topology inspection only; shard-log serving, daemon policy, and
|
||||
game-session authority remain separate responsibilities.
|
||||
|
||||
## Local Fast Lane
|
||||
|
||||
`cultnet-rs` now mirrors the raw replication seam from `cultnet-ts`:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "cultnet.shard_catalog_request.v0",
|
||||
"type": "object",
|
||||
"required": ["schemaVersion", "messageId"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"schemaVersion": { "const": "cultnet.shard_catalog_request.v0" },
|
||||
"messageId": { "type": "string", "minLength": 1 },
|
||||
"schemaIds": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "minLength": 1 }
|
||||
},
|
||||
"recordKeys": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "minLength": 1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "cultnet.shard_catalog_response.v0",
|
||||
"type": "object",
|
||||
"required": ["schemaVersion", "messageId", "shards"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"schemaVersion": { "const": "cultnet.shard_catalog_response.v0" },
|
||||
"messageId": { "type": "string", "minLength": 1 },
|
||||
"shards": {
|
||||
"type": "array",
|
||||
"items": { "$ref": "#/$defs/shardDescriptor" }
|
||||
}
|
||||
},
|
||||
"$defs": {
|
||||
"shardDescriptor": {
|
||||
"type": "object",
|
||||
"required": ["shardId", "ownerRuntimeId", "epoch"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"shardId": { "type": "string", "minLength": 1 },
|
||||
"ownerRuntimeId": { "type": "string", "minLength": 1 },
|
||||
"epoch": { "type": "integer", "minimum": 0 },
|
||||
"isPrimary": { "type": "boolean" },
|
||||
"schemaIds": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "minLength": 1 }
|
||||
},
|
||||
"keyPrefix": { "type": "string", "minLength": 1 },
|
||||
"primaryEndpoints": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "minLength": 1 }
|
||||
},
|
||||
"replicaEndpoints": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "minLength": 1 }
|
||||
},
|
||||
"readReplicaEndpoints": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "minLength": 1 }
|
||||
},
|
||||
"region": { "type": "string", "minLength": 1 },
|
||||
"authorityLeaseId": { "type": "string", "minLength": 1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -195,6 +195,53 @@ pub struct CultNetSchemaDescriptor {
|
|||
pub schema_json: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CultNetShardDescriptor {
|
||||
pub shard_id: String,
|
||||
pub owner_runtime_id: String,
|
||||
pub epoch: u64,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub is_primary: Option<bool>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub schema_ids: Vec<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub key_prefix: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub primary_endpoints: Vec<String>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub replica_endpoints: Vec<String>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub read_replica_endpoints: Vec<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub region: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub authority_lease_id: Option<String>,
|
||||
}
|
||||
|
||||
impl CultNetShardDescriptor {
|
||||
pub fn serves(&self, schema_id: Option<&str>, record_key: Option<&str>) -> bool {
|
||||
if let Some(schema_id) = schema_id
|
||||
&& !self.schema_ids.is_empty()
|
||||
&& !self
|
||||
.schema_ids
|
||||
.iter()
|
||||
.any(|candidate| candidate == schema_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(record_key) = record_key
|
||||
&& let Some(prefix) = self.key_prefix.as_deref()
|
||||
&& !record_key.starts_with(prefix)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(tag = "schemaVersion")]
|
||||
pub enum CultNetMessage {
|
||||
|
|
@ -294,6 +341,19 @@ pub enum CultNetMessage {
|
|||
message_id: String,
|
||||
schemas: Vec<CultNetSchemaDescriptor>,
|
||||
},
|
||||
#[serde(rename = "cultnet.shard_catalog_request.v0", rename_all = "camelCase")]
|
||||
ShardCatalogRequest {
|
||||
message_id: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
schema_ids: Option<Vec<String>>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
record_keys: Option<Vec<String>>,
|
||||
},
|
||||
#[serde(rename = "cultnet.shard_catalog_response.v0", rename_all = "camelCase")]
|
||||
ShardCatalogResponse {
|
||||
message_id: String,
|
||||
shards: Vec<CultNetShardDescriptor>,
|
||||
},
|
||||
}
|
||||
|
||||
pub fn parse_cultnet_message(
|
||||
|
|
@ -485,6 +545,21 @@ fn validate_message(message: &CultNetMessage) -> Result<()> {
|
|||
validate_schema_descriptor(schema)?;
|
||||
}
|
||||
}
|
||||
CultNetMessage::ShardCatalogRequest {
|
||||
message_id,
|
||||
schema_ids,
|
||||
record_keys,
|
||||
} => {
|
||||
require_non_empty(message_id, "messageId")?;
|
||||
require_optional_string_vec(schema_ids.as_deref(), "schemaIds")?;
|
||||
require_optional_string_vec(record_keys.as_deref(), "recordKeys")?;
|
||||
}
|
||||
CultNetMessage::ShardCatalogResponse { message_id, shards } => {
|
||||
require_non_empty(message_id, "messageId")?;
|
||||
for shard in shards {
|
||||
validate_shard_descriptor(shard)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -557,6 +632,22 @@ fn validate_schema_descriptor(schema: &CultNetSchemaDescriptor) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_shard_descriptor(shard: &CultNetShardDescriptor) -> Result<()> {
|
||||
require_non_empty(&shard.shard_id, "shardId")?;
|
||||
require_non_empty(&shard.owner_runtime_id, "ownerRuntimeId")?;
|
||||
require_optional_string_vec(Some(shard.schema_ids.as_slice()), "schemaIds")?;
|
||||
require_optional_non_empty(shard.key_prefix.as_deref(), "keyPrefix")?;
|
||||
require_optional_string_vec(Some(shard.primary_endpoints.as_slice()), "primaryEndpoints")?;
|
||||
require_optional_string_vec(Some(shard.replica_endpoints.as_slice()), "replicaEndpoints")?;
|
||||
require_optional_string_vec(
|
||||
Some(shard.read_replica_endpoints.as_slice()),
|
||||
"readReplicaEndpoints",
|
||||
)?;
|
||||
require_optional_non_empty(shard.region.as_deref(), "region")?;
|
||||
require_optional_non_empty(shard.authority_lease_id.as_deref(), "authorityLeaseId")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn require_non_empty(value: &str, field: &str) -> Result<()> {
|
||||
if value.trim().is_empty() {
|
||||
return Err(anyhow!("CultNet field {field} must be non-empty"));
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ mod replication;
|
|||
mod rudp;
|
||||
mod schema_discovery;
|
||||
mod security;
|
||||
mod shard_catalog;
|
||||
mod transport;
|
||||
|
||||
pub use contracts::*;
|
||||
|
|
@ -14,4 +15,5 @@ pub use replication::*;
|
|||
pub use rudp::*;
|
||||
pub use schema_discovery::*;
|
||||
pub use security::*;
|
||||
pub use shard_catalog::*;
|
||||
pub use transport::*;
|
||||
|
|
|
|||
|
|
@ -353,6 +353,20 @@ pub fn builtin_schema_registry() -> Result<CultNetSchemaRegistry> {
|
|||
Some("cultnet.schema_catalog_response.v0"),
|
||||
None,
|
||||
)?,
|
||||
schema_registration(
|
||||
include_str!("../contracts/cultnet.shard-catalog-request.schema.json"),
|
||||
CultNetSchemaKind::WireMessage,
|
||||
vec![CultNetWireContract::CultNetSchemaV0],
|
||||
Some("cultnet.shard_catalog_request.v0"),
|
||||
None,
|
||||
)?,
|
||||
schema_registration(
|
||||
include_str!("../contracts/cultnet.shard-catalog-response.schema.json"),
|
||||
CultNetSchemaKind::WireMessage,
|
||||
vec![CultNetWireContract::CultNetSchemaV0],
|
||||
Some("cultnet.shard_catalog_response.v0"),
|
||||
None,
|
||||
)?,
|
||||
schema_registration(
|
||||
include_str!("../contracts/ghostlight.agent-state.schema.json"),
|
||||
CultNetSchemaKind::DocumentPayload,
|
||||
|
|
|
|||
134
packages/cultnet-rs/src/shard_catalog.rs
Normal file
134
packages/cultnet-rs/src/shard_catalog.rs
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use crate::CultNetMessage;
|
||||
use crate::CultNetShardDescriptor;
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct CultNetShardCatalogOptions {
|
||||
pub schema_ids: Option<Vec<String>>,
|
||||
pub record_keys: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct CultNetShardCatalog {
|
||||
shards: BTreeMap<String, CultNetShardDescriptor>,
|
||||
}
|
||||
|
||||
impl CultNetShardCatalog {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn upsert(&mut self, descriptor: CultNetShardDescriptor) -> Result<()> {
|
||||
validate_descriptor(&descriptor)?;
|
||||
self.shards.insert(descriptor.shard_id.clone(), descriptor);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get(&self, shard_id: &str) -> Option<&CultNetShardDescriptor> {
|
||||
self.shards.get(shard_id)
|
||||
}
|
||||
|
||||
pub fn list(&self, options: &CultNetShardCatalogOptions) -> Vec<CultNetShardDescriptor> {
|
||||
let schema_ids = options
|
||||
.schema_ids
|
||||
.as_ref()
|
||||
.map(|values| values.iter().cloned().collect::<BTreeSet<_>>());
|
||||
let record_keys = options
|
||||
.record_keys
|
||||
.as_ref()
|
||||
.map(|values| values.iter().cloned().collect::<BTreeSet<_>>());
|
||||
|
||||
self.shards
|
||||
.values()
|
||||
.filter(|shard| {
|
||||
let schema_match = schema_ids.as_ref().is_none_or(|requested| {
|
||||
requested
|
||||
.iter()
|
||||
.any(|schema_id| shard.serves(Some(schema_id), None))
|
||||
});
|
||||
let key_match = record_keys.as_ref().is_none_or(|requested| {
|
||||
requested
|
||||
.iter()
|
||||
.any(|record_key| shard.serves(None, Some(record_key)))
|
||||
});
|
||||
schema_match && key_match
|
||||
})
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn create_catalog_response(&self, request: &CultNetMessage) -> Result<CultNetMessage> {
|
||||
let CultNetMessage::ShardCatalogRequest {
|
||||
message_id,
|
||||
schema_ids,
|
||||
record_keys,
|
||||
} = request
|
||||
else {
|
||||
return Err(anyhow!(
|
||||
"expected cultnet.shard_catalog_request.v0 for shard discovery"
|
||||
));
|
||||
};
|
||||
|
||||
Ok(CultNetMessage::ShardCatalogResponse {
|
||||
message_id: message_id.clone(),
|
||||
shards: self.list(&CultNetShardCatalogOptions {
|
||||
schema_ids: schema_ids.clone(),
|
||||
record_keys: record_keys.clone(),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn apply_response(
|
||||
&mut self,
|
||||
response: &CultNetMessage,
|
||||
) -> Result<Vec<CultNetShardDescriptor>> {
|
||||
let CultNetMessage::ShardCatalogResponse { shards, .. } = response else {
|
||||
return Err(anyhow!(
|
||||
"expected cultnet.shard_catalog_response.v0 for shard discovery"
|
||||
));
|
||||
};
|
||||
|
||||
let mut applied = Vec::with_capacity(shards.len());
|
||||
for shard in shards {
|
||||
self.upsert(shard.clone())?;
|
||||
applied.push(shard.clone());
|
||||
}
|
||||
Ok(applied)
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_descriptor(descriptor: &CultNetShardDescriptor) -> Result<()> {
|
||||
if descriptor.shard_id.trim().is_empty() {
|
||||
return Err(anyhow!("shard_id must be non-empty"));
|
||||
}
|
||||
if descriptor.owner_runtime_id.trim().is_empty() {
|
||||
return Err(anyhow!("owner_runtime_id must be non-empty"));
|
||||
}
|
||||
for schema_id in &descriptor.schema_ids {
|
||||
if schema_id.trim().is_empty() {
|
||||
return Err(anyhow!("schema_ids must not contain empty values"));
|
||||
}
|
||||
}
|
||||
if descriptor
|
||||
.key_prefix
|
||||
.as_deref()
|
||||
.is_some_and(|value| value.trim().is_empty())
|
||||
{
|
||||
return Err(anyhow!("key_prefix must be non-empty when present"));
|
||||
}
|
||||
for endpoint in descriptor
|
||||
.primary_endpoints
|
||||
.iter()
|
||||
.chain(descriptor.replica_endpoints.iter())
|
||||
.chain(descriptor.read_replica_endpoints.iter())
|
||||
{
|
||||
if endpoint.trim().is_empty() {
|
||||
return Err(anyhow!("shard endpoints must not contain empty values"));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -31,6 +31,8 @@ use cultnet_rs::CultNetSchemaKind;
|
|||
use cultnet_rs::CultNetSchemaRegistry;
|
||||
use cultnet_rs::CultNetSecret;
|
||||
use cultnet_rs::CultNetServerSecurityOptions;
|
||||
use cultnet_rs::CultNetShardCatalog;
|
||||
use cultnet_rs::CultNetShardDescriptor;
|
||||
use cultnet_rs::CultNetTransportChannel;
|
||||
use cultnet_rs::CultNetTransportDelivery;
|
||||
use cultnet_rs::CultNetTransportDescriptor;
|
||||
|
|
@ -1456,6 +1458,86 @@ fn builtin_schema_registry_advertises_canonical_ghostlight_schema_without_inline
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builtin_schema_registry_advertises_shard_catalog_wire_messages() -> Result<()> {
|
||||
let registry = builtin_schema_registry()?;
|
||||
let response = registry.create_catalog_response(&CultNetMessage::SchemaCatalogRequest {
|
||||
message_id: "catalog-shards".to_string(),
|
||||
include_schema_json: None,
|
||||
schema_ids: None,
|
||||
kinds: Some(vec![CultNetSchemaKind::WireMessage]),
|
||||
})?;
|
||||
|
||||
let CultNetMessage::SchemaCatalogResponse { schemas, .. } = response else {
|
||||
panic!("expected catalog response");
|
||||
};
|
||||
|
||||
assert!(schemas.iter().any(|schema| {
|
||||
schema.schema_version.as_deref() == Some("cultnet.shard_catalog_request.v0")
|
||||
}));
|
||||
assert!(schemas.iter().any(|schema| {
|
||||
schema.schema_version.as_deref() == Some("cultnet.shard_catalog_response.v0")
|
||||
}));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shard_catalog_filters_descriptors_and_applies_remote_responses() -> Result<()> {
|
||||
let mut catalog = CultNetShardCatalog::new();
|
||||
catalog.upsert(CultNetShardDescriptor {
|
||||
shard_id: "notes-a".to_string(),
|
||||
owner_runtime_id: "rust-primary".to_string(),
|
||||
epoch: 3,
|
||||
is_primary: Some(true),
|
||||
schema_ids: vec!["note.v0".to_string()],
|
||||
key_prefix: Some("note:".to_string()),
|
||||
primary_endpoints: vec!["rudp://127.0.0.1:4100".to_string()],
|
||||
replica_endpoints: vec![],
|
||||
read_replica_endpoints: vec![],
|
||||
region: Some("local".to_string()),
|
||||
authority_lease_id: Some("lease:notes-a".to_string()),
|
||||
})?;
|
||||
catalog.upsert(CultNetShardDescriptor {
|
||||
shard_id: "players-a".to_string(),
|
||||
owner_runtime_id: "rust-primary".to_string(),
|
||||
epoch: 1,
|
||||
is_primary: Some(false),
|
||||
schema_ids: vec!["player.v0".to_string()],
|
||||
key_prefix: Some("player:".to_string()),
|
||||
primary_endpoints: vec!["cultnet://127.0.0.1:3075".to_string()],
|
||||
replica_endpoints: vec![],
|
||||
read_replica_endpoints: vec![],
|
||||
region: None,
|
||||
authority_lease_id: None,
|
||||
})?;
|
||||
|
||||
let response = catalog.create_catalog_response(&CultNetMessage::ShardCatalogRequest {
|
||||
message_id: "shards".to_string(),
|
||||
schema_ids: Some(vec!["note.v0".to_string()]),
|
||||
record_keys: Some(vec!["note:1".to_string()]),
|
||||
})?;
|
||||
|
||||
let CultNetMessage::ShardCatalogResponse { message_id, shards } = &response else {
|
||||
panic!("expected shard catalog response");
|
||||
};
|
||||
assert_eq!(message_id, "shards");
|
||||
assert_eq!(shards.len(), 1);
|
||||
assert_eq!(shards[0].shard_id, "notes-a");
|
||||
|
||||
let bytes = encode_cultnet_message_to_vec(&response, CultNetWireContract::CultNetSchemaV0)?;
|
||||
let decoded = decode_cultnet_message_from_slice(&bytes, CultNetWireContract::CultNetSchemaV0)?;
|
||||
assert_eq!(decoded, response);
|
||||
|
||||
let mut applied = CultNetShardCatalog::new();
|
||||
let applied_shards = applied.apply_response(&decoded)?;
|
||||
assert_eq!(applied_shards.len(), 1);
|
||||
assert!(applied.get("notes-a").is_some_and(|shard| {
|
||||
shard.serves(Some("note.v0"), Some("note:2"))
|
||||
&& !shard.serves(Some("note.v0"), Some("player:2"))
|
||||
}));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schema_discovery_round_trips_over_legacy_gamecult_contract_when_inline_schemas_are_requested()
|
||||
-> Result<()> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue