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

Function test_interrupt_during_long_response

scripts/test_soft_interrupt.py:456–540  ·  view source on GitHub ↗

Test soft interrupt during a genuinely long response. We ask for something that takes time to generate.

()

Source from the content-addressed store, hash-verified

454 destroy_session(session_id)
455
456def test_interrupt_during_long_response():
457 """
458 Test soft interrupt during a genuinely long response.
459 We ask for something that takes time to generate.
460 """
461 print("\n" + "="*60)
462 print("TEST: Interrupt during long response")
463 print("="*60)
464
465 session_id = create_test_session()
466 if not session_id:
467 print("❌ Failed to create session")
468 return False
469 print(f"Created session: {session_id}")
470
471 try:
472 # Ask for something that takes time
473 result_q = queue_mod.Queue()
474 thread = threading.Thread(
475 target=send_message_async,
476 args=("Write a detailed 5-paragraph essay about the history of computing, from ENIAC to modern smartphones.", session_id, result_q)
477 )
478 thread.start()
479
480 # Queue interrupt after a delay
481 time.sleep(2.0)
482 print("Queueing interrupt: 'STOP - just say OK'")
483 ok = queue_interrupt(session_id, "STOP - just say 'OK' and nothing else.")
484 if ok:
485 print("✓ Interrupt queued")
486
487 # Wait for completion
488 thread.join(timeout=180)
489
490 if thread.is_alive():
491 print("❌ Timed out")
492 return False
493
494 ok, _ = result_q.get()
495 if not ok:
496 print("❌ Message failed")
497 return False
498
499 # Check history
500 history = get_history(session_id)
501 print(f"\nHistory ({len(history)} messages):")
502 print_history(history)
503
504 # Look for our interrupt
505 found_stop = False
506 for msg in history:
507 if msg.get('role') == 'user':
508 text = extract_text_from_content(msg.get('content', []))
509 if 'STOP' in text:
510 found_stop = True
511 break
512
513 if found_stop:

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected