test: Add tests for /model command edit_format behavior

This commit is contained in:
Paul Gauthier (aider) 2025-03-28 20:21:39 -10:00
parent 5516e6b279
commit 2adfe1507b

View file

@ -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)