rivetkit 2.0.23 → 2.0.24

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 (228) hide show
  1. package/dist/schemas/actor-persist/v2.ts +3 -3
  2. package/dist/schemas/actor-persist/v3.ts +274 -0
  3. package/dist/schemas/client-protocol/v2.ts +432 -0
  4. package/dist/schemas/file-system-driver/v2.ts +136 -0
  5. package/dist/tsup/actor/errors.cjs +2 -4
  6. package/dist/tsup/actor/errors.cjs.map +1 -1
  7. package/dist/tsup/actor/errors.d.cts +7 -10
  8. package/dist/tsup/actor/errors.d.ts +7 -10
  9. package/dist/tsup/actor/errors.js +9 -11
  10. package/dist/tsup/{actor-router-consts-B3Lu87yJ.d.cts → actor-router-consts-DzI2szci.d.cts} +5 -9
  11. package/dist/tsup/{actor-router-consts-B3Lu87yJ.d.ts → actor-router-consts-DzI2szci.d.ts} +5 -9
  12. package/dist/tsup/{chunk-3JYSUFET.cjs → chunk-3543NCSN.cjs} +45 -57
  13. package/dist/tsup/chunk-3543NCSN.cjs.map +1 -0
  14. package/dist/tsup/chunk-4SHILYS5.cjs +5694 -0
  15. package/dist/tsup/chunk-4SHILYS5.cjs.map +1 -0
  16. package/dist/tsup/{chunk-NCUALX2Q.cjs → chunk-5BZO5XPS.cjs} +3 -3
  17. package/dist/tsup/{chunk-NCUALX2Q.cjs.map → chunk-5BZO5XPS.cjs.map} +1 -1
  18. package/dist/tsup/{chunk-5PKKNNNS.js → chunk-BAIGSF64.js} +189 -187
  19. package/dist/tsup/chunk-BAIGSF64.js.map +1 -0
  20. package/dist/tsup/{chunk-HNYF4T36.cjs → chunk-CHLZBSI2.cjs} +17 -17
  21. package/dist/tsup/chunk-CHLZBSI2.cjs.map +1 -0
  22. package/dist/tsup/chunk-D3SLADUD.cjs +512 -0
  23. package/dist/tsup/chunk-D3SLADUD.cjs.map +1 -0
  24. package/dist/tsup/{chunk-KSRXX3Z4.cjs → chunk-D6762AOA.cjs} +20 -25
  25. package/dist/tsup/chunk-D6762AOA.cjs.map +1 -0
  26. package/dist/tsup/{chunk-C56XVVV4.cjs → chunk-DLK5YCTN.cjs} +187 -185
  27. package/dist/tsup/chunk-DLK5YCTN.cjs.map +1 -0
  28. package/dist/tsup/{chunk-DLYZKFRY.js → chunk-DUJQWGYD.js} +3 -7
  29. package/dist/tsup/chunk-DUJQWGYD.js.map +1 -0
  30. package/dist/tsup/{chunk-5UJQWWO3.js → chunk-EIPANQMF.js} +2 -2
  31. package/dist/tsup/{chunk-54DVMQPT.cjs → chunk-ESMTDP7G.cjs} +6 -6
  32. package/dist/tsup/chunk-ESMTDP7G.cjs.map +1 -0
  33. package/dist/tsup/{chunk-XYK5PY3B.cjs → chunk-FVAKREFB.cjs} +1900 -1737
  34. package/dist/tsup/chunk-FVAKREFB.cjs.map +1 -0
  35. package/dist/tsup/{chunk-PHNIVSG5.js → chunk-I3XT7WOF.js} +44 -56
  36. package/dist/tsup/chunk-I3XT7WOF.js.map +1 -0
  37. package/dist/tsup/{chunk-3I6ZIJVJ.js → chunk-IMDS5T42.js} +3 -3
  38. package/dist/tsup/chunk-IMDS5T42.js.map +1 -0
  39. package/dist/tsup/{chunk-SN4KWTRA.cjs → chunk-J3HZJF2P.cjs} +10 -14
  40. package/dist/tsup/chunk-J3HZJF2P.cjs.map +1 -0
  41. package/dist/tsup/{chunk-NOZSCUPQ.js → chunk-MBBJUHSP.js} +1844 -1681
  42. package/dist/tsup/chunk-MBBJUHSP.js.map +1 -0
  43. package/dist/tsup/{chunk-RVVUS4X6.js → chunk-MO5CB6MD.js} +9 -9
  44. package/dist/tsup/chunk-MO5CB6MD.js.map +1 -0
  45. package/dist/tsup/chunk-OFOTPKAH.js +512 -0
  46. package/dist/tsup/chunk-OFOTPKAH.js.map +1 -0
  47. package/dist/tsup/{chunk-G64QUEDJ.js → chunk-W6RDS6NW.js} +23 -28
  48. package/dist/tsup/chunk-W6RDS6NW.js.map +1 -0
  49. package/dist/tsup/{chunk-XSDSNHSE.cjs → chunk-YC5DUHPM.cjs} +4 -8
  50. package/dist/tsup/chunk-YC5DUHPM.cjs.map +1 -0
  51. package/dist/tsup/{chunk-YAYNBR37.js → chunk-YC7YPM2T.js} +2 -6
  52. package/dist/tsup/chunk-YC7YPM2T.js.map +1 -0
  53. package/dist/tsup/{chunk-FTQ62XTN.js → chunk-ZSPU5R4C.js} +3322 -2251
  54. package/dist/tsup/chunk-ZSPU5R4C.js.map +1 -0
  55. package/dist/tsup/client/mod.cjs +9 -9
  56. package/dist/tsup/client/mod.d.cts +5 -7
  57. package/dist/tsup/client/mod.d.ts +5 -7
  58. package/dist/tsup/client/mod.js +8 -8
  59. package/dist/tsup/common/log.cjs +3 -3
  60. package/dist/tsup/common/log.js +2 -2
  61. package/dist/tsup/common/websocket.cjs +4 -4
  62. package/dist/tsup/common/websocket.js +3 -3
  63. package/dist/tsup/{conn-B3Vhbgnd.d.ts → config-BRDYDraU.d.cts} +1119 -1047
  64. package/dist/tsup/{conn-DJWL3nGx.d.cts → config-Bo-blHpJ.d.ts} +1119 -1047
  65. package/dist/tsup/driver-helpers/mod.cjs +5 -13
  66. package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
  67. package/dist/tsup/driver-helpers/mod.d.cts +11 -9
  68. package/dist/tsup/driver-helpers/mod.d.ts +11 -9
  69. package/dist/tsup/driver-helpers/mod.js +14 -22
  70. package/dist/tsup/driver-test-suite/mod.cjs +474 -303
  71. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  72. package/dist/tsup/driver-test-suite/mod.d.cts +6 -9
  73. package/dist/tsup/driver-test-suite/mod.d.ts +6 -9
  74. package/dist/tsup/driver-test-suite/mod.js +1085 -914
  75. package/dist/tsup/driver-test-suite/mod.js.map +1 -1
  76. package/dist/tsup/inspector/mod.cjs +6 -6
  77. package/dist/tsup/inspector/mod.d.cts +5 -7
  78. package/dist/tsup/inspector/mod.d.ts +5 -7
  79. package/dist/tsup/inspector/mod.js +5 -5
  80. package/dist/tsup/mod.cjs +10 -16
  81. package/dist/tsup/mod.cjs.map +1 -1
  82. package/dist/tsup/mod.d.cts +23 -25
  83. package/dist/tsup/mod.d.ts +23 -25
  84. package/dist/tsup/mod.js +17 -23
  85. package/dist/tsup/test/mod.cjs +11 -11
  86. package/dist/tsup/test/mod.d.cts +4 -6
  87. package/dist/tsup/test/mod.d.ts +4 -6
  88. package/dist/tsup/test/mod.js +10 -10
  89. package/dist/tsup/utils.cjs +3 -5
  90. package/dist/tsup/utils.cjs.map +1 -1
  91. package/dist/tsup/utils.d.cts +1 -2
  92. package/dist/tsup/utils.d.ts +1 -2
  93. package/dist/tsup/utils.js +2 -4
  94. package/package.json +13 -6
  95. package/src/actor/config.ts +56 -44
  96. package/src/actor/conn/driver.ts +61 -0
  97. package/src/actor/conn/drivers/http.ts +17 -0
  98. package/src/actor/conn/drivers/raw-request.ts +24 -0
  99. package/src/actor/conn/drivers/raw-websocket.ts +65 -0
  100. package/src/actor/conn/drivers/websocket.ts +129 -0
  101. package/src/actor/conn/mod.ts +232 -0
  102. package/src/actor/conn/persisted.ts +81 -0
  103. package/src/actor/conn/state-manager.ts +196 -0
  104. package/src/actor/contexts/action.ts +23 -0
  105. package/src/actor/{context.ts → contexts/actor.ts} +19 -8
  106. package/src/actor/contexts/conn-init.ts +31 -0
  107. package/src/actor/contexts/conn.ts +48 -0
  108. package/src/actor/contexts/create-conn-state.ts +13 -0
  109. package/src/actor/contexts/on-before-connect.ts +13 -0
  110. package/src/actor/contexts/on-connect.ts +22 -0
  111. package/src/actor/contexts/request.ts +48 -0
  112. package/src/actor/contexts/websocket.ts +48 -0
  113. package/src/actor/definition.ts +3 -3
  114. package/src/actor/driver.ts +36 -5
  115. package/src/actor/errors.ts +19 -24
  116. package/src/actor/instance/connection-manager.ts +465 -0
  117. package/src/actor/instance/event-manager.ts +292 -0
  118. package/src/actor/instance/kv.ts +15 -0
  119. package/src/actor/instance/mod.ts +1107 -0
  120. package/src/actor/instance/persisted.ts +67 -0
  121. package/src/actor/instance/schedule-manager.ts +349 -0
  122. package/src/actor/instance/state-manager.ts +502 -0
  123. package/src/actor/mod.ts +13 -16
  124. package/src/actor/protocol/old.ts +131 -43
  125. package/src/actor/protocol/serde.ts +19 -4
  126. package/src/actor/router-endpoints.ts +61 -586
  127. package/src/actor/router-websocket-endpoints.ts +408 -0
  128. package/src/actor/router.ts +63 -197
  129. package/src/actor/schedule.ts +1 -1
  130. package/src/client/actor-conn.ts +183 -249
  131. package/src/client/actor-handle.ts +29 -6
  132. package/src/client/client.ts +0 -4
  133. package/src/client/config.ts +1 -4
  134. package/src/client/mod.ts +0 -1
  135. package/src/client/raw-utils.ts +3 -3
  136. package/src/client/utils.ts +85 -39
  137. package/src/common/actor-router-consts.ts +5 -12
  138. package/src/common/{inline-websocket-adapter2.ts → inline-websocket-adapter.ts} +26 -48
  139. package/src/common/log.ts +1 -1
  140. package/src/common/router.ts +28 -17
  141. package/src/common/utils.ts +2 -0
  142. package/src/driver-helpers/mod.ts +7 -10
  143. package/src/driver-helpers/utils.ts +18 -9
  144. package/src/driver-test-suite/mod.ts +26 -50
  145. package/src/driver-test-suite/test-inline-client-driver.ts +27 -51
  146. package/src/driver-test-suite/tests/actor-conn-hibernation.ts +150 -0
  147. package/src/driver-test-suite/tests/actor-conn-state.ts +1 -4
  148. package/src/driver-test-suite/tests/actor-conn.ts +5 -9
  149. package/src/driver-test-suite/tests/actor-destroy.ts +294 -0
  150. package/src/driver-test-suite/tests/actor-driver.ts +0 -7
  151. package/src/driver-test-suite/tests/actor-handle.ts +12 -12
  152. package/src/driver-test-suite/tests/actor-metadata.ts +1 -1
  153. package/src/driver-test-suite/tests/manager-driver.ts +1 -1
  154. package/src/driver-test-suite/tests/raw-http-direct-registry.ts +8 -8
  155. package/src/driver-test-suite/tests/raw-http-request-properties.ts +6 -5
  156. package/src/driver-test-suite/tests/raw-http.ts +5 -5
  157. package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +7 -7
  158. package/src/driver-test-suite/tests/request-access.ts +4 -4
  159. package/src/driver-test-suite/utils.ts +6 -10
  160. package/src/drivers/engine/actor-driver.ts +614 -424
  161. package/src/drivers/engine/mod.ts +0 -1
  162. package/src/drivers/file-system/actor.ts +24 -12
  163. package/src/drivers/file-system/global-state.ts +427 -37
  164. package/src/drivers/file-system/manager.ts +71 -83
  165. package/src/drivers/file-system/mod.ts +3 -0
  166. package/src/drivers/file-system/utils.ts +18 -8
  167. package/src/engine-process/mod.ts +38 -38
  168. package/src/inspector/utils.ts +7 -5
  169. package/src/manager/driver.ts +11 -4
  170. package/src/manager/gateway.ts +4 -29
  171. package/src/manager/protocol/mod.ts +0 -2
  172. package/src/manager/protocol/query.ts +0 -4
  173. package/src/manager/router.ts +67 -64
  174. package/src/manager-api/actors.ts +13 -0
  175. package/src/mod.ts +1 -3
  176. package/src/registry/mod.ts +20 -20
  177. package/src/registry/serve.ts +9 -14
  178. package/src/remote-manager-driver/actor-websocket-client.ts +1 -16
  179. package/src/remote-manager-driver/api-endpoints.ts +13 -1
  180. package/src/remote-manager-driver/api-utils.ts +8 -0
  181. package/src/remote-manager-driver/metadata.ts +58 -0
  182. package/src/remote-manager-driver/mod.ts +47 -62
  183. package/src/remote-manager-driver/ws-proxy.ts +1 -1
  184. package/src/schemas/actor-persist/mod.ts +1 -1
  185. package/src/schemas/actor-persist/versioned.ts +56 -31
  186. package/src/schemas/client-protocol/mod.ts +1 -1
  187. package/src/schemas/client-protocol/versioned.ts +41 -21
  188. package/src/schemas/client-protocol-zod/mod.ts +103 -0
  189. package/src/schemas/file-system-driver/mod.ts +1 -1
  190. package/src/schemas/file-system-driver/versioned.ts +42 -19
  191. package/src/serde.ts +33 -11
  192. package/src/test/mod.ts +7 -3
  193. package/src/utils/node.ts +173 -0
  194. package/src/utils.ts +0 -4
  195. package/dist/tsup/chunk-3I6ZIJVJ.js.map +0 -1
  196. package/dist/tsup/chunk-3JYSUFET.cjs.map +0 -1
  197. package/dist/tsup/chunk-54DVMQPT.cjs.map +0 -1
  198. package/dist/tsup/chunk-5PKKNNNS.js.map +0 -1
  199. package/dist/tsup/chunk-C56XVVV4.cjs.map +0 -1
  200. package/dist/tsup/chunk-D6PCH7FR.cjs +0 -4623
  201. package/dist/tsup/chunk-D6PCH7FR.cjs.map +0 -1
  202. package/dist/tsup/chunk-DLYZKFRY.js.map +0 -1
  203. package/dist/tsup/chunk-FTQ62XTN.js.map +0 -1
  204. package/dist/tsup/chunk-G64QUEDJ.js.map +0 -1
  205. package/dist/tsup/chunk-HNYF4T36.cjs.map +0 -1
  206. package/dist/tsup/chunk-JMLTKMJ7.cjs +0 -1119
  207. package/dist/tsup/chunk-JMLTKMJ7.cjs.map +0 -1
  208. package/dist/tsup/chunk-KSRXX3Z4.cjs.map +0 -1
  209. package/dist/tsup/chunk-NOZSCUPQ.js.map +0 -1
  210. package/dist/tsup/chunk-PHNIVSG5.js.map +0 -1
  211. package/dist/tsup/chunk-RUTBXBRR.js +0 -1119
  212. package/dist/tsup/chunk-RUTBXBRR.js.map +0 -1
  213. package/dist/tsup/chunk-RVVUS4X6.js.map +0 -1
  214. package/dist/tsup/chunk-SN4KWTRA.cjs.map +0 -1
  215. package/dist/tsup/chunk-XSDSNHSE.cjs.map +0 -1
  216. package/dist/tsup/chunk-XYK5PY3B.cjs.map +0 -1
  217. package/dist/tsup/chunk-YAYNBR37.js.map +0 -1
  218. package/src/actor/action.ts +0 -178
  219. package/src/actor/conn-drivers.ts +0 -216
  220. package/src/actor/conn-socket.ts +0 -8
  221. package/src/actor/conn.ts +0 -272
  222. package/src/actor/instance.ts +0 -2336
  223. package/src/actor/persisted.ts +0 -49
  224. package/src/actor/unstable-react.ts +0 -110
  225. package/src/driver-test-suite/tests/actor-reconnect.ts +0 -170
  226. package/src/drivers/engine/kv.ts +0 -3
  227. package/src/manager/hono-websocket-adapter.ts +0 -393
  228. /package/dist/tsup/{chunk-5UJQWWO3.js.map → chunk-EIPANQMF.js.map} +0 -0
