From be54df408459d3ac690bc68a1970f074c29c4735 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 29 Oct 2024 13:19:09 -0700 Subject: [PATCH] refactor: improve path comparison in command tests using os.path.samefile --- tests/basic/test_commands.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/basic/test_commands.py b/tests/basic/test_commands.py index f47117177..7bba0cbb9 100644 --- a/tests/basic/test_commands.py +++ b/tests/basic/test_commands.py @@ -671,10 +671,30 @@ class TestCommands(TestCase): # Verify the session file was created and contains the expected commands self.assertTrue(Path(session_file).exists()) with open(session_file, encoding=io.encoding) as f: - commands_text = f.read() - self.assertIn("/add file1.txt", commands_text) - self.assertIn("/add file2.py", commands_text) - self.assertIn("/read-only subdir/file3.md", commands_text) + commands_text = f.read().splitlines() + + # Convert paths to absolute for comparison + abs_file1 = str(Path("file1.txt").resolve()) + abs_file2 = str(Path("file2.py").resolve()) + abs_file3 = str(Path("subdir/file3.md").resolve()) + + # Check each line for matching paths using os.path.samefile + found_file1 = found_file2 = found_file3 = False + for line in commands_text: + if line.startswith("/add "): + path = Path(line[5:]).resolve() + if os.path.samefile(str(path), abs_file1): + found_file1 = True + elif os.path.samefile(str(path), abs_file2): + found_file2 = True + elif line.startswith("/read-only "): + path = Path(line[11:]).resolve() + if os.path.samefile(str(path), abs_file3): + found_file3 = True + + self.assertTrue(found_file1, "file1.txt not found in commands") + self.assertTrue(found_file2, "file2.py not found in commands") + self.assertTrue(found_file3, "file3.md not found in commands") # Clear the current session commands.cmd_reset("")