bridge.py is now a small splitter with no features: a request for one of Codex's own models goes to chatgpt.com byte for byte, a request for an added model goes to kopru.py, which runs as its own process. Codex's own models no longer pass through the feature code at all, and restarting or losing the bridge process does not touch them. Measured with real Codex on spare ports: own model answers; forced compaction on the own model completes (twice) while the bridge process is restarted; added model answers; no own-model request reaches the bridge process. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
"""Codex compresses request bodies with zstd; the bridge must be able to read them."""
|
|
import ast
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
tree = ast.parse(Path(__file__).with_name("kopru.py").read_text(encoding="utf-8"))
|
|
wanted = {"_zstd_decompress", "_zstd_ready", "decompress"}
|
|
env = {}
|
|
exec(compile(ast.Module(body=[n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name in wanted],
|
|
type_ignores=[]), "bridge.py", "exec"), env)
|
|
|
|
|
|
class Zstd(unittest.TestCase):
|
|
def test_self_check_matches_reality(self):
|
|
try:
|
|
try:
|
|
from compression import zstd as z
|
|
packed = z.compress(b"govde" * 50)
|
|
except ImportError:
|
|
import zstandard
|
|
packed = zstandard.ZstdCompressor().compress(b"govde" * 50)
|
|
except ImportError:
|
|
self.assertFalse(env["_zstd_ready"]()) # no zstd here: the bridge must say so
|
|
return
|
|
self.assertTrue(env["_zstd_ready"]())
|
|
self.assertEqual(env["decompress"](packed, "zstd"), b"govde" * 50)
|
|
|
|
def test_other_encodings(self):
|
|
import gzip
|
|
self.assertEqual(env["decompress"](gzip.compress(b"x"), "gzip"), b"x")
|
|
self.assertEqual(env["decompress"](b"duz", None), b"duz")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|