From 23d3dafc5152b5c7437a484d38e29f282fbc75ad Mon Sep 17 00:00:00 2001 From: BillSchumacher <34168009+BillSchumacher@users.noreply.github.com> Date: Sun, 16 Apr 2023 23:18:29 -0500 Subject: [PATCH] Maybe fix tests, fix safe_path function. --- autogpt/workspace.py | 2 +- tests/test_commands.py | 4 ++-- tests/test_prompt_generator.py | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/autogpt/workspace.py b/autogpt/workspace.py index 964a94d1..e1e99082 100644 --- a/autogpt/workspace.py +++ b/autogpt/workspace.py @@ -35,7 +35,7 @@ def safe_path_join(base: Path, *paths: str | Path) -> Path: """ joined_path = base.joinpath(*paths).resolve() - if not joined_path.is_relative_to(base): + if not str(joined_path.absolute()).startswith(str(base.absolute())): raise ValueError( f"Attempted to access path '{joined_path}' outside of working directory '{base}'." ) diff --git a/tests/test_commands.py b/tests/test_commands.py index 49c09f11..a1fe0cb5 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -139,7 +139,7 @@ class TestCommandRegistry: def test_import_mock_commands_module(self): """Test that the registry can import a module with mock command plugins.""" registry = CommandRegistry() - mock_commands_module = "auto_gpt.tests.mocks.mock_commands" + mock_commands_module = "tests.mocks.mock_commands" registry.import_commands(mock_commands_module) @@ -155,7 +155,7 @@ class TestCommandRegistry: registry = CommandRegistry() # Create a temp command file - src = Path("/app/auto_gpt/tests/mocks/mock_commands.py") + src = Path("mocks/mock_commands.py") temp_commands_file = tmp_path / "mock_commands.py" shutil.copyfile(src, temp_commands_file) diff --git a/tests/test_prompt_generator.py b/tests/test_prompt_generator.py index 59ca7f95..1fa1754d 100644 --- a/tests/test_prompt_generator.py +++ b/tests/test_prompt_generator.py @@ -38,6 +38,7 @@ class TestPromptGenerator(TestCase): "label": command_label, "name": command_name, "args": args, + "function": None, } self.assertIn(command, self.generator.commands)