@rivetkit/effect 0.0.0-06-09-refactor-rivetkit-split-workflow-context-into-workflowcontext-workflowstepcontext.e0c9540 → 0.0.0-bisect-sync-sqlite-1.910d1c7
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.
- package/dist/Action.d.ts +1 -1
- package/dist/Action.js +1 -1
- package/dist/Actor.d.ts +28 -4
- package/dist/Actor.d.ts.map +1 -1
- package/dist/Actor.js +3 -2
- package/dist/Actor.js.map +1 -1
- package/dist/Client.d.ts.map +1 -1
- package/dist/Client.js +6 -4
- package/dist/Client.js.map +1 -1
- package/dist/Registry.d.ts +70 -8
- package/dist/Registry.d.ts.map +1 -1
- package/dist/Registry.js +93 -41
- package/dist/Registry.js.map +1 -1
- package/dist/RivetError.d.ts +61 -3
- package/dist/RivetError.d.ts.map +1 -1
- package/dist/RivetError.js +171 -25
- package/dist/RivetError.js.map +1 -1
- package/dist/RivetLogger.d.ts +41 -0
- package/dist/RivetLogger.d.ts.map +1 -0
- package/dist/RivetLogger.js +41 -0
- package/dist/RivetLogger.js.map +1 -0
- package/dist/State.d.ts +92 -56
- package/dist/State.d.ts.map +1 -1
- package/dist/State.js +51 -57
- package/dist/State.js.map +1 -1
- package/dist/internal/ActionDispatcher.d.ts +3 -3
- package/dist/internal/ActionDispatcher.d.ts.map +1 -1
- package/dist/internal/ActionDispatcher.js +23 -1
- package/dist/internal/ActionDispatcher.js.map +1 -1
- package/dist/internal/ActorInstanceManager.d.ts +7 -0
- package/dist/internal/ActorInstanceManager.d.ts.map +1 -1
- package/dist/internal/ActorInstanceManager.js +44 -4
- package/dist/internal/ActorInstanceManager.js.map +1 -1
- package/dist/internal/ActorStateAdapter.d.ts +1 -1
- package/dist/internal/ActorStateAdapter.d.ts.map +1 -1
- package/dist/internal/ActorStateAdapter.js +2 -7
- package/dist/internal/ActorStateAdapter.js.map +1 -1
- package/dist/internal/StateOptions.d.ts +1 -0
- package/dist/internal/StateOptions.d.ts.map +1 -1
- package/dist/internal/logging.d.ts +6 -7
- package/dist/internal/logging.d.ts.map +1 -1
- package/dist/internal/logging.js +78 -102
- package/dist/internal/logging.js.map +1 -1
- package/dist/mod.d.ts +2 -1
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +2 -1
- package/dist/mod.js.map +1 -1
- package/package.json +14 -7
- package/src/Action.ts +1 -1
- package/src/Actor.ts +57 -4
- package/src/Client.ts +6 -4
- package/src/Registry.ts +132 -71
- package/src/RivetError.ts +184 -25
- package/src/RivetLogger.ts +60 -0
- package/src/State.ts +293 -97
- package/src/internal/ActionDispatcher.ts +37 -9
- package/src/internal/ActorInstanceManager.ts +85 -37
- package/src/internal/ActorStateAdapter.ts +5 -11
- package/src/internal/StateOptions.ts +4 -0
- package/src/internal/logging.ts +103 -143
- package/src/mod.ts +2 -1
- package/dist/Logger.d.ts +0 -29
- package/dist/Logger.d.ts.map +0 -1
- package/dist/Logger.js +0 -31
- package/dist/Logger.js.map +0 -1
- package/src/Actor.test-d.ts +0 -603
- package/src/Actor.test.ts +0 -206
- package/src/Client.test.ts +0 -210
- package/src/Logger.ts +0 -43
- package/src/Registry.test-d.ts +0 -126
- package/src/Registry.test.ts +0 -411
- package/src/RivetError.test.ts +0 -188
- package/src/State.test.ts +0 -181
- package/src/internal/logging.test.ts +0 -288
package/src/Registry.test.ts
DELETED
|
@@ -1,411 +0,0 @@
|
|
|
1
|
-
import { assert, describe, it } from "@effect/vitest";
|
|
2
|
-
import { Action, Actor, Logger, Registry } from "@rivetkit/effect";
|
|
3
|
-
import { Effect, Layer } from "effect";
|
|
4
|
-
import { HttpEffect } from "effect/unstable/http";
|
|
5
|
-
import {
|
|
6
|
-
configureDefaultLogger,
|
|
7
|
-
getBaseLogger,
|
|
8
|
-
type Logger as PinoLogger,
|
|
9
|
-
} from "rivetkit/log";
|
|
10
|
-
import { vi } from "vitest";
|
|
11
|
-
|
|
12
|
-
const TestActor = Actor.make("TestActor", {
|
|
13
|
-
actions: [Action.make("Test")],
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const TestActorLive = TestActor.toLayer({
|
|
17
|
-
Test: () => Effect.void,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const ActorsLayer = Layer.mergeAll(TestActorLive);
|
|
21
|
-
|
|
22
|
-
const RegistryLive = ActorsLayer.pipe(
|
|
23
|
-
Layer.provideMerge(
|
|
24
|
-
Registry.layer({
|
|
25
|
-
endpoint: "http://127.0.0.1:6420",
|
|
26
|
-
noWelcome: true,
|
|
27
|
-
}),
|
|
28
|
-
),
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
function makeTestLogger(): PinoLogger {
|
|
32
|
-
const logger: Record<string, unknown> = {
|
|
33
|
-
level: "debug",
|
|
34
|
-
child: () => logger,
|
|
35
|
-
};
|
|
36
|
-
for (const level of [
|
|
37
|
-
"trace",
|
|
38
|
-
"debug",
|
|
39
|
-
"info",
|
|
40
|
-
"warn",
|
|
41
|
-
"error",
|
|
42
|
-
"fatal",
|
|
43
|
-
]) {
|
|
44
|
-
logger[level] = (): void => {};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return logger as unknown as PinoLogger;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
describe("Registry.toWebHandler", () => {
|
|
51
|
-
it("serves registered actors as a Fetch handler", async () => {
|
|
52
|
-
const { handler, dispose } = Registry.toWebHandler(RegistryLive);
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
const response = await handler(
|
|
56
|
-
new Request("http://runner.test/api/rivet/metadata"),
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
assert.strictEqual(response.status, 200);
|
|
60
|
-
const body = (await response.json()) as {
|
|
61
|
-
readonly actorNames: Record<string, unknown>;
|
|
62
|
-
};
|
|
63
|
-
assert.ok(body.actorNames.TestActor);
|
|
64
|
-
} finally {
|
|
65
|
-
await dispose();
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("uses a custom serverless base path", async () => {
|
|
70
|
-
const { handler, dispose } = Registry.toWebHandler(RegistryLive, {
|
|
71
|
-
basePath: "/",
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
const response = await handler(
|
|
76
|
-
new Request("http://runner.test/metadata"),
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
assert.strictEqual(response.status, 200);
|
|
80
|
-
const body = (await response.json()) as {
|
|
81
|
-
readonly actorNames: Record<string, unknown>;
|
|
82
|
-
};
|
|
83
|
-
assert.ok(body.actorNames.TestActor);
|
|
84
|
-
} finally {
|
|
85
|
-
await dispose();
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("uses the custom base path to identify start requests", async () => {
|
|
90
|
-
const { handler, dispose } = Registry.toWebHandler(RegistryLive, {
|
|
91
|
-
basePath: "/custom",
|
|
92
|
-
maxStartPayloadBytes: 1,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
const defaultPrefix = await handler(
|
|
97
|
-
new Request("http://runner.test/api/rivet/start", {
|
|
98
|
-
method: "POST",
|
|
99
|
-
body: new Uint8Array([1, 2]),
|
|
100
|
-
}),
|
|
101
|
-
);
|
|
102
|
-
assert.notStrictEqual(defaultPrefix.status, 413);
|
|
103
|
-
|
|
104
|
-
const customPrefix = await handler(
|
|
105
|
-
new Request("http://runner.test/custom/start", {
|
|
106
|
-
method: "POST",
|
|
107
|
-
body: new Uint8Array([1, 2]),
|
|
108
|
-
}),
|
|
109
|
-
);
|
|
110
|
-
assert.strictEqual(customPrefix.status, 413);
|
|
111
|
-
const body = (await customPrefix.json()) as {
|
|
112
|
-
readonly group: string;
|
|
113
|
-
readonly code: string;
|
|
114
|
-
readonly message: string;
|
|
115
|
-
};
|
|
116
|
-
assert.deepStrictEqual(
|
|
117
|
-
{ group: body.group, code: body.code },
|
|
118
|
-
{ group: "message", code: "incoming_too_long" },
|
|
119
|
-
);
|
|
120
|
-
assert.match(body.message, /limit is 1 bytes/);
|
|
121
|
-
} finally {
|
|
122
|
-
await dispose();
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("uses a custom serverless start payload size limit", async () => {
|
|
127
|
-
const { handler, dispose } = Registry.toWebHandler(RegistryLive, {
|
|
128
|
-
maxStartPayloadBytes: 1,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
const response = await handler(
|
|
133
|
-
new Request("http://runner.test/api/rivet/start", {
|
|
134
|
-
method: "POST",
|
|
135
|
-
body: new Uint8Array([1, 2]),
|
|
136
|
-
}),
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
assert.strictEqual(response.status, 413);
|
|
140
|
-
const body = (await response.json()) as {
|
|
141
|
-
readonly group: string;
|
|
142
|
-
readonly code: string;
|
|
143
|
-
readonly message: string;
|
|
144
|
-
};
|
|
145
|
-
assert.deepStrictEqual(
|
|
146
|
-
{ group: body.group, code: body.code },
|
|
147
|
-
{ group: "message", code: "incoming_too_long" },
|
|
148
|
-
);
|
|
149
|
-
assert.match(body.message, /limit is 1 bytes/);
|
|
150
|
-
} finally {
|
|
151
|
-
await dispose();
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("does not print the welcome banner when disabled", async () => {
|
|
156
|
-
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
157
|
-
const { handler, dispose } = Registry.toWebHandler(RegistryLive);
|
|
158
|
-
|
|
159
|
-
try {
|
|
160
|
-
const response = await handler(
|
|
161
|
-
new Request("http://runner.test/api/rivet/metadata"),
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
assert.strictEqual(response.status, 200);
|
|
165
|
-
assert.strictEqual(log.mock.calls.length, 0);
|
|
166
|
-
} finally {
|
|
167
|
-
await dispose();
|
|
168
|
-
log.mockRestore();
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("builds the registry layer once across requests", async () => {
|
|
173
|
-
let builds = 0;
|
|
174
|
-
const CountingRegistryLive = Layer.mergeAll(
|
|
175
|
-
RegistryLive,
|
|
176
|
-
Layer.effectDiscard(
|
|
177
|
-
Effect.sync(() => {
|
|
178
|
-
builds += 1;
|
|
179
|
-
}),
|
|
180
|
-
),
|
|
181
|
-
);
|
|
182
|
-
const { handler, dispose } =
|
|
183
|
-
Registry.toWebHandler(CountingRegistryLive);
|
|
184
|
-
|
|
185
|
-
try {
|
|
186
|
-
const first = await handler(
|
|
187
|
-
new Request("http://runner.test/api/rivet/metadata"),
|
|
188
|
-
);
|
|
189
|
-
const second = await handler(
|
|
190
|
-
new Request("http://runner.test/api/rivet/metadata"),
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
assert.strictEqual(first.status, 200);
|
|
194
|
-
assert.strictEqual(second.status, 200);
|
|
195
|
-
assert.strictEqual(builds, 1);
|
|
196
|
-
} finally {
|
|
197
|
-
await dispose();
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("initializes the underlying RivetKit registry once across requests", async () => {
|
|
202
|
-
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
203
|
-
const WelcomeRegistryLive = ActorsLayer.pipe(
|
|
204
|
-
Layer.provideMerge(
|
|
205
|
-
Registry.layer({
|
|
206
|
-
endpoint: "http://127.0.0.1:6420",
|
|
207
|
-
}),
|
|
208
|
-
),
|
|
209
|
-
);
|
|
210
|
-
const { handler, dispose } =
|
|
211
|
-
Registry.toWebHandler(WelcomeRegistryLive);
|
|
212
|
-
|
|
213
|
-
try {
|
|
214
|
-
const first = await handler(
|
|
215
|
-
new Request("http://runner.test/api/rivet/metadata"),
|
|
216
|
-
);
|
|
217
|
-
const callsAfterFirst = log.mock.calls.length;
|
|
218
|
-
const second = await handler(
|
|
219
|
-
new Request("http://runner.test/api/rivet/metadata"),
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
assert.strictEqual(first.status, 200);
|
|
223
|
-
assert.strictEqual(second.status, 200);
|
|
224
|
-
assert.ok(callsAfterFirst > 0);
|
|
225
|
-
assert.strictEqual(log.mock.calls.length, callsAfterFirst);
|
|
226
|
-
} finally {
|
|
227
|
-
await dispose();
|
|
228
|
-
log.mockRestore();
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it("uses a custom logger layer for the underlying RivetKit registry", async () => {
|
|
233
|
-
const baseLogger = makeTestLogger();
|
|
234
|
-
const CustomLoggerRegistryLive = RegistryLive.pipe(
|
|
235
|
-
Layer.provide(Logger.layerPino(baseLogger)),
|
|
236
|
-
);
|
|
237
|
-
const { handler, dispose } =
|
|
238
|
-
Registry.toWebHandler(CustomLoggerRegistryLive);
|
|
239
|
-
|
|
240
|
-
try {
|
|
241
|
-
const response = await handler(
|
|
242
|
-
new Request("http://runner.test/api/rivet/metadata"),
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
assert.strictEqual(response.status, 200);
|
|
246
|
-
assert.strictEqual(getBaseLogger(), baseLogger);
|
|
247
|
-
} finally {
|
|
248
|
-
await dispose();
|
|
249
|
-
configureDefaultLogger("silent");
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it("closes registry layer finalizers on dispose", async () => {
|
|
254
|
-
let finalizers = 0;
|
|
255
|
-
const FinalizedRegistryLive = Layer.mergeAll(
|
|
256
|
-
RegistryLive,
|
|
257
|
-
Layer.effectDiscard(
|
|
258
|
-
Effect.addFinalizer(() =>
|
|
259
|
-
Effect.sync(() => {
|
|
260
|
-
finalizers += 1;
|
|
261
|
-
}),
|
|
262
|
-
),
|
|
263
|
-
),
|
|
264
|
-
);
|
|
265
|
-
const { handler, dispose } = Registry.toWebHandler(
|
|
266
|
-
FinalizedRegistryLive,
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
try {
|
|
270
|
-
const response = await handler(
|
|
271
|
-
new Request("http://runner.test/api/rivet/metadata"),
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
assert.strictEqual(response.status, 200);
|
|
275
|
-
assert.strictEqual(finalizers, 0);
|
|
276
|
-
} finally {
|
|
277
|
-
await dispose();
|
|
278
|
-
}
|
|
279
|
-
assert.strictEqual(finalizers, 1);
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
describe("Registry.toHttpEffect", () => {
|
|
284
|
-
it.effect("serves registered actors as an Effect HTTP handler", () =>
|
|
285
|
-
Effect.scoped(
|
|
286
|
-
Effect.gen(function* () {
|
|
287
|
-
const httpEffect = yield* Registry.toHttpEffect(RegistryLive);
|
|
288
|
-
const handler = HttpEffect.toWebHandler(httpEffect);
|
|
289
|
-
const response = yield* Effect.promise(() =>
|
|
290
|
-
handler(
|
|
291
|
-
new Request("http://runner.test/api/rivet/metadata"),
|
|
292
|
-
),
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
yield* Effect.promise(() =>
|
|
296
|
-
(async (response: Response) => {
|
|
297
|
-
assert.strictEqual(response.status, 200);
|
|
298
|
-
const body = (await response.json()) as {
|
|
299
|
-
readonly actorNames: Record<string, unknown>;
|
|
300
|
-
};
|
|
301
|
-
assert.ok(body.actorNames.TestActor);
|
|
302
|
-
})(response),
|
|
303
|
-
);
|
|
304
|
-
}),
|
|
305
|
-
),
|
|
306
|
-
);
|
|
307
|
-
|
|
308
|
-
it.effect("uses a custom serverless base path", () =>
|
|
309
|
-
Effect.scoped(
|
|
310
|
-
Effect.gen(function* () {
|
|
311
|
-
const httpEffect = yield* Registry.toHttpEffect(RegistryLive, {
|
|
312
|
-
basePath: "/",
|
|
313
|
-
});
|
|
314
|
-
const handler = HttpEffect.toWebHandler(httpEffect);
|
|
315
|
-
const response = yield* Effect.promise(() =>
|
|
316
|
-
handler(new Request("http://runner.test/metadata")),
|
|
317
|
-
);
|
|
318
|
-
|
|
319
|
-
yield* Effect.promise(() =>
|
|
320
|
-
(async (response: Response) => {
|
|
321
|
-
assert.strictEqual(response.status, 200);
|
|
322
|
-
const body = (await response.json()) as {
|
|
323
|
-
readonly actorNames: Record<string, unknown>;
|
|
324
|
-
};
|
|
325
|
-
assert.ok(body.actorNames.TestActor);
|
|
326
|
-
})(response),
|
|
327
|
-
);
|
|
328
|
-
}),
|
|
329
|
-
),
|
|
330
|
-
);
|
|
331
|
-
|
|
332
|
-
it.effect("uses the custom base path to identify start requests", () =>
|
|
333
|
-
Effect.scoped(
|
|
334
|
-
Effect.gen(function* () {
|
|
335
|
-
const httpEffect = yield* Registry.toHttpEffect(RegistryLive, {
|
|
336
|
-
basePath: "/custom",
|
|
337
|
-
maxStartPayloadBytes: 1,
|
|
338
|
-
});
|
|
339
|
-
const handler = HttpEffect.toWebHandler(httpEffect);
|
|
340
|
-
const defaultPrefix = yield* Effect.promise(() =>
|
|
341
|
-
handler(
|
|
342
|
-
new Request("http://runner.test/api/rivet/start", {
|
|
343
|
-
method: "POST",
|
|
344
|
-
body: new Uint8Array([1, 2]),
|
|
345
|
-
}),
|
|
346
|
-
),
|
|
347
|
-
);
|
|
348
|
-
assert.notStrictEqual(defaultPrefix.status, 413);
|
|
349
|
-
|
|
350
|
-
const customPrefix = yield* Effect.promise(() =>
|
|
351
|
-
handler(
|
|
352
|
-
new Request("http://runner.test/custom/start", {
|
|
353
|
-
method: "POST",
|
|
354
|
-
body: new Uint8Array([1, 2]),
|
|
355
|
-
}),
|
|
356
|
-
),
|
|
357
|
-
);
|
|
358
|
-
yield* Effect.promise(() =>
|
|
359
|
-
(async (response: Response) => {
|
|
360
|
-
assert.strictEqual(response.status, 413);
|
|
361
|
-
const body = (await response.json()) as {
|
|
362
|
-
readonly group: string;
|
|
363
|
-
readonly code: string;
|
|
364
|
-
readonly message: string;
|
|
365
|
-
};
|
|
366
|
-
assert.deepStrictEqual(
|
|
367
|
-
{ group: body.group, code: body.code },
|
|
368
|
-
{ group: "message", code: "incoming_too_long" },
|
|
369
|
-
);
|
|
370
|
-
assert.match(body.message, /limit is 1 bytes/);
|
|
371
|
-
})(customPrefix),
|
|
372
|
-
);
|
|
373
|
-
}),
|
|
374
|
-
),
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
it.effect("uses a custom serverless start payload size limit", () =>
|
|
378
|
-
Effect.scoped(
|
|
379
|
-
Effect.gen(function* () {
|
|
380
|
-
const httpEffect = yield* Registry.toHttpEffect(RegistryLive, {
|
|
381
|
-
maxStartPayloadBytes: 1,
|
|
382
|
-
});
|
|
383
|
-
const handler = HttpEffect.toWebHandler(httpEffect);
|
|
384
|
-
const response = yield* Effect.promise(() =>
|
|
385
|
-
handler(
|
|
386
|
-
new Request("http://runner.test/api/rivet/start", {
|
|
387
|
-
method: "POST",
|
|
388
|
-
body: new Uint8Array([1, 2]),
|
|
389
|
-
}),
|
|
390
|
-
),
|
|
391
|
-
);
|
|
392
|
-
|
|
393
|
-
yield* Effect.promise(() =>
|
|
394
|
-
(async (response: Response) => {
|
|
395
|
-
assert.strictEqual(response.status, 413);
|
|
396
|
-
const body = (await response.json()) as {
|
|
397
|
-
readonly group: string;
|
|
398
|
-
readonly code: string;
|
|
399
|
-
readonly message: string;
|
|
400
|
-
};
|
|
401
|
-
assert.deepStrictEqual(
|
|
402
|
-
{ group: body.group, code: body.code },
|
|
403
|
-
{ group: "message", code: "incoming_too_long" },
|
|
404
|
-
);
|
|
405
|
-
assert.match(body.message, /limit is 1 bytes/);
|
|
406
|
-
})(response),
|
|
407
|
-
);
|
|
408
|
-
}),
|
|
409
|
-
),
|
|
410
|
-
);
|
|
411
|
-
});
|
package/src/RivetError.test.ts
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { assert, describe, it } from "@effect/vitest";
|
|
2
|
-
import { RivetError } from "@rivetkit/effect";
|
|
3
|
-
import { Duration, Effect, Schema } from "effect";
|
|
4
|
-
import * as RivetkitErrors from "rivetkit/errors";
|
|
5
|
-
|
|
6
|
-
describe("RivetError", () => {
|
|
7
|
-
it("preserves non-Rivet causes as UnknownError", () => {
|
|
8
|
-
const cause = new Error("plain failure");
|
|
9
|
-
const error = RivetError.fromUnknown(cause);
|
|
10
|
-
|
|
11
|
-
assert.instanceOf(error, RivetError.RivetError);
|
|
12
|
-
assert.instanceOf(error.reason, RivetError.UnknownError);
|
|
13
|
-
assert.strictEqual(error.reason.message, "plain failure");
|
|
14
|
-
assert.strictEqual(error.reason.cause, cause);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("allows UnknownError to wrap arbitrary causes", () => {
|
|
18
|
-
const cause = { group: "not-a-rivet-error", code: 123 };
|
|
19
|
-
const error = new RivetError.UnknownError({
|
|
20
|
-
message: "malformed failure",
|
|
21
|
-
cause,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
assert.strictEqual(error.cause, cause);
|
|
25
|
-
assert.strictEqual(error.group, undefined);
|
|
26
|
-
assert.strictEqual(error.code, undefined);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("keeps structured Rivet errors classified by group and code", () => {
|
|
30
|
-
const cause = new RivetkitErrors.RivetError(
|
|
31
|
-
"rivetkit",
|
|
32
|
-
RivetkitErrors.INTERNAL_ERROR_CODE,
|
|
33
|
-
"internal failure",
|
|
34
|
-
);
|
|
35
|
-
const error = RivetError.fromUnknown(cause);
|
|
36
|
-
|
|
37
|
-
assert.instanceOf(error.reason, RivetError.InternalError);
|
|
38
|
-
assert.strictEqual(error.reason.group, cause.group);
|
|
39
|
-
assert.strictEqual(error.reason.code, cause.code);
|
|
40
|
-
assert.strictEqual(error.reason.message, cause.message);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("exposes normalized isRetryable on every reason", () => {
|
|
44
|
-
const restarting = RivetError.fromUnknown(
|
|
45
|
-
new RivetkitErrors.RivetError("actor", "restarting", "restarting"),
|
|
46
|
-
);
|
|
47
|
-
const forbidden = RivetError.fromUnknown(
|
|
48
|
-
new RivetkitErrors.RivetError("auth", "forbidden", "forbidden"),
|
|
49
|
-
);
|
|
50
|
-
const overloaded = RivetError.fromUnknown(
|
|
51
|
-
new RivetkitErrors.RivetError("actor", "overloaded", "overloaded"),
|
|
52
|
-
);
|
|
53
|
-
const serviceUnavailable = RivetError.fromUnknown(
|
|
54
|
-
new RivetkitErrors.RivetError(
|
|
55
|
-
"guard",
|
|
56
|
-
"service_unavailable",
|
|
57
|
-
"service unavailable",
|
|
58
|
-
),
|
|
59
|
-
);
|
|
60
|
-
const incomingTooLong = RivetError.fromUnknown(
|
|
61
|
-
new RivetkitErrors.RivetError(
|
|
62
|
-
"message",
|
|
63
|
-
"incoming_too_long",
|
|
64
|
-
"too long",
|
|
65
|
-
),
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
assert.strictEqual(restarting.isRetryable, true);
|
|
69
|
-
assert.strictEqual(restarting.reason.isRetryable, true);
|
|
70
|
-
assert.strictEqual(forbidden.isRetryable, false);
|
|
71
|
-
assert.strictEqual(overloaded.isRetryable, true);
|
|
72
|
-
assert.strictEqual(serviceUnavailable.isRetryable, true);
|
|
73
|
-
assert.strictEqual(incomingTooLong.isRetryable, false);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("exposes retryAfter from ActorRestarting metadata", () => {
|
|
77
|
-
const restarting = RivetError.fromUnknown(
|
|
78
|
-
new RivetkitErrors.RivetError(
|
|
79
|
-
"actor",
|
|
80
|
-
"restarting",
|
|
81
|
-
"actor restarting",
|
|
82
|
-
{ metadata: { retryAfterMs: 250 } },
|
|
83
|
-
),
|
|
84
|
-
);
|
|
85
|
-
const restartingNoHint = RivetError.fromUnknown(
|
|
86
|
-
new RivetkitErrors.RivetError(
|
|
87
|
-
"actor",
|
|
88
|
-
"restarting",
|
|
89
|
-
"actor restarting",
|
|
90
|
-
),
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
assert.instanceOf(restarting.reason, RivetError.ActorRestarting);
|
|
94
|
-
assert.deepStrictEqual(restarting.retryAfter, Duration.millis(250));
|
|
95
|
-
assert.deepStrictEqual(
|
|
96
|
-
restarting.reason.retryAfter,
|
|
97
|
-
Duration.millis(250),
|
|
98
|
-
);
|
|
99
|
-
assert.strictEqual(restartingNoHint.retryAfter, undefined);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("returns retryAfter undefined for reasons without retry-timing hints", () => {
|
|
103
|
-
const overloaded = RivetError.fromUnknown(
|
|
104
|
-
new RivetkitErrors.RivetError("actor", "overloaded", "overloaded"),
|
|
105
|
-
);
|
|
106
|
-
assert.strictEqual(overloaded.retryAfter, undefined);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("classifies known guard errors into specific reasons", () => {
|
|
110
|
-
const serviceUnavailable = RivetError.fromUnknown(
|
|
111
|
-
new RivetkitErrors.RivetError(
|
|
112
|
-
"guard",
|
|
113
|
-
"service_unavailable",
|
|
114
|
-
"service unavailable",
|
|
115
|
-
),
|
|
116
|
-
);
|
|
117
|
-
const readyTimeout = RivetError.fromUnknown(
|
|
118
|
-
new RivetkitErrors.RivetError(
|
|
119
|
-
"guard",
|
|
120
|
-
"actor_ready_timeout",
|
|
121
|
-
"actor ready timeout",
|
|
122
|
-
),
|
|
123
|
-
);
|
|
124
|
-
const tunnelTimeout = RivetError.fromUnknown(
|
|
125
|
-
new RivetkitErrors.RivetError(
|
|
126
|
-
"guard",
|
|
127
|
-
"tunnel_message_timeout",
|
|
128
|
-
"tunnel message timeout",
|
|
129
|
-
),
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
assert.instanceOf(
|
|
133
|
-
serviceUnavailable.reason,
|
|
134
|
-
RivetError.GuardServiceUnavailable,
|
|
135
|
-
);
|
|
136
|
-
assert.instanceOf(
|
|
137
|
-
readyTimeout.reason,
|
|
138
|
-
RivetError.GuardActorReadyTimeout,
|
|
139
|
-
);
|
|
140
|
-
assert.instanceOf(
|
|
141
|
-
tunnelTimeout.reason,
|
|
142
|
-
RivetError.GuardTunnelMessageTimeout,
|
|
143
|
-
);
|
|
144
|
-
assert.strictEqual(
|
|
145
|
-
serviceUnavailable.reason.code,
|
|
146
|
-
"service_unavailable",
|
|
147
|
-
);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it("keeps unknown guard errors in UnknownError", () => {
|
|
151
|
-
const error = RivetError.fromUnknown(
|
|
152
|
-
new RivetkitErrors.RivetError(
|
|
153
|
-
"guard",
|
|
154
|
-
"new_guard_code",
|
|
155
|
-
"new guard code",
|
|
156
|
-
),
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
assert.instanceOf(error.reason, RivetError.UnknownError);
|
|
160
|
-
assert.strictEqual(error.reason.code, "new_guard_code");
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("exposes action error decode failures with decode context", () => {
|
|
164
|
-
const cause = new RivetkitErrors.RivetError(
|
|
165
|
-
"user",
|
|
166
|
-
"CounterOverflow",
|
|
167
|
-
"counter overflow",
|
|
168
|
-
{ metadata: { _tag: "EffectActionError", version: 1, error: {} } },
|
|
169
|
-
);
|
|
170
|
-
const schemaError = Effect.runSync(
|
|
171
|
-
Schema.decodeUnknownEffect(Schema.String)(123).pipe(Effect.flip),
|
|
172
|
-
);
|
|
173
|
-
const error = new RivetError.RivetError({
|
|
174
|
-
reason: new RivetError.ActionErrorDecodeFailed({
|
|
175
|
-
cause: schemaError,
|
|
176
|
-
rivetError: cause,
|
|
177
|
-
}),
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
assert.instanceOf(error.reason, RivetError.ActionErrorDecodeFailed);
|
|
181
|
-
assert.strictEqual(error.reason.cause, schemaError);
|
|
182
|
-
assert.strictEqual(error.reason.rivetError, cause);
|
|
183
|
-
assert.strictEqual(
|
|
184
|
-
error.reason.message,
|
|
185
|
-
"Failed to decode action error user.CounterOverflow",
|
|
186
|
-
);
|
|
187
|
-
});
|
|
188
|
-
});
|