Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)
Python
Fix conversation headers in provider smoke tests (#1912)
Ali Khokhar4df2ba3e191c
diff --git a/e2e/test_code_sessions.py b/e2e/test_code_sessions.pyindex 9c2d7e2d..10d1825b 100644--- a/e2e/test_code_sessions.py+++ b/e2e/test_code_sessions.py@@ -597,14 +597,18 @@ def test_settings_apply_preserves_open_creation_and_picker(page, admin_base_url, tmp_path, code_control):pending = []- page.route("**/admin/api/config/apply", lambda route: pending.append(route))- page.expose_function("applyRequestIntercepted", lambda: bool(pending))++ def capture_apply(route):+ pending.append(route)+ page.evaluate("window.applyRequestIntercepted = true")++ page.route("**/admin/api/config/apply", capture_apply)page.goto(f"{admin_base_url}/admin")expect(page.locator("#messageArea")).to_have_text("")page.locator("#field-PORT").fill("8081")page.get_by_role("button", name="Apply", exact=True).click()expect(page.locator("#messageArea")).to_have_text("Applying…")- page.wait_for_function("window.applyRequestIntercepted()")+ page.wait_for_function("window.applyRequestIntercepted === true")assert len(pending) == 1page.get_by_role("button", name="Code sessions", exact=True).click()page.get_by_role("button", name="New code session", exact=True).click()diff --git a/smoke/lib/e2e.py b/smoke/lib/e2e.pyindex 9b731dc6..92233cb1 100644--- a/smoke/lib/e2e.py+++ b/smoke/lib/e2e.py@@ -32,6 +32,7 @@ from free_claude_code.messaging.voice import VoiceCancellationResultfrom free_claude_code.messaging.workflow import MessagingWorkflowfrom smoke.lib.child_process import run_captured_textfrom smoke.lib.config import ProviderModel, SmokeConfig, auth_headers+from smoke.lib.http import conversation_headersfrom smoke.lib.server import RunningServer, start_serverfrom smoke.lib.skips import fail_missing_env, skip_if_upstream_unavailable_events@@ -88,6 +89,7 @@ class ConversationDriver:self.config = configself.messages: list[dict[str, Any]] = []self.turns: list[ConversationTurn] = []+ self._session_id = str(uuid.uuid4())def ask(self,@@ -120,7 +122,7 @@ class ConversationDriver:*,headers: dict[str, str] | None = None,) -> ConversationTurn:- request_headers = headers or auth_headers()+ request_headers = conversation_headers(headers, session_id=self._session_id)stream_payload = {**payload, "stream": True}with httpx.stream("POST",@@ -148,7 +150,7 @@ class ConversationDriver:) -> dict[str, Any]:response = httpx.post(f"{self.server.base_url}/v1/messages",- headers=auth_headers(),+ headers=conversation_headers(session_id=self._session_id),json=payload,timeout=self.config.timeout_s,)diff --git a/smoke/lib/http.py b/smoke/lib/http.pyindex 7eb1759a..e9e7fd3d 100644--- a/smoke/lib/http.py+++ b/smoke/lib/http.py@@ -1,5 +1,6 @@"""HTTP helpers for live smoke requests."""+import uuidfrom typing import Anyimport httpx@@ -10,6 +11,16 @@ from .config import SmokeConfig, auth_headers, redactedfrom .server import RunningServer+def conversation_headers(+ headers: dict[str, str] | None = None, *, session_id: str | None = None+) -> dict[str, str]:+ """Identify a smoke conversation while preserving explicit caller headers."""+ result = httpx.Headers(auth_headers() if headers is None else headers)+ result.setdefault("user-agent", "fcc-smoke/1.0")+ result.setdefault("x-opencode-session", session_id or str(uuid.uuid4()))+ return dict(result)++def message_payload(text: str,*,@@ -35,7 +46,7 @@ def post_json(*,headers: dict[str, str] | None = None,) -> httpx.Response:- request_headers = headers or auth_headers()+ request_headers = conversation_headers(headers)response = httpx.post(f"{server.base_url}{path}",headers=request_headers,@@ -52,7 +63,7 @@ def collect_message_stream(*,headers: dict[str, str] | None = None,) -> list[SSEEvent]:- request_headers = headers or auth_headers()+ request_headers = conversation_headers(headers)stream_payload = {**payload, "stream": True}with httpx.stream("POST",diff --git a/smoke/prereq/test_provider_prereq_live.py b/smoke/prereq/test_provider_prereq_live.pyindex 4f203f38..0db600ce 100644--- a/smoke/prereq/test_provider_prereq_live.py+++ b/smoke/prereq/test_provider_prereq_live.py@@ -8,9 +8,9 @@ from free_claude_code.core.anthropic.stream_contracts import (text_content,thinking_content,)-from smoke.lib.config import ProviderModel, SmokeConfig, auth_headers+from smoke.lib.config import ProviderModel, SmokeConfigfrom smoke.lib.e2e import ProviderMatrixDriver-from smoke.lib.http import collect_message_stream, message_payload+from smoke.lib.http import collect_message_stream, conversation_headers, message_payloadfrom smoke.lib.server import start_serverfrom smoke.lib.skips import (skip_if_upstream_unavailable_events,@@ -97,7 +97,7 @@ def test_client_disconnect_mid_stream_does_not_crash_server(with httpx.stream("POST",f"{server.base_url}/v1/messages",- headers=auth_headers(),+ headers=conversation_headers(),json=message_payload(smoke_config.prompt, model="fcc-smoke-default"),timeout=smoke_config.timeout_s,) as response:diff --git a/smoke/product/test_provider_product_live.py b/smoke/product/test_provider_product_live.pyindex dc9f9328..20a770d2 100644--- a/smoke/product/test_provider_product_live.py+++ b/smoke/product/test_provider_product_live.py@@ -9,7 +9,7 @@ from free_claude_code.core.anthropic.stream_contracts import (SSEEvent,parse_sse_lines,)-from smoke.lib.config import ProviderModel, SmokeConfig, auth_headers+from smoke.lib.config import ProviderModel, SmokeConfigfrom smoke.lib.e2e import (ConversationDriver,ProviderMatrixDriver,@@ -19,7 +19,7 @@ from smoke.lib.e2e import (echo_tool_schema,tool_use_blocks,)-from smoke.lib.http import collect_message_stream+from smoke.lib.http import collect_message_stream, conversation_headersfrom smoke.lib.skips import (skip_if_upstream_unavailable_events,skip_if_upstream_unavailable_exception,@@ -166,7 +166,7 @@ def test_provider_error_e2e(smoke_config: SmokeConfig) -> None:):response = client.post(f"{server.base_url}/v1/messages",- headers=auth_headers(),+ headers=conversation_headers(),json={"model": "fcc-smoke-default","max_tokens": 32,@@ -605,11 +605,12 @@ def _scenario_reasoning_tool_continuation(def _scenario_disconnect(smoke_config: SmokeConfig, provider_model: ProviderModel) -> None:+ headers = conversation_headers()with _server_for_provider(smoke_config, provider_model, "disconnect") as server:with httpx.stream("POST",f"{server.base_url}/v1/messages",- headers=auth_headers(),+ headers=headers,json={"model": "fcc-smoke-default","max_tokens": 512,@@ -623,7 +624,7 @@ def _scenario_disconnect(health = httpx.get(f"{server.base_url}/health", timeout=5)assert health.status_code == 200followup = ConversationDriver(server, smoke_config).ask(- "Reply with one short sentence."+ "Reply with one short sentence.", headers=headers)_assert_provider_product_stream(followup.events)@@ -646,4 +647,4 @@ def _openai_auth_headers(smoke_config: SmokeConfig) -> dict[str, str]:token = smoke_config.settings.proxy_auth_tokenif token:headers["authorization"] = f"Bearer {token}"- return headers+ return conversation_headers(headers)diff --git a/tests/contracts/test_smoke_child_process.py b/tests/contracts/test_smoke_child_process.pyindex eedf9af8..4aeb0efb 100644--- a/tests/contracts/test_smoke_child_process.py+++ b/tests/contracts/test_smoke_child_process.py@@ -1,7 +1,11 @@import subprocess+from contextlib import nullcontextfrom pathlib import Pathfrom unittest.mock import MagicMock+import httpx+import pytest+from free_claude_code.config.settings import Settingsfrom smoke.lib import child_processfrom smoke.lib import e2e as smoke_e2e@@ -12,10 +16,11 @@ from smoke.lib.child_process import (cmd_python_c,run_captured_text,)-from smoke.lib.config import SmokeConfig+from smoke.lib.config import ProviderModel, SmokeConfigfrom smoke.lib.e2e import ConversationDriverfrom smoke.lib.http import collect_message_streamfrom smoke.lib.server import RunningServer+from smoke.product import test_provider_product_live as provider_smokedef test_fcc_server_command_uses_cli_entrypoint() -> None:@@ -116,6 +121,141 @@ def test_conversation_driver_explicitly_requests_sse(assert turn.events[-1].event == "message_stop"+def test_smoke_conversation_identity_survives_turns_and_tool_results(+ monkeypatch, tmp_path: Path+) -> None:+ captured = []++ def fake_stream(_method, _url, **kwargs):+ captured.append(httpx.Headers(kwargs["headers"]))+ return _FakeStreamResponse()++ monkeypatch.setattr(smoke_e2e.httpx, "stream", fake_stream)+ server, config = _running_server(tmp_path), _smoke_config(tmp_path)+ conversation = ConversationDriver(server, config)+ conversation.ask("First turn")+ conversation.ask("Second turn")+ conversation.stream(+ {+ "messages": [+ {+ "role": "user",+ "content": [+ {+ "type": "tool_result",+ "tool_use_id": "tool-1",+ "content": "done",+ }+ ],+ }+ ]+ }+ )+ ConversationDriver(server, config).ask("Different conversation")++ assert captured[0]["x-opencode-session"]+ assert len({h["x-opencode-session"] for h in captured[:3]}) == 1+ assert captured[3]["x-opencode-session"] != captured[0]["x-opencode-session"]+ assert all(h["user-agent"].startswith("fcc-smoke/") for h in captured)+++ "helper", [smoke_http.collect_message_stream, smoke_http.post_json]+)+def test_standalone_smoke_requests_identify_themselves_without_changing_auth(+ monkeypatch, tmp_path: Path, helper+) -> None:+ captured = []++ def capture(*args, **kwargs):+ captured.append(httpx.Headers(kwargs["headers"]))+ return _FakeStreamResponse()++ monkeypatch.setattr(smoke_http.httpx, "stream", capture)+ monkeypatch.setattr(smoke_http.httpx, "post", capture)+ args: list[object] = [_running_server(tmp_path)]+ if helper is smoke_http.post_json:+ args.append("/v1/messages")+ args += [{"messages": []}, _smoke_config(tmp_path)]+ explicit = {+ "Authorization": "Bearer explicit",+ "X-OpenCode-Session": "caller",+ "User-Agent": "caller/1.0",+ }+ helper(*args)+ helper(*args)+ helper(*args, headers=explicit)+ helper(*args, headers={})++ assert captured[0]["x-opencode-session"] != captured[1]["x-opencode-session"]+ assert captured[0]["user-agent"].startswith("fcc-smoke/")+ assert captured[2] == httpx.Headers(explicit)+ assert "authorization" not in captured[3]+ assert explicit["X-OpenCode-Session"] == "caller"+++def test_provider_responses_smoke_sends_conversation_identity(monkeypatch, tmp_path):+ captured = []++ class ResponsesStream(_FakeStreamResponse):+ def iter_lines(self):+ return iter(+ (+ "event: response.created",+ "data: {}",+ "",+ "event: response.output_text.delta",+ 'data: {"delta":"ok"}',+ "",+ "event: response.completed",+ "data: {}",+ "",+ )+ )++ def capture(*args, **kwargs):+ captured.append(httpx.Headers(kwargs["headers"]))+ return ResponsesStream()++ monkeypatch.setattr(+ provider_smoke,+ "_server_for_provider",+ lambda *args: nullcontext(_running_server(tmp_path)),+ )+ monkeypatch.setattr(provider_smoke.httpx, "stream", capture)+ model = ProviderModel("opencode_go", "opencode_go/minimax-m2.7", "test")+ for _ in range(2):+ provider_smoke.test_provider_codex_responses_text_e2e(+ _smoke_config(tmp_path), model+ )+ assert captured[0]["x-opencode-session"] != captured[1]["x-opencode-session"]+ assert all(h["user-agent"].startswith("fcc-smoke/") for h in captured)+++def test_disconnect_smoke_reuses_identity_for_followup(monkeypatch, tmp_path):+ captured = []++ def capture(*args, **kwargs):+ captured.append(httpx.Headers(kwargs["headers"]))+ return _FakeStreamResponse()++ monkeypatch.setattr(+ provider_smoke,+ "_server_for_provider",+ lambda *args: nullcontext(_running_server(tmp_path)),+ )+ monkeypatch.setattr(provider_smoke.httpx, "stream", capture)+ monkeypatch.setattr(+ provider_smoke.httpx, "get", lambda *args, **kwargs: httpx.Response(200)+ )+ model = ProviderModel("opencode_go", "opencode_go/minimax-m2.7", "test")+ provider_smoke._scenario_disconnect(_smoke_config(tmp_path), model)++ assert len(captured) == 2+ assert captured[0]["x-opencode-session"] == captured[1]["x-opencode-session"]+ assert all(h["user-agent"].startswith("fcc-smoke/") for h in captured)++def test_run_captured_text_uses_utf8_replacement(monkeypatch, tmp_path: Path) -> None:calls: dict[str, object] = {}