Test soft interrupt injection when tools are involved. 1. Send message that triggers a tool 2. Queue interrupt during tool execution 3. Verify interrupt appears after tool result
()
| 282 | destroy_session(session_id) |
| 283 | |
| 284 | def test_soft_interrupt_with_tools(): |
| 285 | """ |
| 286 | Test soft interrupt injection when tools are involved. |
| 287 | |
| 288 | 1. Send message that triggers a tool |
| 289 | 2. Queue interrupt during tool execution |
| 290 | 3. Verify interrupt appears after tool result |
| 291 | """ |
| 292 | print("\n" + "="*60) |
| 293 | print("TEST: Soft interrupt with tool execution") |
| 294 | print("="*60) |
| 295 | |
| 296 | session_id = create_test_session(cwd="/tmp") |
| 297 | if not session_id: |
| 298 | print("❌ Failed to create session") |
| 299 | return False |
| 300 | print(f"Created session: {session_id}") |
| 301 | |
| 302 | try: |
| 303 | # Create a test file |
| 304 | test_file = "/tmp/test_interrupt_tools.txt" |
| 305 | with open(test_file, 'w') as f: |
| 306 | f.write("apple\nbanana\ncherry\ndate\nelderberry") |
| 307 | |
| 308 | # Start message that will trigger file read |
| 309 | result_q = queue_mod.Queue() |
| 310 | thread = threading.Thread( |
| 311 | target=send_message_async, |
| 312 | args=(f"Read {test_file} and list each fruit.", session_id, result_q) |
| 313 | ) |
| 314 | thread.start() |
| 315 | |
| 316 | # Wait for tool execution to start, then queue interrupt |
| 317 | time.sleep(0.5) |
| 318 | print("Queueing soft interrupt: 'How many fruits are there?'") |
| 319 | queue_interrupt(session_id, "How many fruits are there in total?") |
| 320 | |
| 321 | # Wait for completion |
| 322 | thread.join(timeout=180) |
| 323 | |
| 324 | if thread.is_alive(): |
| 325 | print("❌ Timed out") |
| 326 | os.remove(test_file) |
| 327 | return False |
| 328 | |
| 329 | ok, output = result_q.get() |
| 330 | os.remove(test_file) |
| 331 | |
| 332 | if not ok: |
| 333 | print(f"❌ Failed: {output[:200]}") |
| 334 | return False |
| 335 | |
| 336 | print(f"Response: {output[:150]}...") |
| 337 | |
| 338 | # Check history |
| 339 | history = get_history(session_id) |
| 340 | print(f"\nHistory ({len(history)} messages):") |
| 341 | print_history(history) |
nothing calls this directly
no test coverage detected