mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-19 19:25:27 -04:00
fix(cookbook): harden remote serve host handling (#4345)
This commit is contained in:
@@ -68,6 +68,14 @@ def test_valid_remote_builds_port_flag():
|
||||
assert port_flag == "-p 2222 "
|
||||
|
||||
|
||||
def test_integer_ssh_port_in_stored_task_normalizes_without_crashing():
|
||||
host, port_flag = codex_routes._ssh_prefix_for_task(
|
||||
{"remoteHost": "user@box", "sshPort": 2222}
|
||||
)
|
||||
assert host == "user@box"
|
||||
assert port_flag == "-p 2222 "
|
||||
|
||||
|
||||
def test_default_ssh_port_omits_flag():
|
||||
host, port_flag = codex_routes._ssh_prefix_for_task(
|
||||
{"remoteHost": "box", "sshPort": "22"}
|
||||
|
||||
@@ -38,11 +38,14 @@ def test_diffusers_is_not_blocked_on_windows_dependencies_panel():
|
||||
assert "new Set(['diffusers'" not in text
|
||||
|
||||
|
||||
def test_diffusers_is_available_on_windows_serve_panel():
|
||||
def test_diffusers_is_available_only_on_local_windows_serve_panel():
|
||||
text = SERVE_SRC.read_text(encoding="utf-8")
|
||||
|
||||
assert "? ['llamacpp', 'diffusers']" in text
|
||||
assert "? [['llamacpp','llama.cpp'],['diffusers','Diffusers']]" in text
|
||||
assert "function _remoteWindowsDiffusersUnsupported(target)" in text
|
||||
assert "return !!(target?.host && target?.platform === 'windows');" in text
|
||||
assert "if (_remoteWindowsDiffusersUnsupported(target)) return [['llamacpp','llama.cpp']];" in text
|
||||
assert "return [['llamacpp','llama.cpp'],['diffusers','Diffusers']];" in text
|
||||
assert "Diffusers serving is not supported on remote Windows servers yet." in text
|
||||
|
||||
|
||||
def test_windows_diffusers_uses_python_not_python3():
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
from starlette.requests import Request
|
||||
|
||||
import routes.cookbook_routes as cookbook_routes
|
||||
from routes.cookbook_helpers import ServeRequest
|
||||
|
||||
|
||||
def _route_endpoint(path: str, method: str):
|
||||
router = cookbook_routes.setup_cookbook_routes()
|
||||
for route in router.routes:
|
||||
if route.path == path and method in route.methods:
|
||||
return route.endpoint
|
||||
raise AssertionError(f"{method} {path} route not found")
|
||||
|
||||
|
||||
def _admin_request() -> Request:
|
||||
request = Request(
|
||||
{
|
||||
"type": "http",
|
||||
"method": "POST",
|
||||
"path": "/api/model/serve",
|
||||
"headers": [],
|
||||
"state": {},
|
||||
}
|
||||
)
|
||||
request.state.current_user = "admin"
|
||||
return request
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_remote_windows_diffusers_is_rejected_before_runner_launch(monkeypatch):
|
||||
monkeypatch.setattr(cookbook_routes, "require_admin", lambda request: None)
|
||||
calls = []
|
||||
|
||||
async def fail_if_shell_runs(*args, **kwargs):
|
||||
calls.append((args, kwargs))
|
||||
raise AssertionError("remote Windows Diffusers should fail before shell launch")
|
||||
|
||||
monkeypatch.setattr(asyncio, "create_subprocess_shell", fail_if_shell_runs)
|
||||
|
||||
endpoint = _route_endpoint("/api/model/serve", "POST")
|
||||
req = ServeRequest(
|
||||
repo_id="diffusers/example",
|
||||
cmd="python scripts/diffusion_server.py --model diffusers/example --port 8100",
|
||||
remote_host="winbox",
|
||||
platform="windows",
|
||||
)
|
||||
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
await endpoint(_admin_request(), req)
|
||||
|
||||
assert exc.value.status_code == 400
|
||||
assert "Remote Windows Diffusers" in str(exc.value.detail)
|
||||
assert calls == []
|
||||
@@ -36,10 +36,22 @@ def test_cookbook_submodules_resolve_visible_profile_selection():
|
||||
assert "_serverByVal(_envState.remoteServerKey || remoteHost)" in HWFIT
|
||||
assert "hk: _currentServerValue()" in HWFIT
|
||||
assert "sel.value = _currentServerValue();" in HWFIT
|
||||
assert "_serverByVal?.(_ssEl.value)" in SERVE
|
||||
assert "_serverByVal?.(select.value)" in SERVE
|
||||
assert "_serverByVal?.(val)" in SERVE
|
||||
assert "_serverByVal?.(_es.remoteServerKey || _es.remoteHost || '')" in SERVE
|
||||
assert "_serverByVal?.(_envState.remoteServerKey || _probeHost)" in SERVE
|
||||
assert "port: host ? (server?.port || _getPort(host) || '') : ''" in SERVE
|
||||
|
||||
|
||||
def test_serve_launch_preflights_use_selected_target_and_port():
|
||||
launch_target = "const launchTarget = _selectedServeTarget(panel);"
|
||||
assert launch_target in SERVE
|
||||
assert "const _hostStr = launchTarget.host || '';" in SERVE
|
||||
assert "const _probeHost = (launchTarget.host || '').trim();" in SERVE
|
||||
assert "if (launchTarget.port) _probeParams.set('ssh_port', launchTarget.port);" in SERVE
|
||||
assert "const _portHost = (launchTarget.host || '').trim();" in SERVE
|
||||
assert "StrictHostKeyChecking=no ${_sshPrefix(launchTarget.port)}${_portHost}" in SERVE
|
||||
assert "let serveHost = launchTarget.host || '';" in SERVE
|
||||
assert SERVE.index(launch_target) < SERVE.index("const _runningMod = await import('./cookbookRunning.js');")
|
||||
|
||||
|
||||
def test_running_tab_resolves_profile_key_not_first_host():
|
||||
|
||||
Reference in New Issue
Block a user