Some checks failed
Deploy Development / deploy (push) Successful in 52s
Test Suite / pytest-backend (push) Failing after 4m37s
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
Co-authored-by: Cursor <cursoragent@cursor.com>
137 lines
4.1 KiB
Python
137 lines
4.1 KiB
Python
"""AP1.7b — Operational API Pflege-Parität (Backlog-Commit, Recurring, Sprint-Zuweisung)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from services import actors as actor_service
|
|
from services.actor_service_tokens import create_service_token
|
|
from tests.factories import provision_user_in_tenant
|
|
from tests.test_initiatives_actions import _auth, _create_initiative, _login
|
|
|
|
|
|
def _agent_token(admin, *, capabilities=None):
|
|
agent = actor_service.create_actor(
|
|
tenant_id=admin["tenant_id"],
|
|
actor_type="agent",
|
|
name="Ops Agent",
|
|
)
|
|
caps = capabilities or [
|
|
"kairo.action.read",
|
|
"kairo.action.manage",
|
|
"kairo.backlog.manage",
|
|
"kairo.recurring.manage",
|
|
"kairo.initiative.read",
|
|
]
|
|
created = create_service_token(
|
|
tenant_id=admin["tenant_id"],
|
|
actor_id=agent["id"],
|
|
label="AP17b",
|
|
created_by_user_id=admin["id"],
|
|
capabilities=caps,
|
|
)
|
|
return created["token"], agent["id"]
|
|
|
|
|
|
def test_operational_convert_backlog_to_sprint(client):
|
|
admin = provision_user_in_tenant(tenant_role="admin")
|
|
user_token = _login(client, admin)
|
|
actor_token, _ = _agent_token(admin)
|
|
|
|
created = _create_initiative(
|
|
client,
|
|
user_token,
|
|
title="Product Ops",
|
|
archetype_key="initiative.product",
|
|
)
|
|
initiative_id = created.json()["id"]
|
|
|
|
cycle = client.post(
|
|
f"/api/initiatives/{initiative_id}/work-cycles",
|
|
json={"title": "Sprint Ops", "status": "active"},
|
|
headers=_auth(user_token),
|
|
)
|
|
assert cycle.status_code == 201
|
|
cycle_id = cycle.json()["id"]
|
|
|
|
backlog = client.post(
|
|
f"/api/initiatives/{initiative_id}/backlog",
|
|
json={"title": "Via Agent", "status": "accepted"},
|
|
headers=_auth(user_token),
|
|
)
|
|
backlog_id = backlog.json()["id"]
|
|
|
|
converted = client.post(
|
|
f"/api/operational/backlog/{backlog_id}/convert-to-action",
|
|
json={"work_cycle_id": cycle_id, "assign_active_sprint": False},
|
|
headers={"X-Actor-Token": actor_token},
|
|
)
|
|
assert converted.status_code == 201
|
|
body = converted.json()
|
|
assert body["ok"] is True
|
|
assert body["data"]["action"]["work_cycle_id"] == cycle_id
|
|
|
|
|
|
def test_operational_patch_recurring_status(client):
|
|
admin = provision_user_in_tenant(tenant_role="admin")
|
|
user_token = _login(client, admin)
|
|
actor_token, _ = _agent_token(admin)
|
|
|
|
created = _create_initiative(
|
|
client,
|
|
user_token,
|
|
title="Spagat Ops",
|
|
archetype_key="initiative.maturity_journey",
|
|
apply_starter_kit=True,
|
|
)
|
|
initiative_id = created.json()["id"]
|
|
|
|
recurring = client.get(
|
|
f"/api/initiatives/{initiative_id}/recurring",
|
|
headers=_auth(user_token),
|
|
).json()
|
|
assert recurring
|
|
recurring_id = recurring[0]["id"]
|
|
|
|
patched = client.patch(
|
|
f"/api/operational/recurring/{recurring_id}",
|
|
json={"status": "paused"},
|
|
headers={"X-Actor-Token": actor_token},
|
|
)
|
|
assert patched.status_code == 200
|
|
assert patched.json()["data"]["status"] == "paused"
|
|
|
|
|
|
def test_operational_assign_action_work_cycle(client):
|
|
admin = provision_user_in_tenant(tenant_role="admin")
|
|
user_token = _login(client, admin)
|
|
actor_token, _ = _agent_token(admin)
|
|
|
|
created = _create_initiative(
|
|
client,
|
|
user_token,
|
|
title="Sprint Assign",
|
|
archetype_key="initiative.product",
|
|
)
|
|
initiative_id = created.json()["id"]
|
|
|
|
cycle = client.post(
|
|
f"/api/initiatives/{initiative_id}/work-cycles",
|
|
json={"title": "Sprint B", "status": "planned"},
|
|
headers=_auth(user_token),
|
|
)
|
|
cycle_id = cycle.json()["id"]
|
|
|
|
action = client.post(
|
|
f"/api/initiatives/{initiative_id}/actions",
|
|
json={"title": "Loose AP", "status": "open"},
|
|
headers=_auth(user_token),
|
|
)
|
|
action_id = action.json()["id"]
|
|
|
|
assigned = client.patch(
|
|
f"/api/operational/actions/{action_id}/work-cycle",
|
|
json={"work_cycle_id": cycle_id},
|
|
headers={"X-Actor-Token": actor_token},
|
|
)
|
|
assert assigned.status_code == 200
|
|
assert assigned.json()["data"]["work_cycle_id"] == cycle_id
|