"""Red-line: `context` injection must be CONDITIONAL + WHITELIST only. - No `context` passed -> `raw_info` stays `{}` (widget WS path unchanged). - `context` passed -> only `vehicle_name`/`vehicle_id` map to `app_*`. """ from sqlalchemy import select from app.models.database import CustomerProfile from app.services.conversation import ConversationManager async def _raw_info_for(async_db, conv_id) -> dict: async with async_db() as db: result = await db.execute( select(CustomerProfile).where( CustomerProfile.conversation_id == conv_id ) ) profile = result.scalar_one() return profile.raw_info or {} async def test_no_context_keeps_raw_info_empty(async_db): async with async_db() as db: mgr = ConversationManager(db) conv = await mgr.create_conversation(context=None) raw = await _raw_info_for(async_db, conv.id) assert raw == {} async def test_context_seeds_whitelist_only(async_db): async with async_db() as db: mgr = ConversationManager(db) conv = await mgr.create_conversation( context={ "vehicle_name": "Tesla Model Y", "vehicle_id": "v123", "evil_key": "should_be_ignored", } ) raw = await _raw_info_for(async_db, conv.id) assert raw == { "app_vehicle_name": "Tesla Model Y", "app_vehicle_id": "v123", }