feat: Phase 1 Group 2 — add account_id to AI branching tables
Tables: session_branches, session_handoffs, fork_points,
ai_session_steps, ai_suggestions
Backfill: session_id → ai_sessions.account_id (all except
ai_suggestions which uses user_id → users.account_id)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -160,3 +160,64 @@ async def test_session_resolution_output_account_id(test_db: AsyncSession):
|
||||
)
|
||||
row = result.scalar_one()
|
||||
assert row.account_id == account.id
|
||||
|
||||
|
||||
# ── Group 2: AI & branching ───────────────────────────────────────────────────
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_session_branch_account_id_matches_ai_session(test_db: AsyncSession):
|
||||
"""session_branches.account_id must match parent ai_session.account_id."""
|
||||
from app.models.session_branch import SessionBranch
|
||||
|
||||
account, user = await _make_account_and_user(test_db, "sb1")
|
||||
ai_session = AISession(
|
||||
user_id=user.id,
|
||||
account_id=account.id,
|
||||
problem_summary="test",
|
||||
problem_domain="networking",
|
||||
status="active",
|
||||
)
|
||||
test_db.add(ai_session)
|
||||
await test_db.flush()
|
||||
|
||||
branch = SessionBranch(
|
||||
session_id=ai_session.id,
|
||||
account_id=account.id,
|
||||
label="Branch A",
|
||||
branch_order=1,
|
||||
conversation_messages=[],
|
||||
)
|
||||
test_db.add(branch)
|
||||
await test_db.commit()
|
||||
|
||||
result = await test_db.execute(
|
||||
select(SessionBranch).where(SessionBranch.id == branch.id)
|
||||
)
|
||||
row = result.scalar_one()
|
||||
assert row.account_id == account.id
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ai_suggestion_account_id_matches_user(test_db: AsyncSession):
|
||||
"""ai_suggestions.account_id must match the creating user's account_id."""
|
||||
from app.models.ai_suggestion import AISuggestion
|
||||
|
||||
account, user = await _make_account_and_user(test_db, "ais1")
|
||||
tree = await _make_tree(test_db, account, user)
|
||||
|
||||
suggestion = AISuggestion(
|
||||
tree_id=tree.id,
|
||||
user_id=user.id,
|
||||
account_id=account.id,
|
||||
action_type="add_node",
|
||||
changes_json={},
|
||||
status="pending",
|
||||
)
|
||||
test_db.add(suggestion)
|
||||
await test_db.commit()
|
||||
|
||||
result = await test_db.execute(
|
||||
select(AISuggestion).where(AISuggestion.id == suggestion.id)
|
||||
)
|
||||
row = result.scalar_one()
|
||||
assert row.account_id == account.id
|
||||
|
||||
Reference in New Issue
Block a user