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 EksTestFunctionLive, { EksTestFunction } from "./handler.ts"; |
| 9 | |
| 10 | const testOptions = { providers: AWS.providers() }; |
| 11 | const { test, beforeAll, afterAll } = Test.make(testOptions); |
| 12 | const sharedStack = Core.scratchStack(testOptions, "EksBindings"); |
| 13 | |
| 14 | // Lambda function URL cold-start (DNS, IAM propagation, init) can take well |
| 15 | // over 60s on a fresh deploy. |
| 16 | const readinessPolicy = Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(75)]); |
| 17 | |
| 18 | let baseUrl: string; |
| 19 | |
| 20 | const getJson = (path: string) => |
| 21 | HttpClient.get(`${baseUrl}${path}`).pipe( |
| 22 | Effect.flatMap((response) => |
| 23 | response.status >= 500 |
| 24 | ? Effect.fail(new Error(`transient ${response.status}`)) |
| 25 | : Effect.succeed(response), |
| 26 | ), |
| 27 | // The fixture occasionally answers a transient 5xx under load (cold |
| 28 | // re-init, IAM propagation on the freshly attached policy). Bounded retry. |
| 29 | Effect.retry({ |
| 30 | schedule: Schedule.max([Schedule.exponential("500 millis"), Schedule.recurs(6)]), |
| 31 | }), |
| 32 | Effect.flatMap((response) => response.json), |
| 33 | ); |
| 34 | |
| 35 | // The account-scoped EKS bindings need no cluster: ListClusters, |
| 36 | // ListAccessPolicies, DescribeClusterVersions, DescribeAddonVersions, and |
| 37 | // DescribeAddonConfiguration all answer against the account/region and the |
| 38 | // AWS-managed catalogs. The cluster-scoped bindings are exercised by the |
| 39 | // env-gated ClusterBindings.test.ts (an EKS control plane takes ~10+ minutes |
| 40 | // to provision — far beyond the routine test budget). |
| 41 | describe.sequential( |
| 42 | "EKS Bindings", |
| 43 | { tags: ["provider:aws", "provider:aws:eks", "provider:aws:lambda", "live"] }, |
| 44 | () => { |
| 45 | beforeAll( |
| 46 | Effect.gen(function* () { |
| 47 | yield* Effect.logInfo("EKS test setup: destroying previous resources"); |
| 48 | yield* sharedStack.destroy(); |
| 49 | |
| 50 | yield* Effect.logInfo("EKS test setup: deploying fixture"); |
| 51 | const attrs = yield* sharedStack.deploy( |
| 52 | Effect.gen(function* () { |
| 53 | return yield* EksTestFunction; |
| 54 | }).pipe(Effect.provide(EksTestFunctionLive)), |
| 55 | ); |
| 56 | |
| 57 | expect(attrs.functionUrl).toBeTruthy(); |
| 58 | baseUrl = attrs.functionUrl!.replace(/\/+$/, ""); |
| 59 | |
| 60 | const readinessUrl = `${baseUrl}/bindings`; |
| 61 | yield* Effect.logInfo(`EKS test setup: probing readiness at ${readinessUrl}`); |
| 62 | yield* HttpClient.get(readinessUrl).pipe( |
| 63 | Effect.flatMap((response) => |
| 64 | response.status === 200 |
| 65 | ? Effect.succeed(response) |
| 66 | : Effect.fail(new Error(`Function not ready: ${response.status}`)), |
| 67 | ), |
| 68 | Effect.tapError((error) => |
| 69 | Effect.logWarning(`EKS test setup: fixture not ready yet (${String(error)})`), |
| 70 | ), |
| 71 | Effect.retry({ schedule: readinessPolicy }), |
| 72 | ); |
| 73 | }), |
| 74 | { timeout: 240_000 }, |
| 75 | ); |
| 76 | |
| 77 | afterAll( |
| 78 | Effect.gen(function* () { |
| 79 | yield* sharedStack.destroy(); |
| 80 | }), |
| 81 | { timeout: 120_000 }, |
| 82 | ); |
| 83 | |
| 84 | describe("binding registration", () => { |
| 85 | test.provider("all 5 capabilities initialize in the runtime", (_stack) => |
| 86 | Effect.gen(function* () { |
| 87 | const response = (yield* getJson("/bindings")) as { bound: string[] }; |
| 88 | expect(response.bound).toHaveLength(5); |
| 89 | expect(response.bound).toContain("listClusters"); |
| 90 | expect(response.bound).toContain("describeAddonConfiguration"); |
| 91 | }), |
| 92 | ); |
| 93 | }); |
| 94 | |
| 95 | describe("ListClusters", () => { |
| 96 | test.provider("enumerates the account's clusters", (_stack) => |
| 97 | Effect.gen(function* () { |
| 98 | const response = (yield* getJson("/clusters")) as { count: number }; |
| 99 | expect(typeof response.count).toBe("number"); |
| 100 | expect(response.count).toBeGreaterThanOrEqual(0); |
| 101 | }), |
| 102 | ); |
| 103 | }); |
| 104 | |
| 105 | describe("ListAccessPolicies", () => { |
| 106 | test.provider("returns the AWS-managed access policy catalog", (_stack) => |
| 107 | Effect.gen(function* () { |
| 108 | const response = (yield* getJson("/access-policies")) as { |
| 109 | count: number; |
| 110 | names: string[]; |
| 111 | }; |
| 112 | // AWS ships a standing set of managed policies |
| 113 | // (AmazonEKSAdminPolicy, AmazonEKSViewPolicy, …). |
| 114 | expect(response.count).toBeGreaterThan(0); |
| 115 | expect(response.names).toContain("AmazonEKSViewPolicy"); |
| 116 | }), |
| 117 | ); |
| 118 | }); |
| 119 | |
| 120 | describe("DescribeClusterVersions", () => { |
| 121 | test.provider("reports a default Kubernetes version", (_stack) => |
| 122 | Effect.gen(function* () { |
| 123 | const response = (yield* getJson("/cluster-versions")) as { |
| 124 | count: number; |
| 125 | defaultVersion?: string; |
| 126 | }; |
| 127 | expect(response.count).toBeGreaterThan(0); |
| 128 | expect(response.defaultVersion).toMatch(/^\d+\.\d+$/); |
| 129 | }), |
| 130 | ); |
| 131 | }); |
| 132 | |
| 133 | describe("DescribeAddonVersions", () => { |
| 134 | test.provider("finds the vpc-cni add-on in the catalog", (_stack) => |
| 135 | Effect.gen(function* () { |
| 136 | const response = (yield* getJson("/addon-versions")) as { |
| 137 | count: number; |
| 138 | addonName?: string; |
| 139 | }; |
| 140 | expect(response.count).toBe(1); |
| 141 | expect(response.addonName).toBe("vpc-cni"); |
| 142 | }), |
| 143 | ); |
| 144 | }); |
| 145 | |
| 146 | describe("DescribeAddonConfiguration", () => { |
| 147 | test.provider("reads the configuration schema for a live vpc-cni version", (_stack) => |
| 148 | Effect.gen(function* () { |
| 149 | const response = (yield* getJson("/addon-schema")) as { |
| 150 | addonVersion?: string; |
| 151 | hasSchema?: boolean; |
| 152 | }; |
| 153 | expect(response.addonVersion).toBeTruthy(); |
| 154 | expect(response.hasSchema).toBe(true); |
| 155 | }), |
| 156 | ); |
| 157 | }); |
| 158 | }, |
| 159 | ); |