Files
ewoooc/tests/test_run_scheduler_embed_consistency.py
OoO bdb74b1354
All checks were successful
CD Pipeline / deploy (push) Successful in 55s
告警 BGE embedding 一致性異常
2026-05-13 09:34:03 +08:00

75 lines
2.1 KiB
Python

import importlib
def _load_run_scheduler(monkeypatch):
monkeypatch.setenv("MOMO_ALLOW_INSECURE_CONFIG_FOR_TESTS", "true")
monkeypatch.setenv("USE_POSTGRESQL", "false")
return importlib.import_module("run_scheduler")
def test_embed_consistency_mismatch_notifies_event_router(monkeypatch):
run_scheduler = _load_run_scheduler(monkeypatch)
import services.rag_service as rag_service
monkeypatch.setattr(
rag_service,
"verify_embedding_consistency",
lambda: {
"ok": False,
"reachable": ["gcp_a", "gcp_b", "fallback_111"],
"max_diff": 0.125,
"signature": "abc123",
},
)
notifications = []
def fake_notify(task_name, error, **kwargs):
notifications.append((task_name, str(error), kwargs))
monkeypatch.setattr(run_scheduler, "_notify_scheduler_failure", fake_notify)
run_scheduler.run_embed_consistency_check()
assert notifications == [
(
"run_embed_consistency_check",
"BGE-M3 embedding consistency mismatch "
"reachable=['gcp_a', 'gcp_b', 'fallback_111'] "
"max_diff=1.25e-01 signature=abc123",
{
"source": "Scheduler.RAG",
"event_type": "embed_consistency_mismatch",
"title": "BGE-M3 一致性異常",
"dedup_ttl_sec": 86400,
},
)
]
def test_embed_consistency_ok_does_not_notify(monkeypatch):
run_scheduler = _load_run_scheduler(monkeypatch)
import services.rag_service as rag_service
monkeypatch.setattr(
rag_service,
"verify_embedding_consistency",
lambda: {
"ok": True,
"reachable": ["gcp_a", "gcp_b", "fallback_111"],
"max_diff": 0.0,
"signature": "abc123",
},
)
notifications = []
monkeypatch.setattr(
run_scheduler,
"_notify_scheduler_failure",
lambda *args, **kwargs: notifications.append((args, kwargs)),
)
run_scheduler.run_embed_consistency_check()
assert notifications == []