重构 改为标准化输出
This commit is contained in:
@@ -46,8 +46,8 @@ def _read_schema_document(path_value: str, modified_ns: int) -> dict[str, Any]:
|
||||
schema = json.loads(schema_path.read_text(encoding="utf-8"))
|
||||
except (OSError, json.JSONDecodeError) as error:
|
||||
raise RuntimeError("The local engine schema document is unavailable or invalid") from error
|
||||
if not isinstance(schema, dict) or not isinstance(schema.get("feature_atomic_ids"), dict):
|
||||
raise RuntimeError("The local engine schema has no feature_atomic_ids contract")
|
||||
if not isinstance(schema, dict) or not isinstance(schema.get("operation_contracts"), dict):
|
||||
raise RuntimeError("The local engine schema has no v3 operation contract registry")
|
||||
return schema
|
||||
|
||||
|
||||
@@ -60,31 +60,6 @@ def _engine_schema(engine: Any) -> dict[str, Any]:
|
||||
return _read_schema_document(str(schema_path), modified_ns)
|
||||
|
||||
|
||||
def feature_atomic_contract(engine: Any, atomic_id: str) -> dict[str, Any]:
|
||||
"""Return the runtime-supported parameter contract for one atomic feature."""
|
||||
schema = _engine_schema(engine)
|
||||
normalized_id = str(atomic_id or "").strip()
|
||||
contracts = schema["feature_atomic_ids"]
|
||||
contract = contracts.get(normalized_id)
|
||||
registered = {str(item) for item in getattr(engine, "SUPPORTED_ATOMIC_IDS", ())}
|
||||
declared = {str(item) for item in schema.get("runtime_supported_atomic_ids") or ()}
|
||||
if normalized_id not in registered or normalized_id not in declared or not isinstance(contract, dict):
|
||||
raise ValueError(f"Unsupported runtime atomic_id: {normalized_id}")
|
||||
required = contract.get("required_params") or []
|
||||
optional = contract.get("optional_params") or []
|
||||
if not all(isinstance(item, str) and item for item in [*required, *optional]):
|
||||
raise RuntimeError(f"Runtime feature contract is invalid for {normalized_id}")
|
||||
return {
|
||||
"atomic_id": normalized_id,
|
||||
"summary": str(contract.get("summary") or ""),
|
||||
"required_params": list(dict.fromkeys(required)),
|
||||
"optional_params": [item for item in dict.fromkeys(optional) if item not in required],
|
||||
"position_format": str(contract.get("position_format") or ""),
|
||||
"requires_sketch": contract.get("requires_sketch") is True,
|
||||
"selector_slot": copy.deepcopy(contract.get("selector_slot")) if isinstance(contract.get("selector_slot"), dict) else None,
|
||||
}
|
||||
|
||||
|
||||
@lru_cache(maxsize=16)
|
||||
def _cdsl_validator(path_value: str, modified_ns: int) -> Draft202012Validator:
|
||||
"""Compile the JSON Schema once per runtime schema revision."""
|
||||
@@ -152,11 +127,11 @@ def validate_cdsl(cdsl: dict[str, Any], engine: Any) -> None:
|
||||
raise ValueError("CDSL requires a feature list and a geometry.sketches array")
|
||||
sketch_ids = {str(sketch.get("id")) for sketch in sketches}
|
||||
semantic_contract = _engine_schema(engine)
|
||||
atomic_contracts = semantic_contract["feature_atomic_ids"]
|
||||
declared_atomic_ids = {
|
||||
str(atomic_id)
|
||||
for atomic_id in semantic_contract.get("runtime_supported_atomic_ids", atomic_contracts)
|
||||
}
|
||||
try:
|
||||
atomic_contracts = engine.materialized_feature_contracts(semantic_contract)
|
||||
except (AttributeError, ValueError) as error:
|
||||
raise RuntimeError("The local engine operation contract registry is invalid") from error
|
||||
declared_atomic_ids = {str(atomic_id) for atomic_id in atomic_contracts}
|
||||
registered_atomic_ids = {str(atomic_id) for atomic_id in getattr(engine, "SUPPORTED_ATOMIC_IDS", ())}
|
||||
supported_atomic_ids = sorted(declared_atomic_ids & registered_atomic_ids)
|
||||
feature_ids: set[str] = set()
|
||||
|
||||
Reference in New Issue
Block a user