fix: detect dollar prefix as shell mode trigger in InputModeRouter
The spec requires both ! and dollar sign to activate shell mode, but detect_mode() only recognised ! as the shell mode trigger. This caused dollar-prefixed inputs like dollar-sign-echo-hello to be routed to NORMAL mode instead of SHELL mode. - Add dollar sign to detect_mode() shell prefix check alongside ! - Add BDD tests for dollar prefix shell mode detection - Add step definitions for detect_mode() direct testing Closes #10412
This commit is contained in:
@@ -143,3 +143,13 @@ def step_run_fallback_tui_app(context: Context) -> None:
|
||||
def step_fallback_tui_fails(context: Context, message: str) -> None:
|
||||
assert context.tui_fallback_error is not None
|
||||
assert message in str(context.tui_fallback_error)
|
||||
|
||||
|
||||
@when('I detect mode for "{text}"')
|
||||
def step_detect_mode(context: Context, text: str) -> None:
|
||||
context.detected_mode = InputModeRouter.detect_mode(text)
|
||||
|
||||
|
||||
@then('the detected mode should be "{mode}"')
|
||||
def step_detected_mode_equals(context: Context, mode: str) -> None:
|
||||
assert context.detected_mode.value == mode
|
||||
|
||||
@@ -37,3 +37,23 @@ Feature: TUI input modes
|
||||
Then TUI textual availability should be boolean
|
||||
When I run fallback TUI app
|
||||
Then fallback TUI app should fail with "Textual dependency missing."
|
||||
|
||||
Scenario: Dollar prefix activates shell mode
|
||||
When I route TUI input "$echo hello"
|
||||
Then the TUI mode should be "shell"
|
||||
And the TUI shell stdout should contain "hello"
|
||||
|
||||
Scenario: Dollar prefix detect_mode returns shell
|
||||
When I detect mode for "$echo hello"
|
||||
Then the detected mode should be "shell"
|
||||
|
||||
|
||||
Scenario: Dollar prefix with leading whitespace activates shell mode
|
||||
When I detect mode for " $echo hello"
|
||||
Then the detected mode should be "shell"
|
||||
|
||||
|
||||
Scenario: Dollar prefix blocks dangerous command by default
|
||||
When I route TUI input "$rm -rf /"
|
||||
Then the TUI mode should be "shell"
|
||||
And the TUI shell stderr should contain "blocked dangerous shell command"
|
||||
|
||||
@@ -51,7 +51,7 @@ class InputModeRouter:
|
||||
stripped = text.lstrip()
|
||||
if stripped.startswith("/"):
|
||||
return InputMode.COMMAND
|
||||
if stripped.startswith("!"):
|
||||
if stripped.startswith(("!", "$")):
|
||||
return InputMode.SHELL
|
||||
return InputMode.NORMAL
|
||||
|
||||
|
||||
Reference in New Issue
Block a user