Python 88.3%
TypeScript 7.6%
Shell 4.1%
1"""Thinking smoke tests: extended thinking on Haiku 4.5 (blocks, signature, streaming deltas, incompatibilities),2adaptive rejection on Haiku, and context-editing response field. ≈$0.002 per run.3"""4from __future__ import annotations56import json78import pytest910THINK = {"type": "enabled", "budget_tokens": 1024}11Q = [{"role": "user", "content": "What is 2+2? Reply with the number."}]121314def test_extended_thinking_block_and_signature(anthropic, models):15 st, body, _ = anthropic("POST", "/v1/messages", {"model": models["anthropic"], "max_tokens": 1200, "thinking": THINK, "messages": Q},16 est_cost_usd=0.0003, note="test_thinking enabled")17 assert st == 200, body18 kinds = [b["type"] for b in body["content"]]19 assert kinds[0] == "thinking" and "text" in kinds20 tb = body["content"][0]21 assert isinstance(tb["signature"], str) and len(tb["signature"]) > 2022 assert body["usage"]["output_tokens_details"]["thinking_tokens"] > 0232425def test_extended_thinking_streaming_deltas(anthropic, models):26 st, lines, _ = anthropic("POST", "/v1/messages", {"model": models["anthropic"], "max_tokens": 1200, "thinking": THINK, "messages": Q, "stream": True},27 stream=True, est_cost_usd=0.0003, note="test_thinking stream")28 assert st == 20029 deltas = []30 for line in lines:31 if line.startswith("data:"):32 d = json.loads(line[5:])33 if d["type"] == "content_block_delta":34 deltas.append(d["delta"]["type"])35 assert "thinking_delta" in deltas and deltas.count("signature_delta") == 136 assert deltas.index("signature_delta") < deltas.index("text_delta")373839@pytest.mark.parametrize("extra,fragment", [40 ({"temperature": 0.5}, "temperature"),41 ({"top_k": 5}, "top_k"),42 ({"thinking": {"type": "enabled", "budget_tokens": 512}}, "1024"),43 ({"thinking": {"type": "enabled", "budget_tokens": 2000}}, "max_tokens"),44 ({"thinking": {"type": "adaptive"}}, "adaptive thinking is not supported"),45])46def test_thinking_incompatibilities(anthropic, models, extra, fragment):47 body = {"model": models["anthropic"], "max_tokens": 1200, "thinking": THINK, "messages": Q}48 body.update(extra)49 st, out, _ = anthropic("POST", "/v1/messages", body, note=f"test_thinking incompatibility {fragment}")50 assert st == 400, out51 assert fragment in out["error"]["message"]525354def test_display_omitted_returns_empty_thinking(anthropic, models):55 st, body, _ = anthropic("POST", "/v1/messages", {"model": models["anthropic"], "max_tokens": 1200, "thinking": {**THINK, "display": "omitted"}, "messages": Q},56 est_cost_usd=0.0003, note="test_thinking display omitted")57 assert st == 200, body58 tb = body["content"][0]59 assert tb["type"] == "thinking" and tb["thinking"] == "" and tb["signature"]606162def test_context_editing_clear_tool_uses(anthropic, models):63 tool = {"name": "lookup", "description": "Looks up a record.", "input_schema": {"type": "object", "properties": {"id": {"type": "string"}}}}64 msgs = [{"role": "user", "content": "Look up r0 r1 r2 then reply OK."}]65 for i in range(3):66 msgs.append({"role": "assistant", "content": [{"type": "tool_use", "id": f"toolu_t{i}", "name": "lookup", "input": {"id": f"r{i}"}}]})67 msgs.append({"role": "user", "content": [{"type": "tool_result", "tool_use_id": f"toolu_t{i}", "content": "record " + "x" * 400}]})68 msgs.append({"role": "user", "content": "Reply with OK. Do not call tools."})69 cm = {"edits": [{"type": "clear_tool_uses_20250919", "trigger": {"type": "input_tokens", "value": 1}, "keep": {"type": "tool_uses", "value": 1}}]}70 st, body, _ = anthropic("POST", "/v1/messages", {"model": models["anthropic"], "max_tokens": 8, "tools": [tool], "messages": msgs, "context_management": cm},71 beta="context-management-2025-06-27", est_cost_usd=0.001, note="test_thinking context editing")72 assert st == 200, body73 edits = body["context_management"]["applied_edits"]74 assert edits and edits[0]["type"] == "clear_tool_uses_20250919" and edits[0]["cleared_tool_uses"] >= 175