forked from ChelseaKR/permit-bearings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow_context.py
More file actions
113 lines (104 loc) · 3.63 KB
/
Copy pathworkflow_context.py
File metadata and controls
113 lines (104 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""Load one registry entry as a source-review context.
This shared boundary keeps the review-worklist and source-release CLIs on the
same registry traversal and artifact-binding semantics. It validates portable
registry paths and IDs; it does not activate, approve, or publish a workflow.
"""
from __future__ import annotations
from pathlib import Path
from .journey import load_journey_config
from .program_availability import load_program_availability
from .readiness import (
load_readiness_packet,
load_readiness_remedies,
load_readiness_workflow,
)
from .review_queue import ReadinessReviewContext
from .workflow_registry import FingerprintedArtifact, WorkflowRegistryEntry
def _assert_registered_path(
root: Path,
artifact: FingerprintedArtifact,
override: Path | None,
option: str,
) -> Path:
selected = artifact.resolve(root)
if override is not None and override.resolve() != selected:
raise ValueError(f"--{option}: path does not match the registered workflow")
return selected
def load_registered_review_context(
entry: WorkflowRegistryEntry,
root: Path,
sources_path: Path,
*,
workflow_override: Path | None = None,
packet_override: Path | None = None,
remedies_override: Path | None = None,
journey_override: Path | None = None,
) -> ReadinessReviewContext:
"""Load one exact registered workflow, packet, remedy, and journey set."""
workflow = load_readiness_workflow(
_assert_registered_path(
root,
entry.artifacts.readiness_workflow,
workflow_override,
"workflow",
),
sources_path,
)
packet = load_readiness_packet(
_assert_registered_path(
root,
entry.artifacts.readiness_packet,
packet_override,
"packet",
),
workflow,
)
remedies = load_readiness_remedies(
_assert_registered_path(
root,
entry.artifacts.readiness_remedies,
remedies_override,
"remedies",
),
workflow,
)
journey = load_journey_config(
_assert_registered_path(
root,
entry.artifacts.journey,
journey_override,
"journey",
)
)
availability = load_program_availability(
entry.artifacts.program_availability.resolve(root),
policy=entry.availability_policy,
)
if workflow.workflow_id != entry.workflow_id:
raise ValueError("registered workflow ID does not match its artifact")
if packet.workflow_id != entry.workflow_id or packet.packet_id != entry.packet_id:
raise ValueError("registered packet IDs do not match its artifact")
if journey.journey_id != entry.journey_id:
raise ValueError("registered journey ID does not match its artifact")
if (
journey.readiness_workflow_id != entry.workflow_id
or journey.readiness_packet_id != entry.packet_id
):
raise ValueError("registered journey references do not match its workflow")
if (
availability.workflow_id != entry.workflow_id
or availability.program_id != entry.program_id
):
raise ValueError("registered availability IDs do not match its artifact")
if (
workflow.jurisdiction != entry.jurisdiction
or packet.jurisdiction != entry.jurisdiction
or availability.jurisdiction != entry.jurisdiction
):
raise ValueError("registered jurisdiction does not match its artifacts")
return ReadinessReviewContext(
workflow=workflow,
packet=packet,
remedies=remedies,
journeys=(journey,),
)