cadrumo.adapters.outbound.aeat.sede._declarations_fetch module

Sede declarations fetch primitives: URLs, read guards, artefact capture.

The lowest layer of the declarations register adapter — how a URL is built for the listing and cotejo surfaces, the guards asserting a read stayed a read, the per-interaction timeouts, and the two artefact captures that pull a row’s PDF or submitted file.

Separated from the register session so that module holds the navigation and observation flow rather than also owning the primitives it drives. The guards travel with the URL builders deliberately: a URL and the assertion that fetching it did not mutate anything are one decision, and splitting them invites a new fetch path that forgets the guard.

origin_of(landed_url)[source]

Return the scheme and host a read actually landed on.

AEAT load-balances an authenticated session across its numbered sede hosts: the host that answers is ASSIGNED, not chosen, and a session minted on one may be refused by another. A URL recorded onto stored evidence must therefore name the host the read actually happened on. Reconstructing it from a fixed host writes a false provenance claim - the same class of defect as a casilla carrying legal refs it was not derived from, and for the same reason: the record is what a value is defended with later.

REFUSES when the landing is unusable, rather than falling back to the origin the navigation was issued against.

That fallback used to be defended as “the best true answer available”, and the defence does not hold. Its truth is guaranteed only in the case where it is never needed: AEAT load-balances the authenticated session across its numbered pool, so precisely when the landing cannot be read is when there is no evidence the read stayed on the requested host. The fallback is therefore a guess printed in the same field as a measurement, and a downstream reader cannot tell the two apart.

An origin that cannot be established is missing evidence, and missing evidence must read as missing. The censal reader already refused for this reason; this conforms to it.

Raises:

SedeNavigationError – When the landing carries no usable scheme + host.

Return type:

str

Parameters:

landed_url (str | None)

listing_url_for(origin, *, modelo, ejercicio)[source]

Return the declarations-listing URL for one query against origin.

Return type:

str

Parameters:
cotejo_document_url(origin, csv)[source]

Return the cotejo document URL for csv against origin.

Return type:

str

Parameters:
get_form_interaction_timeout_ms()[source]
Return type:

int

get_buscar_settle_ms()[source]
Return type:

int

get_ver_click_timeout_ms()[source]
Return type:

int

assert_cotejo_read_landing(landing_url, *, policy=RemoteStateGuardPolicy(id='aeat-sede-declarations-read', evidence_tier=<EvidenceTier.OFFICIAL_SOURCE_GUIDANCE: 'official_source_guidance'>, classification='authenticated_read_surface', allowed_hosts=('www6.agenciatributaria.gob.es', ), allowed_host_suffixes=('agenciatributaria.gob.es', ), allowed_read_paths=(), allowed_read_post_paths=(), allowed_browser_action_patterns=('alert-modal-continuar', 'select-modelo', 'select-ejercicio', 'select-option-*', 'buscar-declaraciones-presentadas', 'open-cotejo-pdf', 'download-filed-data-file'), synthetic_data_allowed=False, requires_authentication=True, requires_aeat_authorization=True, forbidden_actions=(), allows_gov_idp_hosts=False))[source]

Refuse a justificante popup that did not land on the cotejo view.

The Ver click opens a NEW page, so the landing is chosen entirely by AEAT and by whatever the row’s control points at. The CSV this module then extracts from that URL becomes the identifier it fetches the PDF bytes with, and those bytes are stored as filing evidence – so a landing that is not the cotejo view produces evidence attributed to a document nobody established.

Parameters:
  • landing_url (str) – The URL the popup actually served, read off the page.

  • policy (RemoteStateGuardPolicy) – The read guard policy; defaults to the module’s own.

Raises:

SedeNavigationError – When the popup is not on the cotejo view.

Return type:

None

async capture_row_pdf_artefact(*, context, row_locator, declaration, cell_index, kind, read_policy)[source]
Return type:

tuple[FiledDeclaracionArtefact, bytes]

Parameters:
async capture_submitted_file_artefact(*, context, page, row_locator, declaration, cell_index, read_policy)[source]
Return type:

tuple[FiledDeclaracionArtefact, bytes]

Parameters:
assert_declarations_read_http(method, url, *, policy=RemoteStateGuardPolicy(id='aeat-sede-declarations-read', evidence_tier=<EvidenceTier.OFFICIAL_SOURCE_GUIDANCE: 'official_source_guidance'>, classification='authenticated_read_surface', allowed_hosts=('www6.agenciatributaria.gob.es', ), allowed_host_suffixes=('agenciatributaria.gob.es', ), allowed_read_paths=(), allowed_read_post_paths=(), allowed_browser_action_patterns=('alert-modal-continuar', 'select-modelo', 'select-ejercicio', 'select-option-*', 'buscar-declaraciones-presentadas', 'open-cotejo-pdf', 'download-filed-data-file'), synthetic_data_allowed=False, requires_authentication=True, requires_aeat_authorization=True, forbidden_actions=(), allows_gov_idp_hosts=False))[source]
Return type:

None

Parameters:
assert_declarations_read_browser_action(action, *, policy=RemoteStateGuardPolicy(id='aeat-sede-declarations-read', evidence_tier=<EvidenceTier.OFFICIAL_SOURCE_GUIDANCE: 'official_source_guidance'>, classification='authenticated_read_surface', allowed_hosts=('www6.agenciatributaria.gob.es', ), allowed_host_suffixes=('agenciatributaria.gob.es', ), allowed_read_paths=(), allowed_read_post_paths=(), allowed_browser_action_patterns=('alert-modal-continuar', 'select-modelo', 'select-ejercicio', 'select-option-*', 'buscar-declaraciones-presentadas', 'open-cotejo-pdf', 'download-filed-data-file'), synthetic_data_allowed=False, requires_authentication=True, requires_aeat_authorization=True, forbidden_actions=(), allows_gov_idp_hosts=False))[source]
Return type:

None

Parameters: