1+ import { describe , expect , test } from "vitest" ;
2+ import type { DriverTestConfig } from "../mod" ;
3+ import { setupDriverTest } from "../utils" ;
4+
5+ export function runActorInlineClientTests ( driverTestConfig : DriverTestConfig ) {
6+ describe ( "Actor Inline Client Tests" , ( ) => {
7+ describe ( "Stateless Client Calls" , ( ) => {
8+ test ( "should make stateless calls to other actors" , async ( c ) => {
9+ const { client } = await setupDriverTest ( c , driverTestConfig ) ;
10+
11+ // Create the inline client actor
12+ const inlineClientHandle = client . inlineClientActor . getOrCreate ( [ "inline-client-test" ] ) ;
13+
14+ // Test calling counter.increment via inline client
15+ const result = await inlineClientHandle . callCounterIncrement ( 5 ) ;
16+ expect ( result ) . toBe ( 5 ) ;
17+
18+ // Verify the counter state was actually updated
19+ const counterState = await inlineClientHandle . getCounterState ( ) ;
20+ expect ( counterState ) . toBe ( 5 ) ;
21+
22+ // Check that messages were logged
23+ const messages = await inlineClientHandle . getMessages ( ) ;
24+ expect ( messages ) . toHaveLength ( 2 ) ;
25+ expect ( messages [ 0 ] ) . toContain ( "Called counter.increment(5), result: 5" ) ;
26+ expect ( messages [ 1 ] ) . toContain ( "Got counter state: 5" ) ;
27+ } ) ;
28+
29+ test ( "should handle multiple stateless calls" , async ( c ) => {
30+ const { client } = await setupDriverTest ( c , driverTestConfig ) ;
31+
32+ // Create the inline client actor
33+ const inlineClientHandle = client . inlineClientActor . getOrCreate ( [ "inline-client-multi" ] ) ;
34+
35+ // Clear any existing messages
36+ await inlineClientHandle . clearMessages ( ) ;
37+
38+ // Make multiple calls
39+ const result1 = await inlineClientHandle . callCounterIncrement ( 3 ) ;
40+ const result2 = await inlineClientHandle . callCounterIncrement ( 7 ) ;
41+ const finalState = await inlineClientHandle . getCounterState ( ) ;
42+
43+ expect ( result1 ) . toBe ( 3 ) ;
44+ expect ( result2 ) . toBe ( 10 ) ; // 3 + 7
45+ expect ( finalState ) . toBe ( 10 ) ;
46+
47+ // Check messages
48+ const messages = await inlineClientHandle . getMessages ( ) ;
49+ expect ( messages ) . toHaveLength ( 3 ) ;
50+ expect ( messages [ 0 ] ) . toContain ( "Called counter.increment(3), result: 3" ) ;
51+ expect ( messages [ 1 ] ) . toContain ( "Called counter.increment(7), result: 10" ) ;
52+ expect ( messages [ 2 ] ) . toContain ( "Got counter state: 10" ) ;
53+ } ) ;
54+ } ) ;
55+
56+ describe ( "Stateful Client Calls" , ( ) => {
57+ test ( "should connect to other actors and receive events" , async ( c ) => {
58+ const { client } = await setupDriverTest ( c , driverTestConfig ) ;
59+
60+ // Create the inline client actor
61+ const inlineClientHandle = client . inlineClientActor . getOrCreate ( [ "inline-client-stateful" ] ) ;
62+
63+ // Clear any existing messages
64+ await inlineClientHandle . clearMessages ( ) ;
65+
66+ // Test stateful connection with events
67+ const result = await inlineClientHandle . connectToCounterAndIncrement ( 4 ) ;
68+
69+ expect ( result . result1 ) . toBe ( 4 ) ;
70+ expect ( result . result2 ) . toBe ( 12 ) ; // 4 + 8
71+ expect ( result . events ) . toEqual ( [ 4 , 12 ] ) ; // Should have received both events
72+
73+ // Check that message was logged
74+ const messages = await inlineClientHandle . getMessages ( ) ;
75+ expect ( messages ) . toHaveLength ( 1 ) ;
76+ expect ( messages [ 0 ] ) . toContain ( "Connected to counter, incremented by 4 and 8" ) ;
77+ expect ( messages [ 0 ] ) . toContain ( "results: 4, 12" ) ;
78+ expect ( messages [ 0 ] ) . toContain ( "events: [4,12]" ) ;
79+ } ) ;
80+
81+ test ( "should handle stateful connection independently" , async ( c ) => {
82+ const { client } = await setupDriverTest ( c , driverTestConfig ) ;
83+
84+ // Create the inline client actor
85+ const inlineClientHandle = client . inlineClientActor . getOrCreate ( [ "inline-client-independent" ] ) ;
86+
87+ // Clear any existing messages
88+ await inlineClientHandle . clearMessages ( ) ;
89+
90+ // Test with different increment values
91+ const result = await inlineClientHandle . connectToCounterAndIncrement ( 2 ) ;
92+
93+ expect ( result . result1 ) . toBe ( 2 ) ;
94+ expect ( result . result2 ) . toBe ( 6 ) ; // 2 + 4
95+ expect ( result . events ) . toEqual ( [ 2 , 6 ] ) ;
96+
97+ // Verify the state is independent from previous tests
98+ const messages = await inlineClientHandle . getMessages ( ) ;
99+ expect ( messages ) . toHaveLength ( 1 ) ;
100+ expect ( messages [ 0 ] ) . toContain ( "Connected to counter, incremented by 2 and 4" ) ;
101+ } ) ;
102+ } ) ;
103+
104+ describe ( "Mixed Client Usage" , ( ) => {
105+ test ( "should handle both stateless and stateful calls" , async ( c ) => {
106+ const { client } = await setupDriverTest ( c , driverTestConfig ) ;
107+
108+ // Create the inline client actor
109+ const inlineClientHandle = client . inlineClientActor . getOrCreate ( [ "inline-client-mixed" ] ) ;
110+
111+ // Clear any existing messages
112+ await inlineClientHandle . clearMessages ( ) ;
113+
114+ // Start with stateless calls
115+ await inlineClientHandle . callCounterIncrement ( 1 ) ;
116+ const statelessResult = await inlineClientHandle . getCounterState ( ) ;
117+ expect ( statelessResult ) . toBe ( 1 ) ;
118+
119+ // Then do stateful call
120+ const statefulResult = await inlineClientHandle . connectToCounterAndIncrement ( 3 ) ;
121+ expect ( statefulResult . result1 ) . toBe ( 3 ) ;
122+ expect ( statefulResult . result2 ) . toBe ( 9 ) ; // 3 + 6
123+
124+ // Check all messages were logged
125+ const messages = await inlineClientHandle . getMessages ( ) ;
126+ expect ( messages ) . toHaveLength ( 3 ) ;
127+ expect ( messages [ 0 ] ) . toContain ( "Called counter.increment(1), result: 1" ) ;
128+ expect ( messages [ 1 ] ) . toContain ( "Got counter state: 1" ) ;
129+ expect ( messages [ 2 ] ) . toContain ( "Connected to counter, incremented by 3 and 6" ) ;
130+ } ) ;
131+ } ) ;
132+ } ) ;
133+ }
0 commit comments