Skip to content

Commit a7622cf

Browse files
authored
Merge pull request #1200 from transformerlab/fix/plugins-empty-list
Stop plugin gallery errors in remote mode
2 parents 9d26a5d + fcbb612 commit a7622cf

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,16 @@ Our Alembic setup lives under `api/alembic`. Use the API Conda/uv environment be
258258

259259
To roll back the most recent migration while iterating, run `alembic downgrade -1`.
260260

261+
### Running API Tests Locally
262+
263+
To run API tests locally:
264+
265+
```bash
266+
conda activate ~/.transformerlab/envs/transformerlab
267+
cd api
268+
pytest --cov=transformerlab --cov-branch --cov-report=xml -k 'not test_teams'
269+
```
270+
261271
<!-- LICENSE -->
262272

263273
## License

api/test/api/test_plugins.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ def test_plugins_gallery(client):
1414
assert "name" in plugin or "description" in plugin
1515

1616

17+
def test_plugins_gallery_remote_mode(client, monkeypatch):
18+
"""Test that plugins/gallery returns empty list in remote mode (TFL_API_STORAGE_URI is set)"""
19+
# Set TFL_API_STORAGE_URI to enable remote mode
20+
monkeypatch.setenv("TFL_API_STORAGE_URI", "true")
21+
22+
# The endpoint reads env vars at request time, so monkeypatch should work
23+
resp = client.get("/plugins/gallery")
24+
assert resp.status_code == 200
25+
data = resp.json()
26+
assert isinstance(data, list)
27+
assert data == [] # Should return empty list in remote mode
28+
29+
1730
def test_plugins_list(client):
1831
resp = client.get("/plugins/list")
1932
assert resp.status_code == 200
@@ -24,6 +37,19 @@ def test_plugins_list(client):
2437
assert "name" in plugin or "description" in plugin
2538

2639

40+
def test_plugins_list_remote_mode(client, monkeypatch):
41+
"""Test that plugins/list returns empty list in remote mode (TFL_API_STORAGE_URI is set)"""
42+
# Set TFL_API_STORAGE_URI to enable remote mode
43+
monkeypatch.setenv("TFL_API_STORAGE_URI", "true")
44+
45+
# The endpoint reads env vars at request time, so monkeypatch should work
46+
resp = client.get("/plugins/list")
47+
assert resp.status_code == 200
48+
data = resp.json()
49+
assert isinstance(data, list)
50+
assert data == [] # Should return empty list in remote mode
51+
52+
2753
def test_plugins_install(client):
2854
resp = client.get("/plugins/gallery/fastchat_server/install")
2955
assert resp.status_code in (200, 404)

api/transformerlab/routers/plugins.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
async def plugin_gallery():
2525
"""Get list of plugins that we can access"""
2626

27+
# In remote mode (TFL_API_STORAGE_URI is set), plugins are not available
28+
# Return empty list to match sidebar behavior where plugins menu is hidden
29+
if os.getenv("TFL_API_STORAGE_URI"):
30+
return []
31+
2732
local_workspace_gallery_directory = dirs.PLUGIN_PRELOADED_GALLERY
2833
# today the remote gallery is a local file, we will move it remote later
2934
remote_gallery_file = os.path.join(dirs.TFL_SOURCE_CODE_DIR, "transformerlab/galleries/plugin-gallery.json")
@@ -429,6 +434,11 @@ async def run_installer_script(plugin_id: str):
429434
async def list_plugins() -> list[object]:
430435
"""Get list of plugins that are currently installed"""
431436

437+
# In remote mode (TFL_API_STORAGE_URI is set), plugins are not available
438+
# Return empty list to match sidebar behavior where plugins menu is hidden
439+
if os.getenv("TFL_API_STORAGE_URI"):
440+
return []
441+
432442
from lab.dirs import get_plugin_dir
433443

434444
local_workspace_gallery_directory = await get_plugin_dir()

0 commit comments

Comments
 (0)