From 2adfe1507b0e9ac3756ab08b2f06c9251001b09d Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Fri, 28 Mar 2025 20:21:39 -1000 Subject: [PATCH] test: Add tests for /model command edit_format behavior --- tests/basic/test_commands.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/basic/test_commands.py b/tests/basic/test_commands.py index 154b32885..bfd17f374 100644 --- a/tests/basic/test_commands.py +++ b/tests/basic/test_commands.py @@ -1682,6 +1682,27 @@ class TestCommands(TestCase): self.assertEqual( context.exception.kwargs.get("main_model").weak_model.name, self.GPT35.weak_model.name ) + # Check that the edit format is updated to the new model's default + self.assertEqual(context.exception.kwargs.get("edit_format"), "whole") + + def test_cmd_model_preserves_explicit_edit_format(self): + io = InputOutput(pretty=False, fancy_input=False, yes=True) + # Use gpt-3.5-turbo (default 'diff') + coder = Coder.create(self.GPT35, None, io) + # Explicitly set edit format to something else + coder.edit_format = "udiff" + commands = Commands(io, coder) + + # Mock sanity check to avoid network calls + with mock.patch("aider.models.sanity_check_models"): + # Test switching the main model to gpt-4 (default 'whole') + with self.assertRaises(SwitchCoder) as context: + commands.cmd_model("gpt-4") + + # Check that the SwitchCoder exception contains the correct model configuration + self.assertEqual(context.exception.kwargs.get("main_model").name, "gpt-4") + # Check that the edit format is preserved + self.assertEqual(context.exception.kwargs.get("edit_format"), "udiff") def test_cmd_editor_model(self): io = InputOutput(pretty=False, fancy_input=False, yes=True)