Source code for cadrumo.domain.renta.first_slice_routing_integrity
"""Snapshot-time referential integrity for the first-slice routing table.When the registry builds a Modelo 100 snapshot, every casilla id anactual ``ledger_renta_gastos_estimacion_directa_aggregation`` binding on THAT revisiontargets MUST be a real casilla on the same revision. A divergencebetween a revision's own bindings and its own casilla set is asnapshot-build error, not a silent runtime ``KeyError`` when the rentadeductibility validator runs.This check is intentionally scoped to each revision's OWN bindings(:func:`~cadrumo.domain.calculations.registry.ledger_renta_gastos_estimacion_directa_bindings.renta_first_slice_binding_target_casillas`),not the universal BOE-prescribed routing projection spanning every filing year.Casilla ids are added, split, andrenumbered across Modelo 100 revisions -- for example "Aportaciones amutualidades alternativas" shares a combined casilla with SeguridadSocial contributions (id ``0186``) on the 2020-2022 revisions but getsits own dedicated casilla (id ``0195``) from 2023 onward. Revisionsthat declare no ``ledger_renta_gastos_estimacion_directa_aggregation`` bindings at all(the ledger-aggregation mechanism did not exist for them yet) have alegitimately empty required set; requiring the full universal codomainon every revision would fail revisions that never route through it.This check is owned by the ``renta`` domain because the routing tableis renta domain knowledge. The registry must not import ``renta``directly -- that reverses the dependency direction the hexagonalarchitecture enforces. Instead this module registers a:class:`~cadrumo.domain.calculations.registry.validate_cross_domain_snapshot.CrossDomainSnapshotCheck`with the registry validator via:func:`~cadrumo.domain.calculations.registry.validate_cross_domain_snapshot.register_cross_domain_snapshot_check`.The registration runs at ``renta`` package import time (see:mod:`cadrumo.domain.renta` ``__init__``); the registry calls the checkthrough the abstract Protocol without naming ``renta``."""from__future__importannotationsfrom...core.casilla_idimportCasillaIdfrom...core.modeloimportModelofrom..calculations.registry.validate_cross_domain_snapshotimportregister_cross_domain_snapshot_check
[docs]defcheck_first_slice_routing(modelo_id:str,casilla_ids:frozenset[CasillaId],renta_first_slice_binding_targets:frozenset[CasillaId],revision_binding_ids:frozenset[str]=frozenset(),# shared Protocol shape, unused here)->list[str]:"""Assert every casilla a revision's own first-slice bindings target exists on it. Returns a list of failure strings (empty when consistent). The registry validator prefixes each failure with the snapshot coordinates and raises a single ``RegistryValidationError``. """ifmodelo_id!=Modelo("100"):return[]missing=renta_first_slice_binding_targets-casilla_idsifnotmissing:return[]return[f"renta first-slice routing targets casillas {sorted(missing)!r} that are absent from the modelo-100 revision",]