Home / Function/ test_shell_middleware_resumable_after_interrupt() — langchain Function Reference

test_shell_middleware_resumable_after_interrupt() — langchain Function Reference

Architecture documentation for the test_shell_middleware_resumable_after_interrupt() function in test_shell_tool.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  ef6ef526_b19f_5c71_daba_c59c64f4da02["test_shell_middleware_resumable_after_interrupt()"]
  f21fd460_1d0c_cb92_cfa1_eae0890e2f58["test_shell_tool.py"]
  ef6ef526_b19f_5c71_daba_c59c64f4da02 -->|defined in| f21fd460_1d0c_cb92_cfa1_eae0890e2f58
  1bc202d6_8b54_02e9_fadd_ff3171c38a75["_empty_state()"]
  ef6ef526_b19f_5c71_daba_c59c64f4da02 -->|calls| 1bc202d6_8b54_02e9_fadd_ff3171c38a75
  style ef6ef526_b19f_5c71_daba_c59c64f4da02 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_shell_tool.py lines 455–507

def test_shell_middleware_resumable_after_interrupt(tmp_path: Path) -> None:
    """Test that shell middleware is resumable after an interrupt.

    This test simulates a scenario where:
    1. The middleware creates a shell session
    2. A command is executed
    3. The agent is interrupted (state is preserved)
    4. The agent resumes with the same state
    5. The shell session is reused (not recreated)
    """
    workspace = tmp_path / "workspace"
    middleware = ShellToolMiddleware(workspace_root=workspace)

    # Simulate first execution (before interrupt)
    runtime = Runtime()
    state = _empty_state()
    updates = middleware.before_agent(state, runtime)
    if updates:
        state.update(cast("ShellToolState", updates))

    # Get the resources and verify they exist
    resources = middleware._get_or_create_resources(state)
    initial_session = resources.session
    initial_tempdir = resources.tempdir

    # Execute a command to set state
    middleware._run_shell_tool(resources, {"command": "export TEST_VAR=hello"}, tool_call_id=None)

    # Simulate interrupt - state is preserved, but we don't call after_agent
    # In a real scenario, the state would be checkpointed here

    # Simulate resumption - call before_agent again with same state
    # This should reuse existing resources, not create new ones
    updates = middleware.before_agent(state, runtime)
    if updates:
        state.update(cast("ShellToolState", updates))

    # Get resources again - should be the same session
    resumed_resources = middleware._get_or_create_resources(state)

    # Verify the session was reused (same object reference)
    assert resumed_resources.session is initial_session
    assert resumed_resources.tempdir is initial_tempdir

    # Verify the session state persisted (environment variable still set)
    result = middleware._run_shell_tool(
        resumed_resources, {"command": "echo ${TEST_VAR:-unset}"}, tool_call_id=None
    )
    assert "hello" in result
    assert "unset" not in result

    # Clean up
    middleware.after_agent(state, runtime)

Domain

Subdomains

Frequently Asked Questions

What does test_shell_middleware_resumable_after_interrupt() do?
test_shell_middleware_resumable_after_interrupt() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_shell_tool.py.
Where is test_shell_middleware_resumable_after_interrupt() defined?
test_shell_middleware_resumable_after_interrupt() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_shell_tool.py at line 455.
What does test_shell_middleware_resumable_after_interrupt() call?
test_shell_middleware_resumable_after_interrupt() calls 1 function(s): _empty_state.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free