@@ -1,10 +1,9 @@
1
1
  import { serve as honoServe } from "@hono/node-server";
2
2
  import { createNodeWebSocket, type NodeWebSocket } from "@hono/node-ws";
3
- import { bundleRequire } from "bundle-require";
4
3
  import invariant from "invariant";
5
4
  import { describe } from "vitest";
6
5
  import { ClientConfigSchema } from "@/client/config";
7
- import type { Encoding, Transport } from "@/client/mod";
6
+ import type { Encoding } from "@/client/mod";
8
7
  import { configureInspectorAccessToken } from "@/inspector/utils";
9
8
  import { createManagerRouter } from "@/manager/router";
10
9
  import {
@@ -19,17 +18,15 @@ import { logger } from "./log";
19
18
  import { runActionFeaturesTests } from "./tests/action-features";
20
19
  import { runActorConnTests } from "./tests/actor-conn";
21
20
  import { runActorConnStateTests } from "./tests/actor-conn-state";
22
- import {
23
- runActorDriverTests,
24
- runActorDriverTestsWithTransport,
25
- } from "./tests/actor-driver";
21
+ import { runActorDestroyTests } from "./tests/actor-destroy";
22
+ import { runActorDriverTests } from "./tests/actor-driver";
26
23
  import { runActorErrorHandlingTests } from "./tests/actor-error-handling";
27
24
  import { runActorHandleTests } from "./tests/actor-handle";
25
+ import { runActorConnHibernationTests } from "./tests/actor-conn-hibernation";
28
26
  import { runActorInlineClientTests } from "./tests/actor-inline-client";
29
27
  import { runActorInspectorTests } from "./tests/actor-inspector";
30
28
  import { runActorMetadataTests } from "./tests/actor-metadata";
31
29
  import { runActorOnStateChangeTests } from "./tests/actor-onstatechange";
32
- import { runActorReconnectTests } from "./tests/actor-reconnect";
33
30
  import { runActorVarsTests } from "./tests/actor-vars";
34
31
  import { runManagerDriverTests } from "./tests/manager-driver";
35
32
  import { runRawHttpTests } from "./tests/raw-http";
@@ -40,7 +37,7 @@ import { runRequestAccessTests } from "./tests/request-access";
40
37
  export interface SkipTests {
41
38
  schedule?: boolean;
42
39
  sleep?: boolean;
43
- sse?: boolean;
40
+ hibernation?: boolean;
44
41
  inline?: boolean;
45
42
  }
46
43
 
@@ -59,8 +56,6 @@ export interface DriverTestConfig {
59
56
 
60
57
  skip?: SkipTests;
61
58
 
62
- transport?: Transport;
63
-
64
59
  encoding?: Encoding;
65
60
 
66
61
  clientType: ClientType;
@@ -86,10 +81,7 @@ export interface DriverDeployOutput {
86
81
 
87
82
  /** Runs all Vitest tests against the provided drivers. */
88
83
  export function runDriverTests(
89
- driverTestConfigPartial: Omit<
90
- DriverTestConfig,
91
- "clientType" | "transport" | "encoding"
92
- >,
84
+ driverTestConfigPartial: Omit<DriverTestConfig, "clientType" | "encoding">,
93
85
  ) {
94
86
  const clientTypes: ClientType[] = driverTestConfigPartial.skip?.inline
95
87
  ? ["http"]
@@ -109,37 +101,15 @@ export function runDriverTests(
109
101
  runActorDriverTests(driverTestConfig);
110
102
  runManagerDriverTests(driverTestConfig);
111
103
 
112
- const transports: Transport[] = driverTestConfig.skip?.sse
113
- ? ["websocket"]
114
- : ["websocket", "sse"];
115
- for (const transport of transports) {
116
- describe(`transport (${transport})`, () => {
117
- runActorConnTests({
118
- ...driverTestConfig,
119
- transport,
120
- });
121
-
122
- runActorConnStateTests({
123
- ...driverTestConfig,
124
- transport,
125
- });
126
-
127
- runActorReconnectTests({
128
- ...driverTestConfig,
129
- transport,
130
- });
131
-
132
- runRequestAccessTests({
133
- ...driverTestConfig,
134
- transport,
135
- });
136
-
137
- runActorDriverTestsWithTransport({
138
- ...driverTestConfig,
139
- transport,
140
- });
141
- });
142
- }
104
+ runActorConnTests(driverTestConfig);
105
+
106
+ runActorConnStateTests(driverTestConfig);
107
+
108
+ runActorConnHibernationTests(driverTestConfig);
109
+
110
+ runActorDestroyTests(driverTestConfig);
111
+
112
+ runRequestAccessTests(driverTestConfig);
143
113
 
144
114
  runActorHandleTests(driverTestConfig);
145
115
 
@@ -192,11 +162,17 @@ export async function createTestRuntime(
192
162
  cleanup?: () => Promise<void>;
193
163
  }>,
194
164
  ): Promise<DriverDeployOutput> {
195
- const {
196
- mod: { registry },
197
- } = await bundleRequire<{ registry: Registry<any> }>({
198
- filepath: registryPath,
199
- });
165
+ // Import using dynamic imports with vitest alias resolution
166
+ //
167
+ // Vitest is configured to resolve `import ... from "rivetkit"` to the
168
+ // appropriate source files
169
+ //
170
+ // We need to preserve the `import ... from "rivetkit"` in the fixtures so
171
+ // targets that run the server separately from the Vitest tests (such as
172
+ // Cloudflare Workers) still function.
173
+ const { registry } = (await import(registryPath)) as {
174
+ registry: Registry<any>;
175
+ };
200
176
 
201
177
  // TODO: Find a cleaner way of flagging an registry as test mode (ideally not in the config itself)
202
178
  // Force enable test
@@ -5,7 +5,6 @@ import type { WebSocket } from "ws";
5
5
  import type { Encoding } from "@/actor/protocol/serde";
6
6
  import { assertUnreachable } from "@/actor/utils";
7
7
  import { ActorError as ClientActorError } from "@/client/errors";
8
- import type { Transport } from "@/client/mod";
9
8
  import {
10
9
  HEADER_ACTOR_QUERY,
11
10
  HEADER_CONN_PARAMS,
@@ -13,9 +12,9 @@ import {
13
12
  WS_PROTOCOL_ACTOR,
14
13
  WS_PROTOCOL_CONN_PARAMS,
15
14
  WS_PROTOCOL_ENCODING,
16
- WS_PROTOCOL_PATH,
15
+ WS_PROTOCOL_STANDARD,
17
16
  WS_PROTOCOL_TARGET,
18
- WS_PROTOCOL_TRANSPORT,
17
+ WS_TEST_PROTOCOL_PATH,
19
18
  } from "@/common/actor-router-consts";
20
19
  import type { UniversalEventSource } from "@/common/eventsource-interface";
21
20
  import type { DeconstructedError } from "@/common/utils";
@@ -27,6 +26,7 @@ import {
27
26
  type GetOrCreateWithKeyInput,
28
27
  type GetWithKeyInput,
29
28
  HEADER_ACTOR_ID,
29
+ type ListActorsInput,
30
30
  type ManagerDisplayInformation,
31
31
  type ManagerDriver,
32
32
  } from "@/driver-helpers/mod";
@@ -37,7 +37,6 @@ import { logger } from "./log";
37
37
 
38
38
  export interface TestInlineDriverCallRequest {
39
39
  encoding: Encoding;
40
- transport: Transport;
41
40
  method: string;
42
41
  args: unknown[];
43
42
  }
@@ -56,46 +55,28 @@ export type TestInlineDriverCallResponse<T> =
56
55
  export function createTestInlineClientDriver(
57
56
  endpoint: string,
58
57
  encoding: Encoding,
59
- transport: Transport,
60
58
  ): ManagerDriver {
61
59
  return {
62
60
  getForId(input: GetForIdInput): Promise<ActorOutput | undefined> {
63
- return makeInlineRequest(
64
- endpoint,
65
- encoding,
66
- transport,
67
- "getForId",
68
- [input],
69
- );
61
+ return makeInlineRequest(endpoint, encoding, "getForId", [input]);
70
62
  },
71
63
  getWithKey(input: GetWithKeyInput): Promise<ActorOutput | undefined> {
72
- return makeInlineRequest(
73
- endpoint,
74
- encoding,
75
- transport,
76
- "getWithKey",
77
- [input],
78
- );
64
+ return makeInlineRequest(endpoint, encoding, "getWithKey", [input]);
79
65
  },
80
66
  getOrCreateWithKey(
81
67
  input: GetOrCreateWithKeyInput,
82
68
  ): Promise<ActorOutput> {
83
- return makeInlineRequest(
84
- endpoint,
85
- encoding,
86
- transport,
87
- "getOrCreateWithKey",
88
- [input],
89
- );
69
+ return makeInlineRequest(endpoint, encoding, "getOrCreateWithKey", [
70
+ input,
71
+ ]);
90
72
  },
91
73
  createActor(input: CreateInput): Promise<ActorOutput> {
92
- return makeInlineRequest(
93
- endpoint,
94
- encoding,
95
- transport,
96
- "createActor",
97
- [input],
98
- );
74
+ return makeInlineRequest(endpoint, encoding, "createActor", [
75
+ input,
76
+ ]);
77
+ },
78
+ listActors(input: ListActorsInput): Promise<ActorOutput[]> {
79
+ return makeInlineRequest(endpoint, encoding, "listActors", [input]);
99
80
  },
100
81
  async sendRequest(
101
82
  actorId: string,
@@ -153,7 +134,7 @@ export function createTestInlineClientDriver(
153
134
  if (errorData.error) {
154
135
  // Handle both error formats:
155
136
  // 1. { error: { code, message, metadata } } - structured format
156
- // 2. { error: "message" } - simple string format (from custom onFetch handlers)
137
+ // 2. { error: "message" } - simple string format (from custom onRequest handlers)
157
138
  if (typeof errorData.error === "object") {
158
139
  throw new ClientActorError(
159
140
  errorData.error.code,
@@ -162,7 +143,7 @@ export function createTestInlineClientDriver(
162
143
  );
163
144
  }
164
145
  // For simple string errors, just return the response as-is
165
- // This allows custom onFetch handlers to return their own error formats
146
+ // This allows custom onRequest handlers to return their own error formats
166
147
  }
167
148
  } catch (e) {
168
149
  // If it's not our error format, just return the response as-is
@@ -180,8 +161,6 @@ export function createTestInlineClientDriver(
180
161
  actorId: string,
181
162
  encoding: Encoding,
182
163
  params: unknown,
183
- connId?: string,
184
- connToken?: string,
185
164
  ): Promise<UniversalWebSocket> {
186
165
  const WebSocket = await importWebSocket();
187
166
 
@@ -202,16 +181,14 @@ export function createTestInlineClientDriver(
202
181
  const wsProtocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
203
182
  const finalWsUrl = `${wsProtocol}//${wsUrl.host}${wsUrl.pathname}`;
204
183
 
205
- logger().debug({ msg: "connecting to websocket", url: finalWsUrl });
206
-
207
184
  // Build protocols for the connection
208
185
  const protocols: string[] = [];
186
+ protocols.push(WS_PROTOCOL_STANDARD);
209
187
  protocols.push(`${WS_PROTOCOL_TARGET}actor`);
210
- protocols.push(`${WS_PROTOCOL_ACTOR}${actorId}`);
188
+ protocols.push(`${WS_PROTOCOL_ACTOR}${encodeURIComponent(actorId)}`);
211
189
  protocols.push(`${WS_PROTOCOL_ENCODING}${encoding}`);
212
- protocols.push(`${WS_PROTOCOL_TRANSPORT}${transport}`);
213
190
  protocols.push(
214
- `${WS_PROTOCOL_PATH}${encodeURIComponent(normalizedPath)}`,
191
+ `${WS_TEST_PROTOCOL_PATH}${encodeURIComponent(normalizedPath)}`,
215
192
  );
216
193
  if (params !== undefined) {
217
194
  protocols.push(
@@ -219,6 +196,12 @@ export function createTestInlineClientDriver(
219
196
  );
220
197
  }
221
198
 
199
+ logger().debug({
200
+ msg: "connecting to websocket",
201
+ url: finalWsUrl,
202
+ protocols,
203
+ });
204
+
222
205
  // Create and return the WebSocket
223
206
  // Node & browser WebSocket types are incompatible
224
207
  const ws = new WebSocket(finalWsUrl, protocols) as any;
@@ -263,7 +246,6 @@ export function createTestInlineClientDriver(
263
246
  // return makeInlineRequest<Response>(
264
247
  // endpoint,
265
248
  // encoding,
266
- // transport,
267
249
  // "action",
268
250
  // [undefined, actorQuery, encoding, params, name, args],
269
251
  // );
@@ -278,7 +260,6 @@ export function createTestInlineClientDriver(
278
260
  // return makeInlineRequest<string>(
279
261
  // endpoint,
280
262
  // encodingKind,
281
- // transport,
282
263
  // "resolveActorId",
283
264
  // [undefined, actorQuery, encodingKind, params],
284
265
  // );
@@ -400,7 +381,6 @@ export function createTestInlineClientDriver(
400
381
  // actorId,
401
382
  // encoding,
402
383
  // connectionId,
403
- // transport,
404
384
  // });
405
385
  //
406
386
  // const result = await fetch(
@@ -412,7 +392,6 @@ export function createTestInlineClientDriver(
412
392
  // },
413
393
  // body: JSON.stringify({
414
394
  // encoding,
415
- // transport,
416
395
  // method: "sendHttpMessage",
417
396
  // args: [
418
397
  // undefined,
@@ -483,7 +462,7 @@ export function createTestInlineClientDriver(
483
462
  // if (errorData.error) {
484
463
  // // Handle both error formats:
485
464
  // // 1. { error: { code, message, metadata } } - structured format
486
- // // 2. { error: "message" } - simple string format (from custom onFetch handlers)
465
+ // // 2. { error: "message" } - simple string format (from custom onRequest handlers)
487
466
  // if (typeof errorData.error === "object") {
488
467
  // throw new ClientActorError(
489
468
  // errorData.error.code,
@@ -492,7 +471,7 @@ export function createTestInlineClientDriver(
492
471
  // );
493
472
  // }
494
473
  // // For simple string errors, just return the response as-is
495
- // // This allows custom onFetch handlers to return their own error formats
474
+ // // This allows custom onRequest handlers to return their own error formats
496
475
  // }
497
476
  // } catch (e) {
498
477
  // // If it's not our error format, just return the response as-is
@@ -573,14 +552,12 @@ export function createTestInlineClientDriver(
573
552
  async function makeInlineRequest<T>(
574
553
  endpoint: string,
575
554
  encoding: Encoding,
576
- transport: Transport,
577
555
  method: string,
578
556
  args: unknown[],
579
557
  ): Promise<T> {
580
558
  logger().debug({
581
559
  msg: "sending inline request",
582
560
  encoding,
583
- transport,
584
561
  method,
585
562
  args,
586
563
  });
@@ -593,7 +570,6 @@ async function makeInlineRequest<T>(
593
570
  },
594
571
  body: cbor.encode({
595
572
  encoding,
596
- transport,
597
573
  method,
598
574
  args,
599
575
  } satisfies TestInlineDriverCallRequest),
@@ -0,0 +1,150 @@
1
+ import { describe, expect, test, vi } from "vitest";
2
+ import { HIBERNATION_SLEEP_TIMEOUT } from "../../../fixtures/driver-test-suite/hibernation";
3
+ import type { DriverTestConfig } from "../mod";
4
+ import { setupDriverTest, waitFor } from "../utils";
5
+
6
+ export function runActorConnHibernationTests(driverTestConfig: DriverTestConfig) {
7
+ describe.skipIf(driverTestConfig.skip?.hibernation)(
8
+ "Connection Hibernation",
9
+ () => {
10
+ test("basic conn hibernation", async (c) => {
11
+ const { client } = await setupDriverTest(c, driverTestConfig);
12
+
13
+ // Create actor with connection
14
+ const hibernatingActor = client.hibernationActor
15
+ .getOrCreate()
16
+ .connect();
17
+
18
+ // Initial RPC call
19
+ const ping1 = await hibernatingActor.ping();
20
+ expect(ping1).toBe("pong");
21
+
22
+ // Trigger sleep
23
+ await hibernatingActor.triggerSleep();
24
+
25
+ // Wait for actor to sleep (give it time to hibernate)
26
+ await waitFor(
27
+ driverTestConfig,
28
+ HIBERNATION_SLEEP_TIMEOUT + 100,
29
+ );
30
+
31
+ // Call RPC again - this should wake the actor and work
32
+ const ping2 = await hibernatingActor.ping();
33
+ expect(ping2).toBe("pong");
34
+
35
+ // Clean up
36
+ await hibernatingActor.dispose();
37
+ });
38
+
39
+ test("conn state persists through hibernation", async (c) => {
40
+ const { client } = await setupDriverTest(c, driverTestConfig);
41
+
42
+ // Create actor with connection
43
+ const hibernatingActor = client.hibernationActor
44
+ .getOrCreate()
45
+ .connect();
46
+
47
+ // Increment connection count
48
+ const count1 = await hibernatingActor.connIncrement();
49
+ expect(count1).toBe(1);
50
+
51
+ const count2 = await hibernatingActor.connIncrement();
52
+ expect(count2).toBe(2);
53
+
54
+ // Get initial lifecycle counts
55
+ const initialLifecycle =
56
+ await hibernatingActor.getConnLifecycleCounts();
57
+ expect(initialLifecycle.connectCount).toBe(1);
58
+ expect(initialLifecycle.disconnectCount).toBe(0);
59
+
60
+ // Get initial actor counts
61
+ const initialActorCounts =
62
+ await hibernatingActor.getActorCounts();
63
+ expect(initialActorCounts.wakeCount).toBe(1);
64
+ expect(initialActorCounts.sleepCount).toBe(0);
65
+
66
+ // Trigger sleep
67
+ await hibernatingActor.triggerSleep();
68
+
69
+ // Wait for actor to sleep
70
+ await waitFor(
71
+ driverTestConfig,
72
+ HIBERNATION_SLEEP_TIMEOUT + 100,
73
+ );
74
+
75
+ // Check that connection state persisted
76
+ const count3 = await hibernatingActor.getConnCount();
77
+ expect(count3).toBe(2);
78
+
79
+ // Verify lifecycle hooks:
80
+ // - onDisconnect and onConnect should NOT be called during sleep/wake
81
+ // - onSleep and onWake should be called
82
+ const finalLifecycle =
83
+ await hibernatingActor.getConnLifecycleCounts();
84
+ expect(finalLifecycle.connectCount).toBe(1); // No additional connects
85
+ expect(finalLifecycle.disconnectCount).toBe(0); // No disconnects
86
+
87
+ const finalActorCounts =
88
+ await hibernatingActor.getActorCounts();
89
+ expect(finalActorCounts.wakeCount).toBe(2); // Woke up once more
90
+ expect(finalActorCounts.sleepCount).toBe(1); // Slept once
91
+
92
+ // Clean up
93
+ await hibernatingActor.dispose();
94
+ });
95
+
96
+ test("closing connection during hibernation", async (c) => {
97
+ const { client } = await setupDriverTest(c, driverTestConfig);
98
+
99
+ // Create actor with first connection
100
+ const conn1 = client.hibernationActor.getOrCreate().connect();
101
+
102
+ // Initial RPC call
103
+ await conn1.ping();
104
+
105
+ // Get connection ID
106
+ const connectionIds = await conn1.getConnectionIds();
107
+ expect(connectionIds.length).toBe(1);
108
+ const conn1Id = connectionIds[0];
109
+
110
+ // Trigger sleep
111
+ await conn1.triggerSleep();
112
+
113
+ // Wait for actor to hibernate
114
+ await waitFor(
115
+ driverTestConfig,
116
+ HIBERNATION_SLEEP_TIMEOUT + 100,
117
+ );
118
+
119
+ // Disconnect first connection while actor is sleeping
120
+ await conn1.dispose();
121
+
122
+ // Wait a bit for disconnection to be processed
123
+ await waitFor(driverTestConfig, 250);
124
+
125
+ // Create second connection to verify first connection disconnected
126
+ const conn2 = client.hibernationActor.getOrCreate().connect();
127
+
128
+ // Wait for connection to be established
129
+ await vi.waitFor(
130
+ async () => {
131
+ const newConnectionIds = await conn2.getConnectionIds();
132
+ expect(newConnectionIds.length).toBe(1);
133
+ expect(newConnectionIds[0]).not.toBe(conn1Id);
134
+ },
135
+ {
136
+ timeout: 5000,
137
+ interval: 100,
138
+ },
139
+ );
140
+
141
+ // Verify onDisconnect was called for the first connection
142
+ const lifecycle = await conn2.getConnLifecycleCounts();
143
+ expect(lifecycle.disconnectCount).toBe(0); // Only for conn2, not conn1
144
+
145
+ // Clean up
146
+ await conn2.dispose();
147
+ });
148
+ },
149
+ );
150
+ }
@@ -147,10 +147,7 @@ export function runActorConnStateTests(driverTestConfig: DriverTestConfig) {
147
147
  });
148
148
 
149
149
  describe("Connection Lifecycle", () => {
150
- test.skipIf(
151
- driverTestConfig.transport === "sse" &&
152
- driverTestConfig.clientType === "inline",
153
- )("should track connection and disconnection events", async (c) => {
150
+ test("should track connection and disconnection events", async (c) => {
154
151
  const { client } = await setupDriverTest(c, driverTestConfig);
155
152
 
156
153
  const debugHandle = client.connStateActor.getOrCreate(
@@ -1,5 +1,4 @@
1
1
  import { describe, expect, test, vi } from "vitest";
2
- import { SSE_PING_INTERVAL } from "@/actor/router-endpoints";
3
2
  import type { DriverTestConfig } from "../mod";
4
3
  import { FAKE_TIME, setupDriverTest, waitFor } from "../utils";
5
4
 
@@ -247,10 +246,7 @@ export function runActorConnTests(driverTestConfig: DriverTestConfig) {
247
246
  });
248
247
 
249
248
  describe("Lifecycle Hooks", () => {
250
- test.skipIf(
251
- driverTestConfig.transport === "sse" &&
252
- driverTestConfig.clientType === "inline",
253
- )("should trigger lifecycle hooks", async (c) => {
249
+ test("should trigger lifecycle hooks", async (c) => {
254
250
  const { client } = await setupDriverTest(c, driverTestConfig);
255
251
 
256
252
  // Create and connect
@@ -265,7 +261,7 @@ export function runActorConnTests(driverTestConfig: DriverTestConfig) {
265
261
  // Verify lifecycle events were triggered
266
262
  const events = await connection.getEvents();
267
263
  expect(events).toEqual([
268
- "onStart",
264
+ "onWake",
269
265
  "onBeforeConnect",
270
266
  "onConnect",
271
267
  ]);
@@ -283,18 +279,18 @@ export function runActorConnTests(driverTestConfig: DriverTestConfig) {
283
279
  expect(finalEvents).toBeOneOf([
284
280
  // Still active
285
281
  [
286
- "onStart",
282
+ "onWake",
287
283
  "onBeforeConnect",
288
284
  "onConnect",
289
285
  "onDisconnect",
290
286
  ],
291
287
  // Went to sleep and woke back up
292
288
  [
293
- "onStart",
289
+ "onWake",
294
290
  "onBeforeConnect",
295
291
  "onConnect",
296
292
  "onDisconnect",
297
- "onStart",
293
+ "onWake",
298
294
  ],
299
295
  ]);
300
296
  },