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
| 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 * as Effect from "effect/Effect"; |
| 6 | import * as HttpClient from "effect/http/HttpClient"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import MemoryDBBindingsTestFunctionLive, { |
| 9 | MemoryDBBindingsTestFunction, |
| 10 | } from "./bindings-handler.ts"; |
| 11 | |
| 12 | const testOptions = { providers: AWS.providers() }; |
| 13 | const { test, beforeAll, afterAll } = Test.make(testOptions); |
| 14 | const sharedStack = Core.scratchStack(testOptions, "MemoryDBBindings"); |
| 15 | |
| 16 | const NONEXISTENT_NAME = "alchemy-memorydb-nonexistent-probe"; |
| 17 | |
| 18 | // Lambda function URL cold-start (DNS, IAM propagation, init) can take well |
| 19 | // over 60s on a fresh deploy. |
| 20 | const readinessPolicy = Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(75)]); |
| 21 | |
| 22 | let baseUrl: string; |
| 23 | |
| 24 | const getJson = (path: string) => |
| 25 | HttpClient.get(`${baseUrl}${path}`).pipe( |
| 26 | Effect.flatMap((response) => |
| 27 | response.status >= 500 |
| 28 | ? Effect.fail(new Error(`transient upstream ${response.status}`)) |
| 29 | : Effect.succeed(response), |
| 30 | ), |
| 31 | Effect.retry({ |
| 32 | schedule: Schedule.max([Schedule.exponential("500 millis"), Schedule.recurs(6)]), |
| 33 | }), |
| 34 | Effect.flatMap((r) => r.json), |
| 35 | ); |
| 36 | |
| 37 | describe.sequential( |
| 38 | "MemoryDB Bindings", |
| 39 | { |
| 40 | tags: [ |
| 41 | "provider:aws", |
| 42 | "provider:aws:batch", |
| 43 | "provider:aws:lambda", |
| 44 | "provider:aws:memorydb", |
| 45 | "live", |
| 46 | ], |
| 47 | }, |
| 48 | () => { |
| 49 | beforeAll( |
| 50 | Effect.gen(function* () { |
| 51 | yield* Effect.logInfo("MemoryDB bindings setup: destroying previous resources"); |
| 52 | yield* sharedStack.destroy(); |
| 53 | |
| 54 | yield* Effect.logInfo("MemoryDB bindings setup: deploying fixture"); |
| 55 | const attrs = yield* sharedStack.deploy( |
| 56 | Effect.gen(function* () { |
| 57 | return yield* MemoryDBBindingsTestFunction; |
| 58 | }).pipe(Effect.provide(MemoryDBBindingsTestFunctionLive)), |
| 59 | ); |
| 60 | |
| 61 | expect(attrs.functionUrl).toBeTruthy(); |
| 62 | baseUrl = attrs.functionUrl!.replace(/\/+$/, ""); |
| 63 | |
| 64 | const readinessUrl = `${baseUrl}/bindings`; |
| 65 | yield* HttpClient.get(readinessUrl).pipe( |
| 66 | Effect.flatMap((response) => |
| 67 | response.status === 200 |
| 68 | ? Effect.succeed(response) |
| 69 | : Effect.fail(new Error(`Function not ready: ${response.status}`)), |
| 70 | ), |
| 71 | Effect.retry({ schedule: readinessPolicy }), |
| 72 | ); |
| 73 | }), |
| 74 | { timeout: 240_000 }, |
| 75 | ); |
| 76 | |
| 77 | afterAll(sharedStack.destroy(), { timeout: 120_000 }); |
| 78 | |
| 79 | describe("binding registration", () => { |
| 80 | test.provider("all eight capabilities initialize in the runtime", () => |
| 81 | Effect.gen(function* () { |
| 82 | const response = yield* getJson("/bindings"); |
| 83 | expect((response as any).bound).toHaveLength(8); |
| 84 | }), |
| 85 | ); |
| 86 | }); |
| 87 | |
| 88 | describe("DescribeClusters", () => { |
| 89 | test.provider("lists the account's clusters", () => |
| 90 | Effect.gen(function* () { |
| 91 | const response = yield* getJson("/clusters"); |
| 92 | expect((response as any).count).toBeGreaterThanOrEqual(0); |
| 93 | }), |
| 94 | ); |
| 95 | |
| 96 | test.provider("surfaces the typed not-found tag", () => |
| 97 | Effect.gen(function* () { |
| 98 | const response = yield* getJson(`/cluster-probe?name=${NONEXISTENT_NAME}`); |
| 99 | expect((response as any).tag).toBe("ClusterNotFoundFault"); |
| 100 | }), |
| 101 | ); |
| 102 | }); |
| 103 | |
| 104 | describe("DescribeSnapshots", () => { |
| 105 | test.provider("lists the account's snapshots", () => |
| 106 | Effect.gen(function* () { |
| 107 | const response = yield* getJson("/snapshots"); |
| 108 | expect((response as any).count).toBeGreaterThanOrEqual(0); |
| 109 | }), |
| 110 | ); |
| 111 | }); |
| 112 | |
| 113 | describe("DescribeEvents", () => { |
| 114 | test.provider("lists recent cluster events", () => |
| 115 | Effect.gen(function* () { |
| 116 | const response = yield* getJson("/events"); |
| 117 | expect((response as any).count).toBeGreaterThanOrEqual(0); |
| 118 | }), |
| 119 | ); |
| 120 | }); |
| 121 | |
| 122 | describe("DescribeServiceUpdates", () => { |
| 123 | test.provider("lists the account's service updates", () => |
| 124 | Effect.gen(function* () { |
| 125 | const response = yield* getJson("/service-updates"); |
| 126 | expect((response as any).count).toBeGreaterThanOrEqual(0); |
| 127 | }), |
| 128 | ); |
| 129 | }); |
| 130 | |
| 131 | describe("DescribeEngineVersions", () => { |
| 132 | test.provider("lists supported valkey engine versions", () => |
| 133 | Effect.gen(function* () { |
| 134 | const response = yield* getJson("/engine-versions"); |
| 135 | expect((response as any).count).toBeGreaterThanOrEqual(1); |
| 136 | }), |
| 137 | ); |
| 138 | }); |
| 139 | |
| 140 | describe("BatchUpdateCluster", () => { |
| 141 | test.provider("rejects a nonexistent cluster with a typed outcome", () => |
| 142 | Effect.gen(function* () { |
| 143 | const response = yield* getJson(`/batch-probe?name=${NONEXISTENT_NAME}`); |
| 144 | const { unprocessed, tag } = response as { unprocessed: number; tag: string }; |
| 145 | // Either the cluster comes back unprocessed or the call is rejected |
| 146 | // with a typed tag — an IAM gap would have 500'd the route instead. |
| 147 | // Observed live: ServiceUpdateNotFoundFault ("Service Update ... |
| 148 | // not found"). |
| 149 | expect( |
| 150 | unprocessed >= 1 || |
| 151 | [ |
| 152 | "ServiceUpdateNotFoundFault", |
| 153 | "InvalidParameterCombinationException", |
| 154 | "InvalidParameterValueException", |
| 155 | ].includes(tag), |
| 156 | ).toBe(true); |
| 157 | }), |
| 158 | ); |
| 159 | }); |
| 160 | |
| 161 | describe("DeleteSnapshot", () => { |
| 162 | test.provider("surfaces the typed not-found tag", () => |
| 163 | Effect.gen(function* () { |
| 164 | const response = yield* getJson(`/delete-probe?name=${NONEXISTENT_NAME}`); |
| 165 | // ServiceLinkedRoleNotFoundFault: MemoryDB validates the SLR before |
| 166 | // snapshot existence in accounts that never kept a cluster. |
| 167 | expect(["SnapshotNotFoundFault", "ServiceLinkedRoleNotFoundFault"]).toContain( |
| 168 | (response as any).tag, |
| 169 | ); |
| 170 | }), |
| 171 | ); |
| 172 | }); |
| 173 | |
| 174 | describe("CopySnapshot", () => { |
| 175 | test.provider("rejects a nonexistent source snapshot with a typed tag", () => |
| 176 | Effect.gen(function* () { |
| 177 | const response = yield* getJson(`/copy-probe?name=${NONEXISTENT_NAME}`); |
| 178 | expect([ |
| 179 | "SnapshotNotFoundFault", |
| 180 | "InvalidParameterValueException", |
| 181 | "ServiceLinkedRoleNotFoundFault", |
| 182 | ]).toContain((response as any).tag); |
| 183 | }), |
| 184 | ); |
| 185 | }); |
| 186 | }, |
| 187 | ); |