Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

test(scripts): restore real websockets module before repro smoke test

Adryan Eka Vandra30e7b7c49855
diff --git a/tests/test_scripts/test_repro_codex_replay_smoke.py b/tests/test_scripts/test_repro_codex_replay_smoke.py
index 745b70c81..d6db64e0e 100644
--- a/tests/test_scripts/test_repro_codex_replay_smoke.py
+++ b/tests/test_scripts/test_repro_codex_replay_smoke.py
@@ -13,6 +13,7 @@ from __future__ import annotations
import asyncio
import contextlib
+import importlib
import io
import socket
import sys
@@ -24,6 +25,30 @@ import pytest
import uvicorn
from fastapi import FastAPI, Request, WebSocket, WebSocketDisconnect
+
[email protected](autouse=True)
+def _restore_real_websockets_module() -> Iterator[None]:
+ """Some earlier tests replace ``sys.modules['websockets']`` with a stub.
+
+ uvicorn's websockets-sansio backend imports ``websockets.server`` at
+ connect time; if a stub is installed the import fails and the mock
+ proxy never starts. Force-reload the real package before this test.
+ """
+ originals = {
+ name: sys.modules.pop(name, None)
+ for name in list(sys.modules)
+ if name == "websockets" or name.startswith("websockets.")
+ }
+ importlib.import_module("websockets")
+ importlib.import_module("websockets.asyncio.server")
+ yield
+ for name in list(sys.modules):
+ if name == "websockets" or name.startswith("websockets."):
+ del sys.modules[name]
+ for name, mod in originals.items():
+ if mod is not None:
+ sys.modules[name] = mod
+
# Make sure `scripts/` is importable when running via pytest from repo root.
ROOT = Path(__file__).resolve().parents[2]
SCRIPTS_DIR = ROOT / "scripts"