From d1b3563183f238dc26d39798051be6ea8ae05ba3 Mon Sep 17 00:00:00 2001 From: iomgaa Date: Sat, 5 Sep 2026 04:27:39 -0400 Subject: [PATCH] test: golden the key and fingerprint literals for a declared tier The absent-tier side has had goldens since issue #4; the side that actually carries a tier had none, so swapping str() for repr() in the cache key changed the literal without turning the suite red. Pin both literals. Note the fingerprint's json.dumps emits the same bytes for an Effort member and its .value, so that pair is indistinguishable by any test -- the golden pins the literal itself instead. --- tests/unit/test_cache.py | 23 +++++++++++++++++++++++ tests/unit/test_client.py | 14 ++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/tests/unit/test_cache.py b/tests/unit/test_cache.py index 6f4ea19..9b079ba 100644 --- a/tests/unit/test_cache.py +++ b/tests/unit/test_cache.py @@ -155,6 +155,29 @@ class TestKeyFormula: ) == ("pgw:cache:c54544e8672f4c91373b4a72716a88497445b440b89445aa5379b356b228f58b") + def test_declared_tier_key_is_a_golden(self): + """配了档位那一侧同样要有 golden: 字面量变了就是所有该档缓存冷启动。 + + 存量(不表态)那侧的 golden 由 `test_absent_tier_keeps_legacy_key` 守着, + 而"档位怎么写进 key"此前没有任何字面量断言——变异实测把 `str(...)` 换成 + `repr(...)`,全套件依然全绿(2026-09-05 独立验证查出)。 + """ + assert build_cache_key( + "qwen-max", + [{"role": "user", "content": "hi"}], + "proj", + None, + reasoning_effort=Effort.LOW, + ) == ("pgw:cache:21d7be93729635b27d4ee54e0e7e7310554bb04faf08919f8ce83794ac33f575") + assert build_cache_key( + "qwen-max", + [{"role": "user", "content": "hi"}], + "proj", + "s1", + reasoning_effort=Effort.NONE, + ) == ("pgw:cache:44f4f1ce1ee39e5003a27f4f21a531554cb54d1c66e936d11008d4ff06ddc5e6") + + class _Terminal: def __init__(self, response): self.response = response diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index 27b95be..95b8cbe 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -516,6 +516,20 @@ class TestModelFingerprint: assert build_model_fingerprint([_source(extra_body={"temperature": 0})]) == expected + def test_declared_tier_fingerprint_is_a_golden(self): + """配了档位那一侧的指纹字面量也要钉死: 它变了就是该源整段缓存冷启动。 + + 存量(不表态)那侧由 `test_absent_tier_fingerprint_is_byte_identical_to_before` + 守着;本条守的是"档位怎么摘要进 mark"。字面量硬编码,不在测试里重算—— + 重算等于把实现抄一遍,实现改了两边一起变,断言就白写了。 + """ + from polygateway.client import build_model_fingerprint + + assert build_model_fingerprint([_source(reasoning_effort=Effort.LOW)]) == ( + "qwen-max|76f2b3e419e1a727f7f31b6144da0b40d62a00ca93c91ce5901b4ebd48c0b8c0" + ) + + class TestFactories: def test_from_env_assembles(self): client = GatewayClient.from_env("LLM", env=_ENV)