From 7202cd524eff6b268c735ee06c6294b170991a6b Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Fri, 21 Jun 2024 22:54:03 -0700 Subject: [PATCH] bug: don't match archive with glob In the current directory is the archive (gptscript...tar.gz) and the binary (gptscript or gptscript.exe). The current approach will sometimes match the archive. By removing '*' it will look for the exact filename. --- gptscript/install.py | 2 +- tests/test_gptscript.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gptscript/install.py b/gptscript/install.py index 80bd1ca..b7effeb 100644 --- a/gptscript/install.py +++ b/gptscript/install.py @@ -150,7 +150,7 @@ def install(): # Find the extracted binary and rename/move it to the versioned name in the python bin directory extracted_binary_path = next( - output_dir.glob(gptscript_binary_name + "*"), None + output_dir.glob(gptscript_binary_name), None ) # Adjust the glob pattern if necessary if extracted_binary_path: shutil.move(str(extracted_binary_path), str(versioned_binary_path)) diff --git a/tests/test_gptscript.py b/tests/test_gptscript.py index 4b35c59..6d67547 100644 --- a/tests/test_gptscript.py +++ b/tests/test_gptscript.py @@ -1,11 +1,13 @@ import os import platform +import subprocess import pytest from gptscript.confirm import AuthResponse from gptscript.frame import RunEventType, CallFrame, RunFrame, RunState, PromptFrame from gptscript.gptscript import GPTScript +from gptscript.install import install, gptscript_binary_name, python_bin_dir from gptscript.opts import GlobalOptions, Options from gptscript.prompt import PromptResponse from gptscript.run import Run @@ -77,6 +79,13 @@ def tool_list(): ] +def test_install(): + install() + bin_name = str(python_bin_dir / gptscript_binary_name) + process = subprocess.Popen([bin_name, '-v'], stdout=subprocess.PIPE, text=True) + assert process.stdout.read().startswith('gptscript version ') + + @pytest.mark.asyncio async def test_create_another_gptscript(): g = GPTScript() @@ -420,15 +429,16 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame): for output in frame.output: event_content += output.content - tool = ToolDef(tools=["sys.exec"], instructions="List the files in the current directory.") + tool = ToolDef(tools=["sys.exec"], instructions="List the files in the current directory. If that doesn't work" + "print the word FAIL.") out = await gptscript.evaluate(tool, Options(confirm=True, disableCache=True), event_handlers=[process_event], ).text() assert confirm_event_found, "No confirm event" - assert "authorization error" in out, "Unexpected output: " + out - assert "authorization error" in event_content, "Unexpected event output: " + event_content + assert "FAIL" in out, "Unexpected output: " + out + assert "FAIL" in event_content, "Unexpected event output: " + event_content @pytest.mark.asyncio