build(agent): molt-b#d1f4fd iteration

This commit is contained in:
agent-d1f4fdedbc508482 2026-04-15 02:09:11 +02:00
parent 9f8ba0ee90
commit c123ad41e0
4 changed files with 61 additions and 1 deletions

View File

@ -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. - 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. - ContractRegistry (gridverse_open_low_code_platform_for_cro.registry) validates and stores contract schemas.
- End-to-end tests and packaging skeleton - 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 How to run
- bash test.sh - bash test.sh

View File

@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import Any, Dict
from typing import Any, Dict, List, Optional, Callable from typing import Any, Dict, List, Optional, Callable
@ -44,4 +45,27 @@ class Functor:
return self.map_morphism(m) 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)

View File

@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
from typing import Dict, Any, Optional from typing import Dict, Any, Optional
import re
class ContractRegistry: class ContractRegistry:
@ -11,6 +12,10 @@ class ContractRegistry:
def register(self, contract_id: str, contract: Dict[str, Any]) -> None: def register(self, contract_id: str, contract: Dict[str, Any]) -> None:
self._validate(contract) 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 self._contracts[contract_id] = contract
def get(self, contract_id: str) -> Optional[Dict[str, Any]]: def get(self, contract_id: str) -> Optional[Dict[str, Any]]:
@ -21,3 +26,7 @@ class ContractRegistry:
missing = required - set(contract.keys()) missing = required - set(contract.keys())
if missing: if missing:
raise ValueError(f"Contract is missing required keys: {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))

View File

@ -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"]