The best way to control Claude Code, Codex and more from any computer or phone

main
ts 44 lines 1.71 KB
Raw
1 import { toConsumerSettings } from "@alchemy.run/cloudflare/Queues/EventSource";
2 import { describe, expect, it } from "@alchemy.run/test";
3 import * as Duration from "effect/Duration";
4
5 describe(
6 "toConsumerSettings",
7 { tags: ["unit", "provider:cloudflare", "provider:cloudflare:queue", "local"] },
8 () => {
9 it("passes scalar fields through unchanged", () => {
10 expect(toConsumerSettings({ batchSize: 25, maxConcurrency: 4, maxRetries: 3 })).toEqual({
11 batchSize: 25,
12 maxConcurrency: 4,
13 maxRetries: 3,
14 maxWaitTimeMs: undefined,
15 retryDelay: undefined,
16 });
17 });
18
19 it("converts maxWaitTime to whole milliseconds", () => {
20 expect(toConsumerSettings({ maxWaitTime: Duration.seconds(5) }).maxWaitTimeMs).toBe(5_000);
21 expect(toConsumerSettings({ maxWaitTime: "250 millis" }).maxWaitTimeMs).toBe(250);
22 expect(toConsumerSettings({ maxWaitTime: 1500 }).maxWaitTimeMs).toBe(1500);
23 });
24
25 it("rounds sub-millisecond maxWaitTime up", () => {
26 expect(toConsumerSettings({ maxWaitTime: Duration.nanos(1n) }).maxWaitTimeMs).toBe(1);
27 });
28
29 it("converts retryDelay to whole seconds", () => {
30 expect(toConsumerSettings({ retryDelay: Duration.minutes(2) }).retryDelay).toBe(120);
31 expect(toConsumerSettings({ retryDelay: "30 seconds" }).retryDelay).toBe(30);
32 });
33
34 it("rounds partial-second retryDelay up", () => {
35 expect(toConsumerSettings({ retryDelay: Duration.millis(1500) }).retryDelay).toBe(2);
36 });
37
38 it("leaves missing time fields undefined", () => {
39 const result = toConsumerSettings({ batchSize: 10 });
40 expect(result.maxWaitTimeMs).toBeUndefined();
41 expect(result.retryDelay).toBeUndefined();
42 });
43 },
44 );