chore: import upstream snapshot with attribution
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
"""Tests for structured REPL shell execution."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
from typing import NoReturn
|
||||
|
||||
import pytest
|
||||
|
||||
from tools.interactive_shell.shell.execution import (
|
||||
ShellExecutionResult,
|
||||
execute_shell_command,
|
||||
)
|
||||
from tools.interactive_shell.shell.parsing import parse_shell_command
|
||||
|
||||
|
||||
def test_execute_shell_command_reports_timeout_argv_mode(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def _raise(*_args: object, **_kwargs: object) -> NoReturn: # pragma: no cover
|
||||
raise subprocess.TimeoutExpired(
|
||||
cmd=["sleep", "999"],
|
||||
timeout=1,
|
||||
output="partial out\n",
|
||||
stderr="partial err\n",
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
"tools.interactive_shell.shell.execution.subprocess.run",
|
||||
_raise,
|
||||
)
|
||||
|
||||
result = execute_shell_command(
|
||||
command="ignored",
|
||||
argv=["sleep", "999"],
|
||||
use_shell=False,
|
||||
timeout_seconds=1,
|
||||
max_output_chars=10_000,
|
||||
)
|
||||
|
||||
assert result == ShellExecutionResult(
|
||||
command="ignored",
|
||||
argv=["sleep", "999"],
|
||||
stdout="partial out\n",
|
||||
stderr="partial err\n",
|
||||
exit_code=None,
|
||||
timed_out=True,
|
||||
truncated=False,
|
||||
executed_with_shell=False,
|
||||
)
|
||||
|
||||
|
||||
def test_execute_shell_command_reports_timeout_shell_mode(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def _raise(*_args: object, **_kwargs: object) -> NoReturn: # pragma: no cover
|
||||
raise subprocess.TimeoutExpired(
|
||||
cmd="sleep 999",
|
||||
timeout=1,
|
||||
output="out\n",
|
||||
stderr="err\n",
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
"tools.interactive_shell.shell.execution.subprocess.run",
|
||||
_raise,
|
||||
)
|
||||
|
||||
result = execute_shell_command(
|
||||
command="sleep 999",
|
||||
argv=None,
|
||||
use_shell=True,
|
||||
timeout_seconds=1,
|
||||
max_output_chars=10_000,
|
||||
)
|
||||
|
||||
assert result == ShellExecutionResult(
|
||||
command="sleep 999",
|
||||
argv=None,
|
||||
stdout="out\n",
|
||||
stderr="err\n",
|
||||
exit_code=None,
|
||||
timed_out=True,
|
||||
truncated=False,
|
||||
executed_with_shell=True,
|
||||
)
|
||||
|
||||
|
||||
def test_execute_quoted_heredoc_through_shell() -> None:
|
||||
command = """python3 - <<'PY'
|
||||
print("hello-heredoc")
|
||||
PY"""
|
||||
parsed = parse_shell_command(command, is_windows=False)
|
||||
assert parsed.use_shell is True
|
||||
|
||||
result = execute_shell_command(
|
||||
command=parsed.command,
|
||||
argv=parsed.argv,
|
||||
use_shell=parsed.use_shell,
|
||||
timeout_seconds=10,
|
||||
max_output_chars=10_000,
|
||||
)
|
||||
|
||||
assert result.timed_out is False
|
||||
assert result.exit_code == 0
|
||||
assert "hello-heredoc" in result.stdout
|
||||
Reference in New Issue
Block a user