Files
odysseus/tests/test_chat_image_routing.py
T
the_peaceful b5c45326e4 Fix Windows Cookbook background tasks, exit statuses, and empty SSH logs wrapper (#1389)
This commit consolidates all Windows Cookbook background fixes into a single comprehensive commit based on the latest main branch.

Key fixes included:
1. React looksSuccessful Mismatch: Append 'DOWNLOAD_OK' for pip install commands in routes/cookbook_routes.py.
2. Local Windows SSH Wrapper & Log Directory Mismatch: Bypassed ssh wrappers and dynamically selected odysseus-tmux logs for local tasks in static/js/cookbookRunning.js.
3. WSL Bash Filtration: Filtered out the WSL bash stub at C:\Windows\System32\bash.exe in core/platform_compat.py.
4. Drive-Colon Path Normalization: Replaced .as_posix() with git_bash_path() in routes/shell_routes.py and src/bg_jobs.py.
5. GGUF-Only Hardware Fitting: Restructured local Windows recommendations to rank GGUF only in services/hwfit/fit.py.
6. Safe Win32 Process Liveness Probe: Replaced os.kill(pid, 0) with a safe Win32 API probe using GetExitCodeProcess in core/platform_compat.py.
7. Prebuilt llama-cpp-python Wheels: Supply the CPU extra index during compilation failure fallback.
8. Enforce UTF-8 log encoding: Set PYTHONIOENCODING=utf-8 on Windows bootstrap runners.
9. Fix Linux Llama.cpp Build script syntax error in routes/cookbook_helpers.py.
10. Page Reload Status Check: Run sys.executable instead of 'python3' to bypass Microsoft Store execution stubs on local Windows hosts.
11. Llama.cpp serve build bypass: Bypassed cmake compilation checks on local Windows and verified python bindings directly.
12. Serve Command Path Validation: Masked safe GGUF path printf subshells '' inside the serve command validator.
13. CPU Mismatch Diagnostics: Intercepted AVX2-lacking '0xc000001d' (Illegal Instruction) crashes in static/js/cookbook-diagnosis.js and guided users to Ollama.
14. Windows Pytest stability: Fixed stub import leakage in test files.
2026-06-05 14:41:07 +02:00

89 lines
2.6 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_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"))