test: guard reasoning-free telemetry through real client paths
This commit is contained in:
@@ -533,3 +533,70 @@ class TestEmbeddingSettings:
|
||||
s = EmbeddingSettings.from_env("EMBED", env=self._ENV)
|
||||
client = EmbeddingClient.from_settings(s)
|
||||
assert isinstance(client, EmbeddingClient)
|
||||
|
||||
|
||||
class TestReasonlessTelemetryContract:
|
||||
"""从真实客户端到落库,误配推理配置也不能产生推理档。"""
|
||||
|
||||
@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, config, backend, tmp_path
|
||||
):
|
||||
import sqlite3
|
||||
|
||||
from polygateway.telemetry.sqlite import SQLiteRecorder
|
||||
|
||||
path = tmp_path / "embed.sqlite"
|
||||
recorder = (
|
||||
_MemoryRecorder() if backend == "memory" else SQLiteRecorder(path, auto_migrate=True)
|
||||
)
|
||||
client, _ = _embed_client(
|
||||
[_src(**config)], [TransientError("retry"), "ok"], telemetry=recorder
|
||||
)
|
||||
try:
|
||||
await client.embed(["text"], session_id="run", parent_call_id="embed")
|
||||
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("exhausted", [False, True])
|
||||
async def test_failed_attempts_still_have_null_effort(self, exhausted):
|
||||
from polygateway.errors import AllSourcesExhausted
|
||||
|
||||
script = (
|
||||
[TransientError("retry")] * 3 if exhausted else [RequestRejectedError("bad request")]
|
||||
)
|
||||
recorder = _MemoryRecorder()
|
||||
client, _ = _embed_client([_src(enable_thinking=True)], script, telemetry=recorder)
|
||||
with pytest.raises(AllSourcesExhausted if exhausted else RequestRejectedError):
|
||||
await client.embed(["text"])
|
||||
assert len(recorder.rows) == len(script)
|
||||
assert all(r["error"] and r["reasoning_effort"] is None for r in recorder.rows)
|
||||
|
||||
async def test_embedding_wire_ignores_reasoning_configuration(self):
|
||||
seen = []
|
||||
|
||||
def handler(request):
|
||||
seen.append(json.loads(request.content))
|
||||
return httpx.Response(200, json=_ok_body([[1.0]], usage={"prompt_tokens": 1}))
|
||||
|
||||
transport = _transport_with(handler)
|
||||
try:
|
||||
await transport.embed(
|
||||
texts=["text"],
|
||||
source=_src(enable_thinking=True, reasoning_effort="high"),
|
||||
call_id="wire",
|
||||
)
|
||||
assert seen == [{"model": "embed-1", "input": ["text"]}]
|
||||
finally:
|
||||
await transport.aclose()
|
||||
|
||||
Reference in New Issue
Block a user