test(tui): cover shell safety confirmation callbacks

ISSUES CLOSED: #6361
This commit is contained in:
2026-06-16 22:34:35 -04:00
committed by Forgejo
parent b83b84ca79
commit c78862fe8b
2 changed files with 64 additions and 0 deletions
+37
View File
@@ -9,6 +9,11 @@ from unittest.mock import patch
from behave import given, then, when
from cleveragents.tui.input.modes import InputMode, ModeResult
from cleveragents.tui.shell_safety import (
DangerousCommandWarning,
DangerousPattern,
ShellDangerLevel,
)
from features.steps._tui_helpers import _submit_text, _submit_text_with_mocked_shell
@@ -91,3 +96,35 @@ def step_disable_shell_warnings(context):
app_patcher = patch("cleveragents.tui.app.get_settings", return_value=stub)
app_patcher.start()
context.add_cleanup(app_patcher.stop)
@when('I ask the app to confirm shell command "{command}"')
def step_confirm_shell_command(context, command):
context._tui_shell_confirmation = context._tui_app._confirm_dangerous_shell(command)
@then("the shell confirmation result should be allowed")
def step_shell_confirmation_allowed(context):
assert context._tui_shell_confirmation is True
@then("the shell confirmation result should be blocked")
def step_shell_confirmation_blocked(context):
assert context._tui_shell_confirmation is False
@when("I ask the app to handle a shell warning")
def step_handle_shell_warning(context):
pattern = DangerousPattern(
name="test_warning",
pattern=r"rm -rf",
level=ShellDangerLevel.CRITICAL,
description="test warning",
)
warning = DangerousCommandWarning.from_pattern("rm -rf /tmp", pattern)
context._tui_shell_warning_result = context._tui_app._handle_shell_warning(warning)
@then("the shell warning callback result should be allowed")
def step_shell_warning_callback_allowed(context):
assert context._tui_shell_warning_result is True
+27
View File
@@ -172,6 +172,33 @@ Feature: TUI App Coverage
Then the shell warning indicator should not be visible
And the prompt should not be marked as dangerous
Scenario: ShellSafetyService owns dangerous command confirmation
Given a mock command router and persona state
When I instantiate the Textual TUI app
And I ask the app to confirm shell command "rm -rf /tmp"
Then the shell confirmation result should be allowed
Scenario: shell confirmation allows safe commands without ShellSafetyService
Given shell danger warnings are disabled in settings
And a mock command router and persona state
When I instantiate the Textual TUI app
And I ask the app to confirm shell command "echo safe"
Then the shell confirmation result should be allowed
Scenario: shell confirmation uses the dangerous shell flag without ShellSafetyService
Given shell danger warnings are disabled in settings
And a mock command router and persona state
When I instantiate the Textual TUI app
And I ask the app to confirm shell command "rm -rf /tmp"
Then the shell confirmation result should be blocked
Scenario: shell warning callback allows execution when warnings are disabled
Given shell danger warnings are disabled in settings
And a mock command router and persona state
When I instantiate the Textual TUI app
And I ask the app to handle a shell warning
Then the shell warning callback result should be allowed
# --- on_input_submitted with shell returning None (lines 170-171) ---
Scenario: on_input_submitted handles None shell result