rivetkit 2.0.40 → 2.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/tsup/actor/errors.cjs +2 -2
  2. package/dist/tsup/actor/errors.js +1 -1
  3. package/dist/tsup/chunk-2IJTYN6K.cjs +278 -0
  4. package/dist/tsup/chunk-2IJTYN6K.cjs.map +1 -0
  5. package/dist/tsup/{chunk-SNAUKDDK.cjs → chunk-2XQS746M.cjs} +4 -4
  6. package/dist/tsup/chunk-2XQS746M.cjs.map +1 -0
  7. package/dist/tsup/{chunk-D2HB4PM5.cjs → chunk-3VP5CSHV.cjs} +9 -9
  8. package/dist/tsup/{chunk-D2HB4PM5.cjs.map → chunk-3VP5CSHV.cjs.map} +1 -1
  9. package/dist/tsup/{chunk-J2R742IE.js → chunk-AQFSQMBG.js} +5 -5
  10. package/dist/tsup/{chunk-XCDGPOZT.cjs → chunk-EJVBH5VF.cjs} +3 -3
  11. package/dist/tsup/{chunk-XCDGPOZT.cjs.map → chunk-EJVBH5VF.cjs.map} +1 -1
  12. package/dist/tsup/{chunk-ZUMPCWKF.js → chunk-FJ3KTN4V.js} +15 -5
  13. package/dist/tsup/chunk-FJ3KTN4V.js.map +1 -0
  14. package/dist/tsup/{chunk-6NBNCWEC.cjs → chunk-GD7UXGOE.cjs} +269 -269
  15. package/dist/tsup/chunk-GD7UXGOE.cjs.map +1 -0
  16. package/dist/tsup/{chunk-KVB2SG32.js → chunk-GMAVRZSF.js} +10 -6
  17. package/dist/tsup/chunk-GMAVRZSF.js.map +1 -0
  18. package/dist/tsup/{chunk-HZOBB3KP.cjs → chunk-H4TB4X25.cjs} +20 -10
  19. package/dist/tsup/chunk-H4TB4X25.cjs.map +1 -0
  20. package/dist/tsup/{chunk-J6YRLC6K.js → chunk-JDAD2YFA.js} +19 -9
  21. package/dist/tsup/{chunk-J6YRLC6K.js.map → chunk-JDAD2YFA.js.map} +1 -1
  22. package/dist/tsup/{chunk-4T4UWXHN.js → chunk-KCOVZOPS.js} +5 -5
  23. package/dist/tsup/{chunk-2YHR67M4.js → chunk-LFVF5SCU.js} +4 -4
  24. package/dist/tsup/chunk-LFVF5SCU.js.map +1 -0
  25. package/dist/tsup/{chunk-XCRJ245S.js → chunk-Q6W7RJJP.js} +5 -5
  26. package/dist/tsup/chunk-Q6W7RJJP.js.map +1 -0
  27. package/dist/tsup/{chunk-FB4TVPDQ.cjs → chunk-RUW5CZ5Z.cjs} +49 -49
  28. package/dist/tsup/{chunk-FB4TVPDQ.cjs.map → chunk-RUW5CZ5Z.cjs.map} +1 -1
  29. package/dist/tsup/{chunk-4KNL47JA.cjs → chunk-RZW2DNND.cjs} +85 -81
  30. package/dist/tsup/chunk-RZW2DNND.cjs.map +1 -0
  31. package/dist/tsup/chunk-TCOEBUUE.js +278 -0
  32. package/dist/tsup/chunk-TCOEBUUE.js.map +1 -0
  33. package/dist/tsup/{chunk-B5BMSBR4.cjs → chunk-X35U3YNX.cjs} +110 -100
  34. package/dist/tsup/chunk-X35U3YNX.cjs.map +1 -0
  35. package/dist/tsup/{chunk-7Q7R3QYT.js → chunk-XXGJCOL6.js} +2 -2
  36. package/dist/tsup/client/mod.cjs +6 -6
  37. package/dist/tsup/client/mod.d.cts +2 -2
  38. package/dist/tsup/client/mod.d.ts +2 -2
  39. package/dist/tsup/client/mod.js +5 -5
  40. package/dist/tsup/common/log.cjs +3 -3
  41. package/dist/tsup/common/log.js +2 -2
  42. package/dist/tsup/common/websocket.cjs +4 -4
  43. package/dist/tsup/common/websocket.js +3 -3
  44. package/dist/tsup/{config-OR5ZtHFa.d.ts → config-CLnylLYY.d.ts} +9 -0
  45. package/dist/tsup/{config-cizn-tcF.d.cts → config-CZB2-W8x.d.cts} +9 -0
  46. package/dist/tsup/{driver-BrAG8ioa.d.ts → driver-D0QX9M11.d.ts} +1 -1
  47. package/dist/tsup/driver-helpers/mod.cjs +4 -4
  48. package/dist/tsup/driver-helpers/mod.d.cts +2 -2
  49. package/dist/tsup/driver-helpers/mod.d.ts +2 -2
  50. package/dist/tsup/driver-helpers/mod.js +3 -3
  51. package/dist/tsup/{driver-Bg4evbcN.d.cts → driver-q-zqG7fc.d.cts} +1 -1
  52. package/dist/tsup/driver-test-suite/mod.cjs +187 -448
  53. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  54. package/dist/tsup/driver-test-suite/mod.d.cts +2 -2
  55. package/dist/tsup/driver-test-suite/mod.d.ts +2 -2
  56. package/dist/tsup/driver-test-suite/mod.js +141 -402
  57. package/dist/tsup/driver-test-suite/mod.js.map +1 -1
  58. package/dist/tsup/mod.cjs +8 -8
  59. package/dist/tsup/mod.d.cts +4 -4
  60. package/dist/tsup/mod.d.ts +4 -4
  61. package/dist/tsup/mod.js +7 -7
  62. package/dist/tsup/serve-test-suite/mod.cjs +1499 -0
  63. package/dist/tsup/serve-test-suite/mod.cjs.map +1 -0
  64. package/dist/tsup/serve-test-suite/mod.d.cts +9 -0
  65. package/dist/tsup/serve-test-suite/mod.d.ts +9 -0
  66. package/dist/tsup/serve-test-suite/mod.js +1496 -0
  67. package/dist/tsup/serve-test-suite/mod.js.map +1 -0
  68. package/dist/tsup/test/mod.cjs +8 -8
  69. package/dist/tsup/test/mod.d.cts +1 -1
  70. package/dist/tsup/test/mod.d.ts +1 -1
  71. package/dist/tsup/test/mod.js +7 -7
  72. package/dist/tsup/utils.cjs +3 -3
  73. package/dist/tsup/utils.js +2 -2
  74. package/package.json +14 -4
  75. package/src/actor/errors.ts +4 -4
  76. package/src/common/router.ts +2 -0
  77. package/src/engine-process/mod.ts +8 -1
  78. package/src/registry/config/index.ts +1 -0
  79. package/src/registry/config/serverless.ts +2 -0
  80. package/src/remote-manager-driver/api-endpoints.ts +2 -0
  81. package/src/serve-test-suite/mod.ts +147 -0
  82. package/src/serverless/configure.ts +3 -0
  83. package/dist/tsup/chunk-2YHR67M4.js.map +0 -1
  84. package/dist/tsup/chunk-4KNL47JA.cjs.map +0 -1
  85. package/dist/tsup/chunk-6NBNCWEC.cjs.map +0 -1
  86. package/dist/tsup/chunk-B5BMSBR4.cjs.map +0 -1
  87. package/dist/tsup/chunk-HZOBB3KP.cjs.map +0 -1
  88. package/dist/tsup/chunk-KVB2SG32.js.map +0 -1
  89. package/dist/tsup/chunk-SNAUKDDK.cjs.map +0 -1
  90. package/dist/tsup/chunk-XCRJ245S.js.map +0 -1
  91. package/dist/tsup/chunk-ZUMPCWKF.js.map +0 -1
  92. /package/dist/tsup/{chunk-J2R742IE.js.map → chunk-AQFSQMBG.js.map} +0 -0
  93. /package/dist/tsup/{chunk-4T4UWXHN.js.map → chunk-KCOVZOPS.js.map} +0 -0
  94. /package/dist/tsup/{chunk-7Q7R3QYT.js.map → chunk-XXGJCOL6.js.map} +0 -0
