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 @@
|
||||
# Package marker for mirrored tests.
|
||||
@@ -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
|
||||
@@ -0,0 +1,45 @@
|
||||
"""Tests for shell-specific execution policy.
|
||||
|
||||
Alpha mode allows every shell command (read-only, mutating, restricted,
|
||||
operators, substitution) and only rejects genuinely empty input.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from tools.interactive_shell.shell.policy import evaluate_shell_command
|
||||
|
||||
|
||||
def test_read_only_shell_is_allow() -> None:
|
||||
r = evaluate_shell_command("pwd")
|
||||
assert r.verdict == "allow"
|
||||
assert r.tool_type == "shell"
|
||||
|
||||
|
||||
def test_restricted_shell_is_allow() -> None:
|
||||
"""Alpha mode removed the restricted deny floor; ``sudo`` now runs."""
|
||||
r = evaluate_shell_command("sudo ls /")
|
||||
assert r.verdict == "allow"
|
||||
assert r.shell_classification == "unrestricted"
|
||||
|
||||
|
||||
def test_operator_shell_is_allow() -> None:
|
||||
"""Shell operators run through a shell instead of being blocked."""
|
||||
r = evaluate_shell_command("ls | grep x")
|
||||
assert r.verdict == "allow"
|
||||
|
||||
|
||||
def test_mutating_shell_is_allow() -> None:
|
||||
r = evaluate_shell_command("rm -rf /tmp/x")
|
||||
assert r.verdict == "allow"
|
||||
assert r.shell_classification == "unrestricted"
|
||||
|
||||
|
||||
def test_passthrough_shell_is_allow() -> None:
|
||||
r = evaluate_shell_command("!echo hi")
|
||||
assert r.verdict == "allow"
|
||||
|
||||
|
||||
def test_empty_shell_input_is_deny() -> None:
|
||||
"""Only genuinely empty input is rejected (input validation, not a guardrail)."""
|
||||
r = evaluate_shell_command("!")
|
||||
assert r.verdict == "deny"
|
||||
@@ -0,0 +1,39 @@
|
||||
"""Tests for REPL shell command display formatting."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from tools.interactive_shell.shell.display import format_shell_command_for_display
|
||||
|
||||
|
||||
def test_single_line_command_is_unchanged() -> None:
|
||||
assert format_shell_command_for_display("ls -la") == "ls -la"
|
||||
|
||||
|
||||
def test_quoted_heredoc_body_is_collapsed() -> None:
|
||||
command = """python3 - <<'PY'
|
||||
import json
|
||||
print(1)
|
||||
PY"""
|
||||
assert format_shell_command_for_display(command) == "python3 - <<'PY' … (2 lines)"
|
||||
|
||||
|
||||
def test_unquoted_heredoc_body_is_collapsed() -> None:
|
||||
command = """cat <<EOF
|
||||
alpha
|
||||
beta
|
||||
EOF"""
|
||||
assert format_shell_command_for_display(command) == "cat <<EOF … (2 lines)"
|
||||
|
||||
|
||||
def test_runner_display_hides_github_stars_script() -> None:
|
||||
command = """python3 - <<'PY'
|
||||
import json, urllib.request
|
||||
url='https://api.github.com/repos/tracer-cloud/opensre'
|
||||
with urllib.request.urlopen(url, timeout=10) as r:
|
||||
data=json.load(r)
|
||||
print(data.get('stargazers_count'))
|
||||
PY"""
|
||||
display = format_shell_command_for_display(command)
|
||||
assert display.startswith("python3 - <<'PY' … (")
|
||||
assert "import json" not in display
|
||||
assert "stargazers_count" not in display
|
||||
@@ -0,0 +1,116 @@
|
||||
"""Tests for interactive-shell command parsing.
|
||||
|
||||
Alpha mode removed the shell-command safety policy (allowlist / restricted /
|
||||
mutating classification and the deny floor). Parsing now only decides *how* a
|
||||
command runs — via ``argv`` or through a shell — and never blocks a command for
|
||||
safety. The only non-execution outcome is empty input.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from tools.interactive_shell.shell.parsing import (
|
||||
argv_for_repl_builtin_detection,
|
||||
parse_shell_command,
|
||||
)
|
||||
|
||||
|
||||
def test_parse_shell_command_detects_passthrough_prefix() -> None:
|
||||
parsed = parse_shell_command("!echo hello", is_windows=False)
|
||||
|
||||
assert parsed.passthrough is True
|
||||
assert parsed.use_shell is True
|
||||
assert parsed.command == "echo hello"
|
||||
assert parsed.argv is None
|
||||
assert parsed.parse_error is None
|
||||
|
||||
|
||||
def test_plain_command_uses_argv_without_shell() -> None:
|
||||
parsed = parse_shell_command("rm -rf /tmp/x", is_windows=False)
|
||||
|
||||
assert parsed.passthrough is False
|
||||
assert parsed.use_shell is False
|
||||
assert parsed.argv == ["rm", "-rf", "/tmp/x"]
|
||||
assert parsed.parse_error is None
|
||||
|
||||
|
||||
def test_restricted_command_is_no_longer_blocked() -> None:
|
||||
"""``sudo`` and friends used to be a hard deny; alpha mode just runs them."""
|
||||
parsed = parse_shell_command("sudo systemctl restart nginx", is_windows=False)
|
||||
|
||||
assert parsed.use_shell is False
|
||||
assert parsed.argv == ["sudo", "systemctl", "restart", "nginx"]
|
||||
assert parsed.parse_error is None
|
||||
|
||||
|
||||
def test_operators_run_through_shell_without_block() -> None:
|
||||
parsed = parse_shell_command("ls | wc -l", is_windows=False)
|
||||
|
||||
assert parsed.use_shell is True
|
||||
assert parsed.passthrough is False
|
||||
assert parsed.argv is None
|
||||
assert parsed.parse_error is None
|
||||
|
||||
|
||||
def test_command_substitution_runs_through_shell() -> None:
|
||||
parsed = parse_shell_command("echo $(date)", is_windows=False)
|
||||
|
||||
assert parsed.use_shell is True
|
||||
assert parsed.parse_error is None
|
||||
|
||||
|
||||
def test_quoted_heredoc_runs_through_shell() -> None:
|
||||
command = """python3 - <<'PY'
|
||||
print("hello-heredoc")
|
||||
PY"""
|
||||
parsed = parse_shell_command(command, is_windows=False)
|
||||
|
||||
assert parsed.use_shell is True
|
||||
assert parsed.argv is None
|
||||
assert parsed.command == command.strip()
|
||||
assert parsed.parse_error is None
|
||||
|
||||
|
||||
def test_unquoted_heredoc_runs_through_shell() -> None:
|
||||
command = """cat <<EOF
|
||||
line one
|
||||
EOF"""
|
||||
parsed = parse_shell_command(command, is_windows=False)
|
||||
|
||||
assert parsed.use_shell is True
|
||||
assert parsed.argv is None
|
||||
|
||||
|
||||
def test_unbalanced_quotes_fall_back_to_shell() -> None:
|
||||
parsed = parse_shell_command('echo "unterminated', is_windows=False)
|
||||
|
||||
assert parsed.use_shell is True
|
||||
assert parsed.parse_error is None
|
||||
|
||||
|
||||
def test_empty_passthrough_is_parse_error() -> None:
|
||||
parsed = parse_shell_command("!", is_windows=False)
|
||||
|
||||
assert parsed.parse_error is not None
|
||||
assert parsed.passthrough is True
|
||||
|
||||
|
||||
def test_empty_command_is_parse_error() -> None:
|
||||
parsed = parse_shell_command(" ", is_windows=False)
|
||||
|
||||
assert parsed.parse_error == "empty command."
|
||||
|
||||
|
||||
def test_argv_for_repl_builtin_detection_splits_passthrough_for_cd() -> None:
|
||||
parsed = parse_shell_command("!cd /tmp", is_windows=False)
|
||||
assert argv_for_repl_builtin_detection(parsed=parsed, is_windows=False) == ["cd", "/tmp"]
|
||||
|
||||
|
||||
def test_argv_for_repl_builtin_detection_returns_plain_argv() -> None:
|
||||
parsed = parse_shell_command("pwd", is_windows=False)
|
||||
assert argv_for_repl_builtin_detection(parsed=parsed, is_windows=False) == ["pwd"]
|
||||
|
||||
|
||||
def test_argv_for_repl_builtin_detection_skips_operator_command() -> None:
|
||||
"""A leading ``cd`` in an operator command must not be hijacked as a builtin."""
|
||||
parsed = parse_shell_command("cd /tmp && ls", is_windows=False)
|
||||
assert argv_for_repl_builtin_detection(parsed=parsed, is_windows=False) is None
|
||||
Reference in New Issue
Block a user