From 1abd4531153d66746e4bea5b4e065a2d42d14a76 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 22 Sep 2026 21:05:06 +0200 Subject: [PATCH] Rust R-AB: make cultnet-rs self-contained enough for cargo-mutants schema_discovery.rs embedded the 22 contract schemas via include_str!("../../../contracts/cultnet/*.schema.json"), three levels above src/ and outside packages/cultnet-rs entirely. There is no workspace Cargo.toml tying this crate to its siblings, so cargo-mutants treats this package's own directory as the whole tree it copies - every one of those paths escaped it, and the unmutated baseline build failed on all 22 with "No such file or directory". There was no mutation evidence for the Rust half of this cut at all. Fix: vendor byte-identical copies of the 22 schemas under packages/cultnet-rs/contracts/cultnet/, git-tracked so they travel with the package, and repoint every include_str! at the vendored copy. A build script staging files into OUT_DIR was the other option named for this rule, but it does not actually solve the problem: the script would still have to read from outside the package to find its source, and would fail the same way inside cargo-mutants' copy. Vendoring is "another route that keeps every source path inside the package." Vendoring duplicates files this repo treats as canonical (contracts/cultnet/*.schema.json, shared across every runtime per docs/cultnet-selection-cut.md section 1), so a new test, schema_discovery_contracts.rs, compares every vendored file against its repo-root original byte for byte and fails loudly on drift. It skips (not fails) when the canonical contracts/ tree is not present beside the package - the isolated-copy case R-AB exists to survive - so the check cannot reintroduce the same escape it guards against. cargo-mutants run on the crate, at least covering this cut's diff: report to follow with every survivor triaged. Co-Authored-By: Claude Sonnet 5 --- .../cultnet.document-delete.schema.json | 19 + ...net.document-mutation-contract.schema.json | 40 + .../cultnet.document-put-raw.schema.json | 19 + .../cultnet/cultnet.document-put.schema.json | 19 + .../cultnet/cultnet.error.schema.json | 31 + .../cultnet/cultnet.hello.schema.json | 41 + .../cultnet/cultnet.login-success.schema.json | 17 + .../cultnet/cultnet.login.schema.json | 19 + .../cultnet.raw-document-record.schema.json | 43 + .../cultnet/cultnet.register.schema.json | 21 + .../cultnet.sample-change-name.schema.json | 15 + .../cultnet/cultnet.sample-chat.schema.json | 15 + ...cultnet.schema-catalog-request.schema.json | 31 + ...ultnet.schema-catalog-response.schema.json | 22 + .../cultnet.shard-catalog-request.schema.json | 19 + ...cultnet.shard-catalog-response.schema.json | 47 + .../cultnet.snapshot-request.schema.json | 30 + .../cultnet.snapshot-response-raw.schema.json | 22 + .../cultnet.snapshot-response.schema.json | 22 + .../cultnet.transport-profile.schema.json | 100 +++ .../cultnet/cultnet.verify.schema.json | 17 + .../ghostlight.agent-state.schema.json | 845 ++++++++++++++++++ packages/cultnet-rs/src/schema_discovery.rs | 44 +- .../tests/schema_discovery_contracts.rs | 113 +++ 24 files changed, 1589 insertions(+), 22 deletions(-) create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.document-delete.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.document-mutation-contract.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.document-put-raw.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.document-put.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.error.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.hello.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.login-success.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.login.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.raw-document-record.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.register.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.sample-change-name.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.sample-chat.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.schema-catalog-request.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.schema-catalog-response.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.shard-catalog-request.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.shard-catalog-response.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.snapshot-request.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.snapshot-response-raw.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.snapshot-response.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.transport-profile.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/cultnet.verify.schema.json create mode 100644 packages/cultnet-rs/contracts/cultnet/ghostlight.agent-state.schema.json create mode 100644 packages/cultnet-rs/tests/schema_discovery_contracts.rs diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.document-delete.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.document-delete.schema.json new file mode 100644 index 00000000..3ba5b3fc --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.document-delete.schema.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.document-delete.schema.json", + "title": "CultNet Document Delete Message", + "type": "object", + "required": [ + "schemaVersion", + "messageId", + "schemaId", + "recordKey" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.document_delete.v0" }, + "messageId": { "type": "string", "minLength": 1 }, + "schemaId": { "type": "string", "minLength": 1 }, + "recordKey": { "type": "string", "minLength": 1 } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.document-mutation-contract.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.document-mutation-contract.schema.json new file mode 100644 index 00000000..4f8c9b78 --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.document-mutation-contract.schema.json @@ -0,0 +1,40 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.document-mutation-contract.schema.json", + "title": "CultNet Document Mutation Contract", + "type": "object", + "required": [ + "documentType", + "operations", + "authority" + ], + "additionalProperties": false, + "properties": { + "documentType": { "type": "string", "minLength": 1 }, + "payloadSchemaVersion": { "type": "string", "minLength": 1 }, + "operations": { + "type": "array", + "minItems": 1, + "items": { + "type": "string", + "enum": ["snapshot", "documentPut", "documentDelete", "intentSubmit", "receiptWatch"] + } + }, + "authority": { + "type": "string", + "enum": ["readOnly", "localUser", "coordinator", "runtime", "denied"] + }, + "intentDocumentTypes": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + }, + "receiptDocumentTypes": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + }, + "notes": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.document-put-raw.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.document-put-raw.schema.json new file mode 100644 index 00000000..c2c98030 --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.document-put-raw.schema.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.document-put-raw.schema.json", + "title": "CultNet Raw Document Put Message", + "type": "object", + "required": [ + "schemaVersion", + "messageId", + "document" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.document_put_raw.v0" }, + "messageId": { "type": "string", "minLength": 1 }, + "document": { + "$ref": "./cultnet.raw-document-record.schema.json" + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.document-put.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.document-put.schema.json new file mode 100644 index 00000000..2b92051a --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.document-put.schema.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.document-put.schema.json", + "title": "CultNet Document Put Message", + "type": "object", + "required": [ + "schemaVersion", + "messageId", + "document" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.document_put.v0" }, + "messageId": { "type": "string", "minLength": 1 }, + "document": { + "$ref": "./cultnet.document-record.schema.json" + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.error.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.error.schema.json new file mode 100644 index 00000000..e4277f3c --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.error.schema.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.error.schema.json", + "title": "CultNet Error Message", + "type": "object", + "required": [ + "schemaVersion", + "error" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.error.v0" }, + "error": { "type": "string", "minLength": 1 }, + "code": { + "description": "Machine-readable refusal code (R-N). Additive: a v0 peer that does not know this field ignores it.", + "type": "string", + "enum": ["selection_invalid", "cursor_stale", "cursor_invalid", "reference_outside_target"] + }, + "details": { + "description": "Code-specific structured detail (R-N). Every field is populated only for the code that defines it.", + "type": "object", + "additionalProperties": false, + "properties": { + "field": { "description": "selection_invalid: the selection field that failed.", "type": "string" }, + "value": { "description": "selection_invalid: the offending value, when there is one string worth naming.", "type": "string" }, + "asOf": { "description": "cursor_stale: the cursor's own minted asOf.", "type": "integer", "minimum": 0 }, + "current": { "description": "cursor_stale: the answering server's current asOf.", "type": "integer", "minimum": 0 } + } + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.hello.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.hello.schema.json new file mode 100644 index 00000000..36f9e8cf --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.hello.schema.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.hello.schema.json", + "title": "CultNet Hello Message", + "type": "object", + "required": [ + "schemaVersion", + "runtimeId", + "runtimeKind" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.hello.v0" }, + "runtimeId": { "type": "string", "minLength": 1 }, + "runtimeKind": { "type": "string", "minLength": 1 }, + "agentId": { "type": "string", "minLength": 1 }, + "role": { "type": "string", "minLength": 1 }, + "displayName": { "type": "string", "minLength": 1 }, + "supportedDocumentTypes": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + }, + "supportedMutationContracts": { + "type": "array", + "items": { + "$ref": "./cultnet.document-mutation-contract.schema.json" + } + }, + "supportedMessageVersions": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + }, + "transportProfiles": { + "type": "array", + "items": { + "$ref": "./cultnet.transport-profile.schema.json" + } + }, + "supportsSchemaCatalog": { "type": "boolean" } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.login-success.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.login-success.schema.json new file mode 100644 index 00000000..fbe41690 --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.login-success.schema.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.login-success.schema.json", + "title": "CultNet Login Success Message", + "type": "object", + "required": [ + "schemaVersion", + "nonce", + "session" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.login_success.v0" }, + "nonce": { "type": "string", "minLength": 1 }, + "session": { "type": "string", "minLength": 1 } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.login.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.login.schema.json new file mode 100644 index 00000000..86154717 --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.login.schema.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.login.schema.json", + "title": "CultNet Login Message", + "type": "object", + "required": [ + "schemaVersion", + "nonce", + "auth", + "password" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.login.v0" }, + "nonce": { "type": "string", "minLength": 1 }, + "auth": { "type": "string", "minLength": 1 }, + "password": { "type": "string", "minLength": 1 } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.raw-document-record.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.raw-document-record.schema.json new file mode 100644 index 00000000..445cf8f1 --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.raw-document-record.schema.json @@ -0,0 +1,43 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.raw-document-record.schema.json", + "title": "CultNet Raw Document Record", + "description": "R-S (docs/cultnet-selection-cut.md, fix batch 3): matches MessagePack-CSharp's map-mode output for CultNetRawDocumentRecord - every declared key is written, nil included, so every property here is `required` (present on the wire) even where its value may be null.", + "type": "object", + "required": [ + "schemaId", + "schemaName", + "schemaVersion", + "schemaContentHash", + "recordKey", + "storedAt", + "payloadEncoding", + "payload", + "sourceRuntimeId", + "sourceAgentId", + "sourceRole", + "tags" + ], + "additionalProperties": false, + "properties": { + "schemaId": { "type": "string", "minLength": 1 }, + "schemaName": { "type": ["string", "null"], "minLength": 1 }, + "schemaVersion": { "type": ["string", "null"], "minLength": 1 }, + "schemaContentHash": { "type": ["string", "null"], "minLength": 1 }, + "recordKey": { "type": "string", "minLength": 1 }, + "storedAt": { "type": "string", "minLength": 1 }, + "payloadEncoding": { "const": "messagepack" }, + "payload": { + "type": "string", + "contentEncoding": "base64", + "x-cult-runtime-type": "bytes" + }, + "sourceRuntimeId": { "type": ["string", "null"], "minLength": 1 }, + "sourceAgentId": { "type": ["string", "null"], "minLength": 1 }, + "sourceRole": { "type": ["string", "null"], "minLength": 1 }, + "tags": { + "type": ["array", "null"], + "items": { "type": "string", "minLength": 1 } + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.register.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.register.schema.json new file mode 100644 index 00000000..c5f5ce42 --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.register.schema.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.register.schema.json", + "title": "CultNet Register Message", + "type": "object", + "required": [ + "schemaVersion", + "nonce", + "email", + "password", + "name" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.register.v0" }, + "nonce": { "type": "string", "minLength": 1 }, + "email": { "type": "string", "minLength": 1 }, + "password": { "type": "string", "minLength": 1 }, + "name": { "type": "string", "minLength": 1 } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.sample-change-name.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.sample-change-name.schema.json new file mode 100644 index 00000000..2408a449 --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.sample-change-name.schema.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.sample-change-name.schema.json", + "title": "CultNet Sample Change Name Message", + "type": "object", + "required": [ + "schemaVersion", + "name" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.sample.change_name.v0" }, + "name": { "type": "string", "minLength": 1 } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.sample-chat.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.sample-chat.schema.json new file mode 100644 index 00000000..e9bf544c --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.sample-chat.schema.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.sample-chat.schema.json", + "title": "CultNet Sample Chat Message", + "type": "object", + "required": [ + "schemaVersion", + "text" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.sample.chat.v0" }, + "text": { "type": "string", "minLength": 1 } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.schema-catalog-request.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.schema-catalog-request.schema.json new file mode 100644 index 00000000..5459129b --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.schema-catalog-request.schema.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.schema-catalog-request.schema.json", + "title": "CultNet Schema Catalog Request Message", + "type": "object", + "required": [ + "schemaVersion", + "messageId" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.schema_catalog_request.v0" }, + "messageId": { "type": "string", "minLength": 1 }, + "includeSchemaJson": { "type": "boolean" }, + "schemaIds": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + }, + "kinds": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "wire_message", + "document_payload", + "shared_contract" + ] + } + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.schema-catalog-response.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.schema-catalog-response.schema.json new file mode 100644 index 00000000..dbda847e --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.schema-catalog-response.schema.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.schema-catalog-response.schema.json", + "title": "CultNet Schema Catalog Response Message", + "type": "object", + "required": [ + "schemaVersion", + "messageId", + "schemas" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.schema_catalog_response.v0" }, + "messageId": { "type": "string", "minLength": 1 }, + "schemas": { + "type": "array", + "items": { + "$ref": "./cultnet.schema-descriptor.schema.json" + } + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.shard-catalog-request.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.shard-catalog-request.schema.json new file mode 100644 index 00000000..7e443e60 --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.shard-catalog-request.schema.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.shard-catalog-request.schema.json", + "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 } + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.shard-catalog-response.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.shard-catalog-response.schema.json new file mode 100644 index 00000000..f0b846ac --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.shard-catalog-response.schema.json @@ -0,0 +1,47 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.shard-catalog-response.schema.json", + "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 } + } + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.snapshot-request.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.snapshot-request.schema.json new file mode 100644 index 00000000..9571669c --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.snapshot-request.schema.json @@ -0,0 +1,30 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.snapshot-request.schema.json", + "title": "CultNet Snapshot Request Message", + "type": "object", + "required": [ + "schemaVersion", + "messageId" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.snapshot_request.v0" }, + "messageId": { "type": "string", "minLength": 1 }, + "schemaIds": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + }, + "recordKeys": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + }, + "shardId": { + "type": "string", + "minLength": 1 + }, + "shardEpoch": { + "type": "integer" + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.snapshot-response-raw.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.snapshot-response-raw.schema.json new file mode 100644 index 00000000..538f48de --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.snapshot-response-raw.schema.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.snapshot-response-raw.schema.json", + "title": "CultNet Raw Snapshot Response Message", + "type": "object", + "required": [ + "schemaVersion", + "messageId", + "documents" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.snapshot_response_raw.v0" }, + "messageId": { "type": "string", "minLength": 1 }, + "documents": { + "type": "array", + "items": { + "$ref": "./cultnet.raw-document-record.schema.json" + } + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.snapshot-response.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.snapshot-response.schema.json new file mode 100644 index 00000000..87daf147 --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.snapshot-response.schema.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.snapshot-response.schema.json", + "title": "CultNet Snapshot Response Message", + "type": "object", + "required": [ + "schemaVersion", + "messageId", + "documents" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.snapshot_response.v0" }, + "messageId": { "type": "string", "minLength": 1 }, + "documents": { + "type": "array", + "items": { + "$ref": "./cultnet.document-record.schema.json" + } + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.transport-profile.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.transport-profile.schema.json new file mode 100644 index 00000000..dff458f1 --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.transport-profile.schema.json @@ -0,0 +1,100 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.transport-profile.schema.json", + "title": "CultNet Transport Profile", + "type": "object", + "required": [ + "schemaVersion", + "runtimeId", + "transports" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.transport_profile.v0" }, + "runtimeId": { "type": "string", "minLength": 1 }, + "transports": { + "type": "array", + "items": { + "type": "object", + "required": [ + "transportId", + "protocol", + "channels" + ], + "additionalProperties": false, + "properties": { + "transportId": { "type": "string", "minLength": 1 }, + "protocol": { + "type": "string", + "enum": [ + "tcp_framed", + "litenetlib", + "websocket", + "rudp" + ] + }, + "host": { "type": "string", "minLength": 1 }, + "port": { "type": "integer", "minimum": 1, "maximum": 65535 }, + "path": { "type": "string", "minLength": 1 }, + "discoveryGroup": { "type": "string", "minLength": 1 }, + "wireContracts": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + }, + "reconnectPolicy": { + "type": "object", + "required": [ + "schemaVersion", + "policyId", + "baseDelayMs", + "maxDelayMs", + "maxJitterMs" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.reconnect_policy.v0" }, + "policyId": { "type": "string", "minLength": 1 }, + "baseDelayMs": { "type": "integer", "minimum": 0 }, + "maxDelayMs": { "type": "integer", "minimum": 0 }, + "maxJitterMs": { "type": "integer", "minimum": 0 }, + "maxAttempts": { "type": "integer", "minimum": 1 } + } + }, + "channels": { + "type": "array", + "items": { + "type": "object", + "required": [ + "channelId", + "delivery", + "ordering" + ], + "additionalProperties": false, + "properties": { + "channelId": { "type": "string", "minLength": 1 }, + "delivery": { + "type": "string", + "enum": [ + "reliable", + "unreliable" + ] + }, + "ordering": { + "type": "string", + "enum": [ + "ordered", + "unordered", + "sequenced" + ] + }, + "maxPayloadBytes": { "type": "integer", "minimum": 1 }, + "maxFragmentBytes": { "type": "integer", "minimum": 1 }, + "maxPendingReliablePackets": { "type": "integer", "minimum": 1 } + } + } + } + } + } + } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/cultnet.verify.schema.json b/packages/cultnet-rs/contracts/cultnet/cultnet.verify.schema.json new file mode 100644 index 00000000..301ae338 --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/cultnet.verify.schema.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/CultLib/contracts/cultnet/cultnet.verify.schema.json", + "title": "CultNet Verify Message", + "type": "object", + "required": [ + "schemaVersion", + "nonce", + "session" + ], + "additionalProperties": false, + "properties": { + "schemaVersion": { "const": "cultnet.verify.v0" }, + "nonce": { "type": "string", "minLength": 1 }, + "session": { "type": "string", "minLength": 1 } + } +} diff --git a/packages/cultnet-rs/contracts/cultnet/ghostlight.agent-state.schema.json b/packages/cultnet-rs/contracts/cultnet/ghostlight.agent-state.schema.json new file mode 100644 index 00000000..6437cd01 --- /dev/null +++ b/packages/cultnet-rs/contracts/cultnet/ghostlight.agent-state.schema.json @@ -0,0 +1,845 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/GameCult/Ghostlight/schemas/agent-state.schema.json", + "title": "Ghostlight Agent State Schema", + "description": "First canonical contract for Ghostlight agent, perception, relationship, event, scene, and dialogue-context state.", + "type": "object", + "required": [ + "schema_version", + "world", + "agents", + "relationships", + "events", + "scenes" + ], + "additionalProperties": false, + "properties": { + "schema_version": { + "const": "ghostlight.agent_state.v0" + }, + "world": { + "$ref": "#/$defs/world_state" + }, + "agents": { + "type": "array", + "items": { + "$ref": "#/$defs/agent" + } + }, + "relationships": { + "type": "array", + "items": { + "$ref": "#/$defs/relationship" + } + }, + "events": { + "type": "array", + "items": { + "$ref": "#/$defs/event" + } + }, + "scenes": { + "type": "array", + "items": { + "$ref": "#/$defs/scene" + } + } + }, + "$defs": { + "world_state": { + "type": "object", + "required": [ + "world_id", + "setting", + "time", + "canon_context" + ], + "additionalProperties": false, + "properties": { + "world_id": { + "type": "string" + }, + "setting": { + "type": "string" + }, + "time": { + "type": "object", + "required": [ + "label" + ], + "additionalProperties": true, + "properties": { + "label": { + "type": "string" + } + } + }, + "canon_context": { + "type": "array", + "items": { + "type": "string" + } + }, + "ambient_pressures": { + "type": "array", + "items": { + "$ref": "#/$defs/pressure" + } + } + } + }, + "agent": { + "type": "object", + "required": [ + "agent_id", + "identity", + "canonical_state", + "goals", + "memories", + "perceived_state_overlays" + ], + "additionalProperties": false, + "properties": { + "agent_id": { + "type": "string" + }, + "identity": { + "$ref": "#/$defs/identity" + }, + "canonical_state": { + "$ref": "#/$defs/canonical_state" + }, + "goals": { + "type": "array", + "items": { + "$ref": "#/$defs/goal" + } + }, + "memories": { + "$ref": "#/$defs/memory_bundle" + }, + "perceived_state_overlays": { + "type": "array", + "items": { + "$ref": "#/$defs/perceived_state_overlay" + } + } + } + }, + "identity": { + "type": "object", + "required": [ + "name", + "roles", + "origin", + "public_description" + ], + "additionalProperties": false, + "properties": { + "name": { + "type": "string" + }, + "roles": { + "type": "array", + "items": { + "type": "string" + } + }, + "origin": { + "type": "string" + }, + "public_description": { + "type": "string" + }, + "private_notes": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "canonical_state": { + "type": "object", + "required": [ + "underlying_organization", + "stable_dispositions", + "behavioral_dimensions", + "presentation_strategy", + "voice_style", + "situational_state", + "values" + ], + "additionalProperties": false, + "properties": { + "underlying_organization": { + "$ref": "#/$defs/variable_map" + }, + "stable_dispositions": { + "$ref": "#/$defs/variable_map" + }, + "behavioral_dimensions": { + "$ref": "#/$defs/variable_map" + }, + "presentation_strategy": { + "$ref": "#/$defs/variable_map" + }, + "situational_state": { + "$ref": "#/$defs/variable_map" + }, + "values": { + "type": "array", + "items": { + "$ref": "#/$defs/value_commitment" + } + }, + "voice_style": { + "$ref": "#/$defs/variable_map" + } + } + }, + "variable_map": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/state_variable" + } + }, + "state_variable": { + "type": "object", + "required": [ + "mean", + "plasticity", + "current_activation" + ], + "additionalProperties": false, + "properties": { + "mean": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "plasticity": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "current_activation": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "evidence": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "value_commitment": { + "type": "object", + "required": [ + "value_id", + "label", + "priority", + "unforgivable_if_betrayed" + ], + "additionalProperties": false, + "properties": { + "value_id": { + "type": "string" + }, + "label": { + "type": "string" + }, + "priority": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "unforgivable_if_betrayed": { + "type": "boolean" + } + } + }, + "goal": { + "type": "object", + "required": [ + "goal_id", + "description", + "scope", + "priority", + "emotional_stake", + "status" + ], + "additionalProperties": false, + "properties": { + "goal_id": { + "type": "string" + }, + "description": { + "type": "string" + }, + "scope": { + "enum": [ + "immediate", + "scene", + "case", + "arc", + "life" + ] + }, + "priority": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "emotional_stake": { + "type": "string" + }, + "blockers": { + "type": "array", + "items": { + "type": "string" + } + }, + "status": { + "enum": [ + "active", + "blocked", + "dormant", + "resolved", + "abandoned" + ] + } + } + }, + "memory_bundle": { + "type": "object", + "required": [ + "episodic", + "semantic", + "relationship_summaries" + ], + "additionalProperties": false, + "properties": { + "episodic": { + "type": "array", + "items": { + "$ref": "#/$defs/memory" + } + }, + "semantic": { + "type": "array", + "items": { + "$ref": "#/$defs/memory" + } + }, + "relationship_summaries": { + "type": "array", + "items": { + "$ref": "#/$defs/memory" + } + } + } + }, + "memory": { + "type": "object", + "required": [ + "memory_id", + "summary", + "salience", + "confidence" + ], + "additionalProperties": false, + "properties": { + "memory_id": { + "type": "string" + }, + "summary": { + "type": "string" + }, + "salience": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "confidence": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "linked_event_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "linked_relationship_id": { + "type": "string" + } + } + }, + "perceived_state_overlay": { + "type": "object", + "required": [ + "observer_agent_id", + "target_agent_id", + "perceived_dimensions", + "beliefs", + "distortions" + ], + "additionalProperties": false, + "properties": { + "observer_agent_id": { + "type": "string" + }, + "target_agent_id": { + "type": "string" + }, + "perceived_dimensions": { + "$ref": "#/$defs/inferred_variable_map" + }, + "beliefs": { + "type": "array", + "items": { + "$ref": "#/$defs/belief" + } + }, + "distortions": { + "type": "array", + "items": { + "enum": [ + "hostile_attribution", + "false_reassurance", + "overread_warmth", + "underread_threat", + "false_mask_detection", + "missed_mask_detection", + "status_injury", + "threat_amplification", + "institutional_suspicion_transfer", + "care_underread", + "mask_overfocus" + ] + } + } + } + }, + "belief": { + "type": "object", + "required": [ + "belief_id", + "claim", + "confidence" + ], + "additionalProperties": false, + "properties": { + "belief_id": { + "type": "string" + }, + "claim": { + "type": "string" + }, + "confidence": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "subject_id": { + "type": "string" + }, + "claim_type": { + "enum": [ + "fact", + "identity_inference", + "motive_inference", + "prediction", + "norm", + "value_read", + "relationship_read" + ] + }, + "evidence_event_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "visibility": { + "enum": [ + "private", + "shared", + "public", + "rumor" + ] + }, + "emotional_charge": { + "type": "number", + "minimum": 0, + "maximum": 1 + } + } + }, + "relationship": { + "type": "object", + "required": [ + "relationship_id", + "source_id", + "target_id", + "stance", + "summary" + ], + "additionalProperties": false, + "properties": { + "relationship_id": { + "type": "string" + }, + "source_id": { + "type": "string" + }, + "target_id": { + "type": "string" + }, + "stance": { + "$ref": "#/$defs/variable_map" + }, + "summary": { + "type": "string" + }, + "unresolved_incident_ids": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "event": { + "type": "object", + "required": [ + "event_id", + "kind", + "summary", + "participants", + "pressure_tags" + ], + "additionalProperties": false, + "properties": { + "event_id": { + "type": "string" + }, + "kind": { + "enum": [ + "dialogue", + "action", + "memory", + "relationship_shift", + "scene_outcome", + "author_note" + ] + }, + "summary": { + "type": "string" + }, + "participants": { + "type": "array", + "items": { + "type": "string" + } + }, + "pressure_tags": { + "type": "array", + "items": { + "type": "string" + } + }, + "observed_exchange": { + "type": "array", + "items": { + "$ref": "#/$defs/event_exchange_turn" + } + }, + "private_interpretations": { + "type": "array", + "items": { + "$ref": "#/$defs/event_private_interpretation" + } + }, + "event_effects": { + "type": "array", + "items": { + "$ref": "#/$defs/event_effect" + } + } + } + }, + "scene": { + "type": "object", + "required": [ + "scene_id", + "location", + "participants", + "public_stakes", + "hidden_stakes", + "dialogue_context_packs" + ], + "additionalProperties": false, + "properties": { + "scene_id": { + "type": "string" + }, + "location": { + "type": "string" + }, + "participants": { + "type": "array", + "items": { + "type": "string" + } + }, + "public_stakes": { + "type": "array", + "items": { + "type": "string" + } + }, + "hidden_stakes": { + "type": "array", + "items": { + "type": "string" + } + }, + "dialogue_context_packs": { + "type": "array", + "items": { + "$ref": "#/$defs/dialogue_context_pack" + } + } + } + }, + "dialogue_context_pack": { + "type": "object", + "required": [ + "speaker_agent_id", + "listener_ids", + "speaker_local_truth", + "speaker_beliefs", + "active_memories", + "active_goals", + "presentation_constraints" + ], + "additionalProperties": false, + "properties": { + "speaker_agent_id": { + "type": "string" + }, + "listener_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "speaker_local_truth": { + "type": "array", + "items": { + "type": "string" + } + }, + "speaker_beliefs": { + "type": "array", + "items": { + "type": "string" + } + }, + "active_memories": { + "type": "array", + "items": { + "type": "string" + } + }, + "active_goals": { + "type": "array", + "items": { + "type": "string" + } + }, + "presentation_constraints": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "pressure": { + "type": "object", + "required": [ + "pressure_id", + "label", + "intensity" + ], + "additionalProperties": false, + "properties": { + "pressure_id": { + "type": "string" + }, + "label": { + "type": "string" + }, + "intensity": { + "type": "number", + "minimum": 0, + "maximum": 1 + } + } + }, + "inferred_variable_map": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/inferred_state_variable" + } + }, + "inferred_state_variable": { + "type": "object", + "required": [ + "observed_activation", + "attributed_disposition", + "confidence" + ], + "additionalProperties": false, + "properties": { + "observed_activation": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "attributed_disposition": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "confidence": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "evidence": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "event_exchange_turn": { + "type": "object", + "required": [ + "speaker_id", + "utterance_summary", + "dialogue_function" + ], + "additionalProperties": false, + "properties": { + "speaker_id": { + "type": "string" + }, + "utterance_summary": { + "type": "string" + }, + "dialogue_function": { + "type": "string" + }, + "observable_cues": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "event_private_interpretation": { + "type": "object", + "required": [ + "agent_id", + "interpretation", + "confidence" + ], + "additionalProperties": false, + "properties": { + "agent_id": { + "type": "string" + }, + "interpretation": { + "type": "string" + }, + "attributed_motive": { + "type": "string" + }, + "appraisal_tags": { + "type": "array", + "items": { + "type": "string" + } + }, + "confidence": { + "type": "number", + "minimum": 0, + "maximum": 1 + } + } + }, + "event_effect": { + "type": "object", + "required": [ + "agent_id", + "summary" + ], + "additionalProperties": false, + "properties": { + "agent_id": { + "type": "string" + }, + "summary": { + "type": "string" + }, + "state_deltas": { + "type": "array", + "items": { + "$ref": "#/$defs/state_delta" + } + }, + "new_belief_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "memory_update_ids": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "state_delta": { + "type": "object", + "required": [ + "path", + "delta" + ], + "additionalProperties": false, + "properties": { + "path": { + "type": "string" + }, + "delta": { + "type": "number", + "minimum": -1, + "maximum": 1 + } + } + } + } +} diff --git a/packages/cultnet-rs/src/schema_discovery.rs b/packages/cultnet-rs/src/schema_discovery.rs index a32bc7cb..43211c3c 100644 --- a/packages/cultnet-rs/src/schema_discovery.rs +++ b/packages/cultnet-rs/src/schema_discovery.rs @@ -194,28 +194,28 @@ pub fn builtin_schema_registry() -> Result { for registration in [ schema_registration( - include_str!("../../../contracts/cultnet/cultnet.hello.schema.json"), + include_str!("../contracts/cultnet/cultnet.hello.schema.json"), CultNetSchemaKind::WireMessage, vec![CultNetWireContract::CultNetSchemaV0], Some("cultnet.hello.v0"), None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.document-mutation-contract.schema.json"), + include_str!("../contracts/cultnet/cultnet.document-mutation-contract.schema.json"), CultNetSchemaKind::SharedContract, vec![CultNetWireContract::CultNetSchemaV0], None, None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.transport-profile.schema.json"), + include_str!("../contracts/cultnet/cultnet.transport-profile.schema.json"), CultNetSchemaKind::SharedContract, vec![CultNetWireContract::CultNetSchemaV0], Some("cultnet.transport_profile.v0"), None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.login.schema.json"), + include_str!("../contracts/cultnet/cultnet.login.schema.json"), CultNetSchemaKind::WireMessage, vec![ CultNetWireContract::CultNetSchemaV0, @@ -225,7 +225,7 @@ pub fn builtin_schema_registry() -> Result { None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.register.schema.json"), + include_str!("../contracts/cultnet/cultnet.register.schema.json"), CultNetSchemaKind::WireMessage, vec![ CultNetWireContract::CultNetSchemaV0, @@ -235,7 +235,7 @@ pub fn builtin_schema_registry() -> Result { None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.verify.schema.json"), + include_str!("../contracts/cultnet/cultnet.verify.schema.json"), CultNetSchemaKind::WireMessage, vec![ CultNetWireContract::CultNetSchemaV0, @@ -245,7 +245,7 @@ pub fn builtin_schema_registry() -> Result { None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.login-success.schema.json"), + include_str!("../contracts/cultnet/cultnet.login-success.schema.json"), CultNetSchemaKind::WireMessage, vec![ CultNetWireContract::CultNetSchemaV0, @@ -255,7 +255,7 @@ pub fn builtin_schema_registry() -> Result { None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.error.schema.json"), + include_str!("../contracts/cultnet/cultnet.error.schema.json"), CultNetSchemaKind::WireMessage, vec![ CultNetWireContract::CultNetSchemaV0, @@ -265,7 +265,7 @@ pub fn builtin_schema_registry() -> Result { None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.sample-change-name.schema.json"), + include_str!("../contracts/cultnet/cultnet.sample-change-name.schema.json"), CultNetSchemaKind::WireMessage, vec![ CultNetWireContract::CultNetSchemaV0, @@ -275,7 +275,7 @@ pub fn builtin_schema_registry() -> Result { None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.sample-chat.schema.json"), + include_str!("../contracts/cultnet/cultnet.sample-chat.schema.json"), CultNetSchemaKind::WireMessage, vec![ CultNetWireContract::CultNetSchemaV0, @@ -285,56 +285,56 @@ pub fn builtin_schema_registry() -> Result { None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.document-put.schema.json"), + include_str!("../contracts/cultnet/cultnet.document-put.schema.json"), CultNetSchemaKind::WireMessage, vec![CultNetWireContract::CultNetSchemaV0], Some("cultnet.document_put.v0"), None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.document-delete.schema.json"), + include_str!("../contracts/cultnet/cultnet.document-delete.schema.json"), CultNetSchemaKind::WireMessage, vec![CultNetWireContract::CultNetSchemaV0], Some("cultnet.document_delete.v0"), None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.raw-document-record.schema.json"), + include_str!("../contracts/cultnet/cultnet.raw-document-record.schema.json"), CultNetSchemaKind::SharedContract, vec![CultNetWireContract::CultNetSchemaV0], None, None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.document-put-raw.schema.json"), + include_str!("../contracts/cultnet/cultnet.document-put-raw.schema.json"), CultNetSchemaKind::WireMessage, vec![CultNetWireContract::CultNetSchemaV0], Some("cultnet.document_put_raw.v0"), None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.snapshot-request.schema.json"), + include_str!("../contracts/cultnet/cultnet.snapshot-request.schema.json"), CultNetSchemaKind::WireMessage, vec![CultNetWireContract::CultNetSchemaV0], Some("cultnet.snapshot_request.v0"), None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.snapshot-response.schema.json"), + include_str!("../contracts/cultnet/cultnet.snapshot-response.schema.json"), CultNetSchemaKind::WireMessage, vec![CultNetWireContract::CultNetSchemaV0], Some("cultnet.snapshot_response.v0"), None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.snapshot-response-raw.schema.json"), + include_str!("../contracts/cultnet/cultnet.snapshot-response-raw.schema.json"), CultNetSchemaKind::WireMessage, vec![CultNetWireContract::CultNetSchemaV0], Some("cultnet.snapshot_response_raw.v0"), None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.schema-catalog-request.schema.json"), + include_str!("../contracts/cultnet/cultnet.schema-catalog-request.schema.json"), CultNetSchemaKind::WireMessage, vec![ CultNetWireContract::CultNetSchemaV0, @@ -344,7 +344,7 @@ pub fn builtin_schema_registry() -> Result { None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.schema-catalog-response.schema.json"), + include_str!("../contracts/cultnet/cultnet.schema-catalog-response.schema.json"), CultNetSchemaKind::WireMessage, vec![ CultNetWireContract::CultNetSchemaV0, @@ -354,21 +354,21 @@ pub fn builtin_schema_registry() -> Result { None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.shard-catalog-request.schema.json"), + include_str!("../contracts/cultnet/cultnet.shard-catalog-request.schema.json"), CultNetSchemaKind::WireMessage, vec![CultNetWireContract::CultNetSchemaV0], Some("cultnet.shard_catalog_request.v0"), None, )?, schema_registration( - include_str!("../../../contracts/cultnet/cultnet.shard-catalog-response.schema.json"), + include_str!("../contracts/cultnet/cultnet.shard-catalog-response.schema.json"), CultNetSchemaKind::WireMessage, vec![CultNetWireContract::CultNetSchemaV0], Some("cultnet.shard_catalog_response.v0"), None, )?, schema_registration( - include_str!("../../../contracts/cultnet/ghostlight.agent-state.schema.json"), + include_str!("../contracts/cultnet/ghostlight.agent-state.schema.json"), CultNetSchemaKind::DocumentPayload, vec![CultNetWireContract::CultNetSchemaV0], Some("ghostlight.agent_state.v0"), diff --git a/packages/cultnet-rs/tests/schema_discovery_contracts.rs b/packages/cultnet-rs/tests/schema_discovery_contracts.rs new file mode 100644 index 00000000..7c62b80f --- /dev/null +++ b/packages/cultnet-rs/tests/schema_discovery_contracts.rs @@ -0,0 +1,113 @@ +//! R-AB: `schema_discovery.rs` used to `include_str!("../../../contracts/cultnet/…")`, reaching +//! three levels above `src/` and out of `packages/cultnet-rs` entirely. cargo-mutants builds this +//! crate alone (there is no workspace `Cargo.toml` tying it to its siblings, so its own manifest +//! directory is the whole tree cargo-mutants copies) - a path that escapes the package is a path +//! that does not exist in that copy, and the unmutated baseline build failed with "No such file or +//! directory" on every one of the 22 schemas (`rust-mut3.log`, captured on Soul's whole-cut pass). +//! +//! The fix vendors byte-identical copies of the 22 schemas this crate embeds under +//! `packages/cultnet-rs/contracts/cultnet/`, git-tracked so any tool that copies just this +//! package's directory carries them along, and repoints every `include_str!` at that vendored copy +//! instead of the repo-root `contracts/cultnet/`. A build script staging files into `OUT_DIR` was +//! the other option R-AB named, but it does not actually solve this: the script itself would still +//! need to read from outside the package to find its source, and a build running inside +//! cargo-mutants' copy would fail exactly as `include_str!` did. Vendoring - "another route that +//! keeps every source path inside the package" - is what R-AB's ruling names as the alternative, +//! and it is what actually keeps the crate self-contained. +//! +//! Vendoring is a second copy of files this repo already treats as canonical +//! (`contracts/cultnet/*.schema.json`, the shared source multiple runtimes compile against per +//! `docs/cultnet-selection-cut.md` section 1). A second copy can drift silently, so this test is +//! the thing that makes that impossible without a loud, immediate failure: every vendored file is +//! compared byte-for-byte against its repo-root original. It skips (not fails) when the canonical +//! `contracts/` tree is not present beside the package - i.e. exactly the isolated-copy situation +//! R-AB exists to survive - so this check does not reintroduce the same escape it is guarding +//! against. + +use std::fs; +use std::path::Path; + +/// Every schema this crate's `schema_discovery::builtin_schema_registry` embeds via +/// `include_str!("../contracts/cultnet/…")` - kept in sync with `schema_discovery.rs` by hand; +/// a schema added there and not here is still caught, because the crate would then fail to +/// compile against a file this list never copied to `contracts/cultnet/`. +const VENDORED_SCHEMAS: &[&str] = &[ + "cultnet.hello.schema.json", + "cultnet.document-mutation-contract.schema.json", + "cultnet.transport-profile.schema.json", + "cultnet.login.schema.json", + "cultnet.register.schema.json", + "cultnet.verify.schema.json", + "cultnet.login-success.schema.json", + "cultnet.error.schema.json", + "cultnet.sample-change-name.schema.json", + "cultnet.sample-chat.schema.json", + "cultnet.document-put.schema.json", + "cultnet.document-delete.schema.json", + "cultnet.raw-document-record.schema.json", + "cultnet.document-put-raw.schema.json", + "cultnet.snapshot-request.schema.json", + "cultnet.snapshot-response.schema.json", + "cultnet.snapshot-response-raw.schema.json", + "cultnet.schema-catalog-request.schema.json", + "cultnet.schema-catalog-response.schema.json", + "cultnet.shard-catalog-request.schema.json", + "cultnet.shard-catalog-response.schema.json", + "ghostlight.agent-state.schema.json", +]; + +#[test] +fn vendored_contract_schemas_are_present_and_match_every_include_str_call() { + let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); + let vendored_root = manifest_dir.join("contracts/cultnet"); + for name in VENDORED_SCHEMAS { + let path = vendored_root.join(name); + assert!( + path.is_file(), + "{name} is embedded by schema_discovery.rs but missing from the vendored \ + contracts/cultnet/ copy at {path:?}" + ); + } +} + +#[test] +fn vendored_contract_schemas_match_the_canonical_repo_root_source() { + let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); + let vendored_root = manifest_dir.join("contracts/cultnet"); + // packages/cultnet-rs -> packages -> repo root -> contracts/cultnet + let canonical_root = manifest_dir.join("../../contracts/cultnet"); + + if !canonical_root.is_dir() { + // R-AB: exactly the isolated-copy case this crate's own vendored files exist to survive + // (cargo-mutants, or any tool that copies only this package's directory). Nothing to + // compare against, and that is expected, not a failure. + eprintln!( + "skipping: {canonical_root:?} not present beside the package (isolated build, \ + the case R-AB's vendored copies are for)" + ); + return; + } + + for name in VENDORED_SCHEMAS { + let canonical = fs::read_to_string(canonical_root.join(name)) + .unwrap_or_else(|error| panic!("reading canonical contracts/cultnet/{name}: {error}")); + let vendored = fs::read_to_string(vendored_root.join(name)) + .unwrap_or_else(|error| panic!("reading vendored contracts/cultnet/{name}: {error}")); + assert_eq!( + canonical, vendored, + "packages/cultnet-rs/contracts/cultnet/{name} has drifted from the canonical \ + contracts/cultnet/{name} - re-copy it" + ); + } +} + +#[test] +fn builtin_schema_registry_loads_every_vendored_schema() { + let registry = cultnet_rs::builtin_schema_registry().expect("registry builds from the vendored schemas"); + let listed = registry.list(&cultnet_rs::CultNetSchemaCatalogOptions::default()); + assert_eq!( + listed.len(), + VENDORED_SCHEMAS.len(), + "one registration per vendored schema file" + ); +}