Source code for cadrumo.application.workflow.profile_bucket_scan
"""Committed-capsule profile discovery for workflow projections.Workflow sees only the non-authoritative UUID and label projection emitted bythe custody capsule owner. It does not inspect manifests, buckets, deleteddirectories, or record facts.That projection is exactly what the profile summary inventory observes, so thismodule reads it rather than building a second one. It previously went throughthe authenticated aggregate, which took a per-profile custody lock and couldpublish a label head as a side effect of *resolving a name* -- work no consumerhere needs, and a second definition of "which profiles exist" that coulddisagree with the first.It takes the REFUSING half of that boundary. Callers here receive a pointer or``None``, with no channel to explain a store that could not be read, so anunreadable capsule must raise rather than resolve to "absent" -- healthassessment distinguishes a dangling pointer from an unreadable capsule, andcollapsing the two reports a damaged profile as a missing one."""from__future__importannotationsfrompathlibimportPathfrom..user_profile.profile_summaryimportProfileSummary,require_summariesfrom.errorsimportProfileLabelAmbiguousErrorfrom.profile_bucket_modelsimportProfileBucketPointerdef_summaries(root:Path|None)->tuple[ProfileSummary,...]:returnrequire_summaries(root=root)def_pointer(summary:ProfileSummary)->ProfileBucketPointer:returnProfileBucketPointer(bucket_id=summary.profile_id,label=summary.label)
[docs]defread_profile_bucket(label:str,*,root:Path|None=None,)->ProfileBucketPointer|None:"""Resolve one exact label from committed-capsule label projections."""ifnotlabelornotlabel.strip():returnNonematches=[itemforitemin_summaries(root)ifitem.label.casefold()==label.strip().casefold()]ifnotmatches:returnNoneiflen(matches)!=1:raiseProfileLabelAmbiguousError(translated_message="application.workflow.errors.profile_label_ambiguous",context={"label":label,"count":str(len(matches))},)return_pointer(matches[0])
[docs]defread_profile_bucket_by_id(profile_id:str,*,root:Path|None=None)->ProfileBucketPointer|None:"""Resolve one UUID only when its current capsule is committed."""ifnotprofile_idornotprofile_id.strip():returnNoneidentity=profile_id.strip()returnnext((_pointer(item)foritemin_summaries(root)ifitem.profile_id==identity),None)
[docs]defresolve_profile_bucket(identifier:str,*,root:Path|None=None,)->ProfileBucketPointer|None:"""Resolve a UUID or exact label through the current capsule projection."""ifnotidentifierornotidentifier.strip():returnNonereturnread_profile_bucket_by_id(identifier,root=root)orread_profile_bucket(identifier,root=root)
[docs]deflist_profile_buckets(*,root:Path|None=None,)->dict[str,ProfileBucketPointer]:"""Return every committed capsule's non-authoritative label projection."""return{item.profile_id:_pointer(item)foritemin_summaries(root)}