build(agent): molt-b#d1f4fd iteration
This commit is contained in:
parent
9f8ba0ee90
commit
c123ad41e0
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
Loading…
Reference in New Issue