feat: 手术视频消耗、待确认与持久化改造

- 新增 Alembic 初始迁移、领域明细模型及归档持久化与重试链路\n- 拆分视频会话注册表、分类处理、推理时间窗聚合与流处理\n- 消耗日志:TSV/Markdown 含 top2/top3;item_id 优先产品编码;待确认记「待确认」行,语音确认后落正式行并更新汇总\n- 待确认时内存/DB 明细为占位行,确认后替换;拒绝时移除占位\n- 分类 probs 先 detach/cpu 再转 NumPy,修复 MPS/CUDA 上推理被静默跳过\n- 补充集成测试、归档与设备张量等单测

Made-with: Cursor
This commit is contained in:
Kevin
2026-04-23 20:42:21 +08:00
parent 69980d8073
commit 3d7bd70355
55 changed files with 4544 additions and 2050 deletions

View File

@@ -1,11 +1,9 @@
"""Shared test fixtures (SQLite memory DB, AsyncSessionLocal monkeypatch)."""
"""Shared test fixtures (SQLite memory DB session factory)."""
from __future__ import annotations
import asyncio
from collections.abc import AsyncGenerator, Generator
from collections.abc import AsyncGenerator
import pytest
import pytest_asyncio
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
@@ -15,7 +13,7 @@ from app.db.base import Base
@pytest_asyncio.fixture
async def sqlite_session_factory() -> AsyncGenerator[async_sessionmaker[AsyncSession], None]:
"""In-memory SQLite + create_all; yields async_sessionmaker."""
"""In-memory SQLite + create_all; yields async_sessionmaker suitable for injection."""
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
@@ -28,47 +26,3 @@ async def sqlite_session_factory() -> AsyncGenerator[async_sessionmaker[AsyncSes
)
yield factory
await engine.dispose()
@pytest.fixture
def patched_async_session_local(
monkeypatch: pytest.MonkeyPatch,
) -> Generator[async_sessionmaker[AsyncSession], None, None]:
"""
Replace AsyncSessionLocal in modules that open DB sessions, for sync tests
(e.g. TestClient) that use asyncio.run internally.
"""
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
async def _init() -> None:
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
asyncio.run(_init())
factory = async_sessionmaker(
engine,
class_=AsyncSession,
expire_on_commit=False,
autoflush=False,
autobegin=False,
)
monkeypatch.setattr(
"app.services.video.session_manager.AsyncSessionLocal",
factory,
)
monkeypatch.setattr(
"app.services.surgery_pipeline.AsyncSessionLocal",
factory,
)
monkeypatch.setattr(
"app.services.voice_resolution.AsyncSessionLocal",
factory,
)
yield factory
async def _dispose() -> None:
await engine.dispose()
asyncio.run(_dispose())