Kairo-Jinkendo/backend/tests/test_tech_debt_unit.py
Lars a5154cbd3b
Some checks failed
Deploy Development / deploy (push) Successful in 47s
Test Suite / pytest-backend (push) Failing after 4m15s
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
feat(steering): Kernel v0.4 Agent-Slots, Tech Debt und Review-Attention
K-Ext-4/P8 deklarative Agent-Slots; P7 tech_debt Read Model und Vokabular; Review-Attention in den Kernel verlagert.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-27 11:54:48 +02:00

82 lines
2.3 KiB
Python

"""Unit tests for tech debt read model."""
from __future__ import annotations
from datetime import datetime, timedelta, timezone
from steering.read_models.tech_debt import compute_tech_debt_summary
def _ctx(*, backlog_items, actions, stale_days=30):
class FakeCtx:
initiative_id = "init-1"
operating_context = {
"backlog_vocabulary": {
"kinds": ["story", "bug", "tech_debt"],
},
"agent_slot_config": {"stale_debt_days": stale_days},
}
@property
def backlog_vocabulary(self):
return self.operating_context["backlog_vocabulary"]
@property
def agent_slot_config(self):
return self.operating_context["agent_slot_config"]
@property
def backlog_items(self):
return backlog_items
@property
def actions(self):
return actions
return FakeCtx()
def test_tech_debt_summary_counts_open_and_stale():
old = (datetime.now(timezone.utc) - timedelta(days=45)).isoformat()
recent = datetime.now(timezone.utc).isoformat()
summary = compute_tech_debt_summary(
_ctx(
backlog_items=[
{
"id": "b1",
"title": "Alt",
"item_kind": "tech_debt",
"status": "new",
"created_at": old,
},
{
"id": "b2",
"title": "Neu",
"item_kind": "tech_debt",
"status": "triaged",
"created_at": recent,
},
],
actions=[
{
"id": "a1",
"title": "AP Schuld",
"action_kind": "tech_debt",
"status": "open",
"created_at": old,
}
],
)
)
assert summary["enabled"] is True
assert summary["total_open"] == 3
assert summary["stale_count"] == 2
def test_tech_debt_disabled_when_not_in_vocabulary():
ctx = _ctx(backlog_items=[], actions=[])
ctx.operating_context["backlog_vocabulary"] = {"kinds": ["story", "bug"]}
summary = compute_tech_debt_summary(ctx)
assert summary["enabled"] is False
assert summary["total_open"] == 0