MCPcopy
hub / github.com/Aider-AI/aider / test_gpt_edit_to_dirty_file

Method test_gpt_edit_to_dirty_file

tests/basic/test_coder.py:667–750  ·  view source on GitHub ↗

A dirty file should be committed before the GPT edits are committed

(self)

Source from the content-addressed store, hash-verified

665 self.assertTrue(repo.is_dirty(path=str(fname1)))
666
667 def test_gpt_edit_to_dirty_file(self):
668 """A dirty file should be committed before the GPT edits are committed"""
669
670 with GitTemporaryDirectory():
671 repo = git.Repo()
672
673 fname = Path("file.txt")
674 fname.write_text("one\n")
675 repo.git.add(str(fname))
676
677 fname2 = Path("other.txt")
678 fname2.write_text("other\n")
679 repo.git.add(str(fname2))
680
681 repo.git.commit("-m", "new")
682
683 # dirty
684 fname.write_text("two\n")
685 fname2.write_text("OTHER\n")
686
687 io = InputOutput(yes=True)
688 coder = Coder.create(self.GPT35, "diff", io=io, fnames=[str(fname)])
689
690 def mock_send(*args, **kwargs):
691 coder.partial_response_content = f"""
692Do this:
693
694{str(fname)}
695<<<<<<< SEARCH
696two
697=======
698three
699>>>>>>> REPLACE
700
701"""
702 coder.partial_response_function_call = dict()
703 return []
704
705 saved_diffs = []
706
707 def mock_get_commit_message(diffs, context, user_language=None):
708 saved_diffs.append(diffs)
709 return "commit message"
710
711 coder.repo.get_commit_message = MagicMock(side_effect=mock_get_commit_message)
712 coder.send = mock_send
713
714 coder.run(with_message="hi")
715
716 content = fname.read_text()
717 self.assertEqual(content, "three\n")
718
719 num_commits = len(list(repo.iter_commits(repo.active_branch.name)))
720 self.assertEqual(num_commits, 3)
721
722 diff = repo.git.diff(["HEAD~2", "HEAD~1"])
723 self.assertIn("one", diff)
724 self.assertIn("two", diff)

Callers

nothing calls this directly

Calls 7

InputOutputClass · 0.90
write_textMethod · 0.80
commitMethod · 0.80
createMethod · 0.80
runMethod · 0.45
read_textMethod · 0.45

Tested by

no test coverage detected