fix(codex-link): isolate model transfers and widen local connection capacity
Server CI and Windows package / verify (push) Successful in 2m3s
Server CI and Windows package / windows-package (push) Successful in 6m58s

This commit is contained in:
yilsem committed 2026-10-13 00:35:08 +03:00
1 parent 2718b460ed
commit 369f6c2ca8
16 files changed
+790 -40

No files matched your search

@@ -60,11 +60,18 @@ def zstd(veri):
class Ayirici(unittest.TestCase):
def setUp(self):
self.ozgun = sunucu(duz(200, b'event: response.completed\ndata: {"ok":1}\n\n', "text/event-stream"))
self.kopru = sunucu(duz(200, b'event: response.completed\ndata: {"kopru":1}\n\n', "text/event-stream"))
def worker(h, body):
if h.path.endswith("/prepare-transfer"):
return duz(200, json.dumps({"request": json.loads(body)["request"]}).encode())(h, body)
return duz(200, b'event: response.completed\ndata: {"kopru":1}\n\n', "text/event-stream")(h, body)
self.kopru = sunucu(worker)
self.on = bridge.Sunucu(("127.0.0.1", 0), bridge.H)
threading.Thread(target=self.on.serve_forever, daemon=True).start()
self.eski = (bridge.CHATGPT, bridge.KOPRU, bridge.LOGDIR, dict(bridge.CFG))
self.gecici = tempfile.TemporaryDirectory()
self.transfer_old = bridge.TRANSFER_PATH, dict(bridge.TRANSFERS)
bridge.TRANSFER_PATH = self.gecici.name + "/transfers.json"
bridge.TRANSFERS.clear()
bridge.CHATGPT = f"http://127.0.0.1:{self.ozgun.server_address[1]}"
bridge.KOPRU = f"http://127.0.0.1:{self.kopru.server_address[1]}"
bridge.LOGDIR = self.gecici.name
@@ -77,6 +84,9 @@ class Ayirici(unittest.TestCase):
bridge.CHATGPT, bridge.KOPRU, bridge.LOGDIR, cfg = self.eski
bridge.CFG.clear()
bridge.CFG.update(cfg)
bridge.TRANSFER_PATH, transfers = self.transfer_old
bridge.TRANSFERS.clear()
bridge.TRANSFERS.update(transfers)
self.gecici.cleanup()
def iste(self, yontem, yol, govde=None, baslik=None):
@@ -92,8 +102,8 @@ class Ayirici(unittest.TestCase):
istekler = [{"model": "gpt-6-astra", "input": [{"role": "user", "content": "modeli opus 5 5 yap"}]},
{"model": "gpt-6-luna", "input": [{"role": "user", "content": "."}]},
{"model": "gpt-6-astra", "prompt_cache_key": "s", "input": [{"type": "compaction_trigger"}]},
{"model": "gpt-6-astra", "input": [{"type": "compaction", "encrypted_content": "ASTRABRIDGE-OZET-1:eA=="},
{"type": "reasoning", "id": "rs_chatcmpl-x"}]}]
{"model": "gpt-6-astra", "input": [{"type": "compaction", "encrypted_content": "gAAAA_native"},
{"type": "reasoning", "id": "rs_native"}]}]
for veri in istekler:
ham = json.dumps(veri, ensure_ascii=False).encode("utf-8")
for kodlama, govde in (("zstd", zstd(ham)), ("gzip", gzip.compress(ham)), ("", ham)):
@@ -123,7 +133,7 @@ class Ayirici(unittest.TestCase):
self.assertEqual((basliklar["originator"], basliklar["content-encoding"]), ("Codex Desktop", "zstd"))
bridge.CFG["model_map"] = {"ozel-model": ["rota", "hedef"]}
self.iste("POST", "/backend-api/codex/responses", json.dumps({"model": "ozel-model"}).encode())
self.assertEqual(len(self.kopru.gelen), 3)
self.assertEqual(len([x for x in self.kopru.gelen if x["yol"].endswith("/responses")]), 3)
self.assertEqual(self.ozgun.gelen, [])
def test_a_body_that_cannot_be_read_takes_codex_own_path_untouched(self):
@@ -143,8 +153,8 @@ class Ayirici(unittest.TestCase):
self.assertEqual((durum, liste), (200, b'{"models":[{"slug":"gpt-6-astra"}]}'))
# An added model says so instead of hanging or going to chatgpt.com under another name.
durum, cevap, _ = self.iste("POST", "/backend-api/codex/responses", json.dumps({"model": "ide/Opus-5"}).encode())
self.assertEqual(durum, 503)
self.assertIn("köprüsü şu an çalışmıyor", json.loads(cevap)["error"]["message"])
self.assertEqual(durum, 200)
self.assertIn(b"response.failed", cevap)
self.assertEqual([g["yol"].split("?")[0] for g in self.ozgun.gelen],
["/backend-api/codex/responses", "/backend-api/codex/models"])
# Status still answers in the shape AITURK IDE expects.
@@ -197,7 +207,7 @@ class Ayirici(unittest.TestCase):
def test_status_is_the_bridge_status_plus_the_splitter_fields(self):
self.kopru.cevap = duz(200, b'{"ok": true, "surum": "8", "kod": "abc", "ide_durum": "tamam", "ide_model": 147}')
d = json.loads(self.iste("GET", "/aiturk/codex-baglama/status")[1])
self.assertEqual((d["surum"], d["ide_model"], d["kopru"], d["ayirici"]), ("8", 147, "calisiyor", True))
self.assertEqual((d["surum"], d["ide_model"], d["kopru"], d["ayirici"]), (bridge.SURUM, 147, "calisiyor", True))
def test_a_persistent_connection_is_refused_the_way_it_is_today(self):
durum, _, _ = self.iste("GET", "/backend-api/codex/responses", None, {"Upgrade": "websocket", "Connection": "Upgrade"})