mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-12 15:45:00 +00:00
test: add tests for --no-suggest-shell-commands behavior
This commit is contained in:
parent
a41ad9e778
commit
8735efc2b1
1 changed files with 51 additions and 0 deletions
|
@ -629,3 +629,54 @@ class TestMain(TestCase):
|
|||
return_coder=True,
|
||||
)
|
||||
self.assertTrue(coder.suggest_shell_commands)
|
||||
|
||||
def test_apply_shell_commands_with_no_suggest(self):
|
||||
with GitTemporaryDirectory():
|
||||
shell_md = Path("shell.md")
|
||||
shell_md.write_text("```bash\ntouch no_suggest_file.txt\n```")
|
||||
|
||||
main(
|
||||
["--apply", "shell.md", "--yes", "--no-suggest-shell-commands"],
|
||||
input=DummyInput(),
|
||||
output=DummyOutput(),
|
||||
)
|
||||
|
||||
# Shell commands should not run with --no-suggest-shell-commands
|
||||
self.assertFalse(Path("no_suggest_file.txt").exists())
|
||||
|
||||
def test_apply_shell_commands_with_no_suggest_explicit_approval(self):
|
||||
with GitTemporaryDirectory():
|
||||
shell_md = Path("shell.md")
|
||||
shell_md.write_text("```bash\ntouch explicit_approval_file.txt\n```")
|
||||
|
||||
# Simulate user input for explicit approval
|
||||
input_stream = StringIO("y\n")
|
||||
|
||||
main(
|
||||
["--apply", "shell.md", "--no-suggest-shell-commands"],
|
||||
input=input_stream,
|
||||
output=DummyOutput(),
|
||||
)
|
||||
|
||||
# Shell commands should still not run even with explicit approval
|
||||
self.assertFalse(Path("explicit_approval_file.txt").exists())
|
||||
|
||||
def test_suggest_shell_commands_in_interactive_mode(self):
|
||||
with GitTemporaryDirectory():
|
||||
# Create a file with some content
|
||||
test_file = Path("test_file.txt")
|
||||
test_file.write_text("Hello, world!")
|
||||
|
||||
# Simulate user input
|
||||
input_stream = StringIO("ls\nexit\n")
|
||||
|
||||
# Capture stdout to check if shell command suggestion is printed
|
||||
with patch("sys.stdout", new=StringIO()) as fake_out:
|
||||
main(
|
||||
["--no-suggest-shell-commands"],
|
||||
input=input_stream,
|
||||
output=fake_out,
|
||||
)
|
||||
|
||||
# Check that the shell command suggestion is not in the output
|
||||
self.assertNotIn("Here's how you can run that shell command:", fake_out.getvalue())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue