fix(test): replace fixed sleeps with polling in context_bleed test to fix ordering flake

This commit is contained in:
2026-03-02 10:45:30 -05:00
parent 57efca4f9b
commit e7879f45a6

View File

@@ -14,7 +14,12 @@ def test_gemini_cli_context_bleed_prevention(live_gui: Any) -> None:
""" """
client = ApiHookClient("http://127.0.0.1:8999") client = ApiHookClient("http://127.0.0.1:8999")
client.click("btn_reset") client.click("btn_reset")
time.sleep(1.5) _start = time.time()
while time.time() - _start < 8.0:
s = client.get_session()
if not s or not s.get('session', {}).get('entries'):
break
time.sleep(0.2)
client.set_value("auto_add_history", True) client.set_value("auto_add_history", True)
# Create a specialized mock for context bleed # Create a specialized mock for context bleed
bleed_mock = os.path.abspath("tests/mock_context_bleed.py") bleed_mock = os.path.abspath("tests/mock_context_bleed.py")
@@ -31,7 +36,12 @@ print(json.dumps({"type": "result", "stats": {"total_tokens": 10}}), flush=True)
client.set_value("ai_input", "Test context bleed") client.set_value("ai_input", "Test context bleed")
client.click("btn_gen_send") client.click("btn_gen_send")
# Wait for completion # Wait for completion
time.sleep(3) _start = time.time()
while time.time() - _start < 15.0:
s = client.get_session()
if any(e.get('role') == 'AI' for e in s.get('session', {}).get('entries', [])):
break
time.sleep(0.3)
session = client.get_session() session = client.get_session()
entries = session.get("session", {}).get("entries", []) entries = session.get("session", {}).get("entries", [])
# Verify: We expect exactly one AI entry, and it must NOT contain the echoed user message # Verify: We expect exactly one AI entry, and it must NOT contain the echoed user message