From c123ad41e09ebdbe4d3afe75db88ab51424cc805 Mon Sep 17 00:00:00 2001 From: agent-d1f4fdedbc508482 Date: Wed, 15 Apr 2026 02:09:11 +0200 Subject: [PATCH] build(agent): molt-b#d1f4fd iteration --- README.md | 4 +++ .../core.py | 26 ++++++++++++++++++- .../registry.py | 9 +++++++ .../registry_contracts.py | 23 ++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 gridverse_open_low_code_platform_for_cro/registry_contracts.py diff --git a/README.md b/README.md index b6d314b..7f90fce 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ This repository implements a minimal, Python-based MVP of GridVerse: a modular, - AdapterMarketplace (gridverse_open_low_code_platform_for_cro.marketplace) registers and lists adapters. - ContractRegistry (gridverse_open_low_code_platform_for_cro.registry) validates and stores contract schemas. - End-to-end tests and packaging skeleton +- MVP extensions in progress +- DeltaSync: lightweight delta-state helper for cross-domain messaging (gridverse_open_low_code_platform_for_cro/core.py) +- registry_contracts: minimal helpers for contract schema validation (gridverse_open_low_code_platform_for_cro/registry_contracts.py) + How to run - bash test.sh diff --git a/gridverse_open_low_code_platform_for_cro/core.py b/gridverse_open_low_code_platform_for_cro/core.py index ce51be2..a9bb0b9 100644 --- a/gridverse_open_low_code_platform_for_cro/core.py +++ b/gridverse_open_low_code_platform_for_cro/core.py @@ -1,6 +1,7 @@ from __future__ import annotations from dataclasses import dataclass, field +from typing import Any, Dict from typing import Any, Dict, List, Optional, Callable @@ -44,4 +45,27 @@ class Functor: return self.map_morphism(m) -__all__ = ["Object", "Morphism", "Functor"] +__all__ = ["Object", "Morphism", "Functor", "DeltaSync"] + + +@dataclass +class DeltaSync: + """Lightweight delta-sync state container for cross-domain messaging. + + This is a minimal, in-process helper to accumulate deltas from multiple + adapters and expose a snapshot for reconciliation. It is intentionally + tiny and dependency-free to align with the MVP goal of a composable + ecosystem. + """ + + _state: Dict[str, Any] = field(default_factory=dict, repr=False) + + def apply_delta(self, delta: Dict[str, Any]) -> None: + """Apply a delta into the local delta state.""" + if not isinstance(delta, dict): # defensive + raise TypeError("delta must be a dict") + self._state.update(delta) + + def snapshot(self) -> Dict[str, Any]: + """Return a shallow copy of the current delta state.""" + return dict(self._state) diff --git a/gridverse_open_low_code_platform_for_cro/registry.py b/gridverse_open_low_code_platform_for_cro/registry.py index 9e01a9d..94264c9 100644 --- a/gridverse_open_low_code_platform_for_cro/registry.py +++ b/gridverse_open_low_code_platform_for_cro/registry.py @@ -1,6 +1,7 @@ from __future__ import annotations from typing import Dict, Any, Optional +import re class ContractRegistry: @@ -11,6 +12,10 @@ class ContractRegistry: def register(self, contract_id: str, contract: Dict[str, Any]) -> None: self._validate(contract) + # Basic versioning sanity check (semantic versioning like 1.2.3) + v = contract.get("version") + if v is None or not isinstance(v, str) or not _is_semver(v): + raise ValueError("contract version must be a semantic version string like '1.0.0'") self._contracts[contract_id] = contract def get(self, contract_id: str) -> Optional[Dict[str, Any]]: @@ -21,3 +26,7 @@ class ContractRegistry: missing = required - set(contract.keys()) if missing: raise ValueError(f"Contract is missing required keys: {missing}") + +def _is_semver(version: str) -> bool: + # Lightweight semver check: major.minor.patch with digits + return bool(re.match(r"^\d+\.\d+\.\d+$", version)) diff --git a/gridverse_open_low_code_platform_for_cro/registry_contracts.py b/gridverse_open_low_code_platform_for_cro/registry_contracts.py new file mode 100644 index 0000000..fce8e64 --- /dev/null +++ b/gridverse_open_low_code_platform_for_cro/registry_contracts.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from typing import Dict, Any + + +def validate_contract_schema(contract: Dict[str, Any]) -> None: + """Tiny helper to validate a contract dictionary against a minimal schema.""" + if not isinstance(contract, dict): + raise TypeError("contract must be a dict") + required = {"name", "version", "schema"} + missing = required - set(contract.keys()) + if missing: + raise ValueError(f"Contract is missing required keys: {missing}") + # Basic type checks (non-strict, lightweight) + if not isinstance(contract.get("name"), str): + raise TypeError("contract.name must be a string") + if not isinstance(contract.get("version"), str): + raise TypeError("contract.version must be a string") + if not isinstance(contract.get("schema"), dict): + raise TypeError("contract.schema must be a dict") + + +__all__ = ["validate_contract_schema"]