fix: make the sampling invariant test actually enforce the constraint

The test passed overlay and sampling as separate objects while production
aliases them, so an in-place mutation slipped through it. Also syncs the
telemetry schema page and adds the missing postgres round-trip assertion.
This commit is contained in:
2026-07-31 22:01:51 -04:00
parent cce7562d07
commit 15b9b02e96
6 changed files with 57 additions and 8 deletions
+19 -3
View File
@@ -193,7 +193,14 @@ class TestSamplingSnapshotInvariant:
terminal = ScriptedTerminal(["not json at all", '{"answer": 1, "reason": "r"}'])
mw = _mw(strategy=NativeSchemaStrategy(), max_retries=1)
await mw(
ChatRequest(messages=_MSGS, structured=Verdict, sampling=caller_sampling),
# overlay 与 sampling 传**同一个对象**,复现 client.py 的别名关系
# ——否则中间件就地改写 overlay 时不会波及 sampling,这条执法就是空的
ChatRequest(
messages=_MSGS,
structured=Verdict,
overlay=caller_sampling,
sampling=caller_sampling,
),
terminal,
)
assert len(terminal.requests) == 2 # 确实重问过
@@ -205,11 +212,20 @@ class TestSamplingSnapshotInvariant:
assert "response_format" not in seen.sampling
async def test_middleware_does_not_mutate_caller_mapping(self):
"""决策 E 的第二条约束: 中间件只能 replace 派生,不得就地改这两个 dict。"""
"""决策 E 的第二条约束: 中间件只能 replace 派生,不得就地改这两个 dict。
同样传同一对象: 生产中 overlay 与 sampling 是别名,任何对 overlay 的
就地改写都会同步毒化缓存 key 与遥测列。
"""
caller_sampling = {"seed": 7}
terminal = ScriptedTerminal(['{"answer": 1, "reason": "r"}'])
await _mw(strategy=NativeSchemaStrategy())(
ChatRequest(messages=_MSGS, structured=Verdict, sampling=caller_sampling),
ChatRequest(
messages=_MSGS,
structured=Verdict,
overlay=caller_sampling,
sampling=caller_sampling,
),
terminal,
)
assert caller_sampling == {"seed": 7} # 调用方的对象未被污染