Skip to content

Commit a9edb2d

Browse files
committed
Snapshot extension validation messages instead of matching substrings
1 parent c4cfebd commit a9edb2d

1 file changed

Lines changed: 36 additions & 15 deletions

File tree

‎tests/client/test_extension.py‎

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,32 @@ def test_claim_accepts_modern_protocol_versions() -> None:
8888
assert claim.protocol_versions == versions
8989

9090

91-
@pytest.mark.parametrize("result_type", ["complete", "input_required"])
92-
def test_claim_rejects_core_result_type_vocabulary(result_type: str) -> None:
91+
def test_claim_rejects_core_result_type_vocabulary() -> None:
9392
"""SDK-defined: "complete" and "input_required" are core protocol vocabulary —
9493
a claim cannot re-key the shapes the session itself routes on."""
95-
with pytest.raises(ValueError, match="core protocol vocabulary"):
96-
ResultClaim(result_type=result_type, model=_TaskResult, resolve=_resolve)
94+
messages: dict[str, str] = {}
95+
for result_type in ("complete", "input_required"):
96+
with pytest.raises(ValueError) as exc_info:
97+
ResultClaim(result_type=result_type, model=_TaskResult, resolve=_resolve)
98+
messages[result_type] = str(exc_info.value)
99+
100+
assert messages == snapshot(
101+
{
102+
"complete": "resultType 'complete' is core protocol vocabulary",
103+
"input_required": "resultType 'input_required' is core protocol vocabulary",
104+
}
105+
)
97106

98107

99108
@pytest.mark.parametrize("model", [_ClaimedCallToolResult, _ClaimedInputRequiredResult])
100109
def test_claim_rejects_model_subclassing_core_result_types(model: type[Result]) -> None:
101110
"""SDK-defined: a claim model subclassing `CallToolResult` or `InputRequiredResult`
102111
would satisfy the session's isinstance branches and bypass claim routing."""
103-
with pytest.raises(ValueError, match="must not subclass core result types"):
112+
with pytest.raises(ValueError) as exc_info:
104113
_claim(model=model)
105114

115+
assert str(exc_info.value) == snapshot("claim models must not subclass core result types")
116+
106117

107118
def test_claim_rejects_model_without_result_type_field() -> None:
108119
"""SDK-defined: the claim model must declare the discriminating `result_type`
@@ -140,19 +151,29 @@ def test_claim_rejects_empty_protocol_versions() -> None:
140151
assert str(exc_info.value) == snapshot("empty protocol_versions could never activate; use None for all")
141152

142153

143-
@pytest.mark.parametrize(
144-
"versions",
145-
[
154+
def test_claim_rejects_non_modern_protocol_versions() -> None:
155+
"""SDK-defined: claimed shapes cannot be delivered on a legacy wire, so a
156+
non-None version set must be a subset of the modern protocol revisions."""
157+
messages: list[str] = []
158+
for versions in (
146159
frozenset({"2025-11-25"}),
147160
frozenset({"2026-07-28", "2025-11-25"}),
148161
frozenset({"never-a-version"}),
149-
],
150-
)
151-
def test_claim_rejects_non_modern_protocol_versions(versions: frozenset[str]) -> None:
152-
"""SDK-defined: claimed shapes cannot be delivered on a legacy wire, so a
153-
non-None version set must be a subset of the modern protocol revisions."""
154-
with pytest.raises(ValueError, match="not modern protocol revisions"):
155-
_claim(protocol_versions=versions)
162+
):
163+
with pytest.raises(ValueError) as exc_info:
164+
_claim(protocol_versions=versions)
165+
messages.append(str(exc_info.value))
166+
167+
assert messages == snapshot(
168+
[
169+
"protocol_versions ['2025-11-25'] are not modern protocol revisions; claimed shapes "
170+
"cannot be delivered on a legacy wire (None means every modern version)",
171+
"protocol_versions ['2025-11-25'] are not modern protocol revisions; claimed shapes "
172+
"cannot be delivered on a legacy wire (None means every modern version)",
173+
"protocol_versions ['never-a-version'] are not modern protocol revisions; claimed shapes "
174+
"cannot be delivered on a legacy wire (None means every modern version)",
175+
]
176+
)
156177

157178

158179
def test_result_claim_is_frozen() -> None:

0 commit comments

Comments
 (0)