test: guard reasoning-free telemetry through real client paths
This commit is contained in:
@@ -564,3 +564,54 @@ class TestAssembly:
|
||||
client = OcrClient.from_env("OCR", env=dict(self._ENV))
|
||||
await client.aclose()
|
||||
await client.aclose()
|
||||
|
||||
|
||||
class TestReasonlessTelemetryContract:
|
||||
"""text/layout 两个入口分别验证错误行不受源级推理配置污染。"""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"method,action", [("recognize_text", "text"), ("parse_layout", "layout")]
|
||||
)
|
||||
@pytest.mark.parametrize("config", [{"enable_thinking": True}, {"reasoning_effort": "high"}])
|
||||
@pytest.mark.parametrize("backend", ["memory", "sqlite"])
|
||||
async def test_failed_then_successful_attempts_have_null_effort(
|
||||
self, method, action, config, backend, tmp_path
|
||||
):
|
||||
import sqlite3
|
||||
|
||||
from polygateway.telemetry.sqlite import SQLiteRecorder
|
||||
|
||||
path = tmp_path / "ocr.sqlite"
|
||||
recorder = (
|
||||
_MemoryRecorder() if backend == "memory" else SQLiteRecorder(path, auto_migrate=True)
|
||||
)
|
||||
client, _, _ = _client(
|
||||
[_src(**config)], [TransientError("retry"), action], telemetry=recorder
|
||||
)
|
||||
try:
|
||||
await getattr(client, method)(b"image", session_id="run", parent_call_id=method)
|
||||
if backend == "memory":
|
||||
rows = [(r["error"], r["reasoning_effort"]) for r in recorder.rows]
|
||||
else:
|
||||
with sqlite3.connect(path) as db:
|
||||
rows = db.execute("SELECT error, reasoning_effort FROM llm_calls").fetchall()
|
||||
assert len(rows) == 2
|
||||
assert sum(bool(error) for error, _ in rows) == 1
|
||||
assert [tier for _, tier in rows] == [None, None]
|
||||
finally:
|
||||
await client.aclose()
|
||||
if backend == "sqlite":
|
||||
recorder.close()
|
||||
|
||||
@pytest.mark.parametrize("method", ["recognize_text", "parse_layout"])
|
||||
@pytest.mark.parametrize("exhausted", [False, True])
|
||||
async def test_failed_attempts_still_have_null_effort(self, method, exhausted):
|
||||
script = (
|
||||
[TransientError("retry")] * 3 if exhausted else [RequestRejectedError("bad request")]
|
||||
)
|
||||
recorder = _MemoryRecorder()
|
||||
client, _, _ = _client([_src(enable_thinking=True)], script, telemetry=recorder)
|
||||
with pytest.raises(AllSourcesExhausted if exhausted else RequestRejectedError):
|
||||
await getattr(client, method)(b"image")
|
||||
assert len(recorder.rows) == len(script)
|
||||
assert all(r["error"] and r["reasoning_effort"] is None for r in recorder.rows)
|
||||
|
||||
Reference in New Issue
Block a user