Files
aiturk-hermes-ide/apps/desktop/assets/codex-bridge/test_zstd.py
T
yilsemandClaude Opus 5.5 b560950f82 fix(codex-bridge): ship zstd for the agent's Python and refuse to link without it
Codex compresses request bodies with zstd. The agent venv is Python 3.11, which
has no zstd in its standard library, so every Codex request failed on a fresh
install. The matching zstandard build now ships beside the bridge; the status
endpoint reports ok=false when bodies cannot be read, and the IDE then leaves
Codex's config alone. A running bridge from an older build is replaced, and
"Sync now" makes the bridge re-read the IDE session at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRDGW1LiKcDUZYUdKBoWYW
2026-10-09 16:27:55 +03:00

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("bridge.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()