test: close two always-green holes in the dimension tests
The cache-key test only asserted a hit, so a key degraded to a constant would still pass it. Adding a namespace control group that must miss proves the key still distinguishes inputs; verified by degrading build_cache_key to a constant and watching the case go red. The allow_nan=False branch had no test at all. A ChatRequest built with a nan meta value (bypassing the entry validation, i.e. a future entry point that forgets to validate) must drop the row and not raise; verified red by removing allow_nan=False. Also restore the read-only file permissions in a finally block, so a failing assertion does not get masked by a PermissionError from tmp_path cleanup; rename the warnings fixture to captured_warnings so it stops shadowing the stdlib module; and drop a downstream business term from a fixture value (zero-business-assumption rule).
This commit is contained in:
@@ -232,13 +232,23 @@ class TestCallerDimensions:
|
||||
assert recorder.rows == []
|
||||
|
||||
async def test_meta_does_not_enter_cache_key(self):
|
||||
"""仅 meta 不同必须仍命中缓存(F1): 进 key 会让存量缓存全量冷启动且不报错。"""
|
||||
client = _client(cache=InMemoryCache(), cache_namespace="proj", cache_ttl_s=3600)
|
||||
"""仅 meta 不同必须仍命中缓存(F1): 进 key 会让存量缓存全量冷启动且不报错。
|
||||
|
||||
带对照组: 只断言"命中"的话,缓存 key 退化成常量(忽略一切输入)时本用例
|
||||
照样绿——那是恒真断言。故再改一个**确实进 key** 的维度(namespace)断言
|
||||
miss,证明 key 仍在区分输入,"meta 不进 key"才是被测出来的结论。
|
||||
"""
|
||||
cache = InMemoryCache() # 两个 client 共用一份存储,否则对照组的 miss 是白来的
|
||||
client = _client(cache=cache, cache_namespace="proj", cache_ttl_s=3600)
|
||||
async with client:
|
||||
first = await client.chat(self._MSG, meta={"batch": "b-1"})
|
||||
second = await client.chat(self._MSG, meta={"batch": "b-2"})
|
||||
assert first.cache_hit is False and second.cache_hit is True
|
||||
|
||||
other_ns = _client(cache=cache, cache_namespace="other", cache_ttl_s=3600)
|
||||
async with other_ns:
|
||||
assert (await other_ns.chat(self._MSG, meta={"batch": "b-1"})).cache_hit is False
|
||||
|
||||
|
||||
class TestModelFingerprint:
|
||||
"""配置级采样参数须进缓存身份,否则改 temperature 后仍读旧缓存(决策 C)。"""
|
||||
|
||||
Reference in New Issue
Block a user