Skip to content

Commit 9b42f2b

Browse files
authored
tests(sdk): Run tests on toolbox dev version (#19)
1 parent 4cbc0c8 commit 9b42f2b

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

tests/conftest.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from typing import Generator
2626

2727
import google
28+
import pytest
2829
import pytest_asyncio
2930
from google.auth import compute_engine
3031
from google.cloud import secretmanager, storage
@@ -130,21 +131,37 @@ def auth_token2(project_id: str) -> str:
130131

131132

132133
@pytest_asyncio.fixture(scope="session")
133-
def toolbox_server(toolbox_version: str, tools_file_path: str) -> Generator[None]:
134+
def toolbox_server(
135+
tmp_path_factory: pytest.TempPathFactory, toolbox_version: str, tools_file_path: str
136+
) -> Generator[None]:
134137
"""Starts the toolbox server as a subprocess."""
135-
print("Downloading toolbox binary from gcs bucket...")
136-
source_blob_name = get_toolbox_binary_url(toolbox_version)
137-
download_blob("genai-toolbox", source_blob_name, "toolbox")
138-
print("Toolbox binary downloaded successfully.")
138+
# Get a temp dir for toolbox data
139+
tmp_path = tmp_path_factory.mktemp("toolbox_data")
140+
toolbox_binary_path = str(tmp_path) + "/toolbox"
141+
142+
# Get toolbox binary
143+
if toolbox_version == "dev":
144+
print("Compiling the current dev toolbox version...")
145+
subprocess.Popen(["go", "get", "./..."])
146+
subprocess.Popen(["go", "build", "-o", toolbox_binary_path])
147+
# Wait for compilation
148+
time.sleep(5)
149+
print("Toolbox binary compiled successfully.")
150+
else:
151+
print("Downloading toolbox binary from gcs bucket...")
152+
source_blob_name = get_toolbox_binary_url(toolbox_version)
153+
download_blob("genai-toolbox", source_blob_name, toolbox_binary_path)
154+
print("Toolbox binary downloaded successfully.")
155+
156+
# Run toolbox binary
139157
try:
140158
print("Opening toolbox server process...")
141159
# Make toolbox executable
142-
os.chmod("toolbox", 0o700)
160+
os.chmod(toolbox_binary_path, 0o700)
143161
# Run toolbox binary
144162
toolbox_server = subprocess.Popen(
145-
["./toolbox", "--tools_file", tools_file_path]
163+
[toolbox_binary_path, "--tools_file", tools_file_path]
146164
)
147-
148165
# Wait for server to start
149166
# Retry logic with a timeout
150167
for _ in range(5): # retries

0 commit comments

Comments
 (0)