Python
Fix CI: teach provider fakes messages.stream, un-Windows the write-fence probe
Devika Vermafe9cbb00c8ff
diff --git a/tests/test_anthropic_provider.py b/tests/test_anthropic_provider.pyindex 8f5b6065..cfcee3df 100644--- a/tests/test_anthropic_provider.py+++ b/tests/test_anthropic_provider.py@@ -1,9 +1,10 @@"""Native Anthropic provider — message/tool conversion, complete(), stream(). SDK-free:-the fake client mimics the `anthropic` SDK's `messages.create` surface with SimpleNamespace-objects, the same pattern test_providers.py uses for the OpenAI SDK."""+the fake client mimics the `anthropic` SDK's `messages.create` / `messages.stream` surface+with SimpleNamespace objects, the same pattern test_providers.py uses for the OpenAI SDK."""from __future__ import annotations+from contextlib import contextmanagerfrom types import SimpleNamespaceimport pytest@@ -19,8 +20,10 @@ from coworker.providers.anthropic_provider import (class _FakeClient:- """Records the kwargs passed to messages.create and returns a canned response- (or an event iterator when stream=True)."""+ """Records the kwargs passed to messages.create / messages.stream and returns a+ canned response. provider.stream() drives create(stream=True) → event iterator;+ provider.complete() drives the messages.stream(...) context manager and reads+ get_final_message()."""def __init__(self, response=None, events=None):self.kwargs: dict = {}@@ -31,9 +34,14 @@ class _FakeClient:return iter(events or [])return response- self.messages = SimpleNamespace(create=create)+ @contextmanager+ def stream(**kwargs):+ self.kwargs = kwargs+ yield SimpleNamespace(get_final_message=lambda: response)++ self.messages = SimpleNamespace(create=create, stream=stream)# Fable/Mythos route through the beta endpoint (server-side refusal fallback).- self.beta = SimpleNamespace(messages=SimpleNamespace(create=create))+ self.beta = SimpleNamespace(messages=SimpleNamespace(create=create, stream=stream))def _text_response(text="hello", stop_reason="end_turn"):diff --git a/tests/test_mcp_floor.py b/tests/test_mcp_floor.pyindex 07e6728f..81ff2868 100644--- a/tests/test_mcp_floor.py+++ b/tests/test_mcp_floor.py@@ -173,8 +173,12 @@ def test_gate_order_persistent_authority_survives_bypass(tmp_path):def test_gate_order_write_fence_survives_bypass(tmp_path):+ # tmp_path.parent is absolute and out-of-root on every OS; a literal "C:/..." is+ # only absolute on Windows — POSIX reads it as a relative dir named "C:", which+ # _candidate() then resolves INTO the workspace root.+ outside = str(tmp_path.parent / "outside" / "anywhere.txt")d = engine(Mode.BYPASS_APPROVALS, tmp_path).evaluate(- "write_file", {"path": "C:/outside/anywhere.txt", "content": "x"}, None+ "write_file", {"path": outside, "content": "x"}, None)assert not d.allowed # refused, not asked — the fence has no mode switchdiff --git a/tests/test_token_usage.py b/tests/test_token_usage.pyindex 8848a330..663bf7f1 100644--- a/tests/test_token_usage.py+++ b/tests/test_token_usage.py@@ -7,6 +7,7 @@ SDK's response surface, dict events for Bedrock's Converse stream.from __future__ import annotationsimport asyncio+from contextlib import contextmanagerfrom types import SimpleNamespaceimport aisuite as ai@@ -54,8 +55,13 @@ class _FakeAnthropicClient:self.kwargs = kwargsreturn events- self.messages = SimpleNamespace(create=create)- self.beta = SimpleNamespace(messages=SimpleNamespace(create=create))+ @contextmanager+ def stream(**kwargs):+ self.kwargs = kwargs+ yield SimpleNamespace(get_final_message=lambda: events)++ self.messages = SimpleNamespace(create=create, stream=stream)+ self.beta = SimpleNamespace(messages=SimpleNamespace(create=create, stream=stream))def test_anthropic_stream_captures_usage():