@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 79 lines 2.93 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { TopicRule } from "@alchemy.run/aws/IoT";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as iot from "@distilled.cloud/aws/iot";
6 import * as Effect from "effect/Effect";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 // A syntactically valid Lambda ARN for a function that need not exist —
12 // createTopicRule validates the ARN shape, not existence.
13 const FAKE_LAMBDA_ARN = "arn:aws:lambda:us-west-2:391965393224:function:alchemy-iot-topicrule-test";
14
15 const assertRuleGone = (ruleName: string) =>
16 iot.getTopicRule({ ruleName }).pipe(
17 Effect.flatMap(() => Effect.fail(new Error(`topic rule ${ruleName} still exists`))),
18 Effect.catchTag("TopicRuleNotFound", () => Effect.void),
19 Effect.retry({
20 while: (e) => e instanceof Error,
21 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]),
22 }),
23 );
24
25 describe.sequential(
26 "AWS.IoT.TopicRule",
27 { tags: ["provider:aws", "provider:aws:iot", "live"] },
28 () => {
29 test.provider(
30 "creates, updates the SQL in place, and deletes a topic rule",
31 (stack) =>
32 Effect.gen(function* () {
33 yield* stack.destroy();
34
35 const created = yield* stack.deploy(
36 Effect.gen(function* () {
37 const rule = yield* TopicRule("Rule", {
38 sql: "SELECT * FROM 'alchemy/iot/test/v1'",
39 actions: [{ lambda: { functionArn: FAKE_LAMBDA_ARN } }],
40 });
41 return { ruleName: rule.ruleName, ruleArn: rule.ruleArn };
42 }),
43 );
44
45 // Verify out-of-band.
46 const observed = yield* iot.getTopicRule({ ruleName: created.ruleName });
47 expect(observed.rule?.sql).toEqual("SELECT * FROM 'alchemy/iot/test/v1'");
48
49 // Update the SQL — same name, so this is an in-place replaceTopicRule.
50 yield* stack.deploy(
51 Effect.gen(function* () {
52 yield* TopicRule("Rule", {
53 sql: "SELECT temperature FROM 'alchemy/iot/test/v2'",
54 actions: [{ lambda: { functionArn: FAKE_LAMBDA_ARN } }],
55 });
56 }),
57 );
58 const updated = yield* iot.getTopicRule({ ruleName: created.ruleName });
59 expect(updated.rule?.sql).toEqual("SELECT temperature FROM 'alchemy/iot/test/v2'");
60
61 yield* stack.destroy();
62 yield* assertRuleGone(created.ruleName);
63 }),
64 { timeout: 180_000 },
65 );
66
67 test.provider(
68 "getTopicRule on a missing rule surfaces the typed TopicRuleNotFound tag",
69 () =>
70 Effect.gen(function* () {
71 const result = yield* iot
72 .getTopicRule({ ruleName: "alchemy_definitely_missing_rule_xyz" })
73 .pipe(Effect.flip);
74 expect(result._tag).toEqual("TopicRuleNotFound");
75 }),
76 { timeout: 60_000 },
77 );
78 },
79 );