Home / File/ test_shell_execution_policies.py — langchain Source File

test_shell_execution_policies.py — langchain Source File

Architecture documentation for test_shell_execution_policies.py, a python file in the langchain codebase. 11 imports, 0 dependents.

File python LangChainCore Runnables 11 imports 23 functions 3 classes

Entity Profile

Dependency Diagram

graph LR
  6b16168d_9880_7f41_060c_9fcd5b337996["test_shell_execution_policies.py"]
  0029f612_c503_ebcf_a452_a0fae8c9f2c3["os"]
  6b16168d_9880_7f41_060c_9fcd5b337996 --> 0029f612_c503_ebcf_a452_a0fae8c9f2c3
  d9ebf537_3893_4fe5_9403_53e4951b9cbb["shutil"]
  6b16168d_9880_7f41_060c_9fcd5b337996 --> d9ebf537_3893_4fe5_9403_53e4951b9cbb
  1e712485_2e6d_569a_0ba8_66be0da75ea6["subprocess"]
  6b16168d_9880_7f41_060c_9fcd5b337996 --> 1e712485_2e6d_569a_0ba8_66be0da75ea6
  02625e10_fb78_7ecd_1ee2_105ee470faf5["sys"]
  6b16168d_9880_7f41_060c_9fcd5b337996 --> 02625e10_fb78_7ecd_1ee2_105ee470faf5
  927570d8_11a6_5c17_0f0d_80baae0c733e["pathlib"]
  6b16168d_9880_7f41_060c_9fcd5b337996 --> 927570d8_11a6_5c17_0f0d_80baae0c733e
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  6b16168d_9880_7f41_060c_9fcd5b337996 --> feec1ec4_6917_867b_d228_b134d0ff8099
  23cb242e_1754_041d_200a_553fcb8abe1b["unittest.mock"]
  6b16168d_9880_7f41_060c_9fcd5b337996 --> 23cb242e_1754_041d_200a_553fcb8abe1b
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  6b16168d_9880_7f41_060c_9fcd5b337996 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  598be07d_58e8_b830_8ebe_d631441aa2fe["langchain.agents.middleware"]
  6b16168d_9880_7f41_060c_9fcd5b337996 --> 598be07d_58e8_b830_8ebe_d631441aa2fe
  0f767285_fa0a_afed_9c89_dfda4eacfe4d["langchain.agents.middleware.shell_tool"]
  6b16168d_9880_7f41_060c_9fcd5b337996 --> 0f767285_fa0a_afed_9c89_dfda4eacfe4d
  2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"]
  6b16168d_9880_7f41_060c_9fcd5b337996 --> 2bf6d401_816d_d011_3b05_a6114f55ff58
  style 6b16168d_9880_7f41_060c_9fcd5b337996 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

import os
import shutil
import subprocess
import sys
from pathlib import Path
from typing import TYPE_CHECKING, Any
from unittest.mock import Mock

import pytest

from langchain.agents.middleware import _execution
from langchain.agents.middleware.shell_tool import (
    CodexSandboxExecutionPolicy,
    DockerExecutionPolicy,
    HostExecutionPolicy,
)

if TYPE_CHECKING:
    from collections.abc import Callable, Mapping, Sequence
    from pathlib import Path


def _make_resource(
    *,
    with_prlimit: bool,
    has_rlimit_as: bool = True,
) -> Any:
    """Create a fake ``resource`` module for testing."""

    class _BaseResource:
        RLIMIT_CPU = 0
        RLIMIT_DATA = 2

        if has_rlimit_as:
            RLIMIT_AS = 1

        def __init__(self) -> None:
            self.prlimit_calls: list[tuple[int, int, tuple[int, int]]] = []
            self.setrlimit_calls: list[tuple[int, tuple[int, int]]] = []

        def setrlimit(self, resource_name: int, limits: tuple[int, int]) -> None:
            self.setrlimit_calls.append((resource_name, limits))

    if with_prlimit:

        class _Resource(_BaseResource):
            def prlimit(self, pid: int, resource_name: int, limits: tuple[int, int]) -> None:
                self.prlimit_calls.append((pid, resource_name, limits))

        return _Resource()

    return _BaseResource()


def test_host_policy_validations() -> None:
    with pytest.raises(ValueError, match="max_output_lines must be positive"):
        HostExecutionPolicy(max_output_lines=0)

// ... (350 more lines)

Domain

Subdomains

Dependencies

  • collections.abc
  • langchain.agents.middleware
  • langchain.agents.middleware.shell_tool
  • os
  • pathlib
  • pytest
  • shutil
  • subprocess
  • sys
  • typing
  • unittest.mock

Frequently Asked Questions

What does test_shell_execution_policies.py do?
test_shell_execution_policies.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, Runnables subdomain.
What functions are defined in test_shell_execution_policies.py?
test_shell_execution_policies.py defines 23 function(s): _make_resource, collections, test_codex_policy_auto_platform_failure, test_codex_policy_auto_platform_linux, test_codex_policy_auto_platform_macos, test_codex_policy_formats_override_values, test_codex_policy_resolve_missing_binary, test_codex_policy_sorts_config_overrides, test_codex_policy_spawns_codex_cli, test_docker_policy_read_only_and_user, and 13 more.
What does test_shell_execution_policies.py depend on?
test_shell_execution_policies.py imports 11 module(s): collections.abc, langchain.agents.middleware, langchain.agents.middleware.shell_tool, os, pathlib, pytest, shutil, subprocess, and 3 more.
Where is test_shell_execution_policies.py in the architecture?
test_shell_execution_policies.py is located at libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_shell_execution_policies.py (domain: LangChainCore, subdomain: Runnables, directory: libs/langchain_v1/tests/unit_tests/agents/middleware/implementations).

Analyze Your Own Codebase

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

Try Supermodel Free