feat(steering): Epic Roll-up Read Model und Attention (ADP P4)
Test Suite / pytest-backend (push) Waiting to run
Test Suite / lint-backend (push) Waiting to run
Test Suite / compose-smoke (push) Waiting to run
Test Suite / k6 /api/health Baseline (push) Blocked by required conditions
Test Suite / playwright-smoke (push) Blocked by required conditions
Deploy Development / deploy (push) Has been cancelled
Test Suite / pytest-backend (push) Waiting to run
Test Suite / lint-backend (push) Waiting to run
Test Suite / compose-smoke (push) Waiting to run
Test Suite / k6 /api/health Baseline (push) Blocked by required conditions
Test Suite / playwright-smoke (push) Blocked by required conditions
Deploy Development / deploy (push) Has been cancelled
Schliesst den Backlog/Epic-Track mit kernel-basiertem Fortschritt pro Epic, Steuerungs-Attention und UI-Fortschrittsanzeige im Plan-Eingang ab. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a13913f1a0
commit
ef5ee0d19b
13 files changed
+708
-5
No files matched your search
@@ -125,7 +125,8 @@ def get_initiative_steering_snapshot(
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id, title, status, priority, converted_action_id, created_at, updated_at
|
||||
SELECT id, title, status, priority, converted_action_id, item_kind,
|
||||
parent_backlog_id, created_at, updated_at
|
||||
FROM backlog_items
|
||||
WHERE tenant_id = %s AND initiative_id = %s
|
||||
ORDER BY updated_at DESC
|
||||
@@ -297,6 +298,31 @@ def get_initiative_steering_snapshot(
|
||||
next_actions = evaluation.next_work
|
||||
kernel_attention = evaluation.attention
|
||||
|
||||
from services.operating_context import get_operating_context
|
||||
from steering.read_models.epic_rollup import compute_epic_rollup
|
||||
|
||||
operating = get_operating_context(
|
||||
tenant_id=ctx.tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
epic_rollup: list[dict[str, Any]] = []
|
||||
if operating.get("backlog_vocabulary", {}).get("capabilities", {}).get(
|
||||
"epic_hierarchy"
|
||||
):
|
||||
epic_rollup = compute_epic_rollup(
|
||||
backlog_items=[
|
||||
{
|
||||
"id": _sid(b["id"]),
|
||||
"title": b["title"],
|
||||
"status": b["status"],
|
||||
"item_kind": b.get("item_kind"),
|
||||
"parent_backlog_id": _sid(b.get("parent_backlog_id")),
|
||||
"converted_action_id": _sid(b.get("converted_action_id")),
|
||||
}
|
||||
for b in backlog
|
||||
],
|
||||
actions=actions_raw,
|
||||
)
|
||||
|
||||
steering = get_steering_context_dto(ctx, initiative_id=initiative_id)
|
||||
metadata = steering.get("lifecycle_metadata") or {}
|
||||
if isinstance(metadata, str):
|
||||
@@ -355,6 +381,7 @@ def get_initiative_steering_snapshot(
|
||||
"upcoming_roadmap_items": upcoming_milestones,
|
||||
"next_actions": next_actions,
|
||||
"active_work_cycle": active_work_cycle,
|
||||
"epic_rollup": epic_rollup,
|
||||
"counts": {
|
||||
"actions_open": open_actions,
|
||||
"actions_blocked": blocked_actions,
|
||||
@@ -384,6 +411,8 @@ def get_initiative_steering_snapshot(
|
||||
"id": _sid(b["id"]),
|
||||
"title": b["title"],
|
||||
"status": b["status"],
|
||||
"item_kind": b.get("item_kind"),
|
||||
"parent_backlog_id": _sid(b.get("parent_backlog_id")),
|
||||
"converted_action_id": _sid(b.get("converted_action_id")),
|
||||
}
|
||||
for b in backlog
|
||||
|
||||
@@ -129,6 +129,27 @@ def evaluate_attention(
|
||||
)
|
||||
)
|
||||
|
||||
from services.operating_context import get_operating_context
|
||||
from services import backlog as backlog_service
|
||||
from steering.read_models.epic_rollup import (
|
||||
compute_epic_rollup,
|
||||
epic_rollup_attention_items,
|
||||
)
|
||||
|
||||
operating = get_operating_context(
|
||||
tenant_id=ctx.tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
if operating.get("backlog_vocabulary", {}).get("capabilities", {}).get(
|
||||
"epic_hierarchy"
|
||||
):
|
||||
backlog_items = backlog_service.list_backlog_for_initiative(
|
||||
tenant_id=ctx.tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
rollups = compute_epic_rollup(backlog_items=backlog_items, actions=actions)
|
||||
items.extend(
|
||||
epic_rollup_attention_items(initiative_id=initiative_id, rollups=rollups)
|
||||
)
|
||||
|
||||
if (
|
||||
not next_work
|
||||
and binding.primary_method_key in _GATE_METHODS
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
"""Steering read models — derived views, no OM mutation."""
|
||||
@@ -0,0 +1,170 @@
|
||||
"""Epic roll-up read model — ADP P4 / Backlog-Hierarchie.
|
||||
|
||||
Fortschritt eines Epics = Aggregation committeter/erledigter Stories im Subbaum.
|
||||
Kein Gate-Status; Leading bleibt Action.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Literal
|
||||
|
||||
EpicRollupStatus = Literal["empty", "intake_only", "in_progress", "done"]
|
||||
|
||||
_DONE_ACTION = frozenset({"done"})
|
||||
_ACTIVE_ACTION = frozenset({"open", "ready", "in_progress", "blocked", "review_required"})
|
||||
_CHILD_EXCLUDE = frozenset({"rejected"})
|
||||
|
||||
|
||||
def _action_status(actions_by_id: dict[str, dict[str, Any]], action_id: Any) -> str | None:
|
||||
if not action_id:
|
||||
return None
|
||||
row = actions_by_id.get(str(action_id))
|
||||
return row.get("status") if row else None
|
||||
|
||||
|
||||
def compute_epic_rollup(
|
||||
*,
|
||||
backlog_items: list[dict[str, Any]],
|
||||
actions: list[dict[str, Any]],
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Roll-up pro Epic-BacklogItem (item_kind=epic, nicht rejected)."""
|
||||
actions_by_id = {str(a["id"]): a for a in actions if a.get("id")}
|
||||
epics = [
|
||||
b
|
||||
for b in backlog_items
|
||||
if b.get("item_kind") == "epic" and b.get("status") not in _CHILD_EXCLUDE
|
||||
]
|
||||
|
||||
rollups: list[dict[str, Any]] = []
|
||||
for epic in epics:
|
||||
epic_id = str(epic["id"])
|
||||
children = [
|
||||
b
|
||||
for b in backlog_items
|
||||
if b.get("parent_backlog_id")
|
||||
and str(b["parent_backlog_id"]) == epic_id
|
||||
and b.get("item_kind") != "epic"
|
||||
and b.get("status") not in _CHILD_EXCLUDE
|
||||
]
|
||||
|
||||
child_total = len(children)
|
||||
committed: list[dict[str, Any]] = []
|
||||
uncommitted: list[dict[str, Any]] = []
|
||||
for child in children:
|
||||
if child.get("status") == "converted" or child.get("converted_action_id"):
|
||||
committed.append(child)
|
||||
else:
|
||||
uncommitted.append(child)
|
||||
|
||||
actions_done = actions_in_progress = actions_open = 0
|
||||
for child in committed:
|
||||
status = _action_status(actions_by_id, child.get("converted_action_id"))
|
||||
if status in _DONE_ACTION:
|
||||
actions_done += 1
|
||||
elif status in _ACTIVE_ACTION:
|
||||
actions_in_progress += 1
|
||||
actions_open += 1
|
||||
elif status:
|
||||
actions_open += 1
|
||||
|
||||
if child_total == 0:
|
||||
rollup_status: EpicRollupStatus = "empty"
|
||||
elif len(committed) == 0:
|
||||
rollup_status = "intake_only"
|
||||
elif actions_done == child_total:
|
||||
rollup_status = "done"
|
||||
else:
|
||||
rollup_status = "in_progress"
|
||||
|
||||
completion_ratio = actions_done / child_total if child_total else None
|
||||
commit_ratio = len(committed) / child_total if child_total else None
|
||||
|
||||
rollups.append(
|
||||
{
|
||||
"epic_backlog_id": epic_id,
|
||||
"epic_title": epic.get("title") or "Epic",
|
||||
"child_total": child_total,
|
||||
"child_uncommitted": len(uncommitted),
|
||||
"child_committed": len(committed),
|
||||
"actions_done": actions_done,
|
||||
"actions_in_progress": actions_in_progress,
|
||||
"actions_open": actions_open,
|
||||
"completion_ratio": completion_ratio,
|
||||
"commit_ratio": commit_ratio,
|
||||
"status": rollup_status,
|
||||
"data_source": "epic_rollup_v0.1",
|
||||
}
|
||||
)
|
||||
|
||||
rollups.sort(key=lambda r: (r["status"] != "in_progress", r["epic_title"].lower()))
|
||||
return rollups
|
||||
|
||||
|
||||
def epic_rollup_attention_items(
|
||||
*,
|
||||
initiative_id: str,
|
||||
rollups: list[dict[str, Any]],
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Attention aus Epic-Roll-up — Steuerung, nicht nur Anzeige."""
|
||||
items: list[dict[str, Any]] = []
|
||||
|
||||
for rollup in rollups:
|
||||
epic_id = rollup["epic_backlog_id"]
|
||||
title = rollup["epic_title"]
|
||||
child_total = rollup["child_total"]
|
||||
if child_total == 0:
|
||||
continue
|
||||
|
||||
if rollup["child_committed"] == 0:
|
||||
items.append(
|
||||
{
|
||||
"kind": "epic_awaiting_commit",
|
||||
"severity": "info",
|
||||
"title": title,
|
||||
"summary": (
|
||||
f"Epic hat {rollup['child_uncommitted']} Item(s) im Eingang — "
|
||||
"noch keine committete Arbeit"
|
||||
),
|
||||
"scope_type": "backlog",
|
||||
"scope_id": epic_id,
|
||||
"initiative_id": initiative_id,
|
||||
"reason_code": "epic_awaiting_commit",
|
||||
"data_source": "epic_rollup",
|
||||
}
|
||||
)
|
||||
continue
|
||||
|
||||
if rollup["child_uncommitted"] > 0 and rollup["actions_in_progress"] > 0:
|
||||
items.append(
|
||||
{
|
||||
"kind": "epic_uncommitted_during_execution",
|
||||
"severity": "warning",
|
||||
"title": title,
|
||||
"summary": (
|
||||
f"{rollup['child_uncommitted']} Item(s) noch im Eingang, "
|
||||
f"während {rollup['actions_in_progress']} Arbeitspaket(e) laufen"
|
||||
),
|
||||
"scope_type": "backlog",
|
||||
"scope_id": epic_id,
|
||||
"initiative_id": initiative_id,
|
||||
"reason_code": "epic_uncommitted_during_execution",
|
||||
"data_source": "epic_rollup",
|
||||
}
|
||||
)
|
||||
|
||||
if rollup["status"] == "done":
|
||||
items.append(
|
||||
{
|
||||
"kind": "epic_complete",
|
||||
"severity": "info",
|
||||
"title": title,
|
||||
"summary": "Alle Stories im Epic erledigt",
|
||||
"scope_type": "backlog",
|
||||
"scope_id": epic_id,
|
||||
"initiative_id": initiative_id,
|
||||
"reason_code": "epic_complete",
|
||||
"data_source": "epic_rollup",
|
||||
}
|
||||
)
|
||||
|
||||
return items
|
||||
@@ -0,0 +1,141 @@
|
||||
"""AP2.2h — Epic Roll-up Read Model (ADP P4)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from tests.factories import provision_user_in_tenant
|
||||
from tests.test_initiatives_actions import _auth, _create_initiative, _login
|
||||
|
||||
|
||||
def _create_product_initiative(client, token, title="Epic Rollup"):
|
||||
created = _create_initiative(
|
||||
client,
|
||||
token,
|
||||
title=title,
|
||||
archetype_key="initiative.product",
|
||||
)
|
||||
assert created.status_code == 201
|
||||
return created.json()["id"]
|
||||
|
||||
|
||||
def test_steering_snapshot_includes_epic_rollup(client):
|
||||
user = provision_user_in_tenant(tenant_role="admin")
|
||||
token = _login(client, user)
|
||||
initiative_id = _create_product_initiative(client, token)
|
||||
|
||||
epic = client.post(
|
||||
f"/api/initiatives/{initiative_id}/backlog",
|
||||
json={"title": "Checkout Epic", "item_kind": "epic", "status": "accepted"},
|
||||
headers=_auth(token),
|
||||
)
|
||||
epic_id = epic.json()["id"]
|
||||
|
||||
story_a = client.post(
|
||||
f"/api/initiatives/{initiative_id}/backlog",
|
||||
json={
|
||||
"title": "Login Story",
|
||||
"item_kind": "story",
|
||||
"parent_backlog_id": epic_id,
|
||||
"status": "accepted",
|
||||
},
|
||||
headers=_auth(token),
|
||||
)
|
||||
story_a_id = story_a.json()["id"]
|
||||
|
||||
client.post(
|
||||
f"/api/initiatives/{initiative_id}/backlog",
|
||||
json={
|
||||
"title": "Payment Story",
|
||||
"item_kind": "story",
|
||||
"parent_backlog_id": epic_id,
|
||||
"status": "accepted",
|
||||
},
|
||||
headers=_auth(token),
|
||||
)
|
||||
|
||||
converted = client.post(
|
||||
f"/api/backlog/{story_a_id}/convert-to-action",
|
||||
json={},
|
||||
headers=_auth(token),
|
||||
)
|
||||
assert converted.status_code == 201
|
||||
action_id = converted.json()["action"]["id"]
|
||||
|
||||
done = client.patch(
|
||||
f"/api/actions/{action_id}",
|
||||
json={"status": "done"},
|
||||
headers=_auth(token),
|
||||
)
|
||||
assert done.status_code == 200
|
||||
|
||||
snapshot = client.get(
|
||||
f"/api/initiatives/{initiative_id}/steering-snapshot",
|
||||
headers=_auth(token),
|
||||
)
|
||||
assert snapshot.status_code == 200
|
||||
body = snapshot.json()
|
||||
assert "epic_rollup" in body
|
||||
assert len(body["epic_rollup"]) == 1
|
||||
|
||||
rollup = body["epic_rollup"][0]
|
||||
assert rollup["epic_backlog_id"] == epic_id
|
||||
assert rollup["child_total"] == 2
|
||||
assert rollup["child_uncommitted"] == 1
|
||||
assert rollup["child_committed"] == 1
|
||||
assert rollup["actions_done"] == 1
|
||||
assert rollup["status"] == "in_progress"
|
||||
assert rollup["completion_ratio"] == 0.5
|
||||
|
||||
|
||||
def test_steering_snapshot_epic_attention_awaiting_commit(client):
|
||||
user = provision_user_in_tenant(tenant_role="admin")
|
||||
token = _login(client, user)
|
||||
initiative_id = _create_product_initiative(client, token, title="Epic Attention")
|
||||
|
||||
epic = client.post(
|
||||
f"/api/initiatives/{initiative_id}/backlog",
|
||||
json={"title": "Epic", "item_kind": "epic", "status": "accepted"},
|
||||
headers=_auth(token),
|
||||
)
|
||||
epic_id = epic.json()["id"]
|
||||
|
||||
client.post(
|
||||
f"/api/initiatives/{initiative_id}/backlog",
|
||||
json={
|
||||
"title": "Story",
|
||||
"item_kind": "story",
|
||||
"parent_backlog_id": epic_id,
|
||||
"status": "accepted",
|
||||
},
|
||||
headers=_auth(token),
|
||||
)
|
||||
|
||||
snapshot = client.get(
|
||||
f"/api/initiatives/{initiative_id}/steering-snapshot",
|
||||
headers=_auth(token),
|
||||
)
|
||||
assert snapshot.status_code == 200
|
||||
attention_codes = [
|
||||
item.get("code") or item.get("reason_code")
|
||||
for item in snapshot.json().get("attention_items", [])
|
||||
]
|
||||
assert "epic_awaiting_commit" in attention_codes
|
||||
|
||||
|
||||
def test_linear_initiative_has_no_epic_rollup(client):
|
||||
user = provision_user_in_tenant(tenant_role="admin")
|
||||
token = _login(client, user)
|
||||
|
||||
created = _create_initiative(
|
||||
client,
|
||||
token,
|
||||
title="Linear Rollup",
|
||||
archetype_key="initiative.linear_project",
|
||||
)
|
||||
initiative_id = created.json()["id"]
|
||||
|
||||
snapshot = client.get(
|
||||
f"/api/initiatives/{initiative_id}/steering-snapshot",
|
||||
headers=_auth(token),
|
||||
)
|
||||
assert snapshot.status_code == 200
|
||||
assert snapshot.json().get("epic_rollup") == []
|
||||
@@ -0,0 +1,125 @@
|
||||
"""Unit tests — Epic roll-up read model (P4)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from steering.read_models.epic_rollup import (
|
||||
compute_epic_rollup,
|
||||
epic_rollup_attention_items,
|
||||
)
|
||||
|
||||
|
||||
def _item(
|
||||
*,
|
||||
id: str,
|
||||
title: str,
|
||||
item_kind: str = "story",
|
||||
status: str = "accepted",
|
||||
parent_backlog_id: str | None = None,
|
||||
converted_action_id: str | None = None,
|
||||
) -> dict:
|
||||
return {
|
||||
"id": id,
|
||||
"title": title,
|
||||
"item_kind": item_kind,
|
||||
"status": status,
|
||||
"parent_backlog_id": parent_backlog_id,
|
||||
"converted_action_id": converted_action_id,
|
||||
}
|
||||
|
||||
|
||||
def test_epic_rollup_empty_epic():
|
||||
rollups = compute_epic_rollup(
|
||||
backlog_items=[_item(id="e1", title="Epic", item_kind="epic")],
|
||||
actions=[],
|
||||
)
|
||||
assert len(rollups) == 1
|
||||
assert rollups[0]["status"] == "empty"
|
||||
assert rollups[0]["child_total"] == 0
|
||||
|
||||
|
||||
def test_epic_rollup_intake_only():
|
||||
rollups = compute_epic_rollup(
|
||||
backlog_items=[
|
||||
_item(id="e1", title="Checkout", item_kind="epic"),
|
||||
_item(id="s1", title="Login", parent_backlog_id="e1"),
|
||||
_item(id="s2", title="Pay", parent_backlog_id="e1"),
|
||||
],
|
||||
actions=[],
|
||||
)
|
||||
assert rollups[0]["status"] == "intake_only"
|
||||
assert rollups[0]["child_total"] == 2
|
||||
assert rollups[0]["child_uncommitted"] == 2
|
||||
assert rollups[0]["completion_ratio"] == 0.0
|
||||
|
||||
|
||||
def test_epic_rollup_partial_and_done():
|
||||
rollups = compute_epic_rollup(
|
||||
backlog_items=[
|
||||
_item(id="e1", title="Epic", item_kind="epic"),
|
||||
_item(
|
||||
id="s1",
|
||||
title="Done story",
|
||||
parent_backlog_id="e1",
|
||||
status="converted",
|
||||
converted_action_id="a1",
|
||||
),
|
||||
_item(id="s2", title="Open story", parent_backlog_id="e1"),
|
||||
],
|
||||
actions=[
|
||||
{"id": "a1", "status": "done"},
|
||||
{"id": "a2", "status": "in_progress"},
|
||||
],
|
||||
)
|
||||
assert rollups[0]["status"] == "in_progress"
|
||||
assert rollups[0]["actions_done"] == 1
|
||||
assert rollups[0]["child_uncommitted"] == 1
|
||||
assert rollups[0]["completion_ratio"] == 0.5
|
||||
|
||||
|
||||
def test_epic_rollup_all_done():
|
||||
rollups = compute_epic_rollup(
|
||||
backlog_items=[
|
||||
_item(id="e1", title="Epic", item_kind="epic"),
|
||||
_item(
|
||||
id="s1",
|
||||
title="A",
|
||||
parent_backlog_id="e1",
|
||||
status="converted",
|
||||
converted_action_id="a1",
|
||||
),
|
||||
],
|
||||
actions=[{"id": "a1", "status": "done"}],
|
||||
)
|
||||
assert rollups[0]["status"] == "done"
|
||||
assert rollups[0]["completion_ratio"] == 1.0
|
||||
|
||||
|
||||
def test_epic_rollup_attention_awaiting_commit():
|
||||
rollups = compute_epic_rollup(
|
||||
backlog_items=[
|
||||
_item(id="e1", title="Epic", item_kind="epic"),
|
||||
_item(id="s1", title="Story", parent_backlog_id="e1"),
|
||||
],
|
||||
actions=[],
|
||||
)
|
||||
items = epic_rollup_attention_items(initiative_id="init-1", rollups=rollups)
|
||||
assert any(i["reason_code"] == "epic_awaiting_commit" for i in items)
|
||||
|
||||
|
||||
def test_epic_rollup_attention_split_focus():
|
||||
rollups = compute_epic_rollup(
|
||||
backlog_items=[
|
||||
_item(id="e1", title="Epic", item_kind="epic"),
|
||||
_item(
|
||||
id="s1",
|
||||
title="Running",
|
||||
parent_backlog_id="e1",
|
||||
status="converted",
|
||||
converted_action_id="a1",
|
||||
),
|
||||
_item(id="s2", title="Waiting", parent_backlog_id="e1"),
|
||||
],
|
||||
actions=[{"id": "a1", "status": "in_progress"}],
|
||||
)
|
||||
items = epic_rollup_attention_items(initiative_id="init-1", rollups=rollups)
|
||||
assert any(i["reason_code"] == "epic_uncommitted_during_execution" for i in items)
|
||||
Reference in new issue
Block a user