Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions tests/run_agent/test_real_interrupt_subagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,21 @@ class TestRealSubagentInterrupt(unittest.TestCase):
def setUp(self):
set_interrupt(False)
os.environ.setdefault("OPENAI_API_KEY", "test-key")
self._old_terminal_env = os.environ.get("TERMINAL_ENV")
self._old_terminal_modal_mode = os.environ.get("TERMINAL_MODAL_MODE")
os.environ["TERMINAL_ENV"] = "local"
os.environ.pop("TERMINAL_MODAL_MODE", None)

def tearDown(self):
set_interrupt(False)
if self._old_terminal_env is None:
os.environ.pop("TERMINAL_ENV", None)
else:
os.environ["TERMINAL_ENV"] = self._old_terminal_env
if self._old_terminal_modal_mode is None:
os.environ.pop("TERMINAL_MODAL_MODE", None)
else:
os.environ["TERMINAL_MODAL_MODE"] = self._old_terminal_modal_mode

def test_interrupt_child_during_api_call(self):
"""Real AIAgent child interrupted while making API call."""
Expand Down Expand Up @@ -95,8 +107,12 @@ def run_delegate():
mock_client.close = MagicMock()
MockOpenAI.return_value = mock_client

# Patch the instance method so it skips prompt assembly
with patch.object(AIAgent, '_build_system_prompt', return_value="You are a test agent"):
# Patch instance methods unrelated to interrupt behavior so
# the test stays hermetic and focused on delegate interrupt
# propagation rather than prompt assembly / auxiliary model
# preflight checks.
with patch.object(AIAgent, '_build_system_prompt', return_value="You are a test agent"), \
patch.object(AIAgent, '_check_compression_model_feasibility', return_value=None):
# Signal when child starts
original_run = AIAgent.run_conversation

Expand All @@ -106,7 +122,7 @@ def patched_run(self_agent, *args, **kwargs):

with patch.object(AIAgent, 'run_conversation', patched_run):
# Build a real child agent (AIAgent is NOT patched here,
# only run_conversation and _build_system_prompt are)
# only run_conversation and unrelated preflight helpers are)
child = AIAgent(
base_url="http://localhost:1",
api_key="test-key",
Expand Down