AP2.4: Steuerungselement-Registry und Methoden-Vertrag.
Deploy Development / deploy (push) Successful in 46s
Test Suite / pytest-backend (push) Failing after 3m17s
Test Suite / k6 /api/health Baseline (push) Has been skipped
Test Suite / playwright-smoke (push) Has been skipped
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped

MethodDefinition traegt steering_elements/ui_features/graph_profile; operating-context und FE-Registry ohne Archetyp-Ifs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-07-25 11:27:59 +02:00
1 parent ac475ab92c
commit d3bf3c36e0
25 files changed
+837 -118

No files matched your search

+5 -17
View File
@@ -73,7 +73,6 @@ GENERIC_UI_PROFILE: dict[str, Any] = {
*_COMMON_OM_SLICES[1:],
],
"enabledModes": ["plan", "work", "control"],
"uiFeatures": {},
}
INITIATIVE_UI_PROFILES: dict[str, dict[str, Any]] = {
@@ -99,10 +98,6 @@ INITIATIVE_UI_PROFILES: dict[str, dict[str, Any]] = {
"steering_methods",
],
"enabledModes": ["plan", "work", "control"],
"uiFeatures": {
"continuousProductWorkMode": True,
"steeringSnapshotOnWorkSprint": True,
},
},
"initiative.linear_project": {
"processSteps": list(_LINEAR_PROCESS),
@@ -123,9 +118,6 @@ INITIATIVE_UI_PROFILES: dict[str, dict[str, Any]] = {
"steering_methods",
],
"enabledModes": ["plan", "work", "control"],
"uiFeatures": {
"criticalPathControl": True,
},
},
"initiative.maturity_journey": {
"processSteps": list(_MATURITY_PROCESS),
@@ -145,7 +137,6 @@ INITIATIVE_UI_PROFILES: dict[str, dict[str, Any]] = {
"steering_methods",
],
"enabledModes": ["plan", "work", "control"],
"uiFeatures": {},
},
"initiative.program": {
"processSteps": list(_PROGRAM_PROCESS),
@@ -167,7 +158,6 @@ INITIATIVE_UI_PROFILES: dict[str, dict[str, Any]] = {
"steering_methods",
],
"enabledModes": ["plan", "work", "control"],
"uiFeatures": {},
},
"initiative.support_queue": {
"processSteps": list(_SUPPORT_QUEUE_PROCESS),
@@ -183,7 +173,6 @@ INITIATIVE_UI_PROFILES: dict[str, dict[str, Any]] = {
"steering_methods",
],
"enabledModes": ["plan", "work", "control"],
"uiFeatures": {},
},
"initiative.recurring_program": {
"processSteps": list(_MATURITY_PROCESS),
@@ -200,7 +189,6 @@ INITIATIVE_UI_PROFILES: dict[str, dict[str, Any]] = {
"steering_methods",
],
"enabledModes": ["plan", "work", "control"],
"uiFeatures": {},
},
"initiative.content_project": {
"processSteps": list(_CONTENT_PROCESS),
@@ -219,7 +207,6 @@ INITIATIVE_UI_PROFILES: dict[str, dict[str, Any]] = {
"steering_methods",
],
"enabledModes": ["plan", "work", "control"],
"uiFeatures": {},
},
"initiative.dispute_case": {
"processSteps": list(_DISPUTE_PROCESS),
@@ -237,7 +224,6 @@ INITIATIVE_UI_PROFILES: dict[str, dict[str, Any]] = {
"steering_methods",
],
"enabledModes": ["plan", "work", "control"],
"uiFeatures": {},
},
}
@@ -245,6 +231,8 @@ INITIATIVE_UI_PROFILES: dict[str, dict[str, Any]] = {
def resolve_ui_profile(archetype_key: str) -> dict[str, Any]:
"""UI-Profil aus Code-Seed; unbekannte Archetypen → Generic-Fallback."""
profile = INITIATIVE_UI_PROFILES.get(archetype_key)
if profile:
return dict(profile)
return dict(GENERIC_UI_PROFILE)
resolved = dict(profile) if profile else dict(GENERIC_UI_PROFILE)
slices = resolved.get("dataSlices") or []
resolved["omCapabilities"] = list(resolved.get("omCapabilities") or slices)
resolved.pop("uiFeatures", None)
return resolved
+27 -8
View File
@@ -1,4 +1,4 @@
"""Steering API — methods, profiles and context (AP1.1 / AP2.0)."""
"""Steering API — methods, profiles and context (AP1.1 / AP2.0 / AP2.4)."""
from __future__ import annotations
@@ -7,11 +7,16 @@ from typing import Optional
from capabilities import require_capability
from fastapi import APIRouter, Depends, HTTPException, Query
from pydantic import BaseModel, Field
from entity_archetypes.registry import resolve_default_method_key, resolve_ui_profile
from method_profiles.registry import list_method_profiles
from services import initiatives as initiative_service
from services import steering_context as sc_service
from steering.context import get_steering_context_dto
from steering.methods.registry import list_methods
from steering.methods.registry import (
list_compatible_methods,
list_methods,
method_to_dict,
)
from tenant_context import TenantContext
router = APIRouter(prefix="/api/steering", tags=["steering"])
@@ -23,20 +28,34 @@ class SteeringContextUpdateRequest(BaseModel):
clear_method_profile: bool = False
def _om_capabilities_for_archetype(archetype_key: str | None) -> frozenset[str] | None:
if not archetype_key:
return None
profile = resolve_ui_profile(archetype_key)
caps = profile.get("omCapabilities") or profile.get("dataSlices") or []
return frozenset(caps)
@router.get("/methods")
def list_steering_methods(
archetype_key: Optional[str] = Query(default=None),
ctx: TenantContext = Depends(require_capability("kairo.initiative.read")),
):
_ = ctx
om_caps = _om_capabilities_for_archetype(archetype_key)
if archetype_key:
methods = list_compatible_methods(archetype_key, om_capabilities=om_caps)
default_key = resolve_default_method_key(archetype_key)
else:
methods = list_methods()
default_key = None
return [
{
"key": m.key,
"version": m.version,
"label": m.label,
"description": m.description,
"next_action_strategy_key": m.next_action_strategy_key,
**method_to_dict(m),
"is_default": m.key == default_key if default_key else False,
}
for m in list_methods()
for m in methods
]
+73 -12
View File
@@ -1,4 +1,4 @@
"""Operating Context read model — AP2.3a."""
"""Operating Context read model — AP2.3a / AP2.4."""
from __future__ import annotations
@@ -7,10 +7,20 @@ from typing import Any, Optional
from psycopg2.extras import RealDictCursor
from db import get_connection
from entity_archetypes.registry import get_ui_profile_json, resolve_ui_profile
from entity_archetypes.registry import (
get_ui_profile_json,
resolve_default_method_key,
resolve_ui_profile,
)
from services.initiatives import get_initiative
from services.steering_context import ensure_steering_context, get_steering_context
from steering.methods.registry import get_method
from steering.graph.profiles import LIGHT, graph_profile_as_dict
from steering.methods.registry import (
get_method,
list_compatible_methods,
method_to_dict,
ui_features_as_dict,
)
def _load_ui_profile_from_db(archetype_key: str) -> Optional[dict[str, Any]]:
@@ -32,8 +42,6 @@ def _load_ui_profile_from_db(archetype_key: str) -> Optional[dict[str, Any]]:
if isinstance(profile, dict) and profile:
return dict(profile)
return None
except Exception:
return None
finally:
conn.close()
@@ -48,18 +56,22 @@ def _resolve_ui_profile(archetype_key: str) -> dict[str, Any]:
return resolve_ui_profile(archetype_key)
def _resolve_om_capabilities(ui_profile: dict[str, Any]) -> frozenset[str]:
caps = ui_profile.get("omCapabilities") or ui_profile.get("dataSlices") or []
return frozenset(caps)
def _resolve_data_slices(
*,
ui_profile: dict[str, Any],
om_capabilities: frozenset[str],
method_key: str,
) -> list[str]:
"""Schnittmenge Archetyp-Default ∩ Method-Slices (Phase E erweitert)."""
archetype_slices = ui_profile.get("dataSlices") or []
"""Schnittmenge Archetyp-OM ∩ Method-Slices."""
method = get_method(method_key)
if method and getattr(method, "data_slices", None):
if method and method.data_slices:
method_slices = set(method.data_slices)
return [s for s in archetype_slices if s in method_slices]
return list(archetype_slices)
return [s for s in om_capabilities if s in method_slices]
return list(om_capabilities)
def _method_capabilities(method_key: str) -> dict[str, Any]:
@@ -75,6 +87,41 @@ def _method_capabilities(method_key: str) -> dict[str, Any]:
}
def _resolve_method_contract(method_key: str) -> dict[str, Any]:
method = get_method(method_key)
if not method:
return {
"steering_elements": [],
"ui_features": {},
"graph_profile": graph_profile_as_dict(LIGHT),
}
return {
"steering_elements": sorted(method.steering_elements),
"ui_features": ui_features_as_dict(method.ui_features),
"graph_profile": graph_profile_as_dict(method.graph_profile),
}
def _compatible_methods_payload(
archetype_key: str,
*,
om_capabilities: frozenset[str],
active_method_key: str,
) -> list[dict[str, Any]]:
default_key = resolve_default_method_key(archetype_key)
methods = list_compatible_methods(
archetype_key, om_capabilities=om_capabilities
)
return [
{
**method_to_dict(m, include_compatibility=False),
"is_default": m.key == default_key,
"is_active": m.key == active_method_key,
}
for m in methods
]
def get_operating_context(
*, tenant_id: str, initiative_id: str
) -> Optional[dict[str, Any]]:
@@ -90,12 +137,17 @@ def get_operating_context(
archetype_key = initiative["archetype_key"]
ui_profile = _resolve_ui_profile(archetype_key)
om_capabilities = _resolve_om_capabilities(ui_profile)
method_key = steering["method_key"]
metadata = steering.get("lifecycle_metadata") or {}
if isinstance(metadata, str):
metadata = {}
method_profile_key = metadata.get("method_profile_key")
data_slices = _resolve_data_slices(ui_profile=ui_profile, method_key=method_key)
data_slices = _resolve_data_slices(
om_capabilities=om_capabilities,
method_key=method_key,
)
method_contract = _resolve_method_contract(method_key)
return {
"initiative_id": initiative_id,
@@ -103,6 +155,15 @@ def get_operating_context(
"method_key": method_key,
"method_profile_key": method_profile_key,
"ui_profile": ui_profile,
"om_capabilities": sorted(om_capabilities),
"data_slices": data_slices,
"method_capabilities": _method_capabilities(method_key),
"steering_elements": method_contract["steering_elements"],
"ui_features": method_contract["ui_features"],
"graph_profile": method_contract["graph_profile"],
"compatible_methods": _compatible_methods_payload(
archetype_key,
om_capabilities=om_capabilities,
active_method_key=method_key,
),
}
+13 -1
View File
@@ -16,6 +16,14 @@ DEFAULT_METHOD_KEY = "generic_operating"
DEFAULT_METHOD_VERSION = "0.1.0"
def _resolve_om_capabilities_for_initiative(initiative: dict[str, Any]) -> frozenset[str]:
from entity_archetypes.registry import resolve_ui_profile
profile = resolve_ui_profile(initiative["archetype_key"])
caps = profile.get("omCapabilities") or profile.get("dataSlices") or []
return frozenset(caps)
def _serialize_row(row: dict[str, Any]) -> dict[str, Any]:
result = dict(row)
for key in ("id", "tenant_id", "initiative_id"):
@@ -229,7 +237,11 @@ def update_method_key(
initiative = get_initiative(tenant_id=tenant_id, initiative_id=initiative_id)
if not initiative:
raise ValueError("Vorhaben nicht gefunden")
if not method_compatible_with_archetype(method, initiative["archetype_key"]):
if not method_compatible_with_archetype(
method,
initiative["archetype_key"],
om_capabilities=_resolve_om_capabilities_for_initiative(initiative),
):
raise ValueError(
f"Methode {method_key} ist nicht kompatibel mit Archetyp "
f"{initiative['archetype_key']}"
+15
View File
@@ -0,0 +1,15 @@
"""Steering element catalog — AP2.4."""
from steering.elements.registry import (
STEERING_ELEMENTS,
get_steering_element,
list_steering_elements,
validate_steering_element_keys,
)
__all__ = [
"STEERING_ELEMENTS",
"get_steering_element",
"list_steering_elements",
"validate_steering_element_keys",
]
+90
View File
@@ -0,0 +1,90 @@
"""Steering element catalog — AP2.4."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Literal
ModeKey = Literal["plan", "work", "control"]
@dataclass(frozen=True)
class SteeringElementDefinition:
key: str
label: str
description: str
modes: tuple[ModeKey, ...]
STEERING_ELEMENTS: dict[str, SteeringElementDefinition] = {
"next_action_primary": SteeringElementDefinition(
key="next_action_primary",
label="Nächster Schritt",
description="Next-Action-Widget als primäre Steuerungsansicht",
modes=("control", "work"),
),
"critical_path": SteeringElementDefinition(
key="critical_path",
label="Kritischer Pfad",
description="Execution-Graph und Pfad-Priorisierung",
modes=("control",),
),
"gate_fulfillment": SteeringElementDefinition(
key="gate_fulfillment",
label="Gate-Erfüllung",
description="Zielzustände, Verify und Fortschritt",
modes=("control", "plan"),
),
"work_cycle_scope": SteeringElementDefinition(
key="work_cycle_scope",
label="Sprint-Zeitbox",
description="Aktive work_cycle und Sprint-Backlog",
modes=("work", "plan"),
),
"recurring_rhythm": SteeringElementDefinition(
key="recurring_rhythm",
label="Rhythmen",
description="RecurringElement und Journey-Fokus",
modes=("control",),
),
"queue_inbox": SteeringElementDefinition(
key="queue_inbox",
label="Queue / Eingang",
description="Pull-Steuerung aus Backlog/Queue",
modes=("plan", "work"),
),
"maturity_stage": SteeringElementDefinition(
key="maturity_stage",
label="Reifegrad-Stufen",
description="Stufen und Routinen in Plan/Kontrolle",
modes=("plan", "control"),
),
"chapter_progression": SteeringElementDefinition(
key="chapter_progression",
label="Kapitel-Fortschritt",
description="Kapitel-basierte Progression",
modes=("plan", "control"),
),
"dispute_timeline": SteeringElementDefinition(
key="dispute_timeline",
label="Verfahren / Fristen",
description="Fristen, Entscheidungen, Verfahrensstrang",
modes=("control",),
),
}
def get_steering_element(key: str) -> SteeringElementDefinition | None:
return STEERING_ELEMENTS.get(key)
def list_steering_elements() -> tuple[SteeringElementDefinition, ...]:
return tuple(STEERING_ELEMENTS.values())
def validate_steering_element_keys(keys: frozenset[str]) -> None:
unknown = [k for k in keys if k not in STEERING_ELEMENTS]
if unknown:
raise ValueError(
f"Unbekannte steering_elements: {', '.join(sorted(unknown))}"
)
+11 -16
View File
@@ -1,4 +1,4 @@
"""Method graph profiles — AP1.4e."""
"""Method graph profiles — AP1.4e / AP2.4 (via MethodDefinition)."""
from __future__ import annotations
@@ -19,25 +19,20 @@ _STRICT = GraphMethodProfile(enforce_gate_blocking=True, emphasize_fulfillment=F
_FULFILLMENT = GraphMethodProfile(enforce_gate_blocking=False, emphasize_fulfillment=True)
_LIGHT = GraphMethodProfile(enforce_gate_blocking=False, emphasize_fulfillment=False)
METHOD_GRAPH_PROFILES: dict[str, GraphMethodProfile] = {
"generic_operating": _LIGHT,
"queue_pull": _LIGHT,
"dispute_procedure": _LIGHT,
"continuous_product": _FULFILLMENT,
"maturity_progression": _FULFILLMENT,
"chapter_based_progression": _FULFILLMENT,
"product_milestone_driven": _STRICT,
"program_delivery": _STRICT,
"sequential_dependency": _STRICT,
"agile_iteration": _STRICT,
"recurring_control": _FULFILLMENT,
}
STRICT = _STRICT
FULFILLMENT = _FULFILLMENT
LIGHT = _LIGHT
def get_graph_profile(method_key: str | None) -> GraphMethodProfile:
if not method_key:
return METHOD_GRAPH_PROFILES[DEFAULT_METHOD_KEY]
return METHOD_GRAPH_PROFILES.get(method_key, _STRICT)
return LIGHT
from steering.methods.registry import get_method
method = get_method(method_key)
if method:
return method.graph_profile
return _STRICT
def enforce_gate_blocking_for_method(method_key: str | None) -> bool:
@@ -1,9 +1,15 @@
"""Shared registration helper for AP2.0 method stubs — AP2.3e data_slices."""
"""Shared registration helper for AP2.0 method stubs — AP2.3e / AP2.4."""
from __future__ import annotations
from typing import Literal
from steering.graph.profiles import (
FULFILLMENT,
GraphMethodProfile,
LIGHT,
STRICT,
)
from steering.lifecycle.states import STANDARD_LIFECYCLE_STEPS
from steering.methods.registry import MethodDefinition, get_method, register_method
@@ -74,6 +80,8 @@ SLICES_GENERIC = SLICES_OM_STANDARD
SLICES_AGILE = SLICES_PRODUCT
ELEM_NEXT = frozenset({"next_action_primary"})
def register_stub_method(
*,
@@ -84,6 +92,11 @@ def register_stub_method(
lifecycle_steps: tuple[str, ...] | None = None,
data_slices: frozenset[str] | None = None,
compatible_archetype_keys: frozenset[str] | Literal["*"] = "*",
steering_elements: frozenset[str] | None = None,
ui_features: frozenset[str] | None = None,
graph_profile: GraphMethodProfile = LIGHT,
method_role: Literal["primary", "modifier"] = "primary",
composes_with: frozenset[str] | None = None,
) -> None:
if get_method(key):
return
@@ -97,6 +110,11 @@ def register_stub_method(
next_action_strategy_key=next_action_strategy_key,
data_slices=data_slices or SLICES_GENERIC,
compatible_archetype_keys=compatible_archetype_keys,
steering_elements=steering_elements or ELEM_NEXT,
ui_features=ui_features or frozenset(),
graph_profile=graph_profile,
method_role=method_role,
composes_with=composes_with or frozenset(),
)
)
@@ -109,6 +127,9 @@ def register_product_like_method(
next_action_strategy_key: str,
data_slices: frozenset[str] | None = None,
compatible_archetype_keys: frozenset[str] | Literal["*"] | None = None,
steering_elements: frozenset[str] | None = None,
ui_features: frozenset[str] | None = None,
graph_profile: GraphMethodProfile = STRICT,
) -> None:
register_stub_method(
key=key,
@@ -120,4 +141,8 @@ def register_product_like_method(
compatible_archetype_keys=compatible_archetype_keys
if compatible_archetype_keys is not None
else frozenset({"initiative.product"}),
steering_elements=steering_elements
or (ELEM_NEXT | frozenset({"gate_fulfillment", "work_cycle_scope"})),
ui_features=ui_features or frozenset(),
graph_profile=graph_profile,
)
@@ -1,13 +1,15 @@
"""AP2.0a — remaining method stubs."""
"""AP2.0a — remaining method stubs — AP2.4 steering elements."""
from __future__ import annotations
from steering.graph.profiles import FULFILLMENT, LIGHT, STRICT
from steering.methods.registrations._helpers import (
ELEM_NEXT,
SLICES_AGILE,
SLICES_MATURITY,
SLICES_OM_STANDARD,
SLICES_QUEUE,
SLICES_RECURRING,
SLICES_AGILE,
SLICES_OM_STANDARD,
register_stub_method,
)
@@ -20,6 +22,9 @@ def register() -> None:
next_action_strategy_key="maturity_progression",
data_slices=SLICES_MATURITY,
compatible_archetype_keys=frozenset({"initiative.maturity_journey"}),
steering_elements=ELEM_NEXT
| frozenset({"maturity_stage", "recurring_rhythm"}),
graph_profile=FULFILLMENT,
)
register_stub_method(
key="sequential_dependency",
@@ -28,6 +33,10 @@ def register() -> None:
next_action_strategy_key="sequential_dependency",
data_slices=SLICES_OM_STANDARD,
compatible_archetype_keys="*",
steering_elements=ELEM_NEXT
| frozenset({"critical_path", "gate_fulfillment"}),
ui_features=frozenset({"criticalPathControl"}),
graph_profile=STRICT,
)
register_stub_method(
key="recurring_control",
@@ -36,6 +45,8 @@ def register() -> None:
next_action_strategy_key="recurring_control",
data_slices=SLICES_RECURRING,
compatible_archetype_keys=frozenset({"initiative.recurring_program"}),
steering_elements=ELEM_NEXT | frozenset({"recurring_rhythm"}),
graph_profile=FULFILLMENT,
)
register_stub_method(
key="queue_pull",
@@ -44,6 +55,8 @@ def register() -> None:
next_action_strategy_key="queue_pull",
data_slices=SLICES_QUEUE,
compatible_archetype_keys="*",
steering_elements=ELEM_NEXT | frozenset({"queue_inbox"}),
graph_profile=LIGHT,
)
register_stub_method(
key="agile_iteration",
@@ -52,6 +65,11 @@ def register() -> None:
next_action_strategy_key="agile_iteration",
data_slices=SLICES_AGILE,
compatible_archetype_keys="*",
steering_elements=ELEM_NEXT | frozenset({"work_cycle_scope"}),
ui_features=frozenset({"steeringSnapshotOnWorkSprint"}),
graph_profile=STRICT,
method_role="modifier",
composes_with=frozenset({"continuous_product", "program_delivery"}),
)
register_stub_method(
key="dispute_procedure",
@@ -69,6 +87,8 @@ def register() -> None:
}
),
compatible_archetype_keys=frozenset({"initiative.dispute_case"}),
steering_elements=ELEM_NEXT | frozenset({"dispute_timeline"}),
graph_profile=LIGHT,
)
register_stub_method(
key="chapter_based_progression",
@@ -87,4 +107,7 @@ def register() -> None:
}
),
compatible_archetype_keys=frozenset({"initiative.content_project"}),
steering_elements=ELEM_NEXT
| frozenset({"chapter_progression", "gate_fulfillment"}),
graph_profile=FULFILLMENT,
)
@@ -1,8 +1,12 @@
"""Built-in method: continuous_product — AP2.0a."""
"""Built-in method: continuous_product — AP2.0a / AP2.4."""
from __future__ import annotations
from steering.methods.registrations._helpers import register_product_like_method
from steering.graph.profiles import FULFILLMENT
from steering.methods.registrations._helpers import (
ELEM_NEXT,
register_product_like_method,
)
def register() -> None:
@@ -11,4 +15,10 @@ def register() -> None:
label="Produkt (kontinuierlich)",
description="Kontinuierlicher Betrieb — Ist zuerst, Plan als Orientierung",
next_action_strategy_key="continuous_product",
graph_profile=FULFILLMENT,
ui_features=frozenset(
{"continuousProductWorkMode", "steeringSnapshotOnWorkSprint"}
),
steering_elements=ELEM_NEXT
| frozenset({"gate_fulfillment", "work_cycle_scope"}),
)
@@ -1,10 +1,11 @@
"""Built-in method: generic_operating."""
"""Built-in method: generic_operating — AP2.4."""
from __future__ import annotations
from steering.lifecycle.states import STANDARD_LIFECYCLE_STEPS
from steering.graph.profiles import LIGHT
from steering.methods.registrations._helpers import ELEM_NEXT, SLICES_GENERIC
from steering.methods.registry import MethodDefinition, get_method, register_method
from steering.methods.registrations._helpers import SLICES_GENERIC
def register() -> None:
@@ -20,5 +21,7 @@ def register() -> None:
next_action_strategy_key="default",
data_slices=SLICES_GENERIC,
compatible_archetype_keys="*",
steering_elements=ELEM_NEXT,
graph_profile=LIGHT,
)
)
@@ -1,10 +1,10 @@
"""Built-in method: product_milestone_driven — AP1.1."""
"""Built-in method: product_milestone_driven — AP1.1 / AP2.4."""
from __future__ import annotations
from steering.lifecycle.states import STANDARD_LIFECYCLE_STEPS
from steering.graph.profiles import STRICT
from steering.methods.registrations._helpers import ELEM_NEXT, SLICES_PRODUCT
from steering.methods.registry import MethodDefinition, get_method, register_method
from steering.methods.registrations._helpers import SLICES_PRODUCT
_PRODUCT_STEPS = (
"intake",
@@ -42,5 +42,8 @@ def register() -> None:
"initiative.program",
}
),
steering_elements=ELEM_NEXT
| frozenset({"gate_fulfillment", "work_cycle_scope"}),
graph_profile=STRICT,
)
)
@@ -1,8 +1,9 @@
"""Built-in method: program_delivery — AP2.0a."""
"""Built-in method: program_delivery — AP2.0a / AP2.4."""
from __future__ import annotations
from steering.methods.registrations._helpers import (
ELEM_NEXT,
SLICES_PROGRAM,
register_product_like_method,
)
@@ -16,4 +17,6 @@ def register() -> None:
next_action_strategy_key="program_delivery",
data_slices=SLICES_PROGRAM,
compatible_archetype_keys=frozenset({"initiative.program"}),
steering_elements=ELEM_NEXT
| frozenset({"gate_fulfillment", "work_cycle_scope"}),
)
+69 -6
View File
@@ -1,9 +1,12 @@
"""Method Registry — built-in steering methods."""
"""Method Registry — built-in steering methods — AP2.3e / AP2.4."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Literal
from typing import Any, Literal
from steering.elements.registry import validate_steering_element_keys
from steering.graph.profiles import GraphMethodProfile, LIGHT
_METHODS: dict[str, "MethodDefinition"] = {}
@@ -18,20 +21,51 @@ class MethodDefinition:
next_action_strategy_key: str = "default"
data_slices: frozenset[str] = frozenset()
compatible_archetype_keys: frozenset[str] | Literal["*"] = "*"
steering_elements: frozenset[str] = frozenset()
ui_features: frozenset[str] = frozenset()
graph_profile: GraphMethodProfile = LIGHT
method_role: Literal["primary", "modifier"] = "primary"
composes_with: frozenset[str] = frozenset()
def ui_features_as_dict(features: frozenset[str]) -> dict[str, bool]:
return {key: True for key in sorted(features)}
def method_compatible_with_archetype(
method: MethodDefinition, archetype_key: str
method: MethodDefinition,
archetype_key: str,
*,
om_capabilities: frozenset[str] | None = None,
) -> bool:
compat = method.compatible_archetype_keys
if compat == "*":
return True
return archetype_key in compat
if compat != "*" and archetype_key not in compat:
return False
if om_capabilities is not None and method.data_slices:
if not method.data_slices.issubset(om_capabilities):
return False
return True
def list_compatible_methods(
archetype_key: str,
*,
om_capabilities: frozenset[str] | None = None,
) -> tuple[MethodDefinition, ...]:
return tuple(
m
for m in _METHODS.values()
if method_compatible_with_archetype(
m, archetype_key, om_capabilities=om_capabilities
)
)
def register_method(defn: MethodDefinition) -> None:
if defn.key in _METHODS:
raise ValueError(f"Method already registered: {defn.key}")
if defn.steering_elements:
validate_steering_element_keys(defn.steering_elements)
_METHODS[defn.key] = defn
@@ -43,5 +77,34 @@ def list_methods() -> tuple[MethodDefinition, ...]:
return tuple(_METHODS.values())
def method_to_dict(
method: MethodDefinition,
*,
include_compatibility: bool = True,
) -> dict[str, Any]:
payload: dict[str, Any] = {
"key": method.key,
"version": method.version,
"label": method.label,
"description": method.description,
"next_action_strategy_key": method.next_action_strategy_key,
"steering_elements": sorted(method.steering_elements),
"ui_features": ui_features_as_dict(method.ui_features),
"graph_profile": {
"enforce_gate_blocking": method.graph_profile.enforce_gate_blocking,
"emphasize_fulfillment": method.graph_profile.emphasize_fulfillment,
},
"method_role": method.method_role,
"composes_with": sorted(method.composes_with),
"data_slices": sorted(method.data_slices),
}
if include_compatibility:
compat = method.compatible_archetype_keys
payload["compatible_archetype_keys"] = (
"*" if compat == "*" else sorted(compat)
)
return payload
def clear_methods_for_tests() -> None:
_METHODS.clear()
@@ -55,6 +55,7 @@ def test_operating_context_linear(client):
assert res.status_code == 200
body = res.json()
assert body["method_key"] == "sequential_dependency"
assert "critical_path" in body["steering_elements"]
assert body["ui_profile"]["planDefaultRoute"] == "/plan/gates"
assert "work_cycles" not in body["data_slices"]
@@ -0,0 +1,124 @@
"""AP2.4 — Steering elements and method contract."""
from __future__ import annotations
from steering.elements.registry import validate_steering_element_keys
from steering.methods.registry import get_method, list_compatible_methods, ui_features_as_dict
from steering.graph.profiles import get_graph_profile
def test_all_methods_have_valid_steering_elements():
from steering.methods.registry import list_methods
for method in list_methods():
validate_steering_element_keys(method.steering_elements)
def test_sequential_dependency_contract():
method = get_method("sequential_dependency")
assert method is not None
assert "critical_path" in method.steering_elements
assert "criticalPathControl" in method.ui_features
assert get_graph_profile("sequential_dependency").enforce_gate_blocking is True
def test_continuous_product_ui_features_from_method():
method = get_method("continuous_product")
assert method is not None
features = ui_features_as_dict(method.ui_features)
assert features["continuousProductWorkMode"] is True
assert features["steeringSnapshotOnWorkSprint"] is True
def test_list_compatible_methods_linear_includes_queue_pull():
methods = list_compatible_methods("initiative.linear_project")
keys = {m.key for m in methods}
assert "sequential_dependency" in keys
assert "queue_pull" in keys
def test_list_compatible_methods_product_excludes_maturity():
methods = list_compatible_methods("initiative.product")
keys = {m.key for m in methods}
assert "continuous_product" in keys
assert "maturity_progression" not in keys
def test_operating_context_includes_method_contract(client):
from tests.factories import provision_user_in_tenant
from tests.test_initiatives_actions import _auth, _create_initiative, _login
user = provision_user_in_tenant(tenant_role="member")
token = _login(client, user)
created = _create_initiative(
client,
token,
title="Linear Contract",
archetype_key="initiative.linear_project",
)
initiative_id = created.json()["id"]
res = client.get(
f"/api/initiatives/{initiative_id}/operating-context",
headers=_auth(token),
)
assert res.status_code == 200
body = res.json()
assert "critical_path" in body["steering_elements"]
assert body["ui_features"].get("criticalPathControl") is True
assert "graph_profile" in body
assert body["compatible_methods"]
assert any(m["key"] == "sequential_dependency" for m in body["compatible_methods"])
def test_steering_methods_filtered_by_archetype(client):
from tests.factories import provision_user_in_tenant
from tests.test_initiatives_actions import _auth, _login
user = provision_user_in_tenant(tenant_role="member")
token = _login(client, user)
res = client.get(
"/api/steering/methods",
params={"archetype_key": "initiative.product"},
headers=_auth(token),
)
assert res.status_code == 200
keys = {m["key"] for m in res.json()}
assert "continuous_product" in keys
assert "maturity_progression" not in keys
product = next(m for m in res.json() if m["key"] == "continuous_product")
assert "steering_elements" in product
assert product["is_default"] is True
def test_queue_pull_on_linear_changes_steering_elements(client):
from tests.factories import provision_user_in_tenant
from tests.test_initiatives_actions import _auth, _create_initiative, _login
user = provision_user_in_tenant(tenant_role="member")
token = _login(client, user)
created = _create_initiative(
client,
token,
title="Linear Queue",
archetype_key="initiative.linear_project",
)
initiative_id = created.json()["id"]
client.patch(
f"/api/steering/initiatives/{initiative_id}/context",
json={"method_key": "queue_pull"},
headers=_auth(token),
)
ctx = client.get(
f"/api/initiatives/{initiative_id}/operating-context",
headers=_auth(token),
)
body = ctx.json()
assert "queue_inbox" in body["steering_elements"]
assert "critical_path" not in body["steering_elements"]
assert body["ui_features"].get("criticalPathControl") is not True