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 { 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 EKSClusterTestFunctionLive, { |
| 9 | EKSClusterTestFunction, |
| 10 | } from "./fixtures/cluster-bindings-handler.ts"; |
| 11 | |
| 12 | const testOptions = { providers: AWS.providers() }; |
| 13 | const { test } = Test.make(testOptions); |
| 14 | const slowStack = Core.scratchStack(testOptions, "EKSClusterBindings"); |
| 15 | |
| 16 | // The cluster-scoped bindings (DescribeCluster, the List*/Describe* |
| 17 | // sub-resource operations, insights, updates) need a real EKS control plane |
| 18 | // (~10 minutes to provision) — gated behind the same standing-infrastructure |
| 19 | // envs as Cluster.test.ts: a cluster IAM role (AWS_TEST_EKS_ROLE_ARN) and at |
| 20 | // least two subnets (AWS_TEST_EKS_SUBNET_IDS, comma-separated). An account |
| 21 | // with that standing infrastructure runs this unchanged. |
| 22 | test.provider.skipIf(!process.env.AWS_TEST_EKS_ROLE_ARN || !process.env.AWS_TEST_EKS_SUBNET_IDS)( |
| 23 | "cluster-scoped bindings against a live control plane", |
| 24 | () => |
| 25 | Effect.gen(function* () { |
| 26 | yield* slowStack.destroy(); |
| 27 | |
| 28 | yield* Effect.gen(function* () { |
| 29 | const { functionUrl } = yield* slowStack.deploy( |
| 30 | Effect.gen(function* () { |
| 31 | return yield* EKSClusterTestFunction; |
| 32 | }).pipe(Effect.provide(EKSClusterTestFunctionLive)), |
| 33 | ); |
| 34 | expect(functionUrl).toBeTruthy(); |
| 35 | const baseUrl = functionUrl!.replace(/\/+$/, ""); |
| 36 | |
| 37 | const get = (path: string) => |
| 38 | HttpClient.get(`${baseUrl}${path}`).pipe( |
| 39 | Effect.retry({ |
| 40 | schedule: Schedule.max([Schedule.exponential("500 millis"), Schedule.recurs(10)]), |
| 41 | }), |
| 42 | Effect.flatMap((r) => r.json), |
| 43 | ); |
| 44 | |
| 45 | const bindings = (yield* get("/bindings")) as { bound: string[] }; |
| 46 | expect(bindings.bound).toHaveLength(22); |
| 47 | |
| 48 | // DescribeCluster returns the live control-plane connection info. |
| 49 | const cluster = (yield* get("/cluster")) as { |
| 50 | status?: string; |
| 51 | endpointPresent: boolean; |
| 52 | caPresent: boolean; |
| 53 | }; |
| 54 | expect(cluster.status).toBe("ACTIVE"); |
| 55 | expect(cluster.endpointPresent).toBe(true); |
| 56 | expect(cluster.caPresent).toBe(true); |
| 57 | |
| 58 | // Every enumeration succeeds (a fresh control plane has no |
| 59 | // sub-resources) — proves each grant + cluster-name injection + |
| 60 | // response decode. |
| 61 | const lists = (yield* get("/lists")) as Record<string, number>; |
| 62 | for (const key of [ |
| 63 | "nodegroups", |
| 64 | "addons", |
| 65 | "fargateProfiles", |
| 66 | "podIdentityAssociations", |
| 67 | "accessEntries", |
| 68 | "insights", |
| 69 | "updates", |
| 70 | "capabilities", |
| 71 | "identityProviderConfigs", |
| 72 | ]) { |
| 73 | expect(lists[key]).toBeGreaterThanOrEqual(0); |
| 74 | } |
| 75 | |
| 76 | // Nonexistent sub-resources surface the services' typed tags — an |
| 77 | // IAM gap or a broken cluster-name injection would surface |
| 78 | // AccessDeniedException / an opaque 500 instead. |
| 79 | const probes = (yield* get("/probes")) as Record<string, string>; |
| 80 | expect(probes.nodegroupTag).toBe("ResourceNotFoundException"); |
| 81 | expect(probes.addonTag).toBe("ResourceNotFoundException"); |
| 82 | expect(probes.fargateProfileTag).toBe("ResourceNotFoundException"); |
| 83 | expect(["ResourceNotFoundException", "InvalidParameterException"]).toContain( |
| 84 | probes.podIdentityTag, |
| 85 | ); |
| 86 | expect(["ResourceNotFoundException", "InvalidRequestException"]).toContain( |
| 87 | probes.accessEntryTag, |
| 88 | ); |
| 89 | expect(["ResourceNotFoundException", "InvalidParameterException"]).toContain( |
| 90 | probes.updateTag, |
| 91 | ); |
| 92 | expect(["ResourceNotFoundException", "InvalidParameterException"]).toContain( |
| 93 | probes.insightTag, |
| 94 | ); |
| 95 | expect(["ResourceNotFoundException", "InvalidRequestException"]).toContain( |
| 96 | probes.associatedPoliciesTag, |
| 97 | ); |
| 98 | expect(["ResourceNotFoundException", "InvalidParameterException"]).toContain( |
| 99 | probes.capabilityTag, |
| 100 | ); |
| 101 | expect(["ResourceNotFoundException", "InvalidParameterException"]).toContain( |
| 102 | probes.identityProviderConfigTag, |
| 103 | ); |
| 104 | |
| 105 | // Insights refresh: kick an on-demand refresh and read its status |
| 106 | // back. A refresh already in flight surfaces the typed |
| 107 | // InvalidRequestException — either outcome proves both grants. |
| 108 | const refresh = (yield* get("/insights-refresh")) as { |
| 109 | startTag: string; |
| 110 | describeTag: string; |
| 111 | }; |
| 112 | expect(typeof refresh.startTag).toBe("string"); |
| 113 | expect(refresh.startTag.length).toBeGreaterThan(0); |
| 114 | expect(typeof refresh.describeTag).toBe("string"); |
| 115 | expect(refresh.describeTag.length).toBeGreaterThan(0); |
| 116 | }).pipe(Effect.ensuring(slowStack.destroy().pipe(Effect.orDie))); |
| 117 | }), |
| 118 | // cluster create (~10 min) + probes + delete (~10 min) in one test. |
| 119 | { |
| 120 | tags: ["provider:aws", "provider:aws:eks", "provider:aws:lambda", "live"], |
| 121 | timeout: 2_400_000, |
| 122 | }, |
| 123 | ); |