aeat.core.access_gate._authorization module¶
Multi-year-renta modelo authorization manifest, types, and derivation.
This module owns the type spine of the multi-year-renta authorization
gate decided in the modelo-multiyear-renta ADR. The gate’s governing
principle is default-deny-by-absence: a modelo’s calculation backend
is treated as NON-FUNCTIONAL until its authorization is derived from the
declarative manifest and verified by an enrolling end-to-end persona
test that drove the real backend across at least two distinct renta
(annual) periods.
Four collaborating pieces live here:
AuthorizationStateandEnrollmentEvidenceClass— the closed value sets, declared asenum.StrEnumper the core-authority ADR (core/owns closed enums).ModeloAuthorizationEntry— the strict pydantic record modelling one manifest entry. The>=2 distinct renta yearsinvariant is enforced at the type boundary so a malformed (single-year) enrollment claim cannot construct.AuthorizationManifest— the parsed, validated view of the directory-mode manifest (authorization.d/<modelo>.tomlfragments, one per enrolled modelo, merged by the loader). Default-deny is literal: an absent directory or one with no fragments authorizes zero modelos.ModeloAuthorization— the derived per-modelo capability the runtime consults. It is computed at the registry boundary (seedomain.calculations.registry.ValidatedRegistryAuthority.authorization()), never authored independently per revision, so the capability cannot drift from the manifest.
The manifest is the only writable authorization surface; everything else
is a derivation of it. This is the same trust-but-verify shape codified
for fixtures in fixture-provenance-declared-in-sidecar: a declaration
in data, cross-checked against evidence the declaration cannot fabricate
(here, the year-set a recorder observes a real test exercising).
- MIN_DISTINCT_RENTA_YEARS: Final[int]¶
Minimum number of distinct renta (annual) years an enrolling test must exercise before a modelo may be authorized. The owner mandate is two distinct years: a single-period test cannot prove cross-year stability.
- AUTHORIZATION_MANIFEST_DIRNAME: Final[str]¶
Directory holding the per-modelo authorization manifest fragments, resolved relative to the AEAT registry root (sibling of
legal/andmodelos/). The manifest is directory-mode: each enrolled modelo owns oneauthorization.d/<modelo>.tomlfile, mirroring the registry’s own directory-mode layout. The loader merges every fragment. Per-modelo files mean concurrent enrollment across the campaign swarm writes disjoint files — zero cross-coder contention on a single manifest.
- CANONICAL_MODELO_FLEET: Final[tuple[str, ...]]¶
The canonical fleet of modelo ids the gate enrolls. The owner mandate is non-negotiable: every modelo enrolls, none is out-of-scope. This is the honest denominator behind the meta-test’s
authorized N/30line. It is the union of every modelo the registry authority can load today plus the engine-build modelos whose registry directory carries nomanifest.tomlyet (151 Beckham, 714 Patrimonio, 721 crypto), which the ADR’s engine-build sub-decision keeps in scope. The meta-test pins this tuple against the live registry so a registry change that adds or drops a modelo surfaces loudly rather than silently moving the denominator. Retired identifiers carried byModelobut with no registry definition (NON_REGISTRY_MODELOS, e.g. the suppressed M037 censo simplificada) are NOT enrolled and are excluded here.
- FLEET_SIZE: Final[int]¶
The enrolled-fleet size used as the meta-test denominator. Derived from the canonical fleet rather than hard-coded so the two cannot disagree.
- class AuthorizationState(*values)[source]¶
Bases:
StrEnumClosed two-state authorization verdict for a modelo’s backend.
UNAUTHORIZEDis the default for every modelo not proven by an enrolling test;AUTHORIZEDis granted only once a verified enrollment record exists in the manifest.- UNAUTHORIZED¶
- AUTHORIZED¶
- class EnrollmentEvidenceClass(*values)[source]¶
Bases:
StrEnumClosed set of enrollment-evidence shapes across the modelo fleet.
The owner mandate keeps every modelo in scope, but the shape of the cross-year evidence varies by modelo class (see the
modelo-multiyear-rentaADR’s cross-modelo-class ruling):CALCULATION— engine plus a cross-year carry (130, 100, 200, 202, 303, 131, …); the recorder captures twofiling_yearvalues computed throughcalculate_modelo_revision.RECONCILIATION— periodic→annual summary reconciled across two years (390, 180, 190, 193).DATA_FIDELITY— informativa year-over-year fidelity plus provenance, with no numeric oracle (347, 184, 721, 232, 349, …).THRESHOLD_CONTINUITY— structural exemption / obligation logic across two years (720, 840, 036).
- CALCULATION¶
- RECONCILIATION¶
- DATA_FIDELITY¶
- THRESHOLD_CONTINUITY¶
- class ModeloAuthorizationEntry(**data)[source]¶
Bases:
BaseModelOne enrolling claim from the authorization manifest.
An entry is a claim the enrolling end-to-end test must verify, not a trusted grant. The
>=2 distinct renta yearsinvariant is enforced here at the pydantic boundary so a single-year (un-cross-year) claim cannot even construct — the minimum-two-years contract is unconstructable to violate, not merely asserted in a test.- Variables:
modelo – The modelo id the entry authorizes (e.g.
"130").renta_years – The distinct renta (annual) years the enrolling evidence must exercise. At least
MIN_DISTINCT_RENTA_YEARSdistinct years are required; duplicates are rejected.evidence_class – The enrollment-evidence shape for this modelo.
enrolling_test – Dotted-or-path reference to the end-to-end persona test that enrolls this modelo. The meta-test confirms the referenced test exists and that the year-set its recorder observes equals
renta_years.
- Parameters:
modelo (str)
evidence_class (EnrollmentEvidenceClass)
enrolling_test (str)
- modelo: str¶
- renta_years: tuple[int, ...]¶
- evidence_class: EnrollmentEvidenceClass¶
- enrolling_test: str¶
- class AuthorizationManifest(**data)[source]¶
Bases:
BaseModelParsed, validated view of the directory-mode authorization manifest.
The manifest is the merge of every
authorization.d/<modelo>.tomlfragment. Default-deny is literal: an absent directory or one with no fragments yields an emptyentriestuple and therefore authorizes zero modelos. A modelo id may appear at most once across fragments; a duplicate is an authoring error, not a silent last-wins overwrite.- Parameters:
entries (tuple[ModeloAuthorizationEntry, ...])
- entries: tuple[ModeloAuthorizationEntry, ...]¶
- entry_for(modelo)[source]¶
Return the enrolling
ModeloAuthorizationEntryformodelo, orNoneif absent.- Return type:
- Parameters:
modelo (str)
- class ModeloAuthorization(**data)[source]¶
Bases:
BaseModelDerived per-modelo authorization capability the runtime consults.
This record is computed at the registry boundary from the manifest cross-checked against the loadable registry — it is never authored independently per revision, so it cannot drift from the manifest. See
domain.calculations.registry.ValidatedRegistryAuthority.authorization().- Variables:
modelo – The modelo id this capability describes.
state –
AUTHORIZEDiff the manifest enrolls the modelo;UNAUTHORIZEDotherwise (the default for every modelo).has_engine – Whether the modelo declares a
calculationsurface application-link in the loaded registry. Drives the CLI ADVISORY-vs-refusal split: an UNAUTHORIZED modelo that has an engine still computes (with an advisory banner); a modelo with no loadable engine is refused atwork createby the established stub guard.entry – The manifest entry backing an
AUTHORIZEDstate, orNonewhenUNAUTHORIZED.
- Parameters:
modelo (str)
state (AuthorizationState)
has_engine (bool)
entry (ModeloAuthorizationEntry | None)
- modelo: str¶
- state: AuthorizationState¶
- has_engine: bool¶
- entry: ModeloAuthorizationEntry | None¶
- manifest_dir(registry_root)[source]¶
Return the
authorization.ddirectory for an AEAT registry root.The directory is a sibling of
legal/andmodelos/under the registry root, so callers that hold the registry root (the authority, the fingerprint walker) resolve it the same way.- Return type:
Path- Parameters:
registry_root (Path)
- load_authorization_manifest(registry_root)[source]¶
Load and validate the directory-mode authorization manifest.
The manifest is directory-mode: every enrolled modelo owns one
authorization.d/<modelo>.tomlfragment underregistry_root. The loader merges every fragment in sorted order into oneAuthorizationManifest.Default-deny-by-absence: when the
authorization.ddirectory is missing or holds no*.tomlfragments, the result is an empty manifest (zero authorized modelos), never an error. A present-but- malformed fragment raisesAuthorizationManifestErrorso a broken authorization surface fails loudly rather than silently authorizing nothing or everything.- Parameters:
registry_root (
Path) – The AEAT registry root directory.- Return type:
- Returns:
The validated
AuthorizationManifest.- Raises:
AuthorizationManifestError – When a fragment cannot be parsed or violates an entry/manifest invariant (single-year claim, duplicate modelo across fragments, stem/id mismatch, unknown field).
- derive_modelo_authorization(modelo, *, manifest, has_engine)[source]¶
Derive the per-modelo capability from the manifest and engine presence.
This is the canonical derivation the registry authority exposes. The capability is a pure function of (a) the manifest entry, if any, and (b) whether the modelo declares a calculation surface in the loaded registry — never an independently authored flag.
- Parameters:
modelo (
str) – The modelo id to derive a capability for.manifest (
AuthorizationManifest) – The loaded authorization manifest (default-deny source).has_engine (
bool) – Whether the modelo declares acalculationsurface application-link in the registry.
- Return type:
- Returns:
The derived
ModeloAuthorization.