cadrumo.adapters.outbound.aeat.verify.contract module¶
Read-only CSV verification against AEAT’s Sede electrónica.
The verify_csv() helper is opt-in: it only runs when the caller supplies
or constructs a adapters.outbound.aeat.browser.factory.DefaultBrowserSession.
It is guarded by domain.calculations.registry.remote_state_guard.RemoteStateGuardPolicy
and never mutates AEAT-side state. The contract is:
open the CSV-keyed Sede viewer,
read back the server response,
return
Trueiff AEAT confirms the document as valid.
The function degrades gracefully when a browser cannot be
constructed and surfaces the underlying error to the caller via
domain.justificante.errors.JustificanteVerificationError.
Public surface: verify_csv() plus the Playwright protocol types
(VerifyBrowserPageLike, VerifyBrowserContextLike,
VerifyBrowserSessionLike, and VerifyBrowserSessionFactory)
shared by the concrete browser adapters.
See also
adapters.outbound.aeat.browser.factory.default_browser_session_factory()Production factory used by
DEFAULT_BROWSER_SESSION_FACTORY.adapters.outbound.aeat.browser.session.BrowserSessionConcrete browser session whose context/page surface these protocols mirror.
domain.calculations.registry.remote_state_guard.assert_remote_operation_allowed()Guard used to allow only the reviewed read-only CSV verification URL.
- class VerifyBrowserPageLike(*args, **kwargs)[source]¶
Bases:
ProtocolSubset of Playwright’s
PageAPI used byverify_csv().The page surface is intentionally small: navigation to the reviewed CSV-keyed Sede URL and HTML content capture for exact result-URL and document-viewer validation.
- class VerifyBrowserContextLike(*args, **kwargs)[source]¶
Bases:
ProtocolSubset of Playwright’s
BrowserContextAPI used byverify_csv().Context ownership depends on the caller:
verify_csv()always closes the context it opens, while the surrounding session is closed only when the helper created it throughDEFAULT_BROWSER_SESSION_FACTORY.- async new_page()[source]¶
Open a new
VerifyBrowserPageLikewithin this browser context.- Return type:
- class VerifyBrowserSessionLike(*args, **kwargs)[source]¶
Bases:
ProtocolBrowser-session surface consumed by
verify_csv().The
create_contextsignature mirrorsadapters.outbound.aeat.browser.session.BrowserSession.create_context()so static checkers see no unsafe overlap between this protocol and the concrete browser sessions.verify_csvitself callscreate_context()with no arguments; production and test sessions accept the same optional kwargs as the centraladapters.outbound.aeat.browser.session.BrowserSessionso the protocol stays structurally honest.- async create_context(*, provisioner=None, storage_state=None)[source]¶
Create and return a configured
VerifyBrowserContextLike.- Return type:
- Parameters:
- VerifyBrowserSessionFactory¶
Callable that builds a self-owned
VerifyBrowserSessionLike.alias of
Callable[[],Awaitable[VerifyBrowserSessionLike]]
- async DEFAULT_BROWSER_SESSION_FACTORY()¶
Module-level factory seam for the self-owned
verify_csv()path.- Return type:
- async verify_csv(csv, *, browser=None, browser_session_factory=None)[source]¶
Verify a justificante CSV against AEAT’s Sede electrónica.
The helper normalises the CSV, opens AEAT’s reviewed CSV-keyed public viewer under the read-only guard, and parses the returned HTML for the exact CSV-bound document iframe. Passing
browserborrows the session from the caller; omitting it builds a self-owned session throughbrowser_session_factoryorDEFAULT_BROWSER_SESSION_FACTORYand closes that session after the round-trip.- Parameters:
csv (
str) – The Código Seguro de Verificación as printed on the receipt.browser (
VerifyBrowserSessionLike|None) – An already-constructedVerifyBrowserSessionLike. WhenNone, one is built from the default settings/profile.browser_session_factory (
Callable[[],Awaitable[VerifyBrowserSessionLike]] |None) – Optional no-argument factory for the self-owned path. Ignored whenbrowseris supplied.
- Return type:
- Returns:
Trueif AEAT confirms the CSV as valid;Falseif AEAT reports the document as unknown.- Raises:
JustificanteVerificationError – If the round-trip cannot be completed because browser construction, navigation, the guard, or parsing fails.