Auto-GPT: Fix a bunch of tests

pull/3972/head
Reinier van der Leer 2023-09-08 23:53:32 +02:00
parent b1dcd83a58
commit 69fdaa45d4
No known key found for this signature in database
GPG Key ID: 64035FE419545762
5 changed files with 10 additions and 25 deletions

View File

@ -61,7 +61,7 @@ def clean_input(config: Config, prompt: str = ""):
def get_bulletin_from_web(): def get_bulletin_from_web():
try: try:
response = requests.get( response = requests.get(
"https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/BULLETIN.md" "https://raw.githubusercontent.com/Significant-Gravitas/Auto-GPT/master/autogpts/autogpt/BULLETIN.md"
) )
if response.status_code == 200: if response.status_code == 200:
return response.text return response.text

View File

@ -30,7 +30,7 @@ def command(
) -> Callable[..., CommandOutput]: ) -> Callable[..., CommandOutput]:
"""The command decorator is used to create Command objects from ordinary functions.""" """The command decorator is used to create Command objects from ordinary functions."""
def decorator(func: Callable[..., CommandOutput]) -> Command: def decorator(func: Callable[..., CommandOutput]):
typed_parameters = [ typed_parameters = [
CommandParameter( CommandParameter(
name=param_name, name=param_name,
@ -55,8 +55,7 @@ def command(
def wrapper(*args, **kwargs) -> Any: def wrapper(*args, **kwargs) -> Any:
return func(*args, **kwargs) return func(*args, **kwargs)
wrapper.command = cmd setattr(wrapper, "command", cmd)
setattr(wrapper, AUTO_GPT_COMMAND_IDENTIFIER, True) setattr(wrapper, AUTO_GPT_COMMAND_IDENTIFIER, True)
return wrapper return wrapper

View File

@ -41,28 +41,15 @@ def test_execute_python_file(python_test_file: str, random_string: str, agent: A
def test_execute_python_code(random_code: str, random_string: str, agent: Agent): def test_execute_python_code(random_code: str, random_string: str, agent: Agent):
ai_name = agent.ai_config.ai_name result: str = sut.execute_python_code(random_code, agent=agent)
result: str = sut.execute_python_code(random_code, "test_code", agent=agent)
assert result.replace("\r", "") == f"Hello {random_string}!\n" assert result.replace("\r", "") == f"Hello {random_string}!\n"
# Check that the code is stored
destination = os.path.join(
agent.config.workspace_path, ai_name, "executed_code", "test_code.py"
)
with open(destination) as f:
assert f.read() == random_code
def test_execute_python_code_disallows_name_arg_path_traversal( def test_execute_python_code_disallows_name_arg_path_traversal(
random_code: str, agent: Agent random_code: str, agent: Agent
): ):
with pytest.raises(AccessDeniedError, match="path traversal"): with pytest.raises(AccessDeniedError, match="path traversal"):
sut.execute_python_code(random_code, name="../../test_code", agent=agent) sut.execute_python_code(random_code, agent=agent)
# Check that the code is not stored in parent directory
dst_with_traversal = agent.workspace.get_path("test_code.py")
assert not dst_with_traversal.is_file(), "Path traversal by filename not prevented"
def test_execute_python_code_overwrites_file(random_code: str, agent: Agent): def test_execute_python_code_overwrites_file(random_code: str, agent: Agent):
@ -75,7 +62,7 @@ def test_execute_python_code_overwrites_file(random_code: str, agent: Agent):
with open(destination, "w+") as f: with open(destination, "w+") as f:
f.write("This will be overwritten") f.write("This will be overwritten")
sut.execute_python_code(random_code, "test_code.py", agent=agent) sut.execute_python_code(random_code, agent=agent)
# Check that the file is updated with the new code # Check that the file is updated with the new code
with open(destination) as f: with open(destination) as f:

View File

@ -21,7 +21,7 @@ def test_initial_values(config: Config) -> None:
assert config.debug_mode == False assert config.debug_mode == False
assert config.continuous_mode == False assert config.continuous_mode == False
assert config.speak_mode == False assert config.speak_mode == False
assert config.fast_llm == "gpt-3.5-turbo" assert config.fast_llm == "gpt-3.5-turbo-16k"
assert config.smart_llm == "gpt-4-0314" assert config.smart_llm == "gpt-4-0314"

View File

@ -245,10 +245,9 @@ def test_write_file_succeeds_if_content_different(
test_file_with_content_path: Path, agent: Agent test_file_with_content_path: Path, agent: Agent
): ):
new_content = "This is different content.\n" new_content = "This is different content.\n"
result = file_ops.write_to_file( file_ops.write_to_file(
str(test_file_with_content_path), new_content, agent=agent str(test_file_with_content_path), new_content, agent=agent
) )
assert result == "File written to successfully."
def test_append_to_file(test_nested_file: Path, agent: Agent): def test_append_to_file(test_nested_file: Path, agent: Agent):
@ -301,7 +300,7 @@ def test_list_files(workspace: Workspace, test_directory: Path, agent: Agent):
with open(os.path.join(test_directory, file_a.name), "w") as f: with open(os.path.join(test_directory, file_a.name), "w") as f:
f.write("This is file A in the subdirectory.") f.write("This is file A in the subdirectory.")
files = file_ops.list_files(str(workspace.root), agent=agent) files = file_ops.list_folder(str(workspace.root), agent=agent)
assert file_a.name in files assert file_a.name in files
assert file_b.name in files assert file_b.name in files
assert os.path.join(Path(test_directory).name, file_a.name) in files assert os.path.join(Path(test_directory).name, file_a.name) in files
@ -314,5 +313,5 @@ def test_list_files(workspace: Workspace, test_directory: Path, agent: Agent):
# Case 2: Search for a file that does not exist and make sure we don't throw # Case 2: Search for a file that does not exist and make sure we don't throw
non_existent_file = "non_existent_file.txt" non_existent_file = "non_existent_file.txt"
files = file_ops.list_files("", agent=agent) files = file_ops.list_folder("", agent=agent)
assert non_existent_file not in files assert non_existent_file not in files