feat(l1): start_ai_build_session

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-29 17:03:05 -04:00
parent e1112a9a36
commit 0facf2f8c9
2 changed files with 40 additions and 0 deletions

View File

@@ -98,6 +98,28 @@ async def start_adhoc_session(
return 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( async def record_step(
db: AsyncSession, db: AsyncSession,
*, *,

View File

@@ -778,6 +778,24 @@ async def test_escalate_without_walk_reason_is_optional(test_db: AsyncSession):
assert session.escalation_reason_category == "no_kb_content" 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) # T14 audit log tests (spec §5.6.1)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------