@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, 04:45 UTC

main
ts 114 lines 4.48 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { EventIntegration } from "@alchemy.run/aws/AppIntegrations";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as appintegrations from "@distilled.cloud/aws/appintegrations";
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 // Ungated typed-error probe: prove the distilled error union carries the
12 // not-found tag this provider's read/delete paths depend on.
13 test.provider(
14 "getEventIntegration on a nonexistent name fails with ResourceNotFoundException",
15 () =>
16 Effect.gen(function* () {
17 const error = yield* Effect.flip(
18 appintegrations.getEventIntegration({
19 Name: "alchemy-nonexistent-event-integration-probe",
20 }),
21 );
22 expect(error._tag).toBe("ResourceNotFoundException");
23 }),
24 { tags: ["provider:aws", "provider:aws:appintegrations", "live"] },
25 );
26
27 const assertGone = (name: string) =>
28 appintegrations.getEventIntegration({ Name: name }).pipe(
29 Effect.flatMap(() => Effect.fail(new Error(`event integration '${name}' still exists`))),
30 Effect.catchTag("ResourceNotFoundException", () => Effect.void),
31 Effect.retry({
32 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]),
33 }),
34 );
35
36 test.provider(
37 "create, update description, replace on source change, delete an event integration",
38 (stack) =>
39 Effect.gen(function* () {
40 yield* stack.destroy();
41
42 const { integration } = yield* stack.deploy(
43 Effect.gen(function* () {
44 const integration = yield* EventIntegration("PartnerEvents", {
45 source: "aws.partner/examplepartner.com",
46 eventBridgeBus: "default",
47 description: "alchemy event integration",
48 tags: { purpose: "alchemy-test" },
49 });
50 return { integration };
51 }),
52 );
53
54 expect(integration.eventIntegrationName).toBeDefined();
55 expect(integration.eventIntegrationArn).toContain(":event-integration/");
56 expect(integration.eventBridgeBus).toBe("default");
57 expect(integration.source).toBe("aws.partner/examplepartner.com");
58
59 // Out-of-band verification via distilled.
60 const observed = yield* appintegrations.getEventIntegration({
61 Name: integration.eventIntegrationName,
62 });
63 expect(observed.Description).toBe("alchemy event integration");
64 expect(observed.EventBridgeBus).toBe("default");
65 expect(observed.EventFilter?.Source).toBe("aws.partner/examplepartner.com");
66 expect(observed.Tags?.purpose).toBe("alchemy-test");
67
68 // Update the description in place (name/arn stable).
69 const { integration: updated } = yield* stack.deploy(
70 Effect.gen(function* () {
71 const integration = yield* EventIntegration("PartnerEvents", {
72 source: "aws.partner/examplepartner.com",
73 eventBridgeBus: "default",
74 description: "alchemy event integration v2",
75 tags: { purpose: "alchemy-test", phase: "two" },
76 });
77 return { integration };
78 }),
79 );
80 expect(updated.eventIntegrationName).toBe(integration.eventIntegrationName);
81 expect(updated.eventIntegrationArn).toBe(integration.eventIntegrationArn);
82
83 const reobserved = yield* appintegrations.getEventIntegration({
84 Name: integration.eventIntegrationName,
85 });
86 expect(reobserved.Description).toBe("alchemy event integration v2");
87 expect(reobserved.Tags?.phase).toBe("two");
88
89 // Changing the source replaces the event integration (new physical
90 // name via a fresh instance id).
91 const { integration: replaced } = yield* stack.deploy(
92 Effect.gen(function* () {
93 const integration = yield* EventIntegration("PartnerEvents", {
94 source: "aws.partner/otherpartner.com",
95 eventBridgeBus: "default",
96 description: "alchemy event integration v2",
97 });
98 return { integration };
99 }),
100 );
101 expect(replaced.source).toBe("aws.partner/otherpartner.com");
102 expect(replaced.eventIntegrationName).not.toBe(integration.eventIntegrationName);
103
104 // The replaced (old) integration is deleted.
105 yield* assertGone(integration.eventIntegrationName);
106
107 yield* stack.destroy();
108 yield* assertGone(replaced.eventIntegrationName);
109 }),
110 {
111 tags: ["provider:aws", "provider:aws:appintegrations", "live"],
112 timeout: 240_000,
113 },
114 );