feat: 配置写死与 baked 模块,Alembic 建表,百度仅 BAIDU_*

- 新增 app/baked/algorithm|pipeline,非部署参数不再走 env;Settings 保留 DB/HTTP/RTSP/海康/百度/MinIO/Demo
- 移除 init_db_schema 与 reload 配置;main 仅 check_database;start*.sh 在 uvicorn 前执行 alembic upgrade head
- 依赖 psycopg[binary] 供 Alembic 同步 URL;alembic/env 注释与预发清单更新
- 撕段门控消费管线、各视频/语音/归档调用改为 baked
- 百度环境变量仅 BAIDU_APP_ID、BAIDU_API_KEY、BAIDU_SECRET_KEY 与 BAIDU_* 超时/ASR;人脸脚本与 baidu_speech 文案同步
- 全量单测与 .env.example 更新;.gitignore 忽略 refs/(本地权重/视频不入库)

Made-with: Cursor
This commit is contained in:
Kevin
2026-04-24 15:33:22 +08:00
parent b651364877
commit 8a4bad99d3
47 changed files with 1333 additions and 648 deletions

View File

@@ -7,12 +7,11 @@ from unittest.mock import MagicMock
import pytest
from app.config import Settings
from app.services.consumable_vision_algorithm import ConsumableVisionAlgorithmService
def test_effective_preserves_non_empty_request() -> None:
svc = ConsumableVisionAlgorithmService(Settings())
svc = ConsumableVisionAlgorithmService()
got = svc.effective_candidate_consumables([" 纱布 ", "缝线", "纱布"])
assert got == ["纱布", "缝线"]
@@ -22,8 +21,7 @@ def test_effective_empty_uses_model_when_yaml_has_no_names(
) -> None:
yml = tmp_path / "empty.yaml"
yml.write_text("names: {}\nlabel_id: {}\n", encoding="utf-8")
s = Settings(consumable_classifier_labels_yaml_path=str(yml))
svc = ConsumableVisionAlgorithmService(s)
svc = ConsumableVisionAlgorithmService(labels_yaml_path=str(yml))
mock_cls = MagicMock()
mock_cls.names = {0: "ban", 1: "apple"}
monkeypatch.setattr(svc, "_get_cls", lambda: mock_cls)
@@ -36,8 +34,7 @@ def test_effective_empty_prefers_yaml_class_names(tmp_path: Path) -> None:
"names:\n 0: 商品甲\n 1: 商品乙\nlabel_id:\n 0: a\n 1: b\n",
encoding="utf-8",
)
s = Settings(consumable_classifier_labels_yaml_path=str(yml))
svc = ConsumableVisionAlgorithmService(s)
svc = ConsumableVisionAlgorithmService(labels_yaml_path=str(yml))
assert svc.effective_candidate_consumables([]) == ["商品甲", "商品乙"]
@@ -46,8 +43,7 @@ def test_effective_whitespace_only_treated_as_empty(
) -> None:
yml = tmp_path / "empty.yaml"
yml.write_text("names: {}\nlabel_id: {}\n", encoding="utf-8")
s = Settings(consumable_classifier_labels_yaml_path=str(yml))
svc = ConsumableVisionAlgorithmService(s)
svc = ConsumableVisionAlgorithmService(labels_yaml_path=str(yml))
mock_cls = MagicMock()
mock_cls.names = {0: "x"}
monkeypatch.setattr(svc, "_get_cls", lambda: mock_cls)
@@ -60,8 +56,7 @@ def test_build_name_mapping_from_label_id(tmp_path: Path) -> None:
"names:\n 0: 商品A\nlabel_id:\n 0: y1/y2\n",
encoding="utf-8",
)
s = Settings(consumable_classifier_labels_yaml_path=str(yml))
svc = ConsumableVisionAlgorithmService(s)
svc = ConsumableVisionAlgorithmService(labels_yaml_path=str(yml))
m = svc.build_name_mapping(["商品A"])
assert m["商品A"] == "y1/y2"
@@ -74,7 +69,6 @@ def test_build_name_mapping_uses_name_when_no_id_in_yaml(
"names:\n 0: 仅表内有的\nlabel_id: {}\n",
encoding="utf-8",
)
s = Settings(consumable_classifier_labels_yaml_path=str(yml))
svc = ConsumableVisionAlgorithmService(s)
svc = ConsumableVisionAlgorithmService(labels_yaml_path=str(yml))
m = svc.build_name_mapping(["仅表内有的"])
assert m["仅表内有的"] == "仅表内有的"