Source code for cadrumo.application.calculations.revision_carry_gate
"""Single shared revision-carry gate.Used by :mod:`~.binding_prefill`, :mod:`~.cross_period_clean_state`, and:mod:`~.relation_prefill`: every cross-period or cross-year carry read sharesthis gate.The carry path is the one place a revision error compounds across years: aprior filed under the wrong revision injects that revision's norms into everylater filing that folds it in. The carry read therefore re-confirms eachcarried observation's ``stamped_revision_id`` against the law-determinedrevision for its source context(:meth:`~domain.calculations.registry.authority.ValidatedRegistryAuthority.inspect_revision`,which resolves the same law-determined revision selection without demandingfiling-grade admission -- this gate answers "which revision does the lawselect", never "may this be filed") before trusting the value.This module is the single implementation of that gate: one law-determinedre-confirmation, not three parallel copies that can drift across the carrysites that use it.See Also: :func:`~application.calculations.binding_prefill.resolve_bindings_from_local_store` Previous-filing binding reader that drops unreconfirmable carries. :func:`~application.calculations.relation_prefill.resolve_relations_from_local_store` Relation-prefill reader that applies the same revision-stamp gate. :func:`~application.calculations.cross_period_clean_state.evaluate_cross_period_clean_state` Filing-grade dependency proof that maps the shared outcome to blockers."""from__future__importannotationsfromdataclassesimportdataclassfrom...domain.calculations.registry.authorityimportPinnedAuthorityOperationfrom...domain.calculations.registry.idsimportRevisionIdfrom...domain.calculations.registry.schema_referencesimportRegistrySnapshotReffrom...domain.calculations.registry.temporalimportselect_authored_revision_metadata
[docs]@dataclass(frozen=True,slots=True)classRevisionCarryOutcome:"""Law-determined result of re-confirming one persisted revision stamp."""refused:boolselected_revision_id:RevisionId|Nonedetail:str|None
[docs]defrevision_carry_outcome(snapshot_ref:RegistrySnapshotRef,*,operation:PinnedAuthorityOperation,)->RevisionCarryOutcome:"""Return the single law-determined decision for a carried revision stamp. Resolves through the caller-owned pinned operation. The operation must stay leased for the complete workflow so the re-confirmation cannot cross an authority-generation boundary. - Indeterminate (source context fails to resolve) → carry refused. Current observations must be re-confirmable against the law-determined revision; there is no legacy advisory bridge. - Divergent stamp → carry refused (caller drops the observation or raises ``REGISTRY_REVISION_DIVERGENCE``). - Matching stamp → clean carry. Args: snapshot_ref: Required complete registry coordinate persisted with the source value. operation: Existing generation-pinned indexed operation owned by the enclosing workflow. Returns: A typed outcome containing the selected revision when resolution succeeds, plus the refusal reason when the stamp diverges or cannot be re-confirmed. """try:# A carried prior filing may predate the supported filing floor; the law# still selected a design for it, so the envelope is not applied here.selected_revision_id=str(select_authored_revision_metadata(operation.modelo_directory(str(snapshot_ref.modelo)),filing_year=int(snapshot_ref.modelo_year),period=str(snapshot_ref.period),).id)exceptExceptionasexc:returnRevisionCarryOutcome(refused=True,selected_revision_id=None,detail=f"revision selection failed: {type(exc).__name__}",)ifsnapshot_ref.revision_id!=selected_revision_id:returnRevisionCarryOutcome(refused=True,selected_revision_id=selected_revision_id,detail="stamped revision differs from the law-determined revision",)returnRevisionCarryOutcome(refused=False,selected_revision_id=selected_revision_id,detail=None,)