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,157 @@
|
||||
"""Tests for the execution-policy interaction layer (``execution_allowed``).
|
||||
|
||||
These cover the terminal-facing half of the execution gate: console output and
|
||||
the confirmation prompt. The pure decision is tested in
|
||||
``tests/tools/interactive_shell/shared/test_execution_policy.py``.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
|
||||
from rich.console import Console
|
||||
|
||||
from surfaces.interactive_shell.session import Session
|
||||
from surfaces.interactive_shell.ui.execution_confirm import execution_allowed
|
||||
from tools.interactive_shell.shared import (
|
||||
ExecutionPolicyResult,
|
||||
allow_tool,
|
||||
)
|
||||
|
||||
|
||||
def _ask_result() -> ExecutionPolicyResult:
|
||||
"""An explicit ``ask`` verdict (the default policy no longer emits these)."""
|
||||
return ExecutionPolicyResult(
|
||||
verdict="ask",
|
||||
tool_type="slash",
|
||||
reason="this command may change configuration or run heavy work",
|
||||
)
|
||||
|
||||
|
||||
# --- execution_allowed: default-allow runs without prompting ----------------
|
||||
|
||||
|
||||
def test_allow_verdict_runs_without_prompt() -> None:
|
||||
session = Session()
|
||||
buf = io.StringIO()
|
||||
console = Console(file=buf, force_terminal=False)
|
||||
|
||||
def _confirm(_: str) -> str: # pragma: no cover - must never be called
|
||||
raise AssertionError("default-allow must not prompt for confirmation")
|
||||
|
||||
r = allow_tool("slash")
|
||||
assert execution_allowed(
|
||||
r,
|
||||
session=session,
|
||||
console=console,
|
||||
action_summary="/integrations verify foo",
|
||||
confirm_fn=_confirm,
|
||||
is_tty=True,
|
||||
)
|
||||
assert "Confirm" not in buf.getvalue()
|
||||
|
||||
|
||||
def test_non_tty_allows_default_policy() -> None:
|
||||
"""Default-allow no longer fails closed on non-interactive stdin."""
|
||||
session = Session()
|
||||
buf = io.StringIO()
|
||||
console = Console(file=buf, force_terminal=False)
|
||||
r = allow_tool("slash")
|
||||
assert execution_allowed(
|
||||
r,
|
||||
session=session,
|
||||
console=console,
|
||||
action_summary="/save out.md",
|
||||
is_tty=False,
|
||||
)
|
||||
|
||||
|
||||
def test_deny_verdict_blocks() -> None:
|
||||
session = Session()
|
||||
buf = io.StringIO()
|
||||
console = Console(file=buf, force_terminal=False)
|
||||
# The default policy never emits a deny; construct one explicitly to cover
|
||||
# the execution_allowed deny path.
|
||||
r = ExecutionPolicyResult(
|
||||
verdict="deny",
|
||||
tool_type="shell",
|
||||
reason="empty command.",
|
||||
hint="Enter a command to run.",
|
||||
)
|
||||
assert not execution_allowed(
|
||||
r,
|
||||
session=session,
|
||||
console=console,
|
||||
action_summary="!",
|
||||
is_tty=True,
|
||||
)
|
||||
assert "blocked" in buf.getvalue()
|
||||
|
||||
|
||||
# --- Retained ask machinery (reachable only via explicit ask) ---------------
|
||||
|
||||
|
||||
def test_explicit_ask_trust_mode_allows() -> None:
|
||||
session = Session()
|
||||
session.terminal.trust_mode = True
|
||||
buf = io.StringIO()
|
||||
console = Console(file=buf, force_terminal=False)
|
||||
assert execution_allowed(
|
||||
_ask_result(),
|
||||
session=session,
|
||||
console=console,
|
||||
action_summary="/investigate x",
|
||||
confirm_fn=lambda _: "n",
|
||||
is_tty=True,
|
||||
)
|
||||
|
||||
|
||||
def test_explicit_ask_non_tty_blocks() -> None:
|
||||
session = Session()
|
||||
session.terminal.trust_mode = False
|
||||
buf = io.StringIO()
|
||||
console = Console(file=buf, force_terminal=False)
|
||||
assert not execution_allowed(
|
||||
_ask_result(),
|
||||
session=session,
|
||||
console=console,
|
||||
action_summary="/save out.md",
|
||||
is_tty=False,
|
||||
)
|
||||
assert "not a TTY" in buf.getvalue()
|
||||
|
||||
|
||||
def test_explicit_ask_tty_accepts_empty_confirmation() -> None:
|
||||
session = Session()
|
||||
buf = io.StringIO()
|
||||
console = Console(file=buf, force_terminal=False)
|
||||
captured: list[str] = []
|
||||
|
||||
def _confirm(prompt: str) -> str:
|
||||
captured.append(prompt)
|
||||
return ""
|
||||
|
||||
assert execution_allowed(
|
||||
_ask_result(),
|
||||
session=session,
|
||||
console=console,
|
||||
action_summary="/integrations verify foo",
|
||||
confirm_fn=_confirm,
|
||||
is_tty=True,
|
||||
)
|
||||
assert captured == ["Proceed? [Y/n] "]
|
||||
|
||||
|
||||
def test_explicit_ask_tty_rejects_explicit_no() -> None:
|
||||
session = Session()
|
||||
buf = io.StringIO()
|
||||
console = Console(file=buf, force_terminal=False)
|
||||
assert not execution_allowed(
|
||||
_ask_result(),
|
||||
session=session,
|
||||
console=console,
|
||||
action_summary="/integrations verify foo",
|
||||
confirm_fn=lambda _: "n",
|
||||
is_tty=True,
|
||||
)
|
||||
assert "cancelled" in buf.getvalue()
|
||||
Reference in New Issue
Block a user