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:
@@ -5,7 +5,9 @@ from __future__ import annotations
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from app.config import Settings
|
||||
import pytest
|
||||
|
||||
from app.baked import pipeline as bp
|
||||
from app.services.voice_file_log import (
|
||||
append_voice_tsv_line,
|
||||
emit_voice_event,
|
||||
@@ -14,38 +16,46 @@ from app.services.voice_file_log import (
|
||||
)
|
||||
|
||||
|
||||
def test_resolved_voice_log_path_replaces_surgery_id() -> None:
|
||||
s = Settings()
|
||||
s.voice_file_log_path = "logs/voice_{surgery_id}.txt"
|
||||
p = resolved_voice_log_path("123456", s)
|
||||
def test_resolved_voice_log_path_replaces_surgery_id(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(bp, "VOICE_FILE_LOG_PATH", "logs/voice_{surgery_id}.txt")
|
||||
p = resolved_voice_log_path("123456")
|
||||
assert p.name == "voice_123456.txt"
|
||||
assert "logs" in str(p)
|
||||
|
||||
|
||||
def test_init_and_append_tsv() -> None:
|
||||
def test_init_and_append_tsv(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
base = Path(d)
|
||||
s = Settings()
|
||||
s.voice_file_log_enabled = True
|
||||
s.voice_file_log_path = str((base / "v_{surgery_id}.txt").resolve())
|
||||
init_voice_log_file("999999", s)
|
||||
p = resolved_voice_log_path("999999", s)
|
||||
monkeypatch.setattr(bp, "VOICE_FILE_LOG_ENABLED", True)
|
||||
monkeypatch.setattr(
|
||||
bp,
|
||||
"VOICE_FILE_LOG_PATH",
|
||||
str((base / "v_{surgery_id}.txt").resolve()),
|
||||
)
|
||||
init_voice_log_file("999999")
|
||||
p = resolved_voice_log_path("999999")
|
||||
assert p.exists()
|
||||
h = p.read_text(encoding="utf-8")
|
||||
assert "来源" in h and "confirmation_id" in h
|
||||
line = "ts\ttest\trecognized\tcid1\t同\t品\tfalse\t\tk.wav\n"
|
||||
append_voice_tsv_line("999999", line, s)
|
||||
append_voice_tsv_line("999999", line)
|
||||
assert p.read_text(encoding="utf-8").endswith(line)
|
||||
|
||||
|
||||
def test_emit_voice_event_writes_when_enabled() -> None:
|
||||
s = Settings()
|
||||
s.voice_file_log_enabled = True
|
||||
def test_emit_voice_event_writes_when_enabled(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(bp, "VOICE_FILE_LOG_ENABLED", True)
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
s.voice_file_log_path = str((Path(d) / "v_{surgery_id}.txt").resolve())
|
||||
init_voice_log_file("111111", s)
|
||||
monkeypatch.setattr(
|
||||
bp,
|
||||
"VOICE_FILE_LOG_PATH",
|
||||
str((Path(d) / "v_{surgery_id}.txt").resolve()),
|
||||
)
|
||||
init_voice_log_file("111111")
|
||||
emit_voice_event(
|
||||
s,
|
||||
surgery_id="111111",
|
||||
source="wav",
|
||||
status="recognized",
|
||||
@@ -55,7 +65,7 @@ def test_emit_voice_event_writes_when_enabled() -> None:
|
||||
rejected=False,
|
||||
audio_object_key="k.wav",
|
||||
)
|
||||
p = resolved_voice_log_path("111111", s)
|
||||
p = resolved_voice_log_path("111111")
|
||||
body = p.read_text(encoding="utf-8")
|
||||
assert "纱布" in body
|
||||
assert "recognized" in body
|
||||
|
||||
Reference in New Issue
Block a user