cadrumo.application.state_projection module¶
The single canonical operator-facing state read-projection.
Every operator-facing state or readiness surface that reports “the
truth” about the active profile - overview status, auth status,
auth test, and modelo readiness - consumes this one projection.
None of them re-derives state from a private subset of the stores.
The OperatorStateProjection is a typed, frozen pydantic model
built by exactly one producer, build_operator_state_projection().
The producer consumes the application-owned profile and workspace read ports,
the auth state, the active-profile health, and the deadline obligations
computed from Schedule, and computes each readiness value exactly
once.
Modelo readiness resolves a RegistrySnapshot only to evaluate
registry-declared profile, binding, and ledger preflight requirements for the
requested ModeloReadinessRequest.
The projection is pure read: building it mutates no store.
Background: overview status once reconstructed workspace
counters from a different store subset than modelo work writes:
it read the ModeloDraft store but never the
WorkUnitCatalogue or
CalculationRevisionCatalogue stores, so an
operator who used
modelo work create / calculate saw drafts: 0. This
projection carries drafts (the declaration-draft
ModeloDraft store) and work_units (the
WorkUnitCatalogue store) as distinct counters, so
neither is silently zero.
See also
OverviewStatusReportOverview emit shape derived from this projection, rather than from a second store assembly path.
build_overview_status_report()Overview producer that consumes this projection instead of rebuilding workspace, auth, and deadline readiness.
AuthStatusResultAuth emit shape that reads the same canonical configured/authenticated readiness values carried here.
inspect_operator_auth()Auth status producer that reads
ProjectionAuthReadinessandProjectionActiveProfilefrom this projection.StateProjectionReadPortsRequired application-owned reads supplied by an outer composition root.
ProjectionWorkspaceSummaryPer-store counter record that keeps declaration drafts, work units, and calculation revisions distinct.
ProjectionModeloReadinessPer-target readiness record built from profile facts, registry snapshots, binding availability, and ledger preflight.
resolve_deadline_stage_obligation()Filing workflow selector that filters a schedule for the workflow gate; it does not consume
pending_obligationsdirectly.compute_obligation_schedule()Single deadline schedule producer used for projection obligations and workflow deadline-stage checks.
RegistrySnapshotRegistry authority snapshot used to resolve modelo-readiness preflight requirements.
Core types:
ModeloRevision,
UserProfileRecord.
- class ProjectionActiveProfile(**data)[source]¶
Bases:
BaseModelActive-profile identity and health, computed once for every surface.
This record is the projection-side form of
ActiveProfileHealth. Auth and overview surfaces read these fields instead of re-running profile pointer or bucket manifest checks.- Variables:
profile_id – Immutable bucket UUID of the active profile, or
Nonewhen no profile is active.label – Operator-chosen display name of the active profile, or
Nonewhen no profile is active or the label cannot be resolved.health_status – The
ActiveProfileHealthstatus string (none/dangling_pointer/incomplete/ready/ …).registered_bucket – Whether the active-profile pointer resolves to a registered bucket.
record_present – Whether the encrypted profile record loaded.
precondition_verdict – The application-owned recovery verdict carried from
assess_active_profile_health().
- Parameters:
data (Any)
- profile_id: ProfileId | None¶
- label: str | None¶
- health_status: str¶
- registered_bucket: bool¶
- record_present: bool¶
- precondition_verdict: PreconditionVerdict | None¶
- class ProjectionWorkspaceSummary(**data)[source]¶
Bases:
BaseModelCounters for every workspace store, so none is silently zero.
draftsandwork_unitsare deliberately distinct counters:modelo filewrites the declaration-draftModeloDraftstore whilemodelo work create/calculatewrite theWorkUnitCataloguestore. Calculation output is counted separately throughCalculationRevisionCatalogue. A singledraftscounter that read only the first store reported0for an operator who used themodelo workflow.- Variables:
transactions – Count of imported transactions.
invoices – Count of imported invoices.
drafts – Count of declaration-draft
ModeloDraftentries.work_units – Count of active (
BORRADOR)WorkUnitCatalogueentries written bymodelo work create. Discarded units are excluded so the counter is never inflated by units the operator has abandoned.discarded_work_units – Count of
DESCARTADOWorkUnitCatalogueentries, carried distinctly so a surface can state the active / discarded split rather than a misleading total.calculation_revisions – Count of
CalculationRevisionCatalogueentries written bymodelo work calculate.unreadable_rows – Count of secure-object rows that failed to decrypt — an integrity warning.
- Parameters:
data (Any)
- transactions: int¶
- invoices: int¶
- drafts: int¶
- work_units: int¶
- discarded_work_units: int¶
- calculation_revisions: int¶
- unreadable_rows: int¶
- class ProjectionObligation(**data)[source]¶
Bases:
BaseModelOne pending filing obligation carried in the projection.
Rows are copied from the
Scheduleobligations produced for the activeTaxpayerProfile. Workflow filing gates later select a narrowerModeloDeadlinefrom the same schedule producer.- Variables:
modelo – Modelo identifier.
period – Typed
Periodfor the obligation window.opens_on – First day the filing window accepts submissions.
closes_on – Last day the filing window accepts submissions.
status – The engine
ObligationStatus.
- Parameters:
data (Any)
- modelo: str¶
- period: Period¶
- opens_on: date¶
- closes_on: date¶
- status: ObligationStatus¶
- class OperatorStateProjection(**data)[source]¶
Bases:
BaseModelThe single canonical operator-facing state view.
Built by exactly one producer,
build_operator_state_projection(), and consumed by every operator-facing surface. Each readiness value it carries is computed once; surfaces present these values, they never recompute.- Variables:
active_profile – Active-profile identity + health.
auth – Auth operational readiness (carries the one canonical
configureddefinition).workspace – Per-store workspace counters.
modelo_readiness – Per-modelo preflight readiness reports, keyed by the
(modelo, revision, year, period)request the caller asked for. Empty when no modelo target was supplied.pending_obligations – The full, unfiltered deadline obligations for the active profile’s current year, as
ProjectionObligationrecords. They are computed throughcompute_obligation_schedule(), the same schedule producer that the workflow deadline stage filters throughresolve_deadline_stage_obligation(). The workflow does not consume this tuple directly; the shared invariant is producer-level schedule agreement.
- Parameters:
data (Any)
- active_profile: ProjectionActiveProfile¶
- auth: ProjectionAuthReadiness¶
- workspace: ProjectionWorkspaceSummary¶
- modelo_readiness: tuple[ProjectionModeloReadiness, ...]¶
- pending_obligations: tuple[ProjectionObligation, ...]¶
- build_active_profile(health)[source]¶
Project one coherent profile-health snapshot into the public record.
- Return type:
- Parameters:
health (ActiveProfileHealth)
- build_pending_obligations(profile, *, today)[source]¶
Compute the deadline obligations for the active profile.
Routes through
compute_obligation_schedule(), the single producer of the pending-obligation datum also used by the workflow deadline stage. This function projects the fullSchedule; the workflow gate separately filters its targetModeloDeadlinethroughresolve_deadline_stage_obligation(). A failure to compute the schedule is logged and degrades to an empty tuple rather than failing the whole projection.- Parameters:
profile (
TaxpayerProfile) – TheTaxpayerProfilewhose deadline obligations are projected.today (
date) – Reference date for fiscal-year selection and obligation status.
- Return type:
- Returns:
The projected
ProjectionObligationrecords.
- class ModeloReadinessRequest(**data)[source]¶
Bases:
BaseModelOne
(modelo, revision, year, period)readiness target.The projection producer accepts a tuple of these and computes one
ProjectionModeloReadinessper request, somodelo readinessnever builds its own profile, registry, binding, or ledger preflight pass.- Variables:
period – Typed
Periodscoping the readiness check, orNonewhen the caller omits the period (the projection uses the annual0Aperiod for registry and ledger preflight resolution).- Parameters:
data (Any)
- modelo: str¶
- revision_id: RevisionId¶
- filing_year: FilingYear¶
- period: Period | None¶
- class ProjectionModeloBindingRequirement(**data)[source]¶
Bases:
BaseModelOne registry calculation binding readiness cannot currently satisfy.
These are non-constant binding declarations from the resolved
RegistrySnapshotthat are not supplied by profile binding resolution, enum/date helpers, or a successful ledger preflight. The parentProjectionModeloReadinesscarries these rows as operator-facing missing input requirements.- Parameters:
data (Any)
- binding_id: str¶
- source: BindingSourceKind¶
- input_channel: str¶
- CLAVES_LOCALE_DISPONIBILIDAD_POR_ORIGEN_VINCULACION_LOCALE_KEYS: Mapping[BindingSourceKind, str]¶
Total locale-key projection for the noun describing each binding source.
- OPERATOR_ACTION_BY_MODELO_READINESS_BINDING_SOURCE: Mapping[BindingSourceKind, OperatorActionAxis]¶
Total action spine for a readiness
missing_bindingssource.
- OPERATOR_ACTION_BY_MODELO_READINESS_LEDGER_ISSUE: Mapping[LedgerPreflightIssueReason, OperatorActionAxis]¶
Total action spine for readiness
ledger_issuesreasons.
- class ProjectionModeloReadiness(**data)[source]¶
Bases:
BaseModelReadiness for one modelo target across all preflight axes.
The projection combines profile requirements, registry-snapshot availability, calculation binding resolution, and ledger preflight into one emit shape.
readyis true only when every axis is ready; aLedgerPreflightIssueblocks readiness only when the resolvedRegistrySnapshotdeclares ledger-backed bindings.- Variables:
profile_id – Active
ProfileIdused for the readiness report.modelo – Modelo identifier from the
ModeloReadinessRequest.revision_id – Registry revision requested or resolved for this target.
filing_year – Filing year used to resolve registry and profile requirements.
missing – Profile fields still required by the
ProfilePreflightReport.profile_refusal – Operator-facing refusal when profile facts are present but disqualify the target period.
registry_ready – Whether the requested modelo/year/period/revision resolved to a usable registry snapshot.
registry_refusal – Operator-facing explanation when registry resolution failed.
binding_ready – Whether every non-constant registry binding can be supplied by the current profile or ledger state.
missing_bindings – Missing
ProjectionModeloBindingRequirementrecords for unresolved calculation inputs.period – Typed
Periodthe readiness check was scoped to.ledger_preflight_required – Whether the registry declares any ledger aggregation binding requiring ledger preflight.
ledger_ready – Ledger-preflight verdict, or
Nonewhen no ledger preflight was required.ledger_period – The
Periodthe ledger preflight was scoped to, orNonewhen no ledger preflight was run.ledger_issues – Blocking
LedgerPreflightIssuerows.per_operation_requirements_assessed – Whether the per-modelo schema-required axis (see
per_operation_requirements_assessed) actually examined any field for this modelo.Falsemeans no schema-required field was checked andprofile_readyreflects only the export-identity and conditional checks; it MUST NOT be rendered as a clean bill of health.
- Parameters:
data (Any)
- profile_id: ProfileId¶
- modelo: str¶
- revision_id: RevisionId¶
- filing_year: FilingYear¶
- period: Period¶
- missing: tuple[ProfilePreflightRequirement, ...]¶
- profile_ready: bool¶
- per_operation_requirements_assessed: bool¶
- profile_refusal: str¶
- registry_ready: bool¶
- registry_refusal: str¶
- binding_ready: bool¶
- missing_bindings: tuple[ProjectionModeloBindingRequirement, ...]¶
- ledger_preflight_required: bool¶
- ledger_ready: bool | None¶
- ledger_period: Period | None¶
- ledger_checked_transaction_count: int¶
- ledger_issues: tuple[LedgerPreflightIssue, ...]¶
- ready: bool¶
- build_operator_state_projection(*, certificate_secret_backend_factory, operator_probe_ports, operator_scope_ports, read_ports, operation, state=None, auth_snapshot=None, requested_provider=None, probe_live_backend=False, include_workspace_summary=True, include_pending_obligations=True, modelo_readiness_requests=(), today=None)[source]¶
Assemble the one canonical operator-facing state projection.
This is the single producer of
OperatorStateProjection. Every operator-facing surface calls it and reads its typed fields; no surface re-derives state.- Parameters:
certificate_secret_backend_factory (
CertificateSecretBackendFactory) – Application-owned certificate-secret backend factory used by auth readiness.operator_probe_ports (
OperatorProbePorts) – Required inward operator-auth probe capabilities.operator_scope_ports (
OperatorScopePorts) – Operator-scoped auth and profile capabilities.read_ports (
StateProjectionReadPorts) – Required application-owned profile and workspace reads composed by the outer entrypoint for this profile scope.operation (
PinnedAuthorityOperation) – Caller-owned generation-pinned authority operation used by profile health and any requested modelo readiness projection.state (
WorkflowState|None) – Pre-loaded workflow state. WhenNoneand a profile is active, the state is loaded throughworkflow_state_repository(); whenNoneand no profile is active, an emptyWorkflowStateis used (opening the bucket database would require a session that does not exist yet). A caller-supplied state has no storage-route provenance, so live backend probing is suppressed rather than combining that snapshot with credentials from the current route.auth_snapshot (
ActiveAuthProjectionSnapshot|None) – Route-witnessed auth state and credentials obtained fromactive_auth_projection_span(). The caller keeps that span open while this function consumes the snapshot. Mutually exclusive withstate; unlike an unproven state value, the snapshot permits its witnessed credentials to feed the live backend probe.requested_provider (
str|None) – Optional provider id the caller scoped the auth readiness to.Nonereports the configured provider.probe_live_backend (
bool) – When set, the live auth backend is queried for theavailable/health_*fields. The probe may downgrade derived authentication readiness, but it never elevates configuration.include_workspace_summary (
bool) – When false, skip ledger, invoice, draft, work-unit, and revision counters. Auth-only surfaces use this so unrelated workspace-store corruption cannot block local auth readiness inspection; overview-style surfaces keep the default full projection.include_pending_obligations (
bool) – When false, skip period deadline projection. Auth-only surfaces do not render obligation rows, so they should not fail because an unrelated period-readiness path changes.modelo_readiness_requests (
tuple[ModeloReadinessRequest,...]) – Optional readiness targets; oneProjectionModeloReadinessis computed per request.today (
date|None) – Reference date for the deadline computation. Defaults todate.today().
- Return type:
- Returns:
The fully-populated
OperatorStateProjection. Building it mutates no store.