Files
cleveragents-core/features/steps/_tui_helpers.py
T
HAL9000 b56c824909 fix(tui): repair shell-safety test scaffolding
Three independent test-scaffold defects blocked the unit_tests and
integration_tests gates on PR #6361's shell-safety wiring:

- features/steps/_tui_helpers.py: the mocked-shell helper patched
  cleveragents.tui.input.shell_exec.run_shell_command, but modes.py
  binds the symbol into its own namespace via `from ... import`. The
  patch was inert, and only the CLEVERAGENTS_ALLOW_DANGEROUS_SHELL=1
  gate kept the real `rm -rf /tmp` from running in the behave runner.
  Patch the use site (modes.run_shell_command) instead.

- src/cleveragents/tui/widgets/prompt.py: _FallbackPromptInput (used
  whenever Textual is mocked or unavailable) had no add_class /
  remove_class / has_class, so the new "prompt should be marked as
  dangerous" assertions raised AttributeError and the three new
  scenarios errored. The production path (_TextualPromptInput) already
  inherits these from textual.containers.Horizontal; the fallback now
  mirrors that contract via a small self._classes set.

- robot/tui_shell_safety.robot: Catenate's space-based argument
  separator collapses multi-space indentation, so the Python function
  bodies (warn_callback, deny) landed at column 0 and the helper
  scripts died with IndentationError before either assertion ran.
  Preserve the 4-space indent with ${SPACE * 4} markers.

ISSUES CLOSED: #6361
2026-06-17 00:21:34 -04:00

40 lines
1.3 KiB
Python

"""Shared TUI step-definition helpers."""
from __future__ import annotations
from types import SimpleNamespace
from typing import Any
from unittest.mock import patch
from cleveragents.tui.input.shell_exec import ShellResult
def _submit_text(context, text: str) -> None:
from cleveragents.tui.widgets.prompt import PromptInput
prompt = context._tui_app.query_one("#prompt", PromptInput)
prompt.value = text
event = SimpleNamespace()
context._tui_app.on_input_submitted(event)
def _submit_text_with_mocked_shell(context, text: str, stdout: str = "mocked") -> None:
"""Submit *text* while faking shell execution.
The patch target is the use site in ``modes`` rather than the
definition site in ``shell_exec``: ``modes`` did
``from cleveragents.tui.input.shell_exec import run_shell_command``,
binding the symbol into its own namespace; patching the source
module would leave that binding (and therefore the real
``subprocess.run`` call) untouched.
"""
def fake_run(command: str, **_: Any) -> ShellResult:
return ShellResult(command=command, exit_code=0, stdout=stdout, stderr="")
with patch(
"cleveragents.tui.input.modes.run_shell_command",
side_effect=fake_run,
):
_submit_text(context, text)