|
25 | 25 | from typing import Generator
|
26 | 26 |
|
27 | 27 | import google
|
| 28 | +import pytest |
28 | 29 | import pytest_asyncio
|
29 | 30 | from google.auth import compute_engine
|
30 | 31 | from google.cloud import secretmanager, storage
|
@@ -130,21 +131,37 @@ def auth_token2(project_id: str) -> str:
|
130 | 131 |
|
131 | 132 |
|
132 | 133 | @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]: |
134 | 137 | """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 |
139 | 157 | try:
|
140 | 158 | print("Opening toolbox server process...")
|
141 | 159 | # Make toolbox executable
|
142 |
| - os.chmod("toolbox", 0o700) |
| 160 | + os.chmod(toolbox_binary_path, 0o700) |
143 | 161 | # Run toolbox binary
|
144 | 162 | toolbox_server = subprocess.Popen(
|
145 |
| - ["./toolbox", "--tools_file", tools_file_path] |
| 163 | + [toolbox_binary_path, "--tools_file", tools_file_path] |
146 | 164 | )
|
147 |
| - |
148 | 165 | # Wait for server to start
|
149 | 166 | # Retry logic with a timeout
|
150 | 167 | for _ in range(5): # retries
|
|
0 commit comments