diff --git a/backend/app/services/l1_session_service.py b/backend/app/services/l1_session_service.py index b6a309a7..b0eb107e 100644 --- a/backend/app/services/l1_session_service.py +++ b/backend/app/services/l1_session_service.py @@ -98,6 +98,28 @@ async def start_adhoc_session( return session +async def start_ai_build_session( + db: AsyncSession, + *, + account_id: UUID, + user: User, + ticket_id: str, + ticket_kind: str, +) -> L1WalkSession: + """Start an AI-built tree session (nodes generated on demand via next-node).""" + session = L1WalkSession( + account_id=account_id, + created_by_user_id=user.id, + acting_as=_resolve_acting_as(user), + ticket_id=ticket_id, + ticket_kind=ticket_kind, + session_kind="ai_build", + ) + db.add(session) + await db.flush() + return session + + async def record_step( db: AsyncSession, *, diff --git a/backend/tests/test_l1_session_service.py b/backend/tests/test_l1_session_service.py index b558b598..072060f4 100644 --- a/backend/tests/test_l1_session_service.py +++ b/backend/tests/test_l1_session_service.py @@ -778,6 +778,24 @@ async def test_escalate_without_walk_reason_is_optional(test_db: AsyncSession): assert session.escalation_reason_category == "no_kb_content" +# --------------------------------------------------------------------------- +# T7: start_ai_build_session +# --------------------------------------------------------------------------- + +@pytest.mark.asyncio +async def test_start_ai_build_session(test_db: AsyncSession): + from app.services import l1_session_service as svc + account = await _make_account(test_db) + l1_user = await _make_user(test_db, account_id=account.id) + s = await svc.start_ai_build_session( + test_db, account_id=account.id, user=l1_user, + ticket_id="t-ai", ticket_kind="internal", + ) + assert s.session_kind == "ai_build" + assert s.flow_id is None and s.flow_proposal_id is None + assert s.status == "active" + + # --------------------------------------------------------------------------- # T14 audit log tests (spec ยง5.6.1) # ---------------------------------------------------------------------------