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 ElastiCache from "@distilled.cloud/aws/elasticache"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Schedule from "effect/Schedule"; |
| 7 | import { |
| 8 | assertReplicationGroupGone, |
| 9 | getProvisionedNetwork, |
| 10 | shareProvisionedNetwork, |
| 11 | } from "./ProvisionedFixture.ts"; |
| 12 | const { test, beforeAll, afterAll } = Test.make({ |
| 13 | providers: AWS.providers(), |
| 14 | }); |
| 15 | shareProvisionedNetwork({ beforeAll, afterAll }); |
| 16 | const waitForAvailable = (replicationGroupId: string) => |
| 17 | ElastiCache.describeReplicationGroups({ |
| 18 | ReplicationGroupId: replicationGroupId, |
| 19 | }).pipe( |
| 20 | Effect.flatMap((response) => |
| 21 | response.ReplicationGroups?.[0]?.Status === "available" |
| 22 | ? Effect.succeed(response.ReplicationGroups[0]) |
| 23 | : Effect.fail(new Error(`replication group '${replicationGroupId}' is not available`)), |
| 24 | ), |
| 25 | Effect.retry({ |
| 26 | schedule: Schedule.max([Schedule.fixed("15 seconds"), Schedule.recurs(60)]), |
| 27 | }), |
| 28 | ); |
| 29 | |
| 30 | test.provider.skipIf(!!process.env.FAST)( |
| 31 | "adds a Valkey replica online and enables high availability", |
| 32 | (stack) => |
| 33 | Effect.gen(function* () { |
| 34 | yield* stack.destroy(); |
| 35 | const deploy = (numNodeGroups: number, replicasPerNodeGroup: number) => |
| 36 | stack.deploy( |
| 37 | Effect.gen(function* () { |
| 38 | const net = yield* getProvisionedNetwork; |
| 39 | const cache = yield* AWS.ElastiCache.ReplicationGroup("Cache", { |
| 40 | description: "alchemy topology cache", |
| 41 | engine: "valkey", |
| 42 | nodeType: "cache.t4g.micro", |
| 43 | subnetGroupName: net.subnetGroupName, |
| 44 | securityGroupIds: [net.securityGroupId], |
| 45 | numNodeGroups, |
| 46 | replicasPerNodeGroup, |
| 47 | automaticFailoverEnabled: replicasPerNodeGroup > 0, |
| 48 | multiAzEnabled: replicasPerNodeGroup > 0, |
| 49 | transitEncryptionEnabled: true, |
| 50 | }); |
| 51 | return { cache }; |
| 52 | }), |
| 53 | ); |
| 54 | |
| 55 | const created = yield* deploy(1, 0); |
| 56 | const withReplica = yield* deploy(1, 1); |
| 57 | const replicaGroup = yield* waitForAvailable(withReplica.cache.replicationGroupId); |
| 58 | expect(replicaGroup.AutomaticFailover).toBe("enabled"); |
| 59 | expect(replicaGroup.MultiAZ).toBe("enabled"); |
| 60 | expect(replicaGroup.NodeGroups?.[0]?.NodeGroupMembers).toHaveLength(2); |
| 61 | |
| 62 | yield* stack.destroy(); |
| 63 | yield* assertReplicationGroupGone(created.cache.replicationGroupId); |
| 64 | }), |
| 65 | { |
| 66 | tags: ["provider:aws", "provider:aws:ec2", "provider:aws:elasticache", "live"], |
| 67 | timeout: 2_700_000, |
| 68 | }, |
| 69 | ); |
| 70 | |
| 71 | test.provider.skipIf(!!process.env.FAST)( |
| 72 | "scales shards online for a cluster-mode-enabled Valkey group", |
| 73 | (stack) => |
| 74 | Effect.gen(function* () { |
| 75 | yield* stack.destroy(); |
| 76 | const deploy = (numNodeGroups: number) => |
| 77 | stack.deploy( |
| 78 | Effect.gen(function* () { |
| 79 | const net = yield* getProvisionedNetwork; |
| 80 | const cache = yield* AWS.ElastiCache.ReplicationGroup("Cache", { |
| 81 | description: "alchemy shard topology cache", |
| 82 | engine: "valkey", |
| 83 | nodeType: "cache.t4g.micro", |
| 84 | subnetGroupName: net.subnetGroupName, |
| 85 | securityGroupIds: [net.securityGroupId], |
| 86 | numNodeGroups, |
| 87 | replicasPerNodeGroup: 0, |
| 88 | transitEncryptionEnabled: true, |
| 89 | }); |
| 90 | return { cache }; |
| 91 | }), |
| 92 | ); |
| 93 | |
| 94 | const created = yield* deploy(2); |
| 95 | const scaled = yield* deploy(3); |
| 96 | const group = yield* waitForAvailable(scaled.cache.replicationGroupId); |
| 97 | expect(group.NodeGroups).toHaveLength(3); |
| 98 | expect(group.NodeGroups?.every((shard) => shard.NodeGroupMembers?.length === 1)).toBe(true); |
| 99 | |
| 100 | yield* stack.destroy(); |
| 101 | yield* assertReplicationGroupGone(created.cache.replicationGroupId); |
| 102 | }), |
| 103 | { |
| 104 | tags: ["provider:aws", "provider:aws:ec2", "provider:aws:elasticache", "live"], |
| 105 | timeout: 2_700_000, |
| 106 | }, |
| 107 | ); |
| 108 | |
| 109 | test.provider.skipIf(!!process.env.FAST)( |
| 110 | "reconciles a highly available replication group", |
| 111 | (stack) => |
| 112 | Effect.gen(function* () { |
| 113 | yield* stack.destroy(); |
| 114 | const deploy = () => |
| 115 | stack.deploy( |
| 116 | Effect.gen(function* () { |
| 117 | const net = yield* getProvisionedNetwork; |
| 118 | const cache = yield* AWS.ElastiCache.ReplicationGroup("Cache", { |
| 119 | description: "alchemy failover cache", |
| 120 | engine: "valkey", |
| 121 | nodeType: "cache.t4g.micro", |
| 122 | subnetGroupName: net.subnetGroupName, |
| 123 | securityGroupIds: [net.securityGroupId], |
| 124 | replicasPerNodeGroup: 1, |
| 125 | automaticFailoverEnabled: true, |
| 126 | multiAzEnabled: true, |
| 127 | transitEncryptionEnabled: true, |
| 128 | }); |
| 129 | return { cache }; |
| 130 | }), |
| 131 | ); |
| 132 | |
| 133 | const { cache } = yield* deploy(); |
| 134 | |
| 135 | const before = yield* waitForAvailable(cache.replicationGroupId); |
| 136 | const nodeGroupId = before.NodeGroups?.[0]?.NodeGroupId; |
| 137 | if (!nodeGroupId) return yield* Effect.fail(new Error("replication group has no node group")); |
| 138 | yield* ElastiCache.testFailover({ |
| 139 | ReplicationGroupId: cache.replicationGroupId, |
| 140 | NodeGroupId: nodeGroupId, |
| 141 | }); |
| 142 | const reconciled = yield* deploy(); |
| 143 | expect(reconciled.cache.replicationGroupId).toBe(cache.replicationGroupId); |
| 144 | const after = yield* waitForAvailable(cache.replicationGroupId); |
| 145 | expect(after.AutomaticFailover).toBe("enabled"); |
| 146 | expect(after.MultiAZ).toBe("enabled"); |
| 147 | expect(after.NodeGroups?.[0]?.NodeGroupMembers).toHaveLength(2); |
| 148 | |
| 149 | yield* stack.destroy(); |
| 150 | yield* assertReplicationGroupGone(cache.replicationGroupId); |
| 151 | }), |
| 152 | { |
| 153 | tags: ["provider:aws", "provider:aws:ec2", "provider:aws:elasticache", "live"], |
| 154 | timeout: 2_700_000, |
| 155 | }, |
| 156 | ); |