@@ -0,0 +1,1496 @@
1
+ import {
2
+ hibernationActor,
3
+ logger,
4
+ sleep,
5
+ sleepWithLongRpc,
6
+ sleepWithNoSleepOption,
7
+ sleepWithRawHttp,
8
+ sleepWithRawWebSocket
9
+ } from "../chunk-TCOEBUUE.js";
10
+ import {
11
+ actor,
12
+ setup
13
+ } from "../chunk-JDAD2YFA.js";
14
+ import {
15
+ createFileSystemOrMemoryDriver
16
+ } from "../chunk-KCOVZOPS.js";
17
+ import "../chunk-Q6W7RJJP.js";
18
+ import "../chunk-XXGJCOL6.js";
19
+ import {
20
+ buildManagerRouter
21
+ } from "../chunk-GMAVRZSF.js";
22
+ import "../chunk-E6ZE2YEA.js";
23
+ import "../chunk-FJ3KTN4V.js";
24
+ import {
25
+ UserError
26
+ } from "../chunk-LFVF5SCU.js";
27
+
28
+ // src/serve-test-suite/mod.ts
29
+ import { serve as honoServe } from "@hono/node-server";
30
+ import { createNodeWebSocket } from "@hono/node-ws";
31
+ import { createServer } from "net";
32
+ import { fileURLToPath } from "url";
33
+ import invariant from "invariant";
34
+
35
+ // fixtures/driver-test-suite/action-inputs.ts
36
+ var inputActor = actor({
37
+ createState: (c, input) => {
38
+ return {
39
+ initialInput: input,
40
+ onCreateInput: void 0
41
+ };
42
+ },
43
+ onCreate: (c, input) => {
44
+ c.state.onCreateInput = input;
45
+ },
46
+ actions: {
47
+ getInputs: (c) => {
48
+ return {
49
+ initialInput: c.state.initialInput,
50
+ onCreateInput: c.state.onCreateInput
51
+ };
52
+ }
53
+ }
54
+ });
55
+
56
+ // fixtures/driver-test-suite/action-timeout.ts
57
+ var shortTimeoutActor = actor({
58
+ state: { value: 0 },
59
+ options: {
60
+ actionTimeout: 50
61
+ // 50ms timeout
62
+ },
63
+ actions: {
64
+ quickAction: async (c) => {
65
+ return "quick response";
66
+ },
67
+ slowAction: async (c) => {
68
+ await new Promise((resolve) => setTimeout(resolve, 100));
69
+ return "slow response";
70
+ }
71
+ }
72
+ });
73
+ var longTimeoutActor = actor({
74
+ state: { value: 0 },
75
+ options: {
76
+ actionTimeout: 200
77
+ // 200ms timeout
78
+ },
79
+ actions: {
80
+ delayedAction: async (c) => {
81
+ await new Promise((resolve) => setTimeout(resolve, 100));
82
+ return "delayed response";
83
+ }
84
+ }
85
+ });
86
+ var defaultTimeoutActor = actor({
87
+ state: { value: 0 },
88
+ actions: {
89
+ normalAction: async (c) => {
90
+ await new Promise((resolve) => setTimeout(resolve, 50));
91
+ return "normal response";
92
+ }
93
+ }
94
+ });
95
+ var syncTimeoutActor = actor({
96
+ state: { value: 0 },
97
+ options: {
98
+ actionTimeout: 50
99
+ // 50ms timeout
100
+ },
101
+ actions: {
102
+ syncAction: (c) => {
103
+ return "sync response";
104
+ }
105
+ }
106
+ });
107
+
108
+ // fixtures/driver-test-suite/action-types.ts
109
+ var syncActionActor = actor({
110
+ state: { value: 0 },
111
+ actions: {
112
+ // Simple synchronous action that returns a value directly
113
+ increment: (c, amount = 1) => {
114
+ c.state.value += amount;
115
+ return c.state.value;
116
+ },
117
+ // Synchronous action that returns an object
118
+ getInfo: (c) => {
119
+ return {
120
+ currentValue: c.state.value,
121
+ timestamp: Date.now()
122
+ };
123
+ },
124
+ // Synchronous action with no return value (void)
125
+ reset: (c) => {
126
+ c.state.value = 0;
127
+ }
128
+ }
129
+ });
130
+ var asyncActionActor = actor({
131
+ state: { value: 0, data: null },
132
+ actions: {
133
+ // Async action with a delay
134
+ delayedIncrement: async (c, amount = 1) => {
135
+ await Promise.resolve();
136
+ c.state.value += amount;
137
+ return c.state.value;
138
+ },
139
+ // Async action that simulates an API call
140
+ fetchData: async (c, id) => {
141
+ await Promise.resolve();
142
+ const data = { id, timestamp: Date.now() };
143
+ c.state.data = data;
144
+ return data;
145
+ },
146
+ // Async action with error handling
147
+ asyncWithError: async (c, shouldError) => {
148
+ await Promise.resolve();
149
+ if (shouldError) {
150
+ throw new UserError("Intentional error");
151
+ }
152
+ return "Success";
153
+ }
154
+ }
155
+ });
156
+ var promiseActor = actor({
157
+ state: { results: [] },
158
+ actions: {
159
+ // Action that returns a resolved promise
160
+ resolvedPromise: (c) => {
161
+ return Promise.resolve("resolved value");
162
+ },
163
+ // Action that returns a promise that resolves after a delay
164
+ delayedPromise: (c) => {
165
+ return new Promise((resolve) => {
166
+ c.state.results.push("delayed");
167
+ resolve("delayed value");
168
+ });
169
+ },
170
+ // Action that returns a rejected promise
171
+ rejectedPromise: (c) => {
172
+ return Promise.reject(new UserError("promised rejection"));
173
+ },
174
+ // Action to check the collected results
175
+ getResults: (c) => {
176
+ return c.state.results;
177
+ }
178
+ }
179
+ });
180
+
181
+ // fixtures/driver-test-suite/actor-onstatechange.ts
182
+ var onStateChangeActor = actor({
183
+ state: {
184
+ value: 0,
185
+ changeCount: 0
186
+ },
187
+ actions: {
188
+ // Action that modifies state - should trigger onStateChange
189
+ setValue: (c, newValue) => {
190
+ c.state.value = newValue;
191
+ return c.state.value;
192
+ },
193
+ // Action that modifies state multiple times - should trigger onStateChange for each change
194
+ incrementMultiple: (c, times) => {
195
+ for (let i = 0; i < times; i++) {
196
+ c.state.value++;
197
+ }
198
+ return c.state.value;
199
+ },
200
+ // Action that doesn't modify state - should NOT trigger onStateChange
201
+ getValue: (c) => {
202
+ return c.state.value;
203
+ },
204
+ // Action that reads and returns without modifying - should NOT trigger onStateChange
205
+ getDoubled: (c) => {
206
+ const doubled = c.state.value * 2;
207
+ return doubled;
208
+ },
209
+ // Get the count of how many times onStateChange was called
210
+ getChangeCount: (c) => {
211
+ return c.state.changeCount;
212
+ },
213
+ // Reset change counter for testing
214
+ resetChangeCount: (c) => {
215
+ c.state.changeCount = 0;
216
+ }
217
+ },
218
+ // Track onStateChange calls
219
+ onStateChange: (c) => {
220
+ c.state.changeCount++;
221
+ }
222
+ });
223
+
224
+ // fixtures/driver-test-suite/conn-params.ts
225
+ var counterWithParams = actor({
226
+ state: { count: 0, initializers: [] },
227
+ createConnState: (c, params) => {
228
+ return {
229
+ name: params.name || "anonymous"
230
+ };
231
+ },
232
+ onConnect: (c, conn) => {
233
+ c.state.initializers.push(conn.state.name);
234
+ },
235
+ actions: {
236
+ increment: (c, x) => {
237
+ c.state.count += x;
238
+ c.broadcast("newCount", {
239
+ count: c.state.count,
240
+ by: c.conn.state.name
241
+ });
242
+ return c.state.count;
243
+ },
244
+ getInitializers: (c) => {
245
+ return c.state.initializers;
246
+ }
247
+ }
248
+ });
249
+
250
+ // fixtures/driver-test-suite/conn-state.ts
251
+ var connStateActor = actor({
252
+ state: {
253
+ sharedCounter: 0,
254
+ disconnectionCount: 0
255
+ },
256
+ // Define connection state
257
+ createConnState: (c, params) => {
258
+ return {
259
+ username: (params == null ? void 0 : params.username) || "anonymous",
260
+ role: (params == null ? void 0 : params.role) || "user",
261
+ counter: 0,
262
+ createdAt: Date.now(),
263
+ noCount: (params == null ? void 0 : params.noCount) ?? false
264
+ };
265
+ },
266
+ // Lifecycle hook when a connection is established
267
+ onConnect: (c, conn) => {
268
+ c.broadcast("userConnected", {
269
+ id: conn.id,
270
+ username: "anonymous",
271
+ role: "user"
272
+ });
273
+ },
274
+ // Lifecycle hook when a connection is closed
275
+ onDisconnect: (c, conn) => {
276
+ var _a;
277
+ if (!((_a = conn.state) == null ? void 0 : _a.noCount)) {
278
+ c.state.disconnectionCount += 1;
279
+ c.broadcast("userDisconnected", {
280
+ id: conn.id
281
+ });
282
+ }
283
+ },
284
+ actions: {
285
+ // Action to increment the connection's counter
286
+ incrementConnCounter: (c, amount = 1) => {
287
+ c.conn.state.counter += amount;
288
+ },
289
+ // Action to increment the shared counter
290
+ incrementSharedCounter: (c, amount = 1) => {
291
+ c.state.sharedCounter += amount;
292
+ return c.state.sharedCounter;
293
+ },
294
+ // Get the connection state
295
+ getConnectionState: (c) => {
296
+ return { id: c.conn.id, ...c.conn.state };
297
+ },
298
+ // Check all active connections
299
+ getConnectionIds: (c) => {
300
+ return c.conns.entries().filter((c2) => {
301
+ var _a;
302
+ return !((_a = c2[1].state) == null ? void 0 : _a.noCount);
303
+ }).map((x) => x[0]).toArray();
304
+ },
305
+ // Get disconnection count
306
+ getDisconnectionCount: (c) => {
307
+ return c.state.disconnectionCount;
308
+ },
309
+ // Get all active connection states
310
+ getAllConnectionStates: (c) => {
311
+ return c.conns.entries().map(([id, conn]) => ({ id, ...conn.state })).toArray();
312
+ },
313
+ // Send message to a specific connection with matching ID
314
+ sendToConnection: (c, targetId, message) => {
315
+ if (c.conns.has(targetId)) {
316
+ c.conns.get(targetId).send("directMessage", { from: c.conn.id, message });
317
+ return true;
318
+ } else {
319
+ return false;
320
+ }
321
+ },
322
+ // Update connection state (simulated for tests)
323
+ updateConnection: (c, updates) => {
324
+ if (updates.username) c.conn.state.username = updates.username;
325
+ if (updates.role) c.conn.state.role = updates.role;
326
+ return c.conn.state;
327
+ },
328
+ disconnectSelf: (c, reason) => {
329
+ c.conn.disconnect(reason ?? "test.disconnect");
330
+ return true;
331
+ }
332
+ }
333
+ });
334
+
335
+ // fixtures/driver-test-suite/counter.ts
336
+ var counter = actor({
337
+ state: { count: 0 },
338
+ actions: {
339
+ increment: (c, x) => {
340
+ c.state.count += x;
341
+ c.broadcast("newCount", c.state.count);
342
+ return c.state.count;
343
+ },
344
+ setCount: (c, x) => {
345
+ c.state.count = x;
346
+ c.broadcast("newCount", x);
347
+ return c.state.count;
348
+ },
349
+ getCount: (c) => {
350
+ return c.state.count;
351
+ }
352
+ }
353
+ });
354
+
355
+ // fixtures/driver-test-suite/counter-conn.ts
356
+ var counterConn = actor({
357
+ state: {
358
+ connectionCount: 0
359
+ },
360
+ connState: { count: 0 },
361
+ onConnect: (c, conn) => {
362
+ c.state.connectionCount += 1;
363
+ },
364
+ onDisconnect: (c, conn) => {
365
+ c.state.connectionCount -= 1;
366
+ },
367
+ actions: {
368
+ increment: (c, x) => {
369
+ c.conn.state.count += x;
370
+ c.broadcast("newCount", c.conn.state.count);
371
+ },
372
+ setCount: (c, x) => {
373
+ c.conn.state.count = x;
374
+ c.broadcast("newCount", x);
375
+ },
376
+ getCount: (c) => {
377
+ return c.conn.state.count;
378
+ },
379
+ getConnectionCount: (c) => {
380
+ return c.state.connectionCount;
381
+ }
382
+ }
383
+ });
384
+
385
+ // fixtures/driver-test-suite/destroy.ts
386
+ var destroyObserver = actor({
387
+ state: { destroyedActors: [] },
388
+ actions: {
389
+ notifyDestroyed: (c, actorKey) => {
390
+ c.state.destroyedActors.push(actorKey);
391
+ },
392
+ wasDestroyed: (c, actorKey) => {
393
+ return c.state.destroyedActors.includes(actorKey);
394
+ },
395
+ reset: (c) => {
396
+ c.state.destroyedActors = [];
397
+ }
398
+ }
399
+ });
400
+ var destroyActor = actor({
401
+ state: { value: 0, key: "" },
402
+ onWake: (c) => {
403
+ c.state.key = c.key.join("/");
404
+ },
405
+ onDestroy: async (c) => {
406
+ const client = c.client();
407
+ const observer = client.destroyObserver.getOrCreate(["observer"]);
408
+ await observer.notifyDestroyed(c.state.key);
409
+ },
410
+ actions: {
411
+ setValue: async (c, newValue) => {
412
+ c.state.value = newValue;
413
+ await c.saveState({ immediate: true });
414
+ return c.state.value;
415
+ },
416
+ getValue: (c) => {
417
+ return c.state.value;
418
+ },
419
+ destroy: (c) => {
420
+ c.destroy();
421
+ }
422
+ }
423
+ });
424
+
425
+ // fixtures/driver-test-suite/error-handling.ts
426
+ var errorHandlingActor = actor({
427
+ state: {
428
+ errorLog: []
429
+ },
430
+ actions: {
431
+ // Action that throws a UserError with just a message
432
+ throwSimpleError: () => {
433
+ throw new UserError("Simple error message");
434
+ },
435
+ // Action that throws a UserError with code and metadata
436
+ throwDetailedError: () => {
437
+ throw new UserError("Detailed error message", {
438
+ code: "detailed_error",
439
+ metadata: {
440
+ reason: "test",
441
+ timestamp: Date.now()
442
+ }
443
+ });
444
+ },
445
+ // Action that throws an internal error
446
+ throwInternalError: () => {
447
+ throw new Error("This is an internal error");
448
+ },
449
+ // Action that returns successfully
450
+ successfulAction: () => {
451
+ return "success";
452
+ },
453
+ // Action that times out (simulated with a long delay)
454
+ timeoutAction: async (c) => {
455
+ return new Promise((resolve) => {
456
+ setTimeout(() => {
457
+ resolve("This should not be reached if timeout works");
458
+ }, 1e4);
459
+ });
460
+ },
461
+ // Action with configurable delay to test timeout edge cases
462
+ delayedAction: async (c, delayMs) => {
463
+ return new Promise((resolve) => {
464
+ setTimeout(() => {
465
+ resolve(`Completed after ${delayMs}ms`);
466
+ }, delayMs);
467
+ });
468
+ },
469
+ // Log an error for inspection
470
+ logError: (c, error) => {
471
+ c.state.errorLog.push(error);
472
+ return c.state.errorLog;
473
+ },
474
+ // Get the error log
475
+ getErrorLog: (c) => {
476
+ return c.state.errorLog;
477
+ },
478
+ // Clear the error log
479
+ clearErrorLog: (c) => {
480
+ c.state.errorLog = [];
481
+ return true;
482
+ }
483
+ },
484
+ options: {
485
+ actionTimeout: 500
486
+ // 500ms timeout for actions
487
+ }
488
+ });
489
+ var customTimeoutActor = actor({
490
+ state: {},
491
+ actions: {
492
+ quickAction: async () => {
493
+ await new Promise((resolve) => setTimeout(resolve, 50));
494
+ return "Quick action completed";
495
+ },
496
+ slowAction: async () => {
497
+ await new Promise((resolve) => setTimeout(resolve, 300));
498
+ return "Slow action completed";
499
+ }
500
+ },
501
+ options: {
502
+ actionTimeout: 200
503
+ // 200ms timeout
504
+ }
505
+ });
506
+
507
+ // fixtures/driver-test-suite/inline-client.ts
508
+ var inlineClientActor = actor({
509
+ state: { messages: [] },
510
+ actions: {
511
+ // Action that uses client to call another actor (stateless)
512
+ callCounterIncrement: async (c, amount) => {
513
+ const client = c.client();
514
+ const result = await client.counter.getOrCreate(["inline-test"]).increment(amount);
515
+ c.state.messages.push(
516
+ `Called counter.increment(${amount}), result: ${result}`
517
+ );
518
+ return result;
519
+ },
520
+ // Action that uses client to get counter state (stateless)
521
+ getCounterState: async (c) => {
522
+ const client = c.client();
523
+ const count = await client.counter.getOrCreate(["inline-test"]).getCount();
524
+ c.state.messages.push(`Got counter state: ${count}`);
525
+ return count;
526
+ },
527
+ // Action that uses client with .connect() for stateful communication
528
+ connectToCounterAndIncrement: async (c, amount) => {
529
+ const client = c.client();
530
+ const handle = client.counter.getOrCreate(["inline-test-stateful"]);
531
+ const connection = handle.connect();
532
+ const events = [];
533
+ connection.on("newCount", (count) => {
534
+ events.push(count);
535
+ });
536
+ const result1 = await connection.increment(amount);
537
+ const result2 = await connection.increment(amount * 2);
538
+ await connection.dispose();
539
+ c.state.messages.push(
540
+ `Connected to counter, incremented by ${amount} and ${amount * 2}, results: ${result1}, ${result2}, events: ${JSON.stringify(events)}`
541
+ );
542
+ return { result1, result2, events };
543
+ },
544
+ // Get all messages from this actor's state
545
+ getMessages: (c) => {
546
+ return c.state.messages;
547
+ },
548
+ // Clear messages
549
+ clearMessages: (c) => {
550
+ c.state.messages = [];
551
+ }
552
+ }
553
+ });
554
+
555
+ // fixtures/driver-test-suite/kv.ts
556
+ var kvActor = actor({
557
+ actions: {
558
+ putText: async (c, key, value) => {
559
+ await c.kv.put(key, value);
560
+ return true;
561
+ },
562
+ getText: async (c, key) => {
563
+ return await c.kv.get(key);
564
+ },
565
+ listText: async (c, prefix) => {
566
+ const results = await c.kv.list(prefix, { keyType: "text" });
567
+ return results.map(([key, value]) => ({
568
+ key,
569
+ value
570
+ }));
571
+ },
572
+ roundtripArrayBuffer: async (c, key, values) => {
573
+ const buffer = new Uint8Array(values).buffer;
574
+ await c.kv.put(key, buffer, { type: "arrayBuffer" });
575
+ const result = await c.kv.get(key, { type: "arrayBuffer" });
576
+ if (!result) {
577
+ return null;
578
+ }
579
+ return Array.from(new Uint8Array(result));
580
+ }
581
+ }
582
+ });
583
+
584
+ // fixtures/driver-test-suite/large-payloads.ts
585
+ var largePayloadActor = actor({
586
+ state: {},
587
+ actions: {
588
+ /**
589
+ * Accepts a large request payload and returns its size
590
+ */
591
+ processLargeRequest: (c, data) => {
592
+ return {
593
+ itemCount: data.items.length,
594
+ firstItem: data.items[0],
595
+ lastItem: data.items[data.items.length - 1]
596
+ };
597
+ },
598
+ /**
599
+ * Returns a large response payload
600
+ */
601
+ getLargeResponse: (c, itemCount) => {
602
+ const items = [];
603
+ for (let i = 0; i < itemCount; i++) {
604
+ items.push(`Item ${i} with some additional text to increase size`);
605
+ }
606
+ return { items };
607
+ },
608
+ /**
609
+ * Echo back the request data
610
+ */
611
+ echo: (c, data) => {
612
+ return data;
613
+ }
614
+ }
615
+ });
616
+ var largePayloadConnActor = actor({
617
+ state: {},
618
+ connState: {
619
+ lastRequestSize: 0
620
+ },
621
+ actions: {
622
+ /**
623
+ * Accepts a large request payload and returns its size
624
+ */
625
+ processLargeRequest: (c, data) => {
626
+ c.conn.state.lastRequestSize = data.items.length;
627
+ return {
628
+ itemCount: data.items.length,
629
+ firstItem: data.items[0],
630
+ lastItem: data.items[data.items.length - 1]
631
+ };
632
+ },
633
+ /**
634
+ * Returns a large response payload
635
+ */
636
+ getLargeResponse: (c, itemCount) => {
637
+ const items = [];
638
+ for (let i = 0; i < itemCount; i++) {
639
+ items.push(`Item ${i} with some additional text to increase size`);
640
+ }
641
+ return { items };
642
+ },
643
+ /**
644
+ * Echo back the request data
645
+ */
646
+ echo: (c, data) => {
647
+ return data;
648
+ },
649
+ /**
650
+ * Get the last request size
651
+ */
652
+ getLastRequestSize: (c) => {
653
+ return c.conn.state.lastRequestSize;
654
+ }
655
+ }
656
+ });
657
+
658
+ // fixtures/driver-test-suite/lifecycle.ts
659
+ var counterWithLifecycle = actor({
660
+ state: {
661
+ count: 0,
662
+ events: []
663
+ },
664
+ createConnState: (c, params) => ({
665
+ joinTime: Date.now()
666
+ }),
667
+ onWake: (c) => {
668
+ c.state.events.push("onWake");
669
+ },
670
+ onBeforeConnect: (c, params) => {
671
+ if (params == null ? void 0 : params.trackLifecycle) c.state.events.push("onBeforeConnect");
672
+ },
673
+ onConnect: (c, conn) => {
674
+ var _a;
675
+ if ((_a = conn.params) == null ? void 0 : _a.trackLifecycle) c.state.events.push("onConnect");
676
+ },
677
+ onDisconnect: (c, conn) => {
678
+ var _a;
679
+ if ((_a = conn.params) == null ? void 0 : _a.trackLifecycle) c.state.events.push("onDisconnect");
680
+ },
681
+ actions: {
682
+ getEvents: (c) => {
683
+ return c.state.events;
684
+ },
685
+ increment: (c, x) => {
686
+ c.state.count += x;
687
+ return c.state.count;
688
+ }
689
+ }
690
+ });
691
+
692
+ // fixtures/driver-test-suite/metadata.ts
693
+ var metadataActor = actor({
694
+ state: {
695
+ lastMetadata: null,
696
+ actorName: "",
697
+ // Store tags and region in state for testing since they may not be
698
+ // available in the context in all environments
699
+ storedTags: {},
700
+ storedRegion: null
701
+ },
702
+ onWake: (c) => {
703
+ c.state.actorName = c.name;
704
+ },
705
+ actions: {
706
+ // Set up test tags - this will be called by tests to simulate tags
707
+ setupTestTags: (c, tags) => {
708
+ c.state.storedTags = tags;
709
+ return tags;
710
+ },
711
+ // Set up test region - this will be called by tests to simulate region
712
+ setupTestRegion: (c, region) => {
713
+ c.state.storedRegion = region;
714
+ return region;
715
+ },
716
+ // Get all available metadata
717
+ getMetadata: (c) => {
718
+ const metadata = {
719
+ name: c.name,
720
+ tags: c.state.storedTags,
721
+ region: c.state.storedRegion
722
+ };
723
+ c.state.lastMetadata = metadata;
724
+ return metadata;
725
+ },
726
+ // Get the actor name
727
+ getActorName: (c) => {
728
+ return c.name;
729
+ },
730
+ // Get a specific tag by key
731
+ getTag: (c, key) => {
732
+ return c.state.storedTags[key] || null;
733
+ },
734
+ // Get all tags
735
+ getTags: (c) => {
736
+ return c.state.storedTags;
737
+ },
738
+ // Get the region
739
+ getRegion: (c) => {
740
+ return c.state.storedRegion;
741
+ },
742
+ // Get the stored actor name (from onWake)
743
+ getStoredActorName: (c) => {
744
+ return c.state.actorName;
745
+ },
746
+ // Get last retrieved metadata
747
+ getLastMetadata: (c) => {
748
+ return c.state.lastMetadata;
749
+ }
750
+ }
751
+ });
752
+
753
+ // fixtures/driver-test-suite/raw-http.ts
754
+ import { Hono } from "hono";
755
+ var rawHttpActor = actor({
756
+ state: {
757
+ requestCount: 0
758
+ },
759
+ onRequest(ctx, request) {
760
+ const url = new URL(request.url);
761
+ const method = request.method;
762
+ ctx.state.requestCount++;
763
+ if (url.pathname === "/api/hello") {
764
+ return new Response(
765
+ JSON.stringify({ message: "Hello from actor!" }),
766
+ {
767
+ headers: { "Content-Type": "application/json" }
768
+ }
769
+ );
770
+ }
771
+ if (url.pathname === "/api/echo" && method === "POST") {
772
+ return new Response(request.body, {
773
+ headers: request.headers
774
+ });
775
+ }
776
+ if (url.pathname === "/api/state") {
777
+ return new Response(
778
+ JSON.stringify({
779
+ requestCount: ctx.state.requestCount
780
+ }),
781
+ {
782
+ headers: { "Content-Type": "application/json" }
783
+ }
784
+ );
785
+ }
786
+ if (url.pathname === "/api/headers") {
787
+ const headers = {};
788
+ request.headers.forEach((value, key) => {
789
+ headers[key] = value;
790
+ });
791
+ return new Response(JSON.stringify(headers), {
792
+ headers: { "Content-Type": "application/json" }
793
+ });
794
+ }
795
+ return new Response("Not Found", { status: 404 });
796
+ },
797
+ actions: {}
798
+ });
799
+ var rawHttpNoHandlerActor = actor({
800
+ actions: {}
801
+ });
802
+ var rawHttpVoidReturnActor = actor({
803
+ onRequest(ctx, request) {
804
+ return void 0;
805
+ },
806
+ actions: {}
807
+ });
808
+ var rawHttpHonoActor = actor({
809
+ createVars() {
810
+ const router = new Hono();
811
+ router.get(
812
+ "/",
813
+ (c) => c.json({ message: "Welcome to Hono actor!" })
814
+ );
815
+ router.get(
816
+ "/users",
817
+ (c) => c.json([
818
+ { id: 1, name: "Alice" },
819
+ { id: 2, name: "Bob" }
820
+ ])
821
+ );
822
+ router.get("/users/:id", (c) => {
823
+ const id = c.req.param("id");
824
+ return c.json({
825
+ id: parseInt(id),
826
+ name: id === "1" ? "Alice" : "Bob"
827
+ });
828
+ });
829
+ router.post("/users", async (c) => {
830
+ const body = await c.req.json();
831
+ return c.json({ id: 3, ...body }, 201);
832
+ });
833
+ router.put("/users/:id", async (c) => {
834
+ const id = c.req.param("id");
835
+ const body = await c.req.json();
836
+ return c.json({ id: parseInt(id), ...body });
837
+ });
838
+ router.delete("/users/:id", (c) => {
839
+ const id = c.req.param("id");
840
+ return c.json({ message: `User ${id} deleted` });
841
+ });
842
+ return { router };
843
+ },
844
+ onRequest(ctx, request) {
845
+ return ctx.vars.router.fetch(request);
846
+ },
847
+ actions: {}
848
+ });
849
+
850
+ // fixtures/driver-test-suite/raw-http-request-properties.ts
851
+ var rawHttpRequestPropertiesActor = actor({
852
+ actions: {},
853
+ onRequest(ctx, request) {
854
+ const url = new URL(request.url);
855
+ const method = request.method;
856
+ const headers = {};
857
+ request.headers.forEach((value, key) => {
858
+ headers[key] = value;
859
+ });
860
+ const handleBody = async () => {
861
+ if (!request.body) {
862
+ return null;
863
+ }
864
+ const contentType = request.headers.get("content-type") || "";
865
+ try {
866
+ if (contentType.includes("application/json")) {
867
+ const text = await request.text();
868
+ return text ? JSON.parse(text) : null;
869
+ } else {
870
+ const text = await request.text();
871
+ return text || null;
872
+ }
873
+ } catch (error) {
874
+ return null;
875
+ }
876
+ };
877
+ if (method === "HEAD") {
878
+ return new Response(null, {
879
+ status: 200
880
+ });
881
+ }
882
+ if (method === "OPTIONS") {
883
+ return new Response(null, {
884
+ status: 204
885
+ });
886
+ }
887
+ return handleBody().then((body) => {
888
+ const responseData = {
889
+ // URL properties
890
+ url: request.url,
891
+ pathname: url.pathname,
892
+ search: url.search,
893
+ searchParams: Object.fromEntries(url.searchParams.entries()),
894
+ hash: url.hash,
895
+ // Method
896
+ method: request.method,
897
+ // Headers
898
+ headers,
899
+ // Body
900
+ body,
901
+ bodyText: typeof body === "string" ? body : body === null && request.body !== null ? "" : null,
902
+ // Additional properties that might be available
903
+ // Note: Some properties like cache, credentials, mode, etc.
904
+ // might not be available in all environments
905
+ cache: request.cache || null,
906
+ credentials: request.credentials || null,
907
+ mode: request.mode || null,
908
+ redirect: request.redirect || null,
909
+ referrer: request.referrer || null
910
+ };
911
+ return new Response(JSON.stringify(responseData), {
912
+ headers: { "Content-Type": "application/json" }
913
+ });
914
+ });
915
+ }
916
+ });
917
+
918
+ // fixtures/driver-test-suite/raw-websocket.ts
919
+ var rawWebSocketActor = actor({
920
+ state: {
921
+ connectionCount: 0,
922
+ messageCount: 0
923
+ },
924
+ onWebSocket(ctx, websocket) {
925
+ ctx.state.connectionCount = ctx.state.connectionCount + 1;
926
+ console.log(
927
+ `[ACTOR] New connection, count: ${ctx.state.connectionCount}`
928
+ );
929
+ websocket.send(
930
+ JSON.stringify({
931
+ type: "welcome",
932
+ connectionCount: ctx.state.connectionCount
933
+ })
934
+ );
935
+ console.log("[ACTOR] Sent welcome message");
936
+ websocket.addEventListener("message", (event) => {
937
+ var _a;
938
+ ctx.state.messageCount = ctx.state.messageCount + 1;
939
+ console.log(
940
+ `[ACTOR] Message received, total count: ${ctx.state.messageCount}, data:`,
941
+ event.data
942
+ );
943
+ const data = event.data;
944
+ if (typeof data === "string") {
945
+ try {
946
+ const parsed = JSON.parse(data);
947
+ if (parsed.type === "ping") {
948
+ websocket.send(
949
+ JSON.stringify({
950
+ type: "pong",
951
+ timestamp: Date.now()
952
+ })
953
+ );
954
+ } else if (parsed.type === "getStats") {
955
+ console.log(
956
+ `[ACTOR] Sending stats - connections: ${ctx.state.connectionCount}, messages: ${ctx.state.messageCount}`
957
+ );
958
+ websocket.send(
959
+ JSON.stringify({
960
+ type: "stats",
961
+ connectionCount: ctx.state.connectionCount,
962
+ messageCount: ctx.state.messageCount
963
+ })
964
+ );
965
+ } else if (parsed.type === "getRequestInfo") {
966
+ const url = ((_a = ctx.request) == null ? void 0 : _a.url) || "ws://actor/websocket";
967
+ const urlObj = new URL(url);
968
+ websocket.send(
969
+ JSON.stringify({
970
+ type: "requestInfo",
971
+ url,
972
+ pathname: urlObj.pathname,
973
+ search: urlObj.search
974
+ })
975
+ );
976
+ } else {
977
+ websocket.send(data);
978
+ }
979
+ } catch {
980
+ websocket.send(data);
981
+ }
982
+ } else {
983
+ websocket.send(data);
984
+ }
985
+ });
986
+ websocket.addEventListener("close", () => {
987
+ ctx.state.connectionCount = ctx.state.connectionCount - 1;
988
+ console.log(
989
+ `[ACTOR] Connection closed, count: ${ctx.state.connectionCount}`
990
+ );
991
+ });
992
+ },
993
+ actions: {
994
+ getStats(ctx) {
995
+ return {
996
+ connectionCount: ctx.state.connectionCount,
997
+ messageCount: ctx.state.messageCount
998
+ };
999
+ }
1000
+ }
1001
+ });
1002
+ var rawWebSocketBinaryActor = actor({
1003
+ onWebSocket(ctx, websocket) {
1004
+ websocket.addEventListener("message", (event) => {
1005
+ const data = event.data;
1006
+ if (data instanceof ArrayBuffer || data instanceof Uint8Array) {
1007
+ const bytes = new Uint8Array(data);
1008
+ const reversed = new Uint8Array(bytes.length);
1009
+ for (let i = 0; i < bytes.length; i++) {
1010
+ reversed[i] = bytes[bytes.length - 1 - i];
1011
+ }
1012
+ websocket.send(reversed);
1013
+ }
1014
+ });
1015
+ },
1016
+ actions: {}
1017
+ });
1018
+
1019
+ // fixtures/driver-test-suite/request-access.ts
1020
+ var requestAccessActor = actor({
1021
+ state: {
1022
+ // Track request info from different hooks
1023
+ onBeforeConnectRequest: {
1024
+ hasRequest: false,
1025
+ requestUrl: null,
1026
+ requestMethod: null,
1027
+ requestHeaders: {}
1028
+ },
1029
+ createConnStateRequest: {
1030
+ hasRequest: false,
1031
+ requestUrl: null,
1032
+ requestMethod: null,
1033
+ requestHeaders: {}
1034
+ },
1035
+ onRequestRequest: {
1036
+ hasRequest: false,
1037
+ requestUrl: null,
1038
+ requestMethod: null,
1039
+ requestHeaders: {}
1040
+ },
1041
+ onWebSocketRequest: {
1042
+ hasRequest: false,
1043
+ requestUrl: null,
1044
+ requestMethod: null,
1045
+ requestHeaders: {}
1046
+ }
1047
+ },
1048
+ createConnState: (c, params) => {
1049
+ let requestInfo = null;
1050
+ if ((params == null ? void 0 : params.trackRequest) && c.request) {
1051
+ const headers = {};
1052
+ c.request.headers.forEach((value, key) => {
1053
+ headers[key] = value;
1054
+ });
1055
+ requestInfo = {
1056
+ hasRequest: true,
1057
+ requestUrl: c.request.url,
1058
+ requestMethod: c.request.method,
1059
+ requestHeaders: headers
1060
+ };
1061
+ }
1062
+ return {
1063
+ trackRequest: (params == null ? void 0 : params.trackRequest) || false,
1064
+ requestInfo
1065
+ };
1066
+ },
1067
+ onConnect: (c, conn) => {
1068
+ if (conn.state.requestInfo) {
1069
+ c.state.createConnStateRequest = conn.state.requestInfo;
1070
+ }
1071
+ },
1072
+ onBeforeConnect: (c, params) => {
1073
+ if (params == null ? void 0 : params.trackRequest) {
1074
+ if (c.request) {
1075
+ c.state.onBeforeConnectRequest.hasRequest = true;
1076
+ c.state.onBeforeConnectRequest.requestUrl = c.request.url;
1077
+ c.state.onBeforeConnectRequest.requestMethod = c.request.method;
1078
+ const headers = {};
1079
+ c.request.headers.forEach((value, key) => {
1080
+ headers[key] = value;
1081
+ });
1082
+ c.state.onBeforeConnectRequest.requestHeaders = headers;
1083
+ } else {
1084
+ c.state.onBeforeConnectRequest.hasRequest = false;
1085
+ }
1086
+ }
1087
+ },
1088
+ onRequest: (c, request) => {
1089
+ c.state.onRequestRequest.hasRequest = true;
1090
+ c.state.onRequestRequest.requestUrl = request.url;
1091
+ c.state.onRequestRequest.requestMethod = request.method;
1092
+ const headers = {};
1093
+ request.headers.forEach((value, key) => {
1094
+ headers[key] = value;
1095
+ });
1096
+ c.state.onRequestRequest.requestHeaders = headers;
1097
+ return new Response(
1098
+ JSON.stringify({
1099
+ hasRequest: true,
1100
+ requestUrl: request.url,
1101
+ requestMethod: request.method,
1102
+ requestHeaders: headers
1103
+ }),
1104
+ {
1105
+ status: 200,
1106
+ headers: { "Content-Type": "application/json" }
1107
+ }
1108
+ );
1109
+ },
1110
+ onWebSocket: (c, websocket) => {
1111
+ if (!c.request) throw "Missing request";
1112
+ c.state.onWebSocketRequest.hasRequest = true;
1113
+ c.state.onWebSocketRequest.requestUrl = c.request.url;
1114
+ c.state.onWebSocketRequest.requestMethod = c.request.method;
1115
+ const headers = {};
1116
+ c.request.headers.forEach((value, key) => {
1117
+ headers[key] = value;
1118
+ });
1119
+ c.state.onWebSocketRequest.requestHeaders = headers;
1120
+ websocket.send(
1121
+ JSON.stringify({
1122
+ hasRequest: true,
1123
+ requestUrl: c.request.url,
1124
+ requestMethod: c.request.method,
1125
+ requestHeaders: headers
1126
+ })
1127
+ );
1128
+ websocket.addEventListener("message", (event) => {
1129
+ websocket.send(event.data);
1130
+ });
1131
+ },
1132
+ actions: {
1133
+ getRequestInfo: (c) => {
1134
+ return {
1135
+ onBeforeConnect: c.state.onBeforeConnectRequest,
1136
+ createConnState: c.state.createConnStateRequest,
1137
+ onRequest: c.state.onRequestRequest,
1138
+ onWebSocket: c.state.onWebSocketRequest
1139
+ };
1140
+ }
1141
+ }
1142
+ });
1143
+
1144
+ // fixtures/driver-test-suite/reject-connection.ts
1145
+ var rejectConnectionActor = actor({
1146
+ onBeforeConnect: async (_c, params) => {
1147
+ if (params == null ? void 0 : params.reject) {
1148
+ await new Promise((resolve) => setTimeout(resolve, 500));
1149
+ throw new UserError("Rejected connection", {
1150
+ code: "rejected"
1151
+ });
1152
+ }
1153
+ },
1154
+ actions: {
1155
+ ping: () => "pong"
1156
+ }
1157
+ });
1158
+
1159
+ // fixtures/driver-test-suite/scheduled.ts
1160
+ var scheduled = actor({
1161
+ state: {
1162
+ lastRun: 0,
1163
+ scheduledCount: 0,
1164
+ taskHistory: []
1165
+ },
1166
+ actions: {
1167
+ // Schedule using 'at' with specific timestamp
1168
+ scheduleTaskAt: (c, timestamp) => {
1169
+ c.schedule.at(timestamp, "onScheduledTask");
1170
+ return timestamp;
1171
+ },
1172
+ // Schedule using 'after' with delay
1173
+ scheduleTaskAfter: (c, delayMs) => {
1174
+ c.schedule.after(delayMs, "onScheduledTask");
1175
+ return Date.now() + delayMs;
1176
+ },
1177
+ // Schedule with a task ID for ordering tests
1178
+ scheduleTaskAfterWithId: (c, taskId, delayMs) => {
1179
+ c.schedule.after(delayMs, "onScheduledTaskWithId", taskId);
1180
+ return { taskId, scheduledFor: Date.now() + delayMs };
1181
+ },
1182
+ // Original method for backward compatibility
1183
+ scheduleTask: (c, delayMs) => {
1184
+ const timestamp = Date.now() + delayMs;
1185
+ c.schedule.at(timestamp, "onScheduledTask");
1186
+ return timestamp;
1187
+ },
1188
+ // Getters for state
1189
+ getLastRun: (c) => {
1190
+ return c.state.lastRun;
1191
+ },
1192
+ getScheduledCount: (c) => {
1193
+ return c.state.scheduledCount;
1194
+ },
1195
+ getTaskHistory: (c) => {
1196
+ return c.state.taskHistory;
1197
+ },
1198
+ clearHistory: (c) => {
1199
+ c.state.taskHistory = [];
1200
+ c.state.scheduledCount = 0;
1201
+ c.state.lastRun = 0;
1202
+ return true;
1203
+ },
1204
+ // Scheduled task handlers
1205
+ onScheduledTask: (c) => {
1206
+ c.state.lastRun = Date.now();
1207
+ c.state.scheduledCount++;
1208
+ c.broadcast("scheduled", {
1209
+ time: c.state.lastRun,
1210
+ count: c.state.scheduledCount
1211
+ });
1212
+ },
1213
+ onScheduledTaskWithId: (c, taskId) => {
1214
+ c.state.lastRun = Date.now();
1215
+ c.state.scheduledCount++;
1216
+ c.state.taskHistory.push(taskId);
1217
+ c.broadcast("scheduledWithId", {
1218
+ taskId,
1219
+ time: c.state.lastRun,
1220
+ count: c.state.scheduledCount
1221
+ });
1222
+ }
1223
+ }
1224
+ });
1225
+
1226
+ // fixtures/driver-test-suite/vars.ts
1227
+ var staticVarActor = actor({
1228
+ state: { value: 0 },
1229
+ connState: { hello: "world" },
1230
+ vars: { counter: 42, name: "test-actor" },
1231
+ actions: {
1232
+ getVars: (c) => {
1233
+ return c.vars;
1234
+ },
1235
+ getName: (c) => {
1236
+ return c.vars.name;
1237
+ }
1238
+ }
1239
+ });
1240
+ var nestedVarActor = actor({
1241
+ state: { value: 0 },
1242
+ connState: { hello: "world" },
1243
+ vars: {
1244
+ counter: 42,
1245
+ nested: {
1246
+ value: "original",
1247
+ array: [1, 2, 3],
1248
+ obj: { key: "value" }
1249
+ }
1250
+ },
1251
+ actions: {
1252
+ getVars: (c) => {
1253
+ return c.vars;
1254
+ },
1255
+ modifyNested: (c) => {
1256
+ c.vars.nested.value = "modified";
1257
+ c.vars.nested.array.push(4);
1258
+ c.vars.nested.obj.key = "new-value";
1259
+ return c.vars;
1260
+ }
1261
+ }
1262
+ });
1263
+ var dynamicVarActor = actor({
1264
+ state: { value: 0 },
1265
+ connState: { hello: "world" },
1266
+ createVars: () => {
1267
+ return {
1268
+ random: Math.random(),
1269
+ computed: `Actor-${Math.floor(Math.random() * 1e3)}`
1270
+ };
1271
+ },
1272
+ actions: {
1273
+ getVars: (c) => {
1274
+ return c.vars;
1275
+ }
1276
+ }
1277
+ });
1278
+ var uniqueVarActor = actor({
1279
+ state: { value: 0 },
1280
+ connState: { hello: "world" },
1281
+ createVars: () => {
1282
+ return {
1283
+ id: Math.floor(Math.random() * 1e6)
1284
+ };
1285
+ },
1286
+ actions: {
1287
+ getVars: (c) => {
1288
+ return c.vars;
1289
+ }
1290
+ }
1291
+ });
1292
+ var driverCtxActor = actor({
1293
+ state: { value: 0 },
1294
+ connState: { hello: "world" },
1295
+ createVars: (c, driverCtx) => {
1296
+ return {
1297
+ hasDriverCtx: Boolean(driverCtx == null ? void 0 : driverCtx.isTest)
1298
+ };
1299
+ },
1300
+ actions: {
1301
+ getVars: (c) => {
1302
+ return c.vars;
1303
+ }
1304
+ }
1305
+ });
1306
+
1307
+ // fixtures/driver-test-suite/registry.ts
1308
+ var registry = setup({
1309
+ use: {
1310
+ // From counter.ts
1311
+ counter,
1312
+ // From counter-conn.ts
1313
+ counterConn,
1314
+ // From lifecycle.ts
1315
+ counterWithLifecycle,
1316
+ // From scheduled.ts
1317
+ scheduled,
1318
+ // From sleep.ts
1319
+ sleep,
1320
+ sleepWithLongRpc,
1321
+ sleepWithRawHttp,
1322
+ sleepWithRawWebSocket,
1323
+ sleepWithNoSleepOption,
1324
+ // From error-handling.ts
1325
+ errorHandlingActor,
1326
+ customTimeoutActor,
1327
+ // From inline-client.ts
1328
+ inlineClientActor,
1329
+ // From kv.ts
1330
+ kvActor,
1331
+ // From action-inputs.ts
1332
+ inputActor,
1333
+ // From action-timeout.ts
1334
+ shortTimeoutActor,
1335
+ longTimeoutActor,
1336
+ defaultTimeoutActor,
1337
+ syncTimeoutActor,
1338
+ // From action-types.ts
1339
+ syncActionActor,
1340
+ asyncActionActor,
1341
+ promiseActor,
1342
+ // From conn-params.ts
1343
+ counterWithParams,
1344
+ // From conn-state.ts
1345
+ connStateActor,
1346
+ // From metadata.ts
1347
+ metadataActor,
1348
+ // From vars.ts
1349
+ staticVarActor,
1350
+ nestedVarActor,
1351
+ dynamicVarActor,
1352
+ uniqueVarActor,
1353
+ driverCtxActor,
1354
+ // From raw-http.ts
1355
+ rawHttpActor,
1356
+ rawHttpNoHandlerActor,
1357
+ rawHttpVoidReturnActor,
1358
+ rawHttpHonoActor,
1359
+ // From raw-http-request-properties.ts
1360
+ rawHttpRequestPropertiesActor,
1361
+ // From raw-websocket.ts
1362
+ rawWebSocketActor,
1363
+ rawWebSocketBinaryActor,
1364
+ // From reject-connection.ts
1365
+ rejectConnectionActor,
1366
+ // From request-access.ts
1367
+ requestAccessActor,
1368
+ // From actor-onstatechange.ts
1369
+ onStateChangeActor,
1370
+ // From destroy.ts
1371
+ destroyActor,
1372
+ destroyObserver,
1373
+ // From hibernation.ts
1374
+ hibernationActor,
1375
+ // From large-payloads.ts
1376
+ largePayloadActor,
1377
+ largePayloadConnActor
1378
+ }
1379
+ });
1380
+
1381
+ // src/serve-test-suite/mod.ts
1382
+ async function getPort() {
1383
+ const MIN_PORT = 1e4;
1384
+ const MAX_PORT = 65535;
1385
+ const getRandomPort = () => Math.floor(Math.random() * (MAX_PORT - MIN_PORT + 1)) + MIN_PORT;
1386
+ let port = getRandomPort();
1387
+ let maxAttempts = 10;
1388
+ while (maxAttempts > 0) {
1389
+ try {
1390
+ const server = await new Promise((resolve, reject) => {
1391
+ const server2 = createServer();
1392
+ server2.once("error", (err) => {
1393
+ if (err.code === "EADDRINUSE") {
1394
+ reject(new Error(`Port ${port} is in use`));
1395
+ } else {
1396
+ reject(err);
1397
+ }
1398
+ });
1399
+ server2.once("listening", () => {
1400
+ resolve(server2);
1401
+ });
1402
+ server2.listen(port);
1403
+ });
1404
+ await new Promise((resolve) => {
1405
+ server.close(() => resolve());
1406
+ });
1407
+ return port;
1408
+ } catch {
1409
+ maxAttempts--;
1410
+ if (maxAttempts <= 0) {
1411
+ break;
1412
+ }
1413
+ port = getRandomPort();
1414
+ }
1415
+ }
1416
+ throw new Error("Could not find an available port after multiple attempts");
1417
+ }
1418
+ async function serveTestSuite() {
1419
+ var _a;
1420
+ registry.config.test = { ...registry.config.test, enabled: true };
1421
+ registry.config.inspector = {
1422
+ enabled: true,
1423
+ token: () => "token"
1424
+ };
1425
+ const port = await getPort();
1426
+ registry.config.managerPort = port;
1427
+ registry.config.serverless = {
1428
+ ...registry.config.serverless,
1429
+ publicEndpoint: `http://127.0.0.1:${port}`
1430
+ };
1431
+ const driver = await createFileSystemOrMemoryDriver(
1432
+ true,
1433
+ `/tmp/rivetkit-test-suite-${crypto.randomUUID()}`
1434
+ );
1435
+ registry.config.driver = driver;
1436
+ let upgradeWebSocket;
1437
+ const parsedConfig = registry.parseConfig();
1438
+ const managerDriver = (_a = driver.manager) == null ? void 0 : _a.call(driver, parsedConfig);
1439
+ invariant(managerDriver, "missing manager driver");
1440
+ const { router } = buildManagerRouter(
1441
+ parsedConfig,
1442
+ managerDriver,
1443
+ () => upgradeWebSocket
1444
+ );
1445
+ const nodeWebSocket = createNodeWebSocket({ app: router });
1446
+ upgradeWebSocket = nodeWebSocket.upgradeWebSocket;
1447
+ managerDriver.setGetUpgradeWebSocket(() => upgradeWebSocket);
1448
+ const server = honoServe({
1449
+ fetch: router.fetch,
1450
+ hostname: "127.0.0.1",
1451
+ port
1452
+ });
1453
+ invariant(
1454
+ nodeWebSocket.injectWebSocket !== void 0,
1455
+ "should have injectWebSocket"
1456
+ );
1457
+ nodeWebSocket.injectWebSocket(server);
1458
+ const endpoint = `http://127.0.0.1:${port}`;
1459
+ logger().info({ msg: "test suite server listening", port });
1460
+ return {
1461
+ endpoint,
1462
+ namespace: "default",
1463
+ runnerName: "default",
1464
+ close: async () => {
1465
+ await new Promise((resolve) => server.close(() => resolve(void 0)));
1466
+ }
1467
+ };
1468
+ }
1469
+ async function runCli() {
1470
+ const result = await serveTestSuite();
1471
+ process.stdout.write(
1472
+ `${JSON.stringify({
1473
+ endpoint: result.endpoint,
1474
+ namespace: result.namespace,
1475
+ runnerName: result.runnerName
1476
+ })}
1477
+ `
1478
+ );
1479
+ const shutdown = async () => {
1480
+ await result.close();
1481
+ process.exit(0);
1482
+ };
1483
+ process.on("SIGINT", shutdown);
1484
+ process.on("SIGTERM", shutdown);
1485
+ }
1486
+ var mainPath = process.argv[1];
1487
+ if (mainPath && mainPath === fileURLToPath(import.meta.url)) {
1488
+ runCli().catch((err) => {
1489
+ logger().error({ msg: "serve-test-suite failed", error: err });
1490
+ process.exit(1);
1491
+ });
1492
+ }
1493
+ export {
1494
+ serveTestSuite
1495
+ };
1496
+ //# sourceMappingURL=mod.js.map