Files
wehub-resource-sync 4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

103 lines
2.6 KiB
Python

"""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