fix(admin): repair model reload rebinding
This commit is contained in:
parent
399cd7ab19
commit
b104abeae6
3 changed files with 59 additions and 1 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -80,3 +80,7 @@ docs/ui-ux/review-shots/
|
|||
|
||||
# Python build metadata (never commit generated egg-info)
|
||||
*.egg-info/
|
||||
|
||||
# Local WebUI runtime data and credentials
|
||||
.webui_password
|
||||
attachments/
|
||||
|
|
|
|||
|
|
@ -14571,7 +14571,6 @@ def handle_post(handler, parsed) -> bool:
|
|||
import api.routes as _routes
|
||||
_routes.get_session = _models.get_session
|
||||
_routes.Session = _models.Session
|
||||
_routes.compact = _models.compact
|
||||
return j(handler, {"status": "ok", "reloaded": "api.models"})
|
||||
|
||||
if parsed.path == "/api/sessions/cleanup":
|
||||
|
|
|
|||
55
tests/test_admin_reload.py
Normal file
55
tests/test_admin_reload.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import json
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
class FakeHandler:
|
||||
def __init__(self):
|
||||
self.status = None
|
||||
self.sent_headers = []
|
||||
self.body = bytearray()
|
||||
self.wfile = self
|
||||
self.rfile = io.BytesIO(b"{}")
|
||||
self.headers = {"Content-Length": "2"}
|
||||
self.client_address = ("127.0.0.1", 0)
|
||||
self.request = None
|
||||
|
||||
def send_response(self, status):
|
||||
self.status = status
|
||||
|
||||
def send_header(self, name, value):
|
||||
self.sent_headers.append((name, value))
|
||||
|
||||
def end_headers(self):
|
||||
pass
|
||||
|
||||
def write(self, data):
|
||||
self.body.extend(data)
|
||||
|
||||
def json_body(self):
|
||||
return json.loads(bytes(self.body).decode("utf-8"))
|
||||
|
||||
|
||||
def test_admin_reload_returns_ok_without_binding_missing_compact(monkeypatch):
|
||||
import importlib
|
||||
from api import routes
|
||||
|
||||
monkeypatch.setattr(routes, "_check_csrf", lambda handler: True)
|
||||
monkeypatch.setattr(
|
||||
routes,
|
||||
"_guard_request_session_visibility",
|
||||
lambda handler, parsed, body=None, method="POST": True,
|
||||
)
|
||||
# Exercise the endpoint bindings without mutating the real api.models module.
|
||||
monkeypatch.setattr(importlib, "reload", lambda module: module)
|
||||
|
||||
handler = FakeHandler()
|
||||
handled = routes.handle_post(handler, urlparse("/api/admin/reload"))
|
||||
|
||||
assert handled is None
|
||||
assert handler.status == 200
|
||||
assert handler.json_body() == {"status": "ok", "reloaded": "api.models"}
|
||||
assert routes.get_session.__module__ == "api.models"
|
||||
assert routes.Session.__module__ == "api.models"
|
||||
Loading…
Reference in a new issue