1
- import { renderHook , waitFor } from "@testing-library/react" ;
2
- import { act } from "react" ;
1
+ import { act , renderHook , waitFor } from "@testing-library/react" ;
3
2
import { expect } from "vitest" ;
4
3
import { useMessageStreamByEvents } from "../useMessageStreamByEvents" ;
5
4
import { useStream } from "../useStream" ;
6
5
import { test } from "./test_extended" ;
7
6
8
7
test ( "should process empty events array" , async ( ) => {
9
8
const { result } = renderHook ( ( ) =>
10
- useMessageStreamByEvents ( { emittedEvents : [ ] } ) ,
9
+ useMessageStreamByEvents ( { sessionStream : [ ] } ) ,
11
10
) ;
12
11
expect ( result . current . isThinking ) . toBe ( false ) ;
13
12
expect ( result . current . messages ) . toEqual ( [ ] ) ;
@@ -16,22 +15,23 @@ test("should process empty events array", async () => {
16
15
test ( "should set isThinking if event is status" , async ( ) => {
17
16
const { result } = renderHook ( ( ) =>
18
17
useMessageStreamByEvents ( {
19
- emittedEvents : [
18
+ sessionStream : [
20
19
{
21
20
id : "63678573-3ac5-45fe-b7b5-1cee2a8a0759" ,
22
- source : "ai_agent" ,
23
- type : "status" ,
24
- correlation_id : "sess1" ,
21
+ event : "status" ,
25
22
data : {
23
+ id : "63678573-3ac5-45fe-b7b5-1cee2a8a0759" ,
24
+ source : "ai_agent" ,
26
25
type : "status" ,
27
- acknowledged_offset : 0 ,
28
- status : "processing" ,
29
- data : { } ,
26
+ correlation_id : "sess1" ,
27
+ data : {
28
+ type : "status" ,
29
+ acknowledged_offset : 0 ,
30
+ status : "processing" ,
31
+ data : { } ,
32
+ } ,
33
+ metadata : null ,
30
34
} ,
31
- metadata : null ,
32
- offset : 0 ,
33
- deleted : false ,
34
- created_at : "2021-08-26T14:00:00.000" ,
35
35
} ,
36
36
] ,
37
37
} ) ,
@@ -44,15 +44,17 @@ test("should set isThinking if event is status", async () => {
44
44
test ( "should handle a new chunk" , async ( ) => {
45
45
const { result } = renderHook ( ( ) =>
46
46
useMessageStreamByEvents ( {
47
- emittedEvents : [
47
+ sessionStream : [
48
48
{
49
- id : "a1b2c3d4e5" ,
50
- correlation_id : "sess1" ,
51
- event_id : "event1" ,
52
- seq : 0 ,
53
- patches : [ { op : "add" , path : "/-" , value : "The" } ] ,
54
- metadata : { agent_id : "foo" , agent_name : "test" } ,
55
- timestamp : 1740583796.8028002 ,
49
+ event : "chunk" ,
50
+ data : {
51
+ correlation_id : "sess1" ,
52
+ event_id : "event1" ,
53
+ seq : 0 ,
54
+ patches : [ { op : "add" , path : "/-" , value : "The" } ] ,
55
+ metadata : { agent_id : "foo" , agent_name : "test" } ,
56
+ timestamp : 1740583796.8028002 ,
57
+ } ,
56
58
} ,
57
59
] ,
58
60
} ) ,
@@ -75,7 +77,7 @@ test("should handle full run", async () => {
75
77
} ) ;
76
78
77
79
const { result } = renderHook ( ( ) =>
78
- useMessageStreamByEvents ( { emittedEvents : useStreamResult . current . events } ) ,
80
+ useMessageStreamByEvents ( { sessionStream : useStreamResult . current . events } ) ,
79
81
) ;
80
82
81
83
expect ( result . current . isThinking ) . toBe ( false ) ;
@@ -101,22 +103,23 @@ test("should handle full run", async () => {
101
103
test ( "should handle persisted events" , async ( ) => {
102
104
const { result } = renderHook ( ( ) =>
103
105
useMessageStreamByEvents ( {
104
- emittedEvents : [
106
+ sessionStream : [
105
107
{
106
108
id : "63678573-3ac5-45fe-b7b5-1cee2a8a0759" ,
107
- source : "ai_agent" ,
108
- type : "status" ,
109
- correlation_id : "sess1" ,
109
+ event : "status" ,
110
110
data : {
111
+ id : "63678573-3ac5-45fe-b7b5-1cee2a8a0759" ,
112
+ source : "ai_agent" ,
111
113
type : "status" ,
112
- acknowledged_offset : 0 ,
113
- status : "processing" ,
114
- data : { } ,
114
+ correlation_id : "sess1" ,
115
+ data : {
116
+ type : "status" ,
117
+ acknowledged_offset : 0 ,
118
+ status : "processing" ,
119
+ data : { } ,
120
+ } ,
121
+ metadata : null ,
115
122
} ,
116
- metadata : null ,
117
- offset : 0 ,
118
- deleted : false ,
119
- created_at : "2021-08-26T14:00:00.000" ,
120
123
} ,
121
124
] ,
122
125
} ) ,
0 commit comments