|
22 | 22 |
|
23 | 23 | from oss.src.core.sessions.interactions.dtos import ( |
24 | 24 | SessionInteractionCreate, |
| 25 | + SessionInteractionData, |
25 | 26 | SessionInteractionKind, |
26 | 27 | SessionInteractionQuery, |
| 28 | + SessionInteractionStatus, |
| 29 | + SessionInteractionTransition, |
27 | 30 | ) |
28 | 31 | from oss.src.core.mounts.dtos import MountCreate |
29 | 32 | import oss.src.models.db_models # noqa: F401 |
@@ -143,6 +146,74 @@ def mounts_dao(): |
143 | 146 | return MountsDAO(engine=get_transactions_engine()) |
144 | 147 |
|
145 | 148 |
|
| 149 | +# --------------------------------------------------------------------------- |
| 150 | +# SessionInteractionsDAO transition resolution |
| 151 | +# --------------------------------------------------------------------------- |
| 152 | + |
| 153 | + |
| 154 | +async def test_interaction_transition_preserves_data_and_optionally_adds_resolution( |
| 155 | + interactions_dao, project |
| 156 | +): |
| 157 | + project_id = project["project_id"] |
| 158 | + session_id = f"interaction-resolution-{uuid.uuid4().hex[:8]}" |
| 159 | + request = {"tool": "bash", "args": {"command": "ls"}} |
| 160 | + |
| 161 | + await interactions_dao.create_interaction( |
| 162 | + project_id=project_id, |
| 163 | + user_id=None, |
| 164 | + interaction=SessionInteractionCreate( |
| 165 | + project_id=project_id, |
| 166 | + session_id=session_id, |
| 167 | + token="approval-token", |
| 168 | + kind=SessionInteractionKind.user_approval, |
| 169 | + data=SessionInteractionData(request=request), |
| 170 | + ), |
| 171 | + ) |
| 172 | + transitioned = await interactions_dao.transition_interaction( |
| 173 | + transition=SessionInteractionTransition( |
| 174 | + project_id=project_id, |
| 175 | + session_id=session_id, |
| 176 | + token="approval-token", |
| 177 | + status=SessionInteractionStatus.resolved, |
| 178 | + resolution={"verdict": "approved", "tool_call_id": "tool-1"}, |
| 179 | + ) |
| 180 | + ) |
| 181 | + |
| 182 | + assert transitioned is not None |
| 183 | + assert transitioned.status == SessionInteractionStatus.resolved |
| 184 | + assert transitioned.data is not None |
| 185 | + assert transitioned.data.request == request |
| 186 | + assert transitioned.data.resolution == { |
| 187 | + "verdict": "approved", |
| 188 | + "tool_call_id": "tool-1", |
| 189 | + } |
| 190 | + |
| 191 | + await interactions_dao.create_interaction( |
| 192 | + project_id=project_id, |
| 193 | + user_id=None, |
| 194 | + interaction=SessionInteractionCreate( |
| 195 | + project_id=project_id, |
| 196 | + session_id=session_id, |
| 197 | + token="client-token", |
| 198 | + kind=SessionInteractionKind.client_tool, |
| 199 | + data=SessionInteractionData(request=request), |
| 200 | + ), |
| 201 | + ) |
| 202 | + transitioned_without_resolution = await interactions_dao.transition_interaction( |
| 203 | + transition=SessionInteractionTransition( |
| 204 | + project_id=project_id, |
| 205 | + session_id=session_id, |
| 206 | + token="client-token", |
| 207 | + status=SessionInteractionStatus.resolved, |
| 208 | + ) |
| 209 | + ) |
| 210 | + |
| 211 | + assert transitioned_without_resolution is not None |
| 212 | + assert transitioned_without_resolution.data is not None |
| 213 | + assert transitioned_without_resolution.data.request == request |
| 214 | + assert transitioned_without_resolution.data.resolution is None |
| 215 | + |
| 216 | + |
146 | 217 | # --------------------------------------------------------------------------- |
147 | 218 | # SessionInteractionsDAO.delete_by_session_id — new hard delete |
148 | 219 | # --------------------------------------------------------------------------- |
|
0 commit comments