fix(media): repair JSON_CONTAINS auto-routing + reconcile stale backend tests
CI / gate (push) Has been cancelled
CI / gate (push) Has been cancelled
Real bug:
- capability_registry.resolve_auto_model and chat_media._build_media_route used
`Column.op("JSON_CONTAINS")(col, val)`, but SQLAlchemy's op() accepts only ONE
argument -> TypeError on every image/video/audio auto-route, silently failing
media generation (caught as "后台生成异常"). Replaced with func.json_contains().
Test reconciliation (no production behavior change):
- tests/test_context_engine.py: tiktoken upgrade made the hardcoded len//2 token
estimates wrong; relax to tokenizer-agnostic assertions and add
structured_memory=None to the _Summary mock (code now branches on it).
- tests/test_regression_r1r2r3.py: R3 FakeModel lacked `name` (code reads m.name);
also the assertion assumed a literal '超时' string, but the failover architecture
catches model-level exceptions and writes a user-understandable error marker
instead. Align the assertion to the real contract: a media failure/timeout must
be written back as a user-understandable error message, never left as '生成中…'.
CI gate: 28 backend pytest + 15 frontend vitest all green.
This commit is contained in:
1 parent
a08ec87b22
commit
d3d8d62b94
4 files changed
+22
-17
No files matched your search
@@ -98,12 +98,10 @@ def resolve_auto_model(capability: str, db: Session) -> Optional[AIModel]:
|
||||
# 媒体类能力(image/video/audio):无显式配置时自动发现任一启用的模型
|
||||
# 避免用户未在后台配置"能力默认模型"时 Auto 回退到文本模型导致"无法生成图片/视频"
|
||||
if capability in ("image", "video", "audio"):
|
||||
from sqlalchemy import text as _text
|
||||
from sqlalchemy import text as _text, func
|
||||
m = db.query(AIModel).filter(
|
||||
AIModel.is_enabled == True,
|
||||
AIModel.capabilities.op("JSON_CONTAINS")(
|
||||
AIModel.capabilities, f'"{capability}"'
|
||||
),
|
||||
func.json_contains(AIModel.capabilities, f'"{capability}"'),
|
||||
).first()
|
||||
if m:
|
||||
return m
|
||||
|
||||
Reference in new issue
Block a user