"""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