feat(backlog): Epic-Hierarchie mit parent_backlog_id (ADP P2)
Deploy Development / deploy (push) Successful in 48s
Test Suite / pytest-backend (push) Successful in 3m54s
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 15s
Deploy Development / deploy (push) Successful in 48s
Test Suite / pytest-backend (push) Successful in 3m54s
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 15s
Epics als Backlog-Container mit Baum-UI, Convert-Guard und pytest-Abdeckung — Roll-up bleibt für P4 offen. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
dc6f25b673
commit
f33135b87f
12 files changed
+473
-27
No files matched your search
+107
-6
@@ -13,15 +13,16 @@ from services.initiatives import PRIORITIES, get_initiative
|
||||
from services.plan_ist import validate_roadmap_item_in_initiative
|
||||
|
||||
BacklogStatus = Literal["new", "triaged", "accepted", "rejected", "converted"]
|
||||
BacklogItemKind = Literal["story", "bug", "issue"]
|
||||
BacklogItemKind = Literal["story", "bug", "issue", "epic"]
|
||||
|
||||
BACKLOG_STATUSES = frozenset({"new", "triaged", "accepted", "rejected", "converted"})
|
||||
BACKLOG_ITEM_KINDS = frozenset({"story", "bug", "issue"})
|
||||
BACKLOG_ITEM_KINDS = frozenset({"story", "bug", "issue", "epic"})
|
||||
CONVERTIBLE_ITEM_KINDS = frozenset({"story", "bug", "issue"})
|
||||
|
||||
_BACKLOG_COLUMNS = """
|
||||
id, tenant_id, initiative_id, title, description, status,
|
||||
priority, roadmap_item_id, converted_action_id, sort_order, item_kind,
|
||||
parent_action_id, created_at, updated_at
|
||||
parent_action_id, parent_backlog_id, created_at, updated_at
|
||||
"""
|
||||
|
||||
|
||||
@@ -34,6 +35,7 @@ def _serialize_row(row: dict[str, Any]) -> dict[str, Any]:
|
||||
"converted_action_id",
|
||||
"roadmap_item_id",
|
||||
"parent_action_id",
|
||||
"parent_backlog_id",
|
||||
):
|
||||
if result.get(key):
|
||||
result[key] = str(result[key])
|
||||
@@ -92,6 +94,48 @@ def _validate_parent_action_in_initiative(
|
||||
raise ValueError("Referenz muss ein Feature-Arbeitspaket sein, kein Bug/Issue")
|
||||
|
||||
|
||||
def _validate_backlog_hierarchy(
|
||||
*,
|
||||
cur,
|
||||
tenant_id: str,
|
||||
initiative_id: str,
|
||||
item_kind: str,
|
||||
parent_backlog_id: Optional[str],
|
||||
parent_action_id: Optional[str],
|
||||
backlog_item_id: Optional[str] = None,
|
||||
) -> None:
|
||||
if item_kind == "epic":
|
||||
if parent_backlog_id:
|
||||
raise ValueError("Epic kann keinem übergeordneten Backlog-Item zugeordnet werden")
|
||||
if parent_action_id:
|
||||
raise ValueError("Epic kann keinem Arbeitspaket zugeordnet werden")
|
||||
return
|
||||
|
||||
if not parent_backlog_id:
|
||||
return
|
||||
|
||||
if backlog_item_id and parent_backlog_id == backlog_item_id:
|
||||
raise ValueError("Item kann nicht sich selbst als Epic referenzieren")
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id, item_kind, initiative_id
|
||||
FROM backlog_items
|
||||
WHERE id = %s AND tenant_id = %s
|
||||
""",
|
||||
(parent_backlog_id, tenant_id),
|
||||
)
|
||||
parent = cur.fetchone()
|
||||
if not parent:
|
||||
raise ValueError("Epic-Referenz nicht gefunden")
|
||||
parent_initiative = parent["initiative_id"] if isinstance(parent, dict) else parent[2]
|
||||
parent_kind = parent["item_kind"] if isinstance(parent, dict) else parent[1]
|
||||
if str(parent_initiative) != initiative_id:
|
||||
raise ValueError("Epic gehört zu einem anderen Vorhaben")
|
||||
if parent_kind != "epic":
|
||||
raise ValueError("Übergeordnetes Item muss ein Epic sein")
|
||||
|
||||
|
||||
def create_backlog_item(
|
||||
*,
|
||||
tenant_id: str,
|
||||
@@ -104,6 +148,7 @@ def create_backlog_item(
|
||||
sort_order: Optional[int] = None,
|
||||
item_kind: BacklogItemKind = "story",
|
||||
parent_action_id: Optional[str] = None,
|
||||
parent_backlog_id: Optional[str] = None,
|
||||
user_id: Optional[str] = None,
|
||||
) -> dict[str, Any]:
|
||||
title = title.strip()
|
||||
@@ -130,6 +175,14 @@ def create_backlog_item(
|
||||
initiative_id=initiative_id,
|
||||
parent_action_id=parent_action_id,
|
||||
)
|
||||
_validate_backlog_hierarchy(
|
||||
cur=cur,
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=initiative_id,
|
||||
item_kind=item_kind,
|
||||
parent_backlog_id=parent_backlog_id,
|
||||
parent_action_id=parent_action_id,
|
||||
)
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT COALESCE(MAX(sort_order), -10) + 10 AS next_order
|
||||
@@ -143,9 +196,9 @@ def create_backlog_item(
|
||||
f"""
|
||||
INSERT INTO backlog_items (
|
||||
tenant_id, initiative_id, title, description, status, priority,
|
||||
roadmap_item_id, sort_order, item_kind, parent_action_id
|
||||
roadmap_item_id, sort_order, item_kind, parent_action_id, parent_backlog_id
|
||||
)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
RETURNING {_BACKLOG_COLUMNS}
|
||||
""",
|
||||
(
|
||||
@@ -159,6 +212,7 @@ def create_backlog_item(
|
||||
sort_order if sort_order is not None else next_order,
|
||||
item_kind,
|
||||
parent_action_id,
|
||||
parent_backlog_id,
|
||||
),
|
||||
)
|
||||
row = _serialize_row(dict(cur.fetchone()))
|
||||
@@ -229,6 +283,8 @@ def update_backlog_item(
|
||||
item_kind: Optional[BacklogItemKind] = None,
|
||||
parent_action_id: Optional[str] = None,
|
||||
clear_parent_action: bool = False,
|
||||
parent_backlog_id: Optional[str] = None,
|
||||
clear_parent_backlog: bool = False,
|
||||
) -> Optional[dict[str, Any]]:
|
||||
existing = get_backlog_item(tenant_id=tenant_id, backlog_item_id=backlog_item_id)
|
||||
if not existing:
|
||||
@@ -285,16 +341,46 @@ def update_backlog_item(
|
||||
elif parent_action_id is not None:
|
||||
updates.append("parent_action_id = %s")
|
||||
params.append(parent_action_id)
|
||||
if clear_parent_backlog:
|
||||
updates.append("parent_backlog_id = NULL")
|
||||
elif parent_backlog_id is not None:
|
||||
updates.append("parent_backlog_id = %s")
|
||||
params.append(parent_backlog_id)
|
||||
|
||||
if not updates:
|
||||
return existing
|
||||
|
||||
effective_kind = item_kind if item_kind is not None else existing.get("item_kind") or "story"
|
||||
effective_parent_backlog = (
|
||||
None
|
||||
if clear_parent_backlog
|
||||
else parent_backlog_id
|
||||
if parent_backlog_id is not None
|
||||
else existing.get("parent_backlog_id")
|
||||
)
|
||||
effective_parent_action = (
|
||||
None
|
||||
if clear_parent_action
|
||||
else parent_action_id
|
||||
if parent_action_id is not None
|
||||
else existing.get("parent_action_id")
|
||||
)
|
||||
|
||||
updates.append("updated_at = NOW()")
|
||||
params.extend([backlog_item_id, tenant_id])
|
||||
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor(cursor_factory=RealDictCursor) as cur:
|
||||
_validate_backlog_hierarchy(
|
||||
cur=cur,
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=existing["initiative_id"],
|
||||
item_kind=effective_kind,
|
||||
parent_backlog_id=effective_parent_backlog,
|
||||
parent_action_id=effective_parent_action,
|
||||
backlog_item_id=backlog_item_id,
|
||||
)
|
||||
if parent_action_id is not None and not clear_parent_action:
|
||||
_validate_parent_action_in_initiative(
|
||||
cur=cur,
|
||||
@@ -348,6 +434,18 @@ def delete_backlog_item(
|
||||
conn = get_connection()
|
||||
try:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id FROM backlog_items
|
||||
WHERE parent_backlog_id = %s AND tenant_id = %s AND status != 'converted'
|
||||
LIMIT 1
|
||||
""",
|
||||
(backlog_item_id, tenant_id),
|
||||
)
|
||||
if cur.fetchone():
|
||||
raise ValueError(
|
||||
"Epic mit untergeordneten Items kann nicht gelöscht werden"
|
||||
)
|
||||
cur.execute(
|
||||
"DELETE FROM backlog_items WHERE id = %s AND tenant_id = %s RETURNING id",
|
||||
(backlog_item_id, tenant_id),
|
||||
@@ -384,6 +482,10 @@ def convert_backlog_to_action(
|
||||
if existing["status"] not in ("accepted", "triaged", "new"):
|
||||
raise ValueError("Backlog-Item kann in diesem Status nicht konvertiert werden")
|
||||
|
||||
item_kind = existing.get("item_kind") or "story"
|
||||
if item_kind not in CONVERTIBLE_ITEM_KINDS:
|
||||
raise ValueError("Epic kann nicht direkt in ein Arbeitspaket umgewandelt werden")
|
||||
|
||||
resolved_cycle_id = work_cycle_id
|
||||
if not resolved_cycle_id and assign_active_sprint:
|
||||
from services.work_cycle import get_active_work_cycle
|
||||
@@ -394,7 +496,6 @@ def convert_backlog_to_action(
|
||||
if active:
|
||||
resolved_cycle_id = active["id"]
|
||||
|
||||
item_kind = existing.get("item_kind") or "story"
|
||||
action = create_action(
|
||||
tenant_id=tenant_id,
|
||||
initiative_id=existing["initiative_id"],
|
||||
|
||||
Reference in new issue
Block a user