fix: harden the observability fields against the verifier findings
This commit is contained in:
@@ -360,6 +360,19 @@ class TestObservabilityFields:
|
||||
result = await _complete(_transport_for(handler), _source())
|
||||
assert result.model_reported == "MiniMax-Text-01-250321"
|
||||
|
||||
async def test_empty_first_model_does_not_block_a_later_real_one(self):
|
||||
"""首帧报空串不得锁死 sink: 守卫按"有效值"判断,否则真实版本会丢。"""
|
||||
|
||||
def handler(request):
|
||||
return _sse_stream(
|
||||
_chunk(content="a", model=""),
|
||||
_chunk(content="b", model="MiniMax-Text-01-250321"),
|
||||
_chunk(usage=_USAGE),
|
||||
)
|
||||
|
||||
result = await _complete(_transport_for(handler), _source())
|
||||
assert result.model_reported == "MiniMax-Text-01-250321"
|
||||
|
||||
@pytest.mark.parametrize("bad", [None, "", " ", 123, {}])
|
||||
async def test_missing_or_malformed_model_is_none(self, bad):
|
||||
def handler(request):
|
||||
|
||||
@@ -77,6 +77,10 @@ class TestCachedInputTier:
|
||||
def test_no_hit_is_billed_in_full(self, cached):
|
||||
assert self._CACHED.cost("m", 1_000_000, 0, cached) == pytest.approx(10.0)
|
||||
|
||||
def test_negative_cached_is_billed_in_full(self):
|
||||
"""负数命中数不得抬高成本: cost() 是公共方法,外部输入须校验后使用(P5)。"""
|
||||
assert self._CACHED.cost("m", 1_000_000, 0, -500_000) == pytest.approx(10.0)
|
||||
|
||||
def test_cached_over_prompt_is_clamped_and_never_negative(self):
|
||||
"""网关口径异常时按输入总数夹取: 全部按缓存价,不得算出负成本。"""
|
||||
clamped = self._CACHED.cost("m", 1_000_000, 0, 5_000_000)
|
||||
|
||||
@@ -202,8 +202,9 @@ class TestSQLiteColumnBackfill:
|
||||
async def test_backfill_failure_keeps_the_recorder_usable(self, tmp_path):
|
||||
"""补列失败只能逐行降级,绝不能把 recorder 整体变成 no-op(设计 D1 纪律)。
|
||||
|
||||
把 llm_calls 建成 view: 表不存在故 CREATE TABLE IF NOT EXISTS 会撞名失败,
|
||||
ALTER 也无从谈起——这是最坏路径。
|
||||
把 llm_calls 建成同名 view: `CREATE TABLE IF NOT EXISTS` 遇 view 静默
|
||||
no-op(不抛),随后的 ALTER 才抛 "Cannot add a column to a view"——正是
|
||||
补列失败这条分支。`_conn` 必须保持非 None,否则整个 recorder 永久失能。
|
||||
"""
|
||||
db = tmp_path / "view.db"
|
||||
conn = sqlite3.connect(db)
|
||||
@@ -213,6 +214,7 @@ class TestSQLiteColumnBackfill:
|
||||
conn.close()
|
||||
|
||||
recorder = SQLiteRecorder(db) # 不得抛
|
||||
assert recorder._conn is not None # 补列失败 ≠ recorder 失能(D1 纪律)
|
||||
await _record_minimal(recorder) # 不得抛
|
||||
recorder.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user