mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-08-05 02:45:28 +00:00
Some checks failed
CI / Focused test guidance (report-only) (push) Has been cancelled
CI / Python syntax (compileall) (push) Has been cancelled
CI / JS syntax (node --check) (push) Has been cancelled
CI / Python tests (pytest) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Container scan / hadolint (Dockerfile lint) (push) Has been cancelled
Container scan (Trivy) / Trivy (image scan, advisory) (push) Has been cancelled
Container scan (Trivy) / Trivy (image scan + SARIF upload) (push) Has been cancelled
Dependency review / dependency-review (PR gate) (push) Has been cancelled
Dependency review / pip-audit (advisory) (push) Has been cancelled
ci / docker publish / build (amd64) (push) Has been cancelled
ci / docker publish / build (arm64) (push) Has been cancelled
Secret scan / gitleaks (push) Has been cancelled
Workflow security / actionlint (push) Has been cancelled
Workflow security / zizmor (Actions SAST) (push) Has been cancelled
ci / docker publish / merge manifest + tag (push) Has been cancelled
97 lines
2.9 KiB
Python
97 lines
2.9 KiB
Python
import sys
|
|
for mod_name in ["src.endpoint_resolver", "src.database", "core.database"]:
|
|
_mod = sys.modules.get(mod_name)
|
|
if _mod is not None and not getattr(_mod, "__file__", None):
|
|
sys.modules.pop(mod_name, None)
|
|
|
|
import json
|
|
from types import SimpleNamespace
|
|
|
|
from tests.helpers.import_state import clear_fake_endpoint_resolver_modules
|
|
|
|
clear_fake_endpoint_resolver_modules("routes.chat_routes")
|
|
|
|
from routes import chat_routes
|
|
|
|
|
|
class _FakeQuery:
|
|
def __init__(self, rows):
|
|
self.rows = rows
|
|
|
|
def filter(self, *conditions):
|
|
return self
|
|
|
|
def all(self):
|
|
return list(self.rows)
|
|
|
|
|
|
class _FakeDb:
|
|
def __init__(self, rows):
|
|
self.rows = rows
|
|
self.closed = False
|
|
|
|
def query(self, model):
|
|
return _FakeQuery(self.rows)
|
|
|
|
def close(self):
|
|
self.closed = True
|
|
|
|
|
|
def _session(model="qwen3.5:latest", endpoint_url="http://localhost:11434/v1/chat/completions"):
|
|
return SimpleNamespace(model=model, endpoint_url=endpoint_url)
|
|
|
|
|
|
def _endpoint(base_url, model_type="image", models=None):
|
|
cached_models = None if models is None else json.dumps(models)
|
|
return SimpleNamespace(
|
|
base_url=base_url,
|
|
model_type=model_type,
|
|
is_enabled=True,
|
|
cached_models=cached_models,
|
|
)
|
|
|
|
|
|
def test_image_model_prefix_routes_to_image_generation_without_endpoint_lookup(monkeypatch):
|
|
def fail_if_called():
|
|
raise AssertionError("prefixed image models should not need a DB lookup")
|
|
|
|
monkeypatch.setattr(chat_routes, "SessionLocal", fail_if_called)
|
|
|
|
assert chat_routes._is_image_generation_session(_session(model="dall-e-3"))
|
|
|
|
|
|
def test_namespaced_gpt_image_model_routes_to_image_generation_without_endpoint_lookup(monkeypatch):
|
|
def fail_if_called():
|
|
raise AssertionError("provider-prefixed image models should not need a DB lookup")
|
|
|
|
monkeypatch.setattr(chat_routes, "SessionLocal", fail_if_called)
|
|
|
|
assert chat_routes._is_image_generation_session(_session(model="openai/gpt-5-image"))
|
|
|
|
|
|
def test_image_endpoint_does_not_catch_text_model_on_different_path(monkeypatch):
|
|
db = _FakeDb([
|
|
_endpoint("http://localhost:11434/v1/images", models=["sdxl-local"]),
|
|
])
|
|
monkeypatch.setattr(chat_routes, "SessionLocal", lambda: db)
|
|
|
|
assert not chat_routes._is_image_generation_session(_session())
|
|
assert db.closed
|
|
|
|
|
|
def test_image_endpoint_cache_must_contain_selected_model(monkeypatch):
|
|
db = _FakeDb([
|
|
_endpoint("http://localhost:11434/v1", models=["sdxl-local"]),
|
|
])
|
|
monkeypatch.setattr(chat_routes, "SessionLocal", lambda: db)
|
|
|
|
assert not chat_routes._is_image_generation_session(_session(model="qwen3.5:latest"))
|
|
|
|
|
|
def test_matching_image_endpoint_routes_selected_image_model(monkeypatch):
|
|
db = _FakeDb([
|
|
_endpoint("http://localhost:11434/v1", models=["sdxl-local"]),
|
|
])
|
|
monkeypatch.setattr(chat_routes, "SessionLocal", lambda: db)
|
|
|
|
assert chat_routes._is_image_generation_session(_session(model="sdxl-local"))
|