Files
aiturk-hermes-ide/apps/desktop/assets/codex-bridge/test_yarim.py
T
yilsemandClaude Opus 5.5 acf88f8314 feat(codex-link): bridge 7 - external models work like subscription models
Measured with the unmodified Codex binary on 10 Oct 2026:
- real context windows per model (NanoGPT list, local table, combo = its
  smallest member, capped at the summarizer's window) so Codex compacts by
  itself when switching to a smaller model; an overflow guard trims
  oversized old parts and reports what still does not fit
- classic tools instead of code mode for external models: GLM 0/3 -> 3/3,
  Qwen 0/3 -> 2/3 on simple tool tasks, Claude/cx/Gemini unchanged
- phase (commentary / final_answer) on external assistant messages
- an answer cut by the client is carried to the next turn once
- images stay for vision-capable targets
- summary brake stops tight loops, not frequent compaction
- permanent gateway errors and tool-less targets fail at once with a
  readable message instead of five reconnects
- a lone "." (used to apply a model change in voice) is answered locally
- the bridge listens within seconds; the IDE waits 45 s for it

Release: AITURK IDE 1.0.0-beta.26.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 22:04:58 +03:00

75 lines
3.5 KiB
Python

"""An answer cut by the client is carried to the next turn of the same conversation, once."""
import json
import unittest
import yarim
def delta(text):
return (b"event: response.output_text.delta\ndata: "
+ json.dumps({"type": "response.output_text.delta", "delta": text}).encode() + b"\n\n")
def user(text):
return {"type": "message", "role": "user", "content": [{"type": "input_text", "text": text}]}
class Yarim(unittest.TestCase):
def setUp(self):
yarim._KAYIT.clear()
def cut(self, key="sohbet-1", text="1. bir sayidir ve ilk siradadir. 2. iki sayidir ve cifttir. 3. uc"):
izle = yarim.Izleyici(key, "ide/x")
raw = delta(text[:20]) + delta(text[20:])
for i in range(0, len(raw), 17):
izle.feed(raw[i:i + 17])
return izle
def test_cut_answer_reaches_the_next_user_message_once(self):
izle = self.cut()
self.assertTrue(yarim.kaydet(izle, simdi=100))
req = {"input": [user("liste yaz"), user("kaldigin yerden devam et")]}
self.assertGreater(yarim.uygula(req, "sohbet-1", simdi=200), 0)
note = req["input"][-1]["content"][-1]["text"]
self.assertIn("3. uc", note)
self.assertIn('model="ide/x"', note)
self.assertEqual(req["input"][-1]["content"][0]["text"], "kaldigin yerden devam et") # the user's words stay first
again = {"input": [user("bir daha")]}
self.assertEqual(yarim.uygula(again, "sohbet-1", simdi=300), 0) # used once
self.assertEqual(yarim.uygula({"input": [user("x")]}, "baska-sohbet", simdi=300), 0)
def test_finished_short_or_keyless_answers_are_not_kept(self):
done = self.cut()
done.feed(b'event: response.completed\ndata: {"type": "response.completed"}\n\n')
self.assertFalse(yarim.kaydet(done))
self.assertFalse(yarim.kaydet(self.cut(text="kisa")))
self.assertFalse(yarim.kaydet(self.cut(key="")))
def test_note_waits_for_a_real_user_turn_and_skips_text_codex_already_saved(self):
yarim.kaydet(self.cut(), simdi=100)
tool_turn = {"input": [user("x"), {"type": "function_call_output", "call_id": "c", "output": "ok"}]}
self.assertEqual(yarim.uygula(tool_turn, "sohbet-1", simdi=110), 0)
compaction = {"input": [user("x"), {"type": "compaction_trigger"}]}
self.assertEqual(yarim.uygula(compaction, "sohbet-1", simdi=110), 0)
self.assertIn("sohbet-1", yarim._KAYIT) # still waiting
saved = {"input": [{"type": "message", "role": "assistant", "content": [
{"type": "output_text", "text": "1. bir sayidir ve ilk siradadir. 2. iki sayidir ve cifttir. 3. uc"}]}, user("devam")]}
self.assertEqual(yarim.uygula(saved, "sohbet-1", simdi=120), 0)
self.assertNotIn("sohbet-1", yarim._KAYIT)
yarim.kaydet(self.cut(), simdi=100)
self.assertEqual(yarim.uygula({"input": [user("gec")]}, "sohbet-1", simdi=100 + yarim.OMUR_SN + 1), 0) # expired
def test_long_text_keeps_head_and_tail(self):
yarim.kaydet(self.cut(text="BAS" + "x" * 40000 + "SON"), simdi=1)
req = {"input": [user("devam")]}
yarim.uygula(req, "sohbet-1", simdi=2)
note = req["input"][-1]["content"][-1]["text"]
self.assertLess(len(note), yarim.EN_COK_KARAKTER + 600)
self.assertIn("BAS", note)
self.assertTrue(note.rstrip().endswith("</yarim_cevap>"))
self.assertIn("SON\n</yarim_cevap>", note)
if __name__ == "__main__":
unittest.main()