chore: snapshot in-progress question-gen work before preflight fixes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""adapters/telemetry.py 单元测试 — SQLiteTelemetryRecorder。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
@@ -9,11 +10,11 @@ import pytest
|
||||
from adapters.telemetry import SQLiteTelemetryRecorder
|
||||
from core.protocols import TelemetryRecorder
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Fixtures
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def db_path(tmp_path):
|
||||
"""返回临时数据库路径。"""
|
||||
@@ -51,6 +52,7 @@ def _make_call_kwargs(*, cache_hit: bool = False, error: str | None = None):
|
||||
# Tests
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_satisfies_protocol(recorder):
|
||||
"""SQLiteTelemetryRecorder 满足 TelemetryRecorder Protocol。"""
|
||||
assert isinstance(recorder, TelemetryRecorder)
|
||||
@@ -86,7 +88,9 @@ async def test_record_with_error(recorder, db_path):
|
||||
|
||||
conn = sqlite3.connect(str(db_path))
|
||||
conn.row_factory = sqlite3.Row
|
||||
row = conn.execute("SELECT error FROM llm_calls WHERE call_id = ?", (kwargs["call_id"],)).fetchone()
|
||||
row = conn.execute(
|
||||
"SELECT error FROM llm_calls WHERE call_id = ?", (kwargs["call_id"],)
|
||||
).fetchone()
|
||||
conn.close()
|
||||
|
||||
assert row["error"] == "RateLimitError: 429"
|
||||
@@ -100,7 +104,9 @@ async def test_record_cache_hit(recorder, db_path):
|
||||
|
||||
conn = sqlite3.connect(str(db_path))
|
||||
conn.row_factory = sqlite3.Row
|
||||
row = conn.execute("SELECT cache_hit FROM llm_calls WHERE call_id = ?", (kwargs["call_id"],)).fetchone()
|
||||
row = conn.execute(
|
||||
"SELECT cache_hit FROM llm_calls WHERE call_id = ?", (kwargs["call_id"],)
|
||||
).fetchone()
|
||||
conn.close()
|
||||
|
||||
assert row["cache_hit"] == 1
|
||||
@@ -130,6 +136,7 @@ async def test_db_error_does_not_propagate(tmp_path):
|
||||
async def test_concurrent_writes_no_lock_error(recorder, db_path):
|
||||
"""16 路并发 record_llm_call 应全部成功,无 database is locked 错误。"""
|
||||
import asyncio
|
||||
|
||||
tasks = []
|
||||
for _ in range(16):
|
||||
kwargs = _make_call_kwargs()
|
||||
|
||||
Reference in New Issue
Block a user