Source code for cadrumo.domain.calculations.registry.checker_oracle_flow
"""Canonical flow for read-only identifier-checker oracles.The shared checker contract owns one observation shape, driver protocol,deterministic replay driver, declarative operation plan, and verificationorchestrator. Concrete GROI and NIF-IVA modules declare only their AEATendpoint policy, catalogue identity, and surface classification."""from__future__importannotationsfromcollections.abcimportMappingfromenumimportStrEnumfromtypingimportLiteralfrompydanticimportBaseModel,Field,field_validatorfrom....core.errors.hierarchyimportpydantic_validation_boundaryfrom....core.identity.tax_idimporttax_id_identity_tokenfrom....core.modelsimportSTRICT_FROZEN_CONFIGfrom.errorsimportRegistryValidationError
[docs]classCheckerDriverMode(StrEnum):"""Whether a checker driver reaches AEAT or replays captured evidence."""LIVE="live""""Executes against the live AEAT surface."""REPLAY="replay""""Replays previously captured evidence and performs no network operation."""
CheckerDriverModeValue=Literal[CheckerDriverMode.LIVE,CheckerDriverMode.REPLAY]"""Both modes, for the Protocol property a driver of either kind satisfies.The concrete drivers narrow this to the single member they actually are, rooted as`Literal[CheckerDriverMode.LIVE]` or `Literal[CheckerDriverMode.REPLAY]`. Thosenarrowings are contracts -- a live driver may never report itself as a replay -- andare deliberately not widened to this alias."""
[docs]classCheckerObservation(BaseModel):"""Normalized verdicts and raw-evidence locator from a checker surface."""model_config=STRICT_FROZEN_CONFIGvalues:dict[str,str]=Field(default_factory=dict)raw_evidence_locator:str|None=Field(default=None,max_length=512)@field_validator("values")@classmethod@pydantic_validation_boundarydef_normalize_values(cls,value:dict[str,str])->dict[str,str]:returnnormalize_verdict_mapping(value,blank_message="Checker observations must not contain blank keys or values",)
[docs]defnormalize_verdict_mapping(values:Mapping[str,str],*,blank_message:str)->dict[str,str]:"""Normalize identifier/verdict mappings and reject blank entries."""cleaned:dict[str,str]={}foridentifier,verdictinvalues.items():normalized_identifier=tax_id_identity_token(identifier)normalized_verdict=verdict.strip().lower()ifnotnormalized_identifierornotnormalized_verdict:raiseRegistryValidationError(blank_message)cleaned[normalized_identifier]=normalized_verdictreturncleaned