From 5878a5371099197dcf06d8f442f5acadd0a53447 Mon Sep 17 00:00:00 2001 From: AI Christianson Date: Tue, 17 Dec 2024 15:12:53 -0500 Subject: [PATCH] fix tests & bump version --- CHANGELOG.md | 2 +- ra_aid/__version__.py | 2 +- tests/ra_aid/tools/test_shell.py | 36 +++++++++++++++++++++----------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d968914..027a211 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [0.6.2] - Allow shell commands to be run in read-only mode. - When asking for shell command approval, allow cowboy mode to be enabled. - Update prompt to suggest commands be run in non-interactive mode if possible, e.g. using --no-pager git flag. diff --git a/ra_aid/__version__.py b/ra_aid/__version__.py index 8d587eb..0dc3f59 100644 --- a/ra_aid/__version__.py +++ b/ra_aid/__version__.py @@ -1,3 +1,3 @@ """Version information.""" -__version__ = "0.6.1" +__version__ = "0.6.2" diff --git a/tests/ra_aid/tools/test_shell.py b/tests/ra_aid/tools/test_shell.py index 4f3a20c..c5495e0 100644 --- a/tests/ra_aid/tools/test_shell.py +++ b/tests/ra_aid/tools/test_shell.py @@ -9,8 +9,8 @@ def mock_console(): yield mock @pytest.fixture -def mock_confirm(): - with patch('ra_aid.tools.shell.Confirm') as mock: +def mock_prompt(): + with patch('ra_aid.tools.shell.Prompt') as mock: yield mock @pytest.fixture @@ -19,7 +19,7 @@ def mock_run_interactive(): mock.return_value = (b"test output", 0) yield mock -def test_shell_command_cowboy_mode(mock_console, mock_confirm, mock_run_interactive): +def test_shell_command_cowboy_mode(mock_console, mock_prompt, mock_run_interactive): """Test shell command execution in cowboy mode (no approval)""" _global_memory['config'] = {'cowboy_mode': True} @@ -28,9 +28,9 @@ def test_shell_command_cowboy_mode(mock_console, mock_confirm, mock_run_interact assert result['success'] is True assert result['return_code'] == 0 assert "test output" in result['output'] - mock_confirm.ask.assert_not_called() + mock_prompt.ask.assert_not_called() -def test_shell_command_cowboy_message(mock_console, mock_confirm, mock_run_interactive): +def test_shell_command_cowboy_message(mock_console, mock_prompt, mock_run_interactive): """Test that cowboy mode displays a properly formatted cowboy message with correct spacing""" _global_memory['config'] = {'cowboy_mode': True} @@ -44,32 +44,44 @@ def test_shell_command_cowboy_message(mock_console, mock_confirm, mock_run_inter mock_console.print.assert_any_call("") mock_get_message.assert_called_once() -def test_shell_command_interactive_approved(mock_console, mock_confirm, mock_run_interactive): +def test_shell_command_interactive_approved(mock_console, mock_prompt, mock_run_interactive): """Test shell command execution with interactive approval""" _global_memory['config'] = {'cowboy_mode': False} - mock_confirm.ask.return_value = True + mock_prompt.ask.return_value = 'y' result = run_shell_command("echo test") assert result['success'] is True assert result['return_code'] == 0 assert "test output" in result['output'] - mock_confirm.ask.assert_called_once() + mock_prompt.ask.assert_called_once_with( + "Execute this command? (y=yes, n=no, c=enable cowboy mode for session)", + choices=["y", "n", "c"], + default="y", + show_choices=True, + show_default=True + ) -def test_shell_command_interactive_rejected(mock_console, mock_confirm, mock_run_interactive): +def test_shell_command_interactive_rejected(mock_console, mock_prompt, mock_run_interactive): """Test shell command rejection in interactive mode""" _global_memory['config'] = {'cowboy_mode': False} - mock_confirm.ask.return_value = False + mock_prompt.ask.return_value = 'n' result = run_shell_command("echo test") assert result['success'] is False assert result['return_code'] == 1 assert "cancelled by user" in result['output'] - mock_confirm.ask.assert_called_once() + mock_prompt.ask.assert_called_once_with( + "Execute this command? (y=yes, n=no, c=enable cowboy mode for session)", + choices=["y", "n", "c"], + default="y", + show_choices=True, + show_default=True + ) mock_run_interactive.assert_not_called() -def test_shell_command_execution_error(mock_console, mock_confirm, mock_run_interactive): +def test_shell_command_execution_error(mock_console, mock_prompt, mock_run_interactive): """Test handling of shell command execution errors""" _global_memory['config'] = {'cowboy_mode': True} mock_run_interactive.side_effect = Exception("Command failed")