fix(tui): remove dead state fields and DRY up step helpers
- Remove `_shell_warning_active` and `_last_shell_warning` from CleverAgentsTuiApp.__init__, _show_shell_warning, and _clear_shell_warning — both fields were set but never consumed - Extract shared `_submit_text` and `_submit_text_with_mocked_shell` into features/steps/_tui_helpers.py; update tui_app_coverage_steps and tui_shell_safety_steps to import from shared module, eliminating the duplicate definitions flagged across multiple review cycles
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
"""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."""
|
||||
|
||||
def fake_run(command: str, **_: Any) -> ShellResult:
|
||||
return ShellResult(command=command, exit_code=0, stdout=stdout, stderr="")
|
||||
|
||||
with patch(
|
||||
"cleveragents.tui.input.shell_exec.run_shell_command",
|
||||
side_effect=fake_run,
|
||||
):
|
||||
_submit_text(context, text)
|
||||
@@ -5,12 +5,14 @@ import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from types import ModuleType, SimpleNamespace
|
||||
from types import ModuleType
|
||||
from typing import Any, cast
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from behave import given, then, when
|
||||
|
||||
from features.steps._tui_helpers import _submit_text
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Mock Textual infrastructure
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -430,19 +432,6 @@ def step_persona_bar_shows_name(context):
|
||||
assert "scope refs" in bar._text
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# on_input_submitted helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
def _submit_text(context, text):
|
||||
"""Set prompt value and fire on_input_submitted."""
|
||||
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)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# on_input_submitted: empty text (lines 144-150)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -4,35 +4,13 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
from behave import given, then, when
|
||||
|
||||
from cleveragents.tui.input.modes import InputMode, ModeResult
|
||||
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."""
|
||||
|
||||
def fake_run(command: str, **_: Any) -> ShellResult:
|
||||
return ShellResult(command=command, exit_code=0, stdout=stdout, stderr="")
|
||||
|
||||
with patch(
|
||||
"cleveragents.tui.input.shell_exec.run_shell_command",
|
||||
side_effect=fake_run,
|
||||
):
|
||||
_submit_text(context, text)
|
||||
from features.steps._tui_helpers import _submit_text, _submit_text_with_mocked_shell
|
||||
|
||||
|
||||
@when('I submit "{text}" to the app')
|
||||
|
||||
@@ -302,8 +302,6 @@ if _TEXTUAL_AVAILABLE:
|
||||
self._settings = get_settings()
|
||||
self._shell_warn_enabled = self._settings.shell_warn_dangerous
|
||||
self._allow_dangerous_shell = self._resolve_allow_dangerous_shell()
|
||||
self._shell_warning_active = False
|
||||
self._last_shell_warning: DangerousCommandWarning | None = None
|
||||
self._shell_safety: ShellSafetyService | None = (
|
||||
ShellSafetyService(warn_callback=self._handle_shell_warning)
|
||||
if self._shell_warn_enabled
|
||||
@@ -621,8 +619,6 @@ if _TEXTUAL_AVAILABLE:
|
||||
shell_warning.display = True
|
||||
if hasattr(prompt, "add_class"):
|
||||
prompt.add_class("dangerous")
|
||||
self._last_shell_warning = warning
|
||||
self._shell_warning_active = True
|
||||
|
||||
def _clear_shell_warning(self) -> None:
|
||||
try:
|
||||
@@ -635,8 +631,6 @@ if _TEXTUAL_AVAILABLE:
|
||||
shell_warning.display = False
|
||||
if hasattr(prompt, "remove_class"):
|
||||
prompt.remove_class("dangerous")
|
||||
self._last_shell_warning = None
|
||||
self._shell_warning_active = False
|
||||
|
||||
@staticmethod
|
||||
def _resolve_allow_dangerous_shell() -> bool:
|
||||
|
||||
Reference in New Issue
Block a user