@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 167 lines 6.21 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { describe, expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as Core from "@alchemy.run/test/Core";
5 import { Region } from "@distilled.cloud/aws/Region";
6 import * as sts from "@distilled.cloud/aws/sts";
7 import * as Effect from "effect/Effect";
8 import * as HttpClient from "effect/http/HttpClient";
9 import * as Schedule from "effect/Schedule";
10 import NeptuneBindingsTestFunctionLive, { NeptuneBindingsTestFunction } from "./fixtures/handler";
11
12 const testOptions = { providers: AWS.providers() };
13 const { test, beforeAll, afterAll } = Test.make(testOptions);
14 const sharedStack = Core.scratchStack(testOptions, "NeptuneBindings");
15
16 // Lambda function URL cold-start (DNS, IAM propagation, init) can take well
17 // over 60s on a fresh deploy.
18 const readinessPolicy = Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(75)]);
19
20 let baseUrl: string;
21
22 const getJson = (path: string) =>
23 HttpClient.get(`${baseUrl}${path}`).pipe(
24 Effect.flatMap((response) =>
25 response.status >= 500
26 ? Effect.fail(new Error(`transient upstream ${response.status}`))
27 : Effect.succeed(response),
28 ),
29 Effect.retry({
30 schedule: Schedule.max([Schedule.exponential("500 millis"), Schedule.recurs(6)]),
31 }),
32 Effect.flatMap((r) => r.json),
33 );
34
35 describe.sequential(
36 "Neptune Bindings",
37 { tags: ["provider:aws", "provider:aws:lambda", "provider:aws:neptune", "live"] },
38 () => {
39 beforeAll(
40 Effect.gen(function* () {
41 yield* Effect.logInfo("Neptune test setup: destroying previous resources");
42 yield* sharedStack.destroy();
43
44 yield* Effect.logInfo("Neptune test setup: deploying fixture");
45 const { functionUrl } = yield* sharedStack.deploy(
46 Effect.gen(function* () {
47 return yield* NeptuneBindingsTestFunction;
48 }).pipe(Effect.provide(NeptuneBindingsTestFunctionLive)),
49 );
50
51 expect(functionUrl).toBeTruthy();
52 baseUrl = functionUrl!.replace(/\/+$/, "");
53
54 const readinessUrl = `${baseUrl}/bindings`;
55 yield* HttpClient.get(readinessUrl).pipe(
56 Effect.flatMap((response) =>
57 response.status === 200
58 ? Effect.succeed(response)
59 : Effect.fail(new Error(`Function not ready: ${response.status}`)),
60 ),
61 Effect.retry({ schedule: readinessPolicy }),
62 );
63 }),
64 { timeout: 240_000 },
65 );
66
67 afterAll(sharedStack.destroy(), { timeout: 120_000 });
68
69 describe("binding registration", () => {
70 test.provider("all capabilities initialize in the runtime", (_stack) =>
71 Effect.gen(function* () {
72 const response = yield* getJson("/bindings");
73 expect((response as any).bound).toHaveLength(9);
74 }),
75 );
76 });
77
78 describe("DescribeDBClusters", () => {
79 test.provider("surfaces the typed not-found tag for a nonexistent cluster", (_stack) =>
80 Effect.gen(function* () {
81 const response = yield* getJson("/clusters");
82 expect((response as any).tag).toBe("DBClusterNotFoundFault");
83 }),
84 );
85 });
86
87 describe("DescribeDBInstances", () => {
88 test.provider("surfaces the typed not-found tag for a nonexistent instance", (_stack) =>
89 Effect.gen(function* () {
90 const response = yield* getJson("/instances");
91 expect((response as any).tag).toBe("DBInstanceNotFoundFault");
92 }),
93 );
94 });
95
96 describe("DescribeEvents", () => {
97 test.provider("lists the account's recent Neptune events", (_stack) =>
98 Effect.gen(function* () {
99 const response = yield* getJson("/events");
100 expect((response as any).count).toBeGreaterThanOrEqual(0);
101 }),
102 );
103 });
104
105 describe("DescribeDBClusterSnapshots", () => {
106 test.provider("lists the account's cluster snapshots", (_stack) =>
107 Effect.gen(function* () {
108 const response = yield* getJson("/snapshots");
109 expect((response as any).count).toBeGreaterThanOrEqual(0);
110 }),
111 );
112 });
113
114 describe("DescribeDBClusterEndpoints", () => {
115 test.provider("lists the account's cluster endpoints", (_stack) =>
116 Effect.gen(function* () {
117 const response = yield* getJson("/endpoints");
118 expect((response as any).count).toBeGreaterThanOrEqual(0);
119 }),
120 );
121 });
122
123 describe("DeleteDBClusterSnapshot", () => {
124 test.provider("surfaces the typed not-found tag for a nonexistent snapshot", (_stack) =>
125 Effect.gen(function* () {
126 const response = yield* getJson("/delete-snapshot-probe");
127 expect((response as any).tag).toBe("DBClusterSnapshotNotFoundFault");
128 }),
129 );
130 });
131
132 describe("CopyDBClusterSnapshot", () => {
133 test.provider(
134 "surfaces the typed not-found tag for a nonexistent source snapshot",
135 (_stack) =>
136 Effect.gen(function* () {
137 const response = yield* getJson("/copy-snapshot-probe");
138 expect((response as any).tag).toBe("DBClusterSnapshotNotFoundFault");
139 }),
140 );
141 });
142
143 describe("DescribePendingMaintenanceActions", () => {
144 test.provider("lists the account's pending maintenance actions", (_stack) =>
145 Effect.gen(function* () {
146 const response = yield* getJson("/pending-maintenance");
147 expect((response as any).count).toBeGreaterThanOrEqual(0);
148 }),
149 );
150 });
151
152 describe("ApplyPendingMaintenanceAction", () => {
153 test.provider("surfaces the typed not-found tag for a nonexistent resource ARN", (_stack) =>
154 Effect.gen(function* () {
155 // Build a well-formed cluster ARN in this account/region that
156 // cannot exist — the apply call must decode ResourceNotFoundFault.
157 // (`Region`'s service value is itself an Effect — resolve twice.)
158 const region = yield* yield* Region;
159 const identity = yield* sts.getCallerIdentity({});
160 const arn = `arn:aws:rds:${region}:${identity.Account}:cluster:alchemy-nonexistent-neptune-probe`;
161 const response = yield* getJson(`/apply-probe?arn=${encodeURIComponent(arn)}`);
162 expect((response as any).tag).toBe("ResourceNotFoundFault");
163 }),
164 );
165 });
166 },
167 );