|
9 | 9 |
|
10 | 10 | from aider.coders import Coder |
11 | 11 | from aider.coders.base_coder import FinishReasonLength, UnknownEditFormat |
| 12 | +from aider.commands import SwitchCoder |
12 | 13 | from aider.dump import dump # noqa: F401 |
13 | 14 | from aider.io import InputOutput |
14 | 15 | from aider.models import Model |
@@ -1384,129 +1385,75 @@ async def test_get_user_language(self): |
1384 | 1385 | with patch("os.environ.get", return_value=None) as mock_env_get: |
1385 | 1386 | assert coder.get_user_language() is None |
1386 | 1387 |
|
1387 | | - @pytest.mark.xfail( |
1388 | | - reason="ArchitectCoder missing args attribute at line 19 in architect_coder.py" |
1389 | | - ) |
1390 | 1388 | async def test_architect_coder_auto_accept_true(self): |
1391 | 1389 | with GitTemporaryDirectory(): |
1392 | 1390 | io = InputOutput(yes=True) |
1393 | | - io.confirm_ask = AsyncMock(return_value=True) |
| 1391 | + io.confirm_ask = AsyncMock(return_value=False) |
1394 | 1392 |
|
1395 | | - # Create an ArchitectCoder with auto_accept_architect=True |
1396 | | - with patch("aider.coders.architect_coder.AskCoder.__init__", return_value=None): |
1397 | | - from aider.coders.architect_coder import ArchitectCoder |
1398 | | - |
1399 | | - coder = ArchitectCoder() |
1400 | | - coder.io = io |
1401 | | - coder.main_model = self.GPT35 |
1402 | | - coder.auto_accept_architect = True |
1403 | | - coder.verbose = False |
1404 | | - coder.total_cost = 0 |
1405 | | - coder.cur_messages = [] |
1406 | | - coder.done_messages = [] |
1407 | | - coder.summarizer = MagicMock() |
1408 | | - coder.summarizer.too_big.return_value = False |
1409 | | - |
1410 | | - # Mock editor_coder creation and execution |
1411 | | - mock_editor = MagicMock() |
1412 | | - with patch( |
1413 | | - "aider.coders.architect_coder.Coder.create", |
1414 | | - return_value=mock_editor, |
1415 | | - ): |
1416 | | - # Set partial response content |
1417 | | - coder.partial_response_content = "Make these changes to the code" |
1418 | | - |
1419 | | - # Call reply_completed |
| 1393 | + coder = await Coder.create(self.GPT35, edit_format="architect", io=io) |
| 1394 | + coder.auto_accept_architect = True |
| 1395 | + coder.partial_response_content = "Make these changes to the code" |
| 1396 | + |
| 1397 | + mock_editor = MagicMock() |
| 1398 | + mock_editor.generate = AsyncMock() |
| 1399 | + mock_editor.total_cost = 0 |
| 1400 | + mock_editor.aider_commit_hashes = [] |
| 1401 | + |
| 1402 | + with patch( |
| 1403 | + "aider.coders.architect_coder.Coder.create", |
| 1404 | + new_callable=AsyncMock, |
| 1405 | + return_value=mock_editor, |
| 1406 | + ): |
| 1407 | + with pytest.raises(SwitchCoder): |
1420 | 1408 | await coder.reply_completed() |
1421 | 1409 |
|
1422 | | - # Verify that confirm_ask was not called (auto-accepted) |
1423 | | - io.confirm_ask.assert_not_called() |
1424 | | - |
1425 | | - # Verify that editor coder was created and run |
1426 | | - mock_editor.run.assert_called_once() |
| 1410 | + io.confirm_ask.assert_called_once_with("Edit the files?", allow_tweak=False) |
| 1411 | + mock_editor.generate.assert_called_once() |
1427 | 1412 |
|
1428 | | - @pytest.mark.xfail( |
1429 | | - reason="ArchitectCoder missing args attribute at line 19 in architect_coder.py" |
1430 | | - ) |
1431 | 1413 | async def test_architect_coder_auto_accept_false_confirmed(self): |
1432 | 1414 | with GitTemporaryDirectory(): |
1433 | 1415 | io = InputOutput(yes=False) |
1434 | 1416 | io.confirm_ask = AsyncMock(return_value=True) |
1435 | 1417 |
|
1436 | | - # Create an ArchitectCoder with auto_accept_architect=False |
1437 | | - with patch("aider.coders.architect_coder.AskCoder.__init__", return_value=None): |
1438 | | - from aider.coders.architect_coder import ArchitectCoder |
1439 | | - |
1440 | | - coder = ArchitectCoder() |
1441 | | - coder.io = io |
1442 | | - coder.main_model = self.GPT35 |
1443 | | - coder.auto_accept_architect = False |
1444 | | - coder.verbose = False |
1445 | | - coder.total_cost = 0 |
1446 | | - coder.cur_messages = [] |
1447 | | - coder.done_messages = [] |
1448 | | - coder.summarizer = MagicMock() |
1449 | | - coder.summarizer.too_big.return_value = False |
1450 | | - coder.cur_messages = [] |
1451 | | - coder.done_messages = [] |
1452 | | - coder.summarizer = MagicMock() |
1453 | | - coder.summarizer.too_big.return_value = False |
1454 | | - |
1455 | | - # Mock editor_coder creation and execution |
1456 | | - mock_editor = MagicMock() |
1457 | | - with patch( |
1458 | | - "aider.coders.architect_coder.Coder.create", |
1459 | | - return_value=mock_editor, |
1460 | | - ): |
1461 | | - # Set partial response content |
1462 | | - coder.partial_response_content = "Make these changes to the code" |
1463 | | - |
1464 | | - # Call reply_completed |
| 1418 | + coder = await Coder.create(self.GPT35, edit_format="architect", io=io) |
| 1419 | + coder.auto_accept_architect = False |
| 1420 | + coder.partial_response_content = "Make these changes to the code" |
| 1421 | + |
| 1422 | + mock_editor = MagicMock() |
| 1423 | + mock_editor.generate = AsyncMock() |
| 1424 | + mock_editor.total_cost = 0 |
| 1425 | + mock_editor.aider_commit_hashes = [] |
| 1426 | + |
| 1427 | + with patch( |
| 1428 | + "aider.coders.architect_coder.Coder.create", |
| 1429 | + new_callable=AsyncMock, |
| 1430 | + return_value=mock_editor, |
| 1431 | + ): |
| 1432 | + with pytest.raises(SwitchCoder): |
1465 | 1433 | await coder.reply_completed() |
1466 | 1434 |
|
1467 | | - # Verify that confirm_ask was called |
1468 | | - io.confirm_ask.assert_called_once_with("Edit the files?") |
1469 | | - |
1470 | | - # Verify that editor coder was created and run |
1471 | | - mock_editor.run.assert_called_once() |
| 1435 | + io.confirm_ask.assert_called_once_with("Edit the files?", allow_tweak=False) |
| 1436 | + mock_editor.generate.assert_called_once() |
1472 | 1437 |
|
1473 | | - @pytest.mark.xfail( |
1474 | | - reason="ArchitectCoder missing args attribute at line 19 in architect_coder.py" |
1475 | | - ) |
1476 | 1438 | async def test_architect_coder_auto_accept_false_rejected(self): |
1477 | 1439 | with GitTemporaryDirectory(): |
1478 | 1440 | io = InputOutput(yes=False) |
1479 | 1441 | io.confirm_ask = AsyncMock(return_value=False) |
1480 | 1442 |
|
1481 | | - # Create an ArchitectCoder with auto_accept_architect=False |
1482 | | - with patch("aider.coders.architect_coder.AskCoder.__init__", return_value=None): |
1483 | | - from aider.coders.architect_coder import ArchitectCoder |
1484 | | - |
1485 | | - coder = ArchitectCoder() |
1486 | | - coder.io = io |
1487 | | - coder.main_model = self.GPT35 |
1488 | | - coder.auto_accept_architect = False |
1489 | | - coder.verbose = False |
1490 | | - coder.total_cost = 0 |
1491 | | - |
1492 | | - # Mock editor_coder creation and execution |
1493 | | - mock_editor = MagicMock() |
1494 | | - with patch( |
1495 | | - "aider.coders.architect_coder.Coder.create", |
1496 | | - return_value=mock_editor, |
1497 | | - ): |
1498 | | - # Set partial response content |
1499 | | - coder.partial_response_content = "Make these changes to the code" |
1500 | | - |
1501 | | - # Call reply_completed |
1502 | | - await coder.reply_completed() |
| 1443 | + coder = await Coder.create(self.GPT35, edit_format="architect", io=io) |
| 1444 | + coder.auto_accept_architect = False |
| 1445 | + coder.partial_response_content = "Make these changes to the code" |
1503 | 1446 |
|
1504 | | - # Verify that confirm_ask was called |
1505 | | - io.confirm_ask.assert_called_once_with("Edit the files?") |
| 1447 | + mock_create = AsyncMock() |
| 1448 | + with patch( |
| 1449 | + "aider.coders.architect_coder.Coder.create", |
| 1450 | + mock_create, |
| 1451 | + ): |
| 1452 | + result = await coder.reply_completed() |
1506 | 1453 |
|
1507 | | - # Verify that editor coder was NOT created or run |
1508 | | - # (because user rejected the changes) |
1509 | | - mock_editor.run.assert_not_called() |
| 1454 | + assert result is None |
| 1455 | + io.confirm_ask.assert_called_once_with("Edit the files?", allow_tweak=False) |
| 1456 | + mock_create.assert_not_called() |
1510 | 1457 |
|
1511 | 1458 | @patch("aider.coders.base_coder.experimental_mcp_client") |
1512 | 1459 | async def test_mcp_server_connection(self, mock_mcp_client): |
|
0 commit comments