mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 04:14:59 +00:00
test: Add tests for auto_accept_architect
feature in ArchitectCoder
This commit is contained in:
parent
d84c755ee8
commit
330bb81206
2 changed files with 92 additions and 1 deletions
|
@ -2,7 +2,7 @@ import os
|
|||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import MagicMock, patch, ANY
|
||||
|
||||
import git
|
||||
|
||||
|
@ -1059,6 +1059,96 @@ This command will print 'Hello, World!' to the console."""
|
|||
sanity_check_messages(coder.cur_messages)
|
||||
self.assertEqual(coder.cur_messages[-1]["role"], "assistant")
|
||||
|
||||
def test_architect_coder_auto_accept_true(self):
|
||||
with GitTemporaryDirectory():
|
||||
io = InputOutput(yes=True)
|
||||
|
||||
# Create an ArchitectCoder with auto_accept_architect=True
|
||||
with patch("aider.coders.architect_coder.AskCoder.__init__", return_value=None):
|
||||
from aider.coders.architect_coder import ArchitectCoder
|
||||
coder = ArchitectCoder()
|
||||
coder.io = io
|
||||
coder.main_model = self.GPT35
|
||||
coder.auto_accept_architect = True
|
||||
coder.verbose = False
|
||||
coder.total_cost = 0
|
||||
|
||||
# Mock editor_coder creation and execution
|
||||
mock_editor = MagicMock()
|
||||
with patch("aider.coders.architect_coder.Coder.create", return_value=mock_editor):
|
||||
# Set partial response content
|
||||
coder.partial_response_content = "Make these changes to the code"
|
||||
|
||||
# Call reply_completed
|
||||
coder.reply_completed()
|
||||
|
||||
# Verify that confirm_ask was not called (auto-accepted)
|
||||
io.confirm_ask.assert_not_called()
|
||||
|
||||
# Verify that editor coder was created and run
|
||||
mock_editor.run.assert_called_once()
|
||||
|
||||
def test_architect_coder_auto_accept_false_confirmed(self):
|
||||
with GitTemporaryDirectory():
|
||||
io = InputOutput(yes=False)
|
||||
io.confirm_ask = MagicMock(return_value=True)
|
||||
|
||||
# Create an ArchitectCoder with auto_accept_architect=False
|
||||
with patch("aider.coders.architect_coder.AskCoder.__init__", return_value=None):
|
||||
from aider.coders.architect_coder import ArchitectCoder
|
||||
coder = ArchitectCoder()
|
||||
coder.io = io
|
||||
coder.main_model = self.GPT35
|
||||
coder.auto_accept_architect = False
|
||||
coder.verbose = False
|
||||
coder.total_cost = 0
|
||||
|
||||
# Mock editor_coder creation and execution
|
||||
mock_editor = MagicMock()
|
||||
with patch("aider.coders.architect_coder.Coder.create", return_value=mock_editor):
|
||||
# Set partial response content
|
||||
coder.partial_response_content = "Make these changes to the code"
|
||||
|
||||
# Call reply_completed
|
||||
coder.reply_completed()
|
||||
|
||||
# Verify that confirm_ask was called
|
||||
io.confirm_ask.assert_called_once_with("Edit the files?")
|
||||
|
||||
# Verify that editor coder was created and run
|
||||
mock_editor.run.assert_called_once()
|
||||
|
||||
def test_architect_coder_auto_accept_false_rejected(self):
|
||||
with GitTemporaryDirectory():
|
||||
io = InputOutput(yes=False)
|
||||
io.confirm_ask = MagicMock(return_value=False)
|
||||
|
||||
# Create an ArchitectCoder with auto_accept_architect=False
|
||||
with patch("aider.coders.architect_coder.AskCoder.__init__", return_value=None):
|
||||
from aider.coders.architect_coder import ArchitectCoder
|
||||
coder = ArchitectCoder()
|
||||
coder.io = io
|
||||
coder.main_model = self.GPT35
|
||||
coder.auto_accept_architect = False
|
||||
coder.verbose = False
|
||||
coder.total_cost = 0
|
||||
|
||||
# Mock editor_coder creation and execution
|
||||
mock_editor = MagicMock()
|
||||
with patch("aider.coders.architect_coder.Coder.create", return_value=mock_editor):
|
||||
# Set partial response content
|
||||
coder.partial_response_content = "Make these changes to the code"
|
||||
|
||||
# Call reply_completed
|
||||
coder.reply_completed()
|
||||
|
||||
# Verify that confirm_ask was called
|
||||
io.confirm_ask.assert_called_once_with("Edit the files?")
|
||||
|
||||
# Verify that editor coder was NOT created or run
|
||||
# (because user rejected the changes)
|
||||
mock_editor.run.assert_not_called()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue