cadrumo.application.modelo._registry_helpers module

Registry lookup and casilla validation helpers for modelo actions.

The helper layer resolves RegistrySnapshot instances through cadrumo.application.modelo._registry_resources, validates operator/imported casilla maps against the selected ModeloRevision, and refuses non-canonical printed-number tokens before the calculation engine or persistence layer sees them.

It also verifies stored CalculationRevision payloads by re-deriving their content-addressed identifiers and checking CasillaObservation/value consistency before stored payloads are trusted by verification or filing workflows.

See also

cadrumo.domain.calculations.registry.authority.bundled_indexed_authority()

Generation-pinned authority used by snapshot-backed guards.

validate_casilla_input_ids()

Boundary validator for operator-supplied casilla maps.

assert_revision_content_integrity()

Read-side guard for stored calculation revision drift.

absent_authority_file(exc)[source]

Name the file whose absence refused an authority read.

The refusal this feeds means one thing only: a published authority descriptor resolved, and the generation it names is not on disk. Nothing resolving at all is a different state, reported by AuthorityDescriptorUnavailableError at the resolution seam itself, which already names the searched location and the command that publishes one.

The path is read from the raised error rather than by re-resolving the descriptor. Re-resolving would name the descriptor, which in this state exists – so the operator would be sent to inspect the one file that is not the problem – and the resolution seam can itself refuse, which inside an exception handler would replace the refusal being built with an unrelated one.

Parameters:

exc (FileNotFoundError) – The refusal raised by the authority read.

Return type:

str

Returns:

The absent file’s path, or the error’s own text when the platform supplied no filename.

reject_incomplete_amendment_casillas(*, modelo, filing_year, period, casilla_values)[source]

Mirror the verify-modelo-revision required-manual gate on amend.

The supplied Period selects the RegistrySnapshot used to read required manual casillas. Missing required manual casillas raise AmendmentVerificationRefusedError before an amendment can be accepted as complete.

Return type:

None

Parameters:
validate_casilla_input_ids(revision, casilla_inputs)[source]

Validate operator-supplied numeric input casillas against the revision.

The ModeloRevision supplies the declared casilla ids, data types, and non-canonical reference targets used to reject ambiguous or malformed operator input. The returned mapping is keyed by canonical CasillaId values and contains only Decimal numeric inputs that the registry engine may consume.

Two declared families may carry a value: the numeric ones over their full range, and the boolean family restricted to 0 / 1, which is how the engine itself reads a boolean casilla. Both arrive as Decimal; a Python bool is refused for either, so widening to booleans never widens toward writing a True onto an amount row.

Return type:

dict[TypeAliasType, Decimal]

Parameters:
reject_unknown_override_casillas(*, modelo, filing_year, period, overrides, operation=None)[source]

Refuse amendment override casillas outside the resolved revision.

Keys are canonicalised as CasillaId values and checked against the RegistrySnapshot selected by modelo, filing_year, and Period. Printed-number aliases and ambiguous reused numbers raise AmendmentOverrideCasillaError instead of being projected to a declared casilla.

Return type:

dict[TypeAliasType, Decimal]

Parameters:
reject_unknown_import_casillas(*, modelo, filing_year, period, casilla_values, operation=None)[source]

Validate imported casilla ids and return the resolved registry snapshot.

The snapshot is a RegistrySnapshot. The returned mapping is keyed by canonical CasillaId values declared by the selected ModeloRevision. Unknown, malformed, and non-canonical printed numbers raise ExternalModeloImportError so imported AEAT values enter observation projection only under registry ids.

Return type:

tuple[RegistrySnapshot, dict[TypeAliasType, Decimal]]

Parameters:
required_input_casilla_ids_for_revision(*, modelo, filing_year, period)[source]

Resolve required manual and replayable input casilla ids for a revision.

Returns None when the registry root or RegistrySnapshot cannot be loaded. The first tuple contains required manual casillas from the selected ModeloRevision; the second contains declared manual, bound, and computed CasillaId values that amendment/import paths may need to carry through replay.

Return type:

tuple[tuple[TypeAliasType, ...], tuple[TypeAliasType, ...]] | None

Parameters:
assert_revision_content_integrity(revision)[source]

Check revision integrity; raise stored-calculation drift on mismatch.

The supplied CalculationRevision is re-hashed from its persisted inputs, bindings, relations, casilla values, and source metadata before its provenance observations are compared with casilla_values. This is a defense-in-depth read-side check for raw storage corruption that bypassed normal model construction; a mismatched observation envelope raises StoredCalculationDriftError before the revision is treated as authoritative.

Return type:

None

Parameters:

revision (CalculationRevision)