AP1.16a-b: Execution-Graph für Arbeitspaket-Abhängigkeiten.
Deploy Development / deploy (push) Successful in 48s
Test Suite / pytest-backend (push) Successful in 2m20s
Test Suite / lint-backend (push) Successful in 3s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 19s
Test Suite / playwright-smoke (push) Successful in 14s
Deploy Development / deploy (push) Successful in 48s
Test Suite / pytest-backend (push) Successful in 2m20s
Test Suite / lint-backend (push) Successful in 3s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 19s
Test Suite / playwright-smoke (push) Successful in 14s
Migration 023, Engine, API und ADP für Durchführungsplan getrennt vom Gate-Graph; Docs und Sprint-Assignment synchronisiert. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a1b353fcee
commit
1166a0c7f1
16 files changed
+1421
-43
No files matched your search
@@ -25,9 +25,11 @@ OPEN_ACTION_STATUSES = frozenset(
|
||||
|
||||
_ACTION_COLUMNS = """
|
||||
id, tenant_id, initiative_id, project_id, roadmap_item_id, title, description,
|
||||
status, priority, due_at, created_at, updated_at
|
||||
status, priority, due_at, sort_order, action_kind, created_at, updated_at
|
||||
"""
|
||||
|
||||
ACTION_KINDS = frozenset({"delivery", "planning", "review"})
|
||||
|
||||
|
||||
def _serialize_row(row: dict[str, Any]) -> dict[str, Any]:
|
||||
result = dict(row)
|
||||
@@ -43,6 +45,11 @@ def _serialize_row(row: dict[str, Any]) -> dict[str, Any]:
|
||||
return result
|
||||
|
||||
|
||||
def _validate_action_kind(action_kind: str) -> None:
|
||||
if action_kind not in ACTION_KINDS:
|
||||
raise ValueError(f"Ungültiger action_kind: {action_kind}")
|
||||
|
||||
|
||||
def _validate_action_status(status: str) -> None:
|
||||
if status not in ACTION_STATUSES:
|
||||
raise ValueError(f"Ungültiger Action-Status: {status}")
|
||||
@@ -138,6 +145,8 @@ def create_action(
|
||||
project_id: Optional[str] = None,
|
||||
roadmap_item_id: Optional[str] = None,
|
||||
assigned_actor_ids: Optional[list[str]] = None,
|
||||
sort_order: int = 0,
|
||||
action_kind: str = "delivery",
|
||||
user_id: Optional[str] = None,
|
||||
) -> dict[str, Any]:
|
||||
title = title.strip()
|
||||
@@ -145,6 +154,7 @@ def create_action(
|
||||
raise ValueError("Titel ist erforderlich")
|
||||
_validate_action_status(status)
|
||||
_validate_priority(priority)
|
||||
_validate_action_kind(action_kind)
|
||||
if not get_initiative(tenant_id=tenant_id, initiative_id=initiative_id):
|
||||
raise ValueError("Initiative nicht gefunden")
|
||||
_validate_project_in_initiative(
|
||||
@@ -169,9 +179,9 @@ def create_action(
|
||||
f"""
|
||||
INSERT INTO actions (
|
||||
tenant_id, initiative_id, project_id, roadmap_item_id, title, description,
|
||||
status, priority, due_at
|
||||
status, priority, due_at, sort_order, action_kind
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING {_ACTION_COLUMNS}
|
||||
""",
|
||||
(
|
||||
@@ -184,6 +194,8 @@ def create_action(
|
||||
status,
|
||||
priority,
|
||||
due_at,
|
||||
sort_order,
|
||||
action_kind,
|
||||
),
|
||||
)
|
||||
row = _serialize_row(dict(cur.fetchone()))
|
||||
@@ -228,7 +240,7 @@ def list_actions_for_initiative(
|
||||
SELECT {_ACTION_COLUMNS}
|
||||
FROM actions
|
||||
WHERE tenant_id = %s AND initiative_id = %s
|
||||
ORDER BY updated_at DESC, title
|
||||
ORDER BY sort_order ASC, title ASC, created_at DESC
|
||||
""",
|
||||
(tenant_id, initiative_id),
|
||||
)
|
||||
@@ -274,6 +286,8 @@ def update_action(
|
||||
clear_project: bool = False,
|
||||
roadmap_item_id: Optional[str] = None,
|
||||
clear_roadmap_item: bool = False,
|
||||
sort_order: Optional[int] = None,
|
||||
action_kind: Optional[str] = None,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
existing = get_action(tenant_id=tenant_id, action_id=action_id)
|
||||
if not existing:
|
||||
@@ -331,6 +345,13 @@ def update_action(
|
||||
conn.close()
|
||||
updates.append("roadmap_item_id = %s")
|
||||
params.append(roadmap_item_id)
|
||||
if sort_order is not None:
|
||||
updates.append("sort_order = %s")
|
||||
params.append(sort_order)
|
||||
if action_kind is not None:
|
||||
_validate_action_kind(action_kind)
|
||||
updates.append("action_kind = %s")
|
||||
params.append(action_kind)
|
||||
|
||||
if not updates:
|
||||
return existing
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
"""Execution plan — Action dependencies CRUD (AP1.16a/b)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Literal, Optional
|
||||
|
||||
from psycopg2.extras import RealDictCursor
|
||||
|
||||
from db import get_connection
|
||||
from services.audit import log_audit
|
||||
from services.actions import get_action
|
||||
|
||||
DependencyKind = Literal["requires", "blocks", "relates"]
|
||||
|
||||
DEPENDENCY_KINDS = frozenset({"requires", "blocks", "relates"})
|
||||
|
||||
|
||||
def _validate_dependency_kind(kind: str) -> None:
|
||||
if kind not in DEPENDENCY_KINDS:
|
||||
raise ValueError(f"Ungültiger dependency_kind: {kind}")
|
||||
|
||||
|
||||
def _serialize_dependency(row: dict[str, Any]) -> dict[str, Any]:
|
||||
result = dict(row)
|
||||
for key in (
|
||||
"id",
|
||||
"tenant_id",
|
||||
"initiative_id",
|
||||
"predecessor_action_id",
|
||||
"successor_action_id",
|
||||
):
|
||||
if result.get(key):
|
||||
result[key] = str(result[key])
|
||||
if result.get("created_at"):
|
||||
result["created_at"] = result["created_at"].isoformat()
|
||||
return result
|
||||
|
||||
|
||||
def _would_create_cycle(
|
||||
*,
|
||||
dependencies: list[dict[str, Any]],
|
||||
predecessor_id: str,
|
||||
successor_id: str,
|
||||
) -> bool:
|
||||
"""Prüft Zyklus wenn successor transitiv predecessor requires."""
|
||||
graph: dict[str, list[str]] = {}
|
||||
for dep in dependencies:
|
||||
if dep.get("dependency_kind", "requires") != "requires":
|
||||
continue
|
||||
pred = str(dep["predecessor_action_id"])
|
||||
succ = str(dep["successor_action_id"])
|
||||
graph.setdefault(succ, []).append(pred)
|
||||
|
||||
graph.setdefault(successor_id, []).append(predecessor_id)
|
||||
|
||||
visiting: set[str] = set()
|
||||
visited: set[str] = set()
|
||||
|
||||
def dfs(node: str) -> bool:
|
||||
if node in visiting:
|
||||
return True
|
||||
if node in visited:
|
||||
return False
|
||||
visiting.add(node)
|
||||
for upstream in graph.get(node, []):
|
||||
if dfs(upstream):
|
||||
return True
|
||||
visiting.remove(node)
|
||||
visited.add(node)
|
||||
return False
|
||||
|
||||
return dfs(successor_id)
|
||||
|
||||
|
||||
def list_dependencies_for_initiative(
|
||||
*, tenant_id: str, initiative_id: str
|
||||
) -> list[dict[str, Any]]:
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id, tenant_id, initiative_id,
|
||||
predecessor_action_id, successor_action_id,
|
||||
dependency_kind, created_at
|
||||
FROM action_dependencies
|
||||
WHERE tenant_id = %s AND initiative_id = %s
|
||||
ORDER BY created_at
|
||||
""",
|
||||
(tenant_id, initiative_id),
|
||||
)
|
||||
return [_serialize_dependency(dict(row)) for row in cur.fetchall()]
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def add_dependency(
|
||||
*,
|
||||
tenant_id: str,
|
||||
predecessor_action_id: str,
|
||||
successor_action_id: str,
|
||||
dependency_kind: DependencyKind = "requires",
|
||||
user_id: Optional[str] = None,
|
||||
) -> dict[str, Any]:
|
||||
_validate_dependency_kind(dependency_kind)
|
||||
if predecessor_action_id == successor_action_id:
|
||||
raise ValueError("Abhängigkeit auf sich selbst nicht erlaubt")
|
||||
|
||||
predecessor = get_action(tenant_id=tenant_id, action_id=predecessor_action_id)
|
||||
successor = get_action(tenant_id=tenant_id, action_id=successor_action_id)
|
||||
if not predecessor or not successor:
|
||||
raise ValueError("Action nicht gefunden")
|
||||
if predecessor["initiative_id"] != successor["initiative_id"]:
|
||||
raise ValueError("Abhängigkeiten nur innerhalb eines Vorhabens")
|
||||
|
||||
initiative_id = predecessor["initiative_id"]
|
||||
existing = list_dependencies_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
if _would_create_cycle(
|
||||
dependencies=existing,
|
||||
predecessor_id=predecessor_action_id,
|
||||
successor_id=successor_action_id,
|
||||
):
|
||||
raise ValueError("Abhängigkeit würde Zyklus erzeugen")
|
||||
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT 1 FROM action_dependencies
|
||||
WHERE tenant_id = %s
|
||||
AND predecessor_action_id = %s
|
||||
AND successor_action_id = %s
|
||||
AND dependency_kind = %s
|
||||
""",
|
||||
(
|
||||
tenant_id,
|
||||
predecessor_action_id,
|
||||
successor_action_id,
|
||||
dependency_kind,
|
||||
),
|
||||
)
|
||||
if cur.fetchone():
|
||||
raise ValueError("Abhängigkeit existiert bereits")
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO action_dependencies (
|
||||
tenant_id, initiative_id,
|
||||
predecessor_action_id, successor_action_id,
|
||||
dependency_kind
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s)
|
||||
RETURNING id, tenant_id, initiative_id,
|
||||
predecessor_action_id, successor_action_id,
|
||||
dependency_kind, created_at
|
||||
""",
|
||||
(
|
||||
tenant_id,
|
||||
initiative_id,
|
||||
predecessor_action_id,
|
||||
successor_action_id,
|
||||
dependency_kind,
|
||||
),
|
||||
)
|
||||
row = _serialize_dependency(dict(cur.fetchone()))
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
log_audit(
|
||||
"action.dependency_added",
|
||||
user_id=user_id,
|
||||
tenant_id=tenant_id,
|
||||
details={
|
||||
"predecessor_action_id": predecessor_action_id,
|
||||
"successor_action_id": successor_action_id,
|
||||
"dependency_kind": dependency_kind,
|
||||
},
|
||||
)
|
||||
return row
|
||||
|
||||
|
||||
def delete_dependency(
|
||||
*, tenant_id: str, dependency_id: str, user_id: Optional[str] = None
|
||||
) -> bool:
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id, predecessor_action_id, successor_action_id, dependency_kind
|
||||
FROM action_dependencies
|
||||
WHERE id = %s AND tenant_id = %s
|
||||
""",
|
||||
(dependency_id, tenant_id),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
raise ValueError("Abhängigkeit nicht gefunden")
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
DELETE FROM action_dependencies
|
||||
WHERE id = %s AND tenant_id = %s
|
||||
""",
|
||||
(dependency_id, tenant_id),
|
||||
)
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
log_audit(
|
||||
"action.dependency_removed",
|
||||
user_id=user_id,
|
||||
tenant_id=tenant_id,
|
||||
details={
|
||||
"dependency_id": dependency_id,
|
||||
"predecessor_action_id": str(row["predecessor_action_id"]),
|
||||
"successor_action_id": str(row["successor_action_id"]),
|
||||
},
|
||||
)
|
||||
return True
|
||||
Reference in new issue
Block a user