MCPcopy Create free account
hub / github.com/1jehuang/jcode / test_soft_interrupt_with_tools

Function test_soft_interrupt_with_tools

scripts/test_soft_interrupt.py:284–373  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

282 destroy_session(session_id)
283
284def 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)

Callers

nothing calls this directly

Calls 10

create_test_sessionFunction · 0.85
queue_interruptFunction · 0.85
get_historyFunction · 0.85
print_historyFunction · 0.85
destroy_sessionFunction · 0.70
writeMethod · 0.45
startMethod · 0.45
removeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected