From 41c43bb5e25900606f0422d8e8879367b1336b1b Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 14 Jun 2026 01:03:39 +0100 Subject: [PATCH] Add Python runtime parity verifier --- packages/cultcache-py/PARITY.md | 54 ++++++++ packages/cultcache-py/README.md | 4 + packages/cultcache-py/pyproject.toml | 1 + .../cultcache-py/src/cultcache_py/verify.py | 120 ++++++++++++++++++ packages/cultcache-py/tests/test_cultcache.py | 7 + 5 files changed, 186 insertions(+) create mode 100644 packages/cultcache-py/PARITY.md create mode 100644 packages/cultcache-py/src/cultcache_py/verify.py diff --git a/packages/cultcache-py/PARITY.md b/packages/cultcache-py/PARITY.md new file mode 100644 index 00000000..d8abfc9f --- /dev/null +++ b/packages/cultcache-py/PARITY.md @@ -0,0 +1,54 @@ +# Python Runtime Parity Map + +This file is the current audit map for `cultcache-py` as a Python runtime for +CultCache, CultNet, and CultMesh. It is evidence, not confetti. + +## Proven Surfaces + +- CultCache v1 store parity: + `packages/cultcache-ts/test/cult-cache.test.ts` includes Python in the shared + TypeScript/Rust/C#/Python store matrix. +- CultNet schema-v0 live interop: + `packages/cultnet-ts/test/interop/cultnet-interop.test.ts` runs a live + TS/Rust/C#/Python peer ring. +- Python CultNet raw client: + Fetches schema catalogs, raw snapshots, shard catalogs, shard logs, and live + database subscription changes. +- Python CultMesh discovery client: + Fetches Verse catalogs and peer exchange responses from the live Python + endpoint over CultNet frames. +- Python CultMesh committed simulation facts: + The live interop harness sends Python a simulation observation, receives a + consensus candidate, then requests the committed `gamecult.mesh.simulation_fact` + document back over the raw snapshot lane and checks its MessagePack slots. +- Python package health: + `cultcache-py-verify --json` checks public exports, `py.typed` markers, and + benchmark sanity for Python-owned hot paths. + +## Local Python Gates + +```powershell +$env:PYTHONPATH="$PWD\packages\cultcache-py\src" +python -m unittest discover -s packages\cultcache-py\tests +python -m cultcache_py.verify --json +python -m cultcache_py.benchmark --records 1000 --json +python -m pip wheel --no-deps -w $env:TEMP packages\cultcache-py +``` + +## Cross-Runtime Gate + +```powershell +$env:PYTHON='C:\Users\Meta\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe' +npx tsc -p packages\cultnet-ts\tsconfig.test.json --pretty false +node --test packages\cultnet-ts\dist-test\test\interop\cultnet-interop.test.js +``` + +## Still Not Claimed + +- Python does not match the C# runtime for raw throughput. It has a measured + baseline, not a performance victory certificate. +- Python does not own LiteNetLib security/session behavior; it speaks the + schema-v0 interop lane used by the package harness. +- Python does not implement the full C# daemon/server stack. Its current role is + package runtime, raw interop peer, local CultMesh session facade, and typed + state participant. diff --git a/packages/cultcache-py/README.md b/packages/cultcache-py/README.md index e4e074d3..1969250c 100644 --- a/packages/cultcache-py/README.md +++ b/packages/cultcache-py/README.md @@ -270,6 +270,9 @@ prediction = session.predict(note_doc, "input:python:move", {"body": "predicted ## Wire Parity +See [PARITY.md](PARITY.md) for the current evidence map, gates, and things this +package still does not claim. + The Python interop peer is `cultcache_py.interop`: ```powershell @@ -308,6 +311,7 @@ The package ships a lightweight benchmark for Python-owned hot paths: ```powershell python -m cultcache_py.benchmark --records 1000 --json +python -m cultcache_py.verify --json ``` It reports slot-indexed `DatabaseEntry` encode/decode throughput, framed diff --git a/packages/cultcache-py/pyproject.toml b/packages/cultcache-py/pyproject.toml index b29db2ec..9dc53769 100644 --- a/packages/cultcache-py/pyproject.toml +++ b/packages/cultcache-py/pyproject.toml @@ -25,6 +25,7 @@ msgpack = ["msgpack>=1.0"] cultcache-py-interop = "cultcache_py.interop:main" cultnet-py-interop = "cultnet_py.interop_peer:main" cultcache-py-benchmark = "cultcache_py.benchmark:main" +cultcache-py-verify = "cultcache_py.verify:main" [tool.setuptools.packages.find] where = ["src"] diff --git a/packages/cultcache-py/src/cultcache_py/verify.py b/packages/cultcache-py/src/cultcache_py/verify.py new file mode 100644 index 00000000..f748a1ff --- /dev/null +++ b/packages/cultcache-py/src/cultcache_py/verify.py @@ -0,0 +1,120 @@ +from __future__ import annotations + +import argparse +import importlib +import json +from importlib import resources +from typing import Any + +from .benchmark import run_benchmark + + +EXPECTED_EXPORTS: dict[str, tuple[str, ...]] = { + "cultcache_py": ( + "CultCache", + "SingleFileMessagePackBackingStore", + "define_database_entry_type", + "define_document_type", + ), + "cultnet_py": ( + "CultNetClientAuthorityScope", + "CultNetRawClient", + "CultNetSimulationConsensus", + "CultNetSimulationObservationHub", + "apply_raw_snapshot", + "apply_shard_log_response", + "database_subscribe", + "document_put_raw", + "simulation_observation", + ), + "cultmesh_py": ( + "CultMesh", + "CultMeshGameSession", + "CultMeshSimulationFact", + "CultMeshStreamCatalog", + "simulation_fact_document", + ), +} + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(prog="cultcache-py-verify") + parser.add_argument("--records", type=int, default=64) + parser.add_argument("--json", action="store_true", dest="emit_json") + args = parser.parse_args(argv) + + result = verify(records=args.records) + if args.emit_json: + print(json.dumps(result, indent=2, sort_keys=True)) + else: + print(f"cultcache-py verify: {result['status']}") + for check in result["checks"]: + print(f"- {check['name']}: {check['status']}") + return 0 if result["status"] == "ok" else 1 + + +def verify(*, records: int = 64) -> dict[str, Any]: + checks = [ + _check_exports(), + _check_typed_markers(), + _check_benchmark(records), + ] + return { + "status": "ok" if all(check["status"] == "ok" for check in checks) else "failed", + "checks": checks, + } + + +def _check_exports() -> dict[str, Any]: + missing: dict[str, list[str]] = {} + for module_name, names in EXPECTED_EXPORTS.items(): + module = importlib.import_module(module_name) + missing_names = [name for name in names if not hasattr(module, name)] + if missing_names: + missing[module_name] = missing_names + return { + "name": "public_exports", + "status": "ok" if not missing else "failed", + "missing": missing, + } + + +def _check_typed_markers() -> dict[str, Any]: + missing = [] + for module_name in EXPECTED_EXPORTS: + package_root = resources.files(module_name) + marker = package_root.joinpath("py.typed") + if not marker.is_file(): + missing.append(module_name) + return { + "name": "typed_markers", + "status": "ok" if not missing else "failed", + "missing": missing, + } + + +def _check_benchmark(records: int) -> dict[str, Any]: + metrics = run_benchmark(records) + required = [ + "database_entry_encode", + "database_entry_decode", + "cultnet_frame_parse", + "raw_snapshot_apply", + ] + metric_map = {metric["name"]: metric for metric in metrics["metrics"]} + missing = [ + name + for name in required + if name not in metric_map or float(metric_map[name].get("opsPerSecond", 0.0)) <= 0.0 + ] + return { + "name": "benchmark_sanity", + "status": "ok" if not missing else "failed", + "records": records, + "missing": missing, + "metrics": metrics, + } + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/packages/cultcache-py/tests/test_cultcache.py b/packages/cultcache-py/tests/test_cultcache.py index 15e505c8..c376b924 100644 --- a/packages/cultcache-py/tests/test_cultcache.py +++ b/packages/cultcache-py/tests/test_cultcache.py @@ -18,6 +18,7 @@ from cultcache_py import ( ) from cultcache_py.benchmark import run_benchmark from cultcache_py.interop import read_note, write_note +from cultcache_py.verify import verify from cultnet_py import ( compute_simulation_claim_hash, CultNetClientAuthorityScope, @@ -213,6 +214,12 @@ class CultCacheTests(unittest.TestCase): }) self.assertTrue(all(metric["opsPerSecond"] > 0 for metric in result["metrics"])) + def test_verify_reports_python_runtime_surface_health(self) -> None: + result = verify(records=4) + + self.assertEqual(result["status"], "ok") + self.assertEqual({check["name"] for check in result["checks"]}, {"public_exports", "typed_markers", "benchmark_sanity"}) + def test_cultnet_schema_message_frame_round_trip(self) -> None: message = hello(runtime_id="python-test", supported_schema_versions=["cultnet.hello.v0"]) parsed = parse_message(decode_frame(encode_frame(message.to_bytes())))