Skip to content

Commit 7d2f5bb

Browse files
committed
test(oci): assert stream termination and full event lifecycle
Strengthen V1 and V2 streaming integration tests to verify streams terminate correctly and produce the expected event sequence: - V1: stream-start → text-generation(s) → stream-end - V2: message-start → content-start → content-delta(s) → content-end → message-end Without these assertions the previous tests would have hung forever on the streaming bug rather than failing with a clear error.
1 parent 2a519a9 commit 7d2f5bb

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

tests/test_oci_client.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_chat(self):
113113
self.assertIn("4", response.text)
114114

115115
def test_chat_stream(self):
116-
"""Test V1 streaming chat."""
116+
"""Test V1 streaming chat terminates and produces correct events."""
117117
events = []
118118
for event in self.client.chat_stream(
119119
model="command-r-08-2024",
@@ -125,6 +125,11 @@ def test_chat_stream(self):
125125
text_events = [e for e in events if hasattr(e, "text") and e.text]
126126
self.assertTrue(len(text_events) > 0)
127127

128+
# Verify stream terminates with correct event lifecycle
129+
event_types = [getattr(e, "event_type", None) for e in events]
130+
self.assertEqual(event_types[0], "stream-start")
131+
self.assertEqual(event_types[-1], "stream-end")
132+
128133

129134
@unittest.skipIf(os.getenv("TEST_OCI") is None, "TEST_OCI not set")
130135
class TestOciClientV2(unittest.TestCase):
@@ -186,7 +191,7 @@ def test_chat_v2(self):
186191
self.assertIsNotNone(response.message)
187192

188193
def test_chat_stream_v2(self):
189-
"""Test streaming chat with v2 client."""
194+
"""Test V2 streaming chat terminates and produces correct event lifecycle."""
190195
events = []
191196
for event in self.client.chat_stream(
192197
model="command-a-03-2025",
@@ -195,11 +200,16 @@ def test_chat_stream_v2(self):
195200
events.append(event)
196201

197202
self.assertTrue(len(events) > 0)
198-
# Verify we received content-delta events with text
199-
content_delta_events = [e for e in events if hasattr(e, "type") and e.type == "content-delta"]
200-
self.assertTrue(len(content_delta_events) > 0)
201203

202-
# Verify we can extract text from events
204+
# Verify full event lifecycle: message-start → content-start → content-delta(s) → content-end → message-end
205+
event_types = [e.type for e in events]
206+
self.assertEqual(event_types[0], "message-start")
207+
self.assertIn("content-start", event_types)
208+
self.assertIn("content-delta", event_types)
209+
self.assertIn("content-end", event_types)
210+
self.assertEqual(event_types[-1], "message-end")
211+
212+
# Verify we can extract text from content-delta events
203213
full_text = ""
204214
for event in events:
205215
if (
@@ -214,7 +224,6 @@ def test_chat_stream_v2(self):
214224
):
215225
full_text += event.delta.message.content.text
216226

217-
# Should have received some text
218227
self.assertTrue(len(full_text) > 0)
219228

220229
@unittest.skipIf(os.getenv("TEST_OCI") is None, "TEST_OCI not set")

0 commit comments

Comments
 (0)