fix: hide stale and effort-preset models without losing checks
Build and deploy / build-deploy (push) Waiting to run
Build and deploy / build-deploy (push) Waiting to run
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""Каталог OmniRoute: пропавшие ID и effort-пресеты не должны загрязнять витрину."""
|
||||
import sqlite3
|
||||
|
||||
|
||||
def test_sync_hides_stale_and_effort_but_preserves_history(core, omni_server):
|
||||
db = sqlite3.connect(core.db_path)
|
||||
db.execute("INSERT INTO checks (model_id,checked_at,ok) VALUES ('zai/test-model-a','2026-10-26T00:00:00+00:00',1)")
|
||||
db.commit()
|
||||
db.close()
|
||||
omni_server.state["models"] = {"data": [
|
||||
{"id": "agy/test-model-b"},
|
||||
{"id": "agy/test-model-b-high"},
|
||||
{"id": "cx/gpt-5.6-terra"},
|
||||
{"id": "cx/gpt-5.6-terra-low"},
|
||||
{"id": "openrouter/foo/model-high:free"},
|
||||
{"id": "openrouter/foo/model:free"},
|
||||
{"id": "agy/kimi-highway"},
|
||||
{"id": "freellmapi/qwen3.8-max"},
|
||||
]}
|
||||
assert core.client.post("/api/sync").status_code == 200
|
||||
ids = {m["id"] for m in core.client.get("/api/models").json()}
|
||||
assert ids == {"agy/test-model-b", "cx/gpt-5.6-terra", "openrouter/foo/model:free", "agy/kimi-highway", "freellmapi/qwen3.8-max"}
|
||||
assert "zai" not in core.client.get("/api/providers").json()
|
||||
db = sqlite3.connect(core.db_path)
|
||||
assert db.execute("SELECT active FROM models WHERE id='zai/test-model-a'").fetchone()[0] == 0
|
||||
assert db.execute("SELECT COUNT(*) FROM checks WHERE model_id='zai/test-model-a'").fetchone()[0] == 1
|
||||
db.close()
|
||||
omni_server.requests.clear()
|
||||
core.probe.run()
|
||||
requested = {x["body"].get("model") for x in omni_server.requests if x["path"] == "/v1/chat/completions"}
|
||||
assert requested == ids
|
||||
# ID возвращается в каталог — снова активен, история на месте.
|
||||
omni_server.state["models"]["data"].append({"id": "zai/test-model-a"})
|
||||
core.client.post("/api/sync")
|
||||
assert "zai/test-model-a" in {m["id"] for m in core.client.get("/api/models").json()}
|
||||
db = sqlite3.connect(core.db_path)
|
||||
assert db.execute("SELECT active FROM models WHERE id='zai/test-model-a'").fetchone()[0] == 1
|
||||
assert db.execute("SELECT COUNT(*) FROM checks WHERE model_id='zai/test-model-a'").fetchone()[0] == 1
|
||||
db.close()
|
||||
|
||||
|
||||
def test_empty_catalog_does_not_hide_everything(core, omni_server):
|
||||
original = {m["id"] for m in core.client.get("/api/models").json()}
|
||||
omni_server.state["models"] = {"data": []}
|
||||
core.client.post("/api/sync")
|
||||
assert {m["id"] for m in core.client.get("/api/models").json()} == original
|
||||
Reference in New Issue
Block a user