integ: merge ORCH-066 plane status model

# Conflicts:
#	CHANGELOG.md
#	docs/architecture/README.md
#	src/plane_sync.py
#	src/webhooks/plane.py
This commit is contained in:
stream
2026-06-08 06:34:37 +00:00
31 changed files with 2195 additions and 38 deletions

View File

@@ -107,6 +107,19 @@ _DEFAULT_STATES = {
# Feature 2 (verdict statuses) — Approved / Rejected.
"approved": "a519a341-dada-4a91-8910-7604f82b79c5",
"rejected": "ba958f3c-5db5-461d-8f82-89425e413b97",
# ORCH-066 (meaningful Plane status model, layer B): six new logical keys.
# Their _DEFAULT_STATES values alias the enduro-trails UUID of their BASE key
# (see _STATE_ALIAS_FALLBACK) so a project without these statuses created
# (enduro / Plane down / partial config) degrades to the current behaviour
# instead of producing an invalid PATCH state. The project-relative
# alias-fallback in get_project_states() overrides these with the *project's
# own* base UUID on the success path; these defaults are the last resort.
"to_analyse": "b873d9eb-993c-48cd-97ac-99a9b1623967", # = in_progress
"analysis": "b873d9eb-993c-48cd-97ac-99a9b1623967", # = in_progress
"code_review": "ba0d802c-5218-41d4-ab43-978b0ea123ed", # = review
"awaiting_deploy": "38fb1f64-aa1e-48a3-92e0-0b109679046b", # = in_review
"deploying": "b873d9eb-993c-48cd-97ac-99a9b1623967", # = in_progress
"monitoring": "381a2833-3c4e-4be5-bd0f-be84cb946ad8", # = done
}
# Backward-compat alias — do NOT remove (tests + webhooks/plane.py import it).
@@ -134,6 +147,29 @@ _PLANE_NAME_TO_KEY: dict[str, str] = {
# this board status (enduro / API fallback) fail-closed — no UUID, no
# confirm-deploy branch, no KeyError (accessed via .get).
"Confirm Deploy": "confirm_deploy",
# ORCH-066: meaningful per-stage / human-input statuses (layer B).
"To Analyse": "to_analyse",
"Analysis": "analysis",
"Code-Review": "code_review",
"Awaiting Deploy": "awaiting_deploy",
"Deploying": "deploying",
"Monitoring after Deploy": "monitoring",
}
# ORCH-066 (BR-12): project-relative alias-fallback for the new logical keys.
# After resolving states by name from the Plane API, any NEW key the project did
# not define degrades to the UUID of its BASE key **from the same project** — so
# the indication falls back to the current status and the PATCH stays valid even
# for a partially-configured project. Enduro (none of the new statuses created)
# collapses every new key onto its base, i.e. strictly the pre-ORCH-066
# behaviour. Strengthened ORCH-059 AC-7 pattern.
_STATE_ALIAS_FALLBACK: dict[str, str] = {
"to_analyse": "in_progress",
"analysis": "in_progress",
"code_review": "review",
"awaiting_deploy": "in_review",
"deploying": "in_progress",
"monitoring": "done",
}
# Per-project state cache: {project_id: {logical_key: state_uuid}}
@@ -181,6 +217,16 @@ def get_project_states(project_id: str) -> dict[str, str]:
if not resolved:
raise ValueError("no recognisable states in API response")
# ORCH-066 (BR-12): project-relative alias-fallback. For each NEW key the
# project did not define, reuse the UUID of its BASE key FROM THIS SAME
# PROJECT (never a foreign/enduro UUID — that would yield an invalid PATCH
# state on a partially-configured orchestrator project). Runs BEFORE the
# _DEFAULT_STATES.setdefault below so a project's own base UUID wins over
# the static enduro default.
for new_key, base_key in _STATE_ALIAS_FALLBACK.items():
if new_key not in resolved and resolved.get(base_key):
resolved[new_key] = resolved[base_key]
# Fill any missing keys from _DEFAULT_STATES so callers always get a
# complete mapping (defensive against partial Plane configs).
for k, v in _DEFAULT_STATES.items():
@@ -216,14 +262,16 @@ def reload_project_states(project_id: str = None) -> None:
# Feature 3: map an orchestrator stage -> the Plane status to show on the board
# when the pipeline ENTERS that stage. analysis stays driven by the existing
# in_progress/in_review/needs_input logic (no dedicated status). deploy keeps
# in_progress until done. Needs Input / In Review / Blocked remain higher
# priority and are set explicitly elsewhere — do NOT override them from here.
# when the pipeline ENTERS that stage. ORCH-066: analysis -> Analysis and
# review -> Code-Review now have dedicated statuses. deploy keeps in_progress
# until its own Phase A/B/C statuses drive it. Needs Input / In Review / Blocked
# remain higher priority and are set explicitly elsewhere — do NOT override them
# from here.
STAGE_VISIBILITY_STATE = {
"analysis": "analysis", # ORCH-066: analysis stage -> Analysis status
"architecture": "architecture",
"development": "development",
"review": "review",
"review": "code_review", # ORCH-066: review stage -> Code-Review status
"testing": "testing",
}
@@ -231,22 +279,27 @@ STAGE_VISIBILITY_STATE = {
# update_issue_state now calls stage_to_state() instead of looking up here.
STAGE_TO_STATE = {
"created": _DEFAULT_STATES["todo"],
"analysis": _DEFAULT_STATES["in_progress"],
# ORCH-066: analysis -> Analysis, review -> Code-Review. The new keys alias
# the same in_progress / review UUIDs in _DEFAULT_STATES, so legacy callers /
# tests that compare against concrete UUIDs see byte-identical values.
"analysis": _DEFAULT_STATES["analysis"],
"architecture": _DEFAULT_STATES["architecture"],
"development": _DEFAULT_STATES["development"],
"review": _DEFAULT_STATES["review"],
"review": _DEFAULT_STATES["code_review"],
"testing": _DEFAULT_STATES["testing"],
"deploy": _DEFAULT_STATES["in_progress"],
"done": _DEFAULT_STATES["done"],
}
# Map orchestrator stage -> logical state key (project-independent).
# ORCH-066: analysis -> analysis, review -> code_review (was in_progress/review).
# deploy stays in_progress (Phase A/B/C drive it directly, not update_issue_state).
_STAGE_TO_STATE_KEY = {
"created": "todo",
"analysis": "in_progress",
"analysis": "analysis",
"architecture": "architecture",
"development": "development",
"review": "review",
"review": "code_review",
"testing": "testing",
"deploy": "in_progress",
"done": "done",
@@ -581,6 +634,58 @@ def set_issue_in_progress(work_item_id: str, project_id: str = None):
_set_issue_state_direct(work_item_id, state_id, project_id)
def set_issue_analysis(work_item_id: str, project_id: str = None):
"""ORCH-066: set issue to 'Analysis' — analyst is working (start / resume).
Degrades to the project's In Progress UUID when the 'Analysis' status is not
created (alias-fallback). never-raise (via _set_issue_state_direct).
"""
project_id = _resolve_project_id(work_item_id, project_id)
state_id = get_project_states(project_id)["analysis"]
_set_issue_state_direct(work_item_id, state_id, project_id)
def set_issue_code_review(work_item_id: str, project_id: str = None):
"""ORCH-066: set issue to 'Code-Review' — review stage indication.
Degrades to the project's Review UUID when 'Code-Review' is not created.
"""
project_id = _resolve_project_id(work_item_id, project_id)
state_id = get_project_states(project_id)["code_review"]
_set_issue_state_direct(work_item_id, state_id, project_id)
def set_issue_awaiting_deploy(work_item_id: str, project_id: str = None):
"""ORCH-066: set issue to 'Awaiting Deploy' — self-deploy Phase A approval-pending.
Degrades to the project's In Review UUID when 'Awaiting Deploy' is not created.
"""
project_id = _resolve_project_id(work_item_id, project_id)
state_id = get_project_states(project_id)["awaiting_deploy"]
_set_issue_state_direct(work_item_id, state_id, project_id)
def set_issue_deploying(work_item_id: str, project_id: str = None):
"""ORCH-066: set issue to 'Deploying' — self-deploy Phase B prod deploy in flight.
Degrades to the project's In Progress UUID when 'Deploying' is not created.
"""
project_id = _resolve_project_id(work_item_id, project_id)
state_id = get_project_states(project_id)["deploying"]
_set_issue_state_direct(work_item_id, state_id, project_id)
def set_issue_monitoring(work_item_id: str, project_id: str = None):
"""ORCH-066: set issue to 'Monitoring after Deploy' — post-deploy window open.
Degrades to the project's Done UUID when 'Monitoring after Deploy' is not
created (so the board shows Done, exactly as before ORCH-066).
"""
project_id = _resolve_project_id(work_item_id, project_id)
state_id = get_project_states(project_id)["monitoring"]
_set_issue_state_direct(work_item_id, state_id, project_id)
def set_issue_stage_state(work_item_id: str, stage: str, project_id: str = None):
"""Feature 3: move the issue to the board status for a pipeline stage.