cadrumo.adapters.outbound.aeat.auth._session_probe module

Shared authenticated-landing navigation probe for AEAT auth providers.

The Cl@ve Móvil and Cl@ve Permanente providers both re-probe a persisted browser session by navigating an owned BrowserContextPort to a target URL and deciding whether the final landing page is an authenticated AEAT surface. The navigation state machine — open a page, goto the probe URL, read the status and landing URL, optionally run a provider-specific on-landing dispatch, classify the landing, and always close the page — was cloned near-byte-identically across both providers.

run_authenticated_landing_probe() owns that one state machine. Each provider supplies:

  • is_authenticated_landing — the provider’s landing predicate.

  • on_landing — an optional hook (Cl@ve Móvil uses it for the selector-page Cl@ve-button dispatch; Cl@ve Permanente passes None).

  • log_label — the operator-facing label used in the navigation-failure and page-close-suppression log lines.

The provider keeps its own guards, target/probe-URL resolution, and typed AeatLoginAssertion assembly; only the navigation probe is shared.

AuthenticatedLandingPredicate

(landing_url, target_path) -> bool provider landing classifier.

alias of Callable[[str, str], bool]

OnLandingHook

(page, landing_url, target_path) -> acted post-landing dispatch hook.

Returning True signals the probe that the hook navigated the page, so the probe re-reads the page’s landing URL afterwards; False leaves the observed landing URL unchanged.

alias of Callable[[BrowserPagePort, str, str], Awaitable[bool]]

class SessionProbeOutcome(**data)[source]

Bases: BaseModel

Result of a single authenticated-landing navigation probe.

Parameters:

data (Any)

status_code: int
landing_url: str | None
error_message: str | None
elapsed_ms: int
async run_authenticated_landing_probe(context, *, probe_url, target_path, navigation_timeout_ms, is_authenticated_landing, on_landing, log_label)[source]

Navigate context to probe_url and classify the landing page.

Opens a new page on the owned context, navigates to probe_url, and reads the response status and landing URL. When on_landing is supplied and a landing URL is observed, the hook runs and — if it reports acting — the landing URL is re-read. The landing counts as an authenticated session only when the status is in [200, 400), a landing URL is present, and is_authenticated_landing accepts it. Navigation failures are captured into error_message; the page is always closed.

Return type:

SessionProbeOutcome

Parameters: