feat(A1): Activity Set am Gate-Detail — Übungen an Zielzustand binden
Deploy Development / deploy (push) Successful in 50s
Test Suite / pytest-backend (push) Successful in 4m54s
Test Suite / lint-backend (push) Successful in 2s
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 13s
Deploy Development / deploy (push) Successful in 50s
Test Suite / pytest-backend (push) Successful in 4m54s
Test Suite / lint-backend (push) Successful in 2s
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 13s
Gate-Detail: Übungen anlegen mit Rhythmus, Gate aktivieren, Link zu Today. API: /roadmap-items/{id}/practices und roadmap_item_id auf Recurring-Create. Damit ist A1 ohne Starter-Kit manuell durchspielbar.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
17add13d9d
commit
87ecee5301
11 files changed
+473
-5
No files matched your search
@@ -132,6 +132,7 @@ class RecurringCreateRequest(BaseModel):
|
||||
status: Literal["active", "paused", "ended"] = "active"
|
||||
interval_days: Optional[int] = Field(default=None, gt=0)
|
||||
next_due_at: Optional[str] = None
|
||||
roadmap_item_id: Optional[str] = None
|
||||
|
||||
|
||||
def _parse_optional_datetime(value: Optional[str], field_name: str) -> Optional[datetime]:
|
||||
@@ -648,6 +649,7 @@ def create_initiative_recurring(
|
||||
status=body.status,
|
||||
interval_days=body.interval_days,
|
||||
next_due_at=next_due_at,
|
||||
roadmap_item_id=body.roadmap_item_id,
|
||||
user_id=ctx.user_id,
|
||||
)
|
||||
except ValueError as exc:
|
||||
|
||||
@@ -22,6 +22,8 @@ class RecurringUpdateRequest(BaseModel):
|
||||
clear_interval_days: bool = False
|
||||
next_due_at: Optional[str] = None
|
||||
clear_next_due_at: bool = False
|
||||
roadmap_item_id: Optional[str] = None
|
||||
clear_roadmap_item_id: bool = False
|
||||
|
||||
|
||||
class RecurringCompleteRequest(BaseModel):
|
||||
@@ -69,6 +71,8 @@ def update_recurring_element(
|
||||
clear_interval_days=body.clear_interval_days,
|
||||
next_due_at=next_due_at,
|
||||
clear_next_due_at=body.clear_next_due_at,
|
||||
roadmap_item_id=body.roadmap_item_id,
|
||||
clear_roadmap_item_id=body.clear_roadmap_item_id,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
@@ -87,6 +87,13 @@ class ReopenRequest(BaseModel):
|
||||
reason: str = ""
|
||||
|
||||
|
||||
class GatePracticeCreateRequest(BaseModel):
|
||||
title: str = Field(min_length=1, max_length=255)
|
||||
description: str = ""
|
||||
status: Literal["active", "paused", "ended"] = "active"
|
||||
interval_days: int = Field(default=1, gt=0)
|
||||
|
||||
|
||||
class PlanSnapshotCreateRequest(BaseModel):
|
||||
reason: str = Field(default="", max_length=2000)
|
||||
|
||||
@@ -309,6 +316,63 @@ def delete_roadmap_item(
|
||||
raise HTTPException(status_code=404, detail="RoadmapItem nicht gefunden")
|
||||
|
||||
|
||||
def _work_gate_or_400(*, tenant_id: str, item_id: str) -> dict[str, Any]:
|
||||
item = roadmap_service.get_roadmap_item(tenant_id=tenant_id, item_id=item_id)
|
||||
if not item:
|
||||
raise HTTPException(status_code=404, detail="RoadmapItem nicht gefunden")
|
||||
if item.get("item_type") == "join_gate":
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Join-Gates haben kein Activity Set (Übungen)",
|
||||
)
|
||||
return item
|
||||
|
||||
|
||||
@items_router.get("/{item_id}/practices")
|
||||
def list_gate_practices(
|
||||
item_id: str,
|
||||
ctx: TenantContext = Depends(require_capability("kairo.recurring.read")),
|
||||
):
|
||||
from services import recurring as recurring_service
|
||||
|
||||
item = _work_gate_or_400(tenant_id=ctx.tenant_id, item_id=item_id)
|
||||
try:
|
||||
return recurring_service.list_recurring_for_gate(
|
||||
tenant_id=ctx.tenant_id,
|
||||
initiative_id=str(item["initiative_id"]),
|
||||
gate_id=item_id,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@items_router.post("/{item_id}/practices", status_code=201)
|
||||
def create_gate_practice(
|
||||
item_id: str,
|
||||
body: GatePracticeCreateRequest,
|
||||
ctx: TenantContext = Depends(require_capability("kairo.recurring.manage")),
|
||||
):
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from services import recurring as recurring_service
|
||||
|
||||
item = _work_gate_or_400(tenant_id=ctx.tenant_id, item_id=item_id)
|
||||
try:
|
||||
return recurring_service.create_recurring_element(
|
||||
tenant_id=ctx.tenant_id,
|
||||
initiative_id=str(item["initiative_id"]),
|
||||
title=body.title,
|
||||
description=body.description,
|
||||
status=body.status,
|
||||
interval_days=body.interval_days,
|
||||
next_due_at=datetime.now(timezone.utc),
|
||||
roadmap_item_id=item_id,
|
||||
user_id=ctx.user_id,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@items_router.post("/{item_id}/verify-reached")
|
||||
def verify_roadmap_item_reached(
|
||||
item_id: str,
|
||||
|
||||
@@ -134,6 +134,15 @@ def list_recurring_for_initiative(
|
||||
return attach_open_instances_to_recurring_list(rows, tenant_id=tenant_id)
|
||||
|
||||
|
||||
def list_recurring_for_gate(
|
||||
*, tenant_id: str, initiative_id: str, gate_id: str
|
||||
) -> list[dict[str, Any]]:
|
||||
items = list_recurring_for_initiative(
|
||||
tenant_id=tenant_id, initiative_id=initiative_id
|
||||
)
|
||||
return [item for item in items if str(item.get("roadmap_item_id") or "") == str(gate_id)]
|
||||
|
||||
|
||||
def get_recurring_element(
|
||||
*, tenant_id: str, recurring_id: str
|
||||
) -> Optional[dict[str, Any]]:
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
"""Gate Activity Set API — A1 minimal usability."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from tests.factories import provision_user_in_tenant
|
||||
from tests.test_initiatives_actions import _auth, _create_initiative, _login
|
||||
|
||||
|
||||
def test_gate_practice_create_and_list(client):
|
||||
user = provision_user_in_tenant(tenant_role="admin")
|
||||
token = _login(client, user)
|
||||
|
||||
created = _create_initiative(
|
||||
client,
|
||||
token,
|
||||
title="A1 Gate Practices",
|
||||
archetype_key="initiative.maturity_journey",
|
||||
apply_starter_kit=False,
|
||||
)
|
||||
initiative_id = created.json()["id"]
|
||||
|
||||
gate = client.post(
|
||||
f"/api/initiatives/{initiative_id}/roadmap/items",
|
||||
json={
|
||||
"title": "Dehnung — Einstieg",
|
||||
"item_type": "maturity_stage",
|
||||
"status": "active",
|
||||
},
|
||||
headers=_auth(token),
|
||||
)
|
||||
assert gate.status_code == 201
|
||||
gate_id = gate.json()["id"]
|
||||
|
||||
empty = client.get(
|
||||
f"/api/roadmap-items/{gate_id}/practices",
|
||||
headers=_auth(token),
|
||||
)
|
||||
assert empty.status_code == 200
|
||||
assert empty.json() == []
|
||||
|
||||
created_practice = client.post(
|
||||
f"/api/roadmap-items/{gate_id}/practices",
|
||||
json={
|
||||
"title": "Vorbeuge halten",
|
||||
"description": "3×30 Sek.",
|
||||
"interval_days": 1,
|
||||
},
|
||||
headers=_auth(token),
|
||||
)
|
||||
assert created_practice.status_code == 201
|
||||
body = created_practice.json()
|
||||
assert body["roadmap_item_id"] == gate_id
|
||||
assert body["interval_days"] == 1
|
||||
|
||||
listed = client.get(
|
||||
f"/api/roadmap-items/{gate_id}/practices",
|
||||
headers=_auth(token),
|
||||
)
|
||||
assert listed.status_code == 200
|
||||
assert len(listed.json()) == 1
|
||||
assert listed.json()[0]["title"] == "Vorbeuge halten"
|
||||
|
||||
|
||||
def test_join_gate_rejects_practices(client):
|
||||
user = provision_user_in_tenant(tenant_role="admin")
|
||||
token = _login(client, user)
|
||||
|
||||
created = _create_initiative(
|
||||
client,
|
||||
token,
|
||||
title="Join no practices",
|
||||
archetype_key="initiative.maturity_journey",
|
||||
apply_starter_kit=False,
|
||||
)
|
||||
initiative_id = created.json()["id"]
|
||||
|
||||
join = client.post(
|
||||
f"/api/initiatives/{initiative_id}/roadmap/items",
|
||||
json={
|
||||
"title": "Konsolidierung",
|
||||
"item_type": "join_gate",
|
||||
"status": "planned",
|
||||
},
|
||||
headers=_auth(token),
|
||||
)
|
||||
assert join.status_code == 201
|
||||
join_id = join.json()["id"]
|
||||
|
||||
rejected = client.post(
|
||||
f"/api/roadmap-items/{join_id}/practices",
|
||||
json={"title": "Nope", "interval_days": 1},
|
||||
headers=_auth(token),
|
||||
)
|
||||
assert rejected.status_code == 400
|
||||
Reference in new issue
Block a user