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

main
ts 48 lines 1.72 KB
Raw
1 import { toTimeoutSeconds } from "@alchemy.run/aws/Lambda/Function";
2 import { describe, expect, it } from "@alchemy.run/test";
3 import * as Duration from "effect/Duration";
4
5 describe(
6 "toTimeoutSeconds",
7 { tags: ["unit", "provider:aws", "provider:aws:lambda", "local"] },
8 () => {
9 it("returns undefined for undefined", () => {
10 expect(toTimeoutSeconds(undefined)).toBeUndefined();
11 });
12
13 it("converts a Duration to whole seconds", () => {
14 expect(toTimeoutSeconds(Duration.seconds(30))).toBe(30);
15 expect(toTimeoutSeconds(Duration.minutes(2))).toBe(120);
16 });
17
18 it("rounds sub-second and partial durations up", () => {
19 expect(toTimeoutSeconds(Duration.millis(1))).toBe(1);
20 expect(toTimeoutSeconds(Duration.millis(1500))).toBe(2);
21 expect(toTimeoutSeconds(Duration.millis(2001))).toBe(3);
22 });
23
24 it("returns undefined for an infinite Duration", () => {
25 expect(toTimeoutSeconds(Duration.infinity)).toBeUndefined();
26 });
27
28 describe("after state JSON round-trip", () => {
29 const roundTrip = (d: Duration.Duration) =>
30 JSON.parse(JSON.stringify(d)) as Duration.Duration;
31
32 it("converts a rehydrated Millis Duration", () => {
33 const json = roundTrip(Duration.seconds(42));
34 expect(json).toEqual({ _id: "Duration", _tag: "Millis", millis: 42_000 });
35 expect(toTimeoutSeconds(json)).toBe(42);
36 });
37
38 it("converts a rehydrated Nanos Duration", () => {
39 const json = roundTrip(Duration.nanos(5_000_000_000n));
40 expect(toTimeoutSeconds(json)).toBe(5);
41 });
42
43 it("returns undefined for a rehydrated Infinity Duration", () => {
44 expect(toTimeoutSeconds(roundTrip(Duration.infinity))).toBeUndefined();
45 });
46 });
47 },
48 );