Source code for cadrumo.adapters.persistence.storage.profile_persistence_composition
"""The one composition of the ports a profile-bound host must bind together.Custody, the login session, workflow persistence and the language resolver areone unit. A host that binds some and not the rest can open a capsule it cannotthen read a record through, and application code says so by refusing ratherthan assuming: an unbound port raises ``InternalInvariantError`` instead ofreporting an absent profile. Discharging that obligation is the host's job, andthis module is where every host discharges it.Four hosts enter this scope -- the shipped frontend composition root, the MCPserver's own root, the pytest session fixture, and the docs-sequence runner --and each used to restate the wiring. The copies had already drifted over whichports belong to the set, which is the failure mode this module removes: a portadded here reaches all of them in the same change.It lives beside the adapters it builds rather than in either process rootbecause the MCP distribution is an outer root in its own right and does notimport the CLI entrypoint, and because a test host must not have to reach intoa ``tests`` package for shipped wiring. Importing this module pulls only thepersistence tree, which is what entering the scope pulls in anyway."""from__future__importannotationsfromcollections.abcimportGeneratorfromcontextlibimportExitStack,contextmanagerfromtypingimportTYPE_CHECKINGifTYPE_CHECKING:from....application.user_profile.custody_portsimportProfileCustodyPort
[docs]@contextmanagerdefcomposed_profile_persistence_ports()->Generator[ProfileCustodyPort]:"""Bind the profile-persistence ports for one host scope, and unbind after. The yielded custody port is the one that was bound, so a caller holding on to it does not build a second instance. """from....application.user_profile.custody_portsimportbind_profile_custody_portfrom....application.user_profile.language_resolverimportregister_language_resolverfrom....application.user_profile.login_session_portimportbind_profile_login_session_portfrom....application.workflow.persistenceimportbind_workflow_persistence_portfrom..workflowimportbuild_workflow_persistence_portfrom.profile_custodyimportbuild_profile_custody_portfrom.profile_login_sessionimportbuild_profile_login_session_portprofile_custody=build_profile_custody_port()withExitStack()ascomposition:composition.enter_context(bind_profile_custody_port(profile_custody))composition.enter_context(bind_profile_login_session_port(build_profile_login_session_port()))composition.enter_context(bind_workflow_persistence_port(build_workflow_persistence_port()))register_language_resolver()yieldprofile_